2020-05-10 21:17:12 +02:00
|
|
|
<?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
|
|
|
|
{
|
2020-05-10 21:27:50 +02:00
|
|
|
print("$block\n");
|
2020-05-10 21:17:12 +02:00
|
|
|
$words = $block->words;
|
|
|
|
while ($word = array_shift($words)) {
|
|
|
|
$method = "{$word}";
|
|
|
|
if (!method_exists($this, $method)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$this->{$method}($block);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-05-10 21:27:50 +02:00
|
|
|
protected function G22(Block $block): void
|
2020-05-10 21:17:12 +02:00
|
|
|
{
|
|
|
|
$number = $block->valueOf('X');
|
|
|
|
$this->machine->SPMC->loadProgram($number);
|
|
|
|
$this->machine->AMC = $this->machine->SPMC;
|
|
|
|
}
|
|
|
|
}
|