42 lines
676 B
PHP
42 lines
676 B
PHP
|
<?php
|
||
|
|
||
|
namespace Automata;
|
||
|
|
||
|
use Program\Block;
|
||
|
|
||
|
class InstructionSet
|
||
|
{
|
||
|
private Machine $machine;
|
||
|
/** @var callable<Machine>[] */
|
||
|
private array $map;
|
||
|
|
||
|
|
||
|
public function __construct(Machine $machine)
|
||
|
{
|
||
|
$this->machine = $machine;
|
||
|
$this->map = [];
|
||
|
}
|
||
|
|
||
|
|
||
|
public function apply(Block $block): void
|
||
|
{
|
||
|
$words = $block->words;
|
||
|
while ($word = array_shift($words)) {
|
||
|
$method = "{$word}";
|
||
|
if (!method_exists($this, $method)) {
|
||
|
continue;
|
||
|
}
|
||
|
$this->{$method}($block);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
public function G22(Block $block): void
|
||
|
{
|
||
|
$number = $block->valueOf('X');
|
||
|
$this->machine->SPMC->loadProgram($number);
|
||
|
$this->machine->AMC = $this->machine->SPMC;
|
||
|
}
|
||
|
}
|