philips-cnc6600-interpreter/src/Automata/Storage/ProgramMemory.php

28 lines
476 B
PHP

<?php
namespace Automata\Storage;
use InvalidArgumentException;
use Program\Program;
class ProgramMemory
{
/** @var Program[] */
private array $memory = [];
public function save(Program $program): void
{
if ($program->N > 9998 || $program->N < 9001) {
throw new InvalidArgumentException('Program number must be in range 9001 - 9998');
}
$this->memory[$program->N] = $program;
}
public function read(int $N): ?Program
{
return @$this->memory[$N];
}
}