Fix parser error that made it ignore the last line
This commit is contained in:
parent
fda22052b8
commit
e2bb39006a
@ -20,6 +20,7 @@ class InstructionSet
|
||||
|
||||
public function apply(Block $block): void
|
||||
{
|
||||
print("$block\n");
|
||||
$words = $block->words;
|
||||
while ($word = array_shift($words)) {
|
||||
$method = "{$word}";
|
||||
@ -32,7 +33,7 @@ class InstructionSet
|
||||
}
|
||||
|
||||
|
||||
public function G22(Block $block): void
|
||||
protected function G22(Block $block): void
|
||||
{
|
||||
$number = $block->valueOf('X');
|
||||
$this->machine->SPMC->loadProgram($number);
|
||||
|
@ -40,12 +40,10 @@ class Machine
|
||||
|
||||
public function step(): void
|
||||
{
|
||||
$block = $this->AMC->next();
|
||||
if (is_null($block) && $this->AMC === $this->SPMC) {
|
||||
// SP ended, back to PP
|
||||
if ($this->AMC === $this->SPMC && count($this->AMC) === 0) {
|
||||
$this->AMC = $this->PPMC;
|
||||
$block = $this->AMC->next();
|
||||
}
|
||||
$block = $this->AMC->next();
|
||||
$this->IS->apply($block);
|
||||
}
|
||||
|
||||
|
@ -61,7 +61,7 @@ class ProgramParser
|
||||
}
|
||||
$program = new Program($firstWord->value);
|
||||
$lineBuffer = null;
|
||||
foreach ($words as $word) {
|
||||
while ($word = array_shift($words)) {
|
||||
if ($word->register === 'N') {
|
||||
if (!is_null($lineBuffer)) {
|
||||
$program->addBlock($lineBuffer);
|
||||
@ -71,6 +71,9 @@ class ProgramParser
|
||||
}
|
||||
$lineBuffer->addWord($word);
|
||||
}
|
||||
if (!is_null($lineBuffer)) {
|
||||
$program->addBlock($lineBuffer);
|
||||
}
|
||||
|
||||
return $program;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user