Add some preparation for sub program execution

This commit is contained in:
Joop Schilder 2020-05-08 12:22:34 +02:00
parent e2b8f1d7aa
commit 96a4705cce
2 changed files with 24 additions and 11 deletions

View File

@ -9,6 +9,14 @@ use Program\Word;
use RuntimeException; use RuntimeException;
use SplStack; use SplStack;
/*
* executing a program:
* - load parts program
* - execute line by line
* - load sub program
* - execute lines from subprogram
* - back to parts program
*/
class Machine class Machine
{ {
public State $state; public State $state;
@ -47,19 +55,23 @@ class Machine
throw new RuntimeException('No program loaded'); throw new RuntimeException('No program loaded');
} }
foreach ($this->activeProgram as $block) { foreach ($this->activeProgram as $block) {
// Do we apply a block or a word? /** @var Word[] $words */
// Answer: depends! Some commands need $words = $block->words;
// more information from other words. while ($word = array_shift($words)) {
// TODO: Interpret commands such as preparation of a work cycle if ('G22' === $word->toString()) {
$identifier = array_shift($words);
$words = array_map(fn(Word $w) => $w->toString(), $block->words); if ($identifier->register !== 'X') {
$words = implode("\t", $words); throw new RuntimeException('Expected X9xxx after G22');
$words = "N{$block->N}\t$words"; }
$subProgram = $this->subProgramMemory->read($identifier->value);
foreach ($block->words as $word) { $this->programStack->push($subProgram);
system('clear');
dump($subProgram);
readline();
continue;
}
$this->state->apply($word); $this->state->apply($word);
system('clear'); system('clear');
print("\n $words\n\n");
dump($this->state); dump($this->state);
readline(); readline();
} }

View File

@ -52,6 +52,7 @@ class State
$this->workCycleSelection->apply($word->value); $this->workCycleSelection->apply($word->value);
// TODO Handle other G commands // TODO Handle other G commands
return; return;
} }
if ($word->register === 'M') { if ($word->register === 'M') {