Refactor, add extensive README.md, add future planning

This commit is contained in:
2020-05-13 00:32:28 +02:00
parent 63fd73f98c
commit 9002db40aa
26 changed files with 666 additions and 226 deletions

View File

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