Initial implementation of instruction set

This commit is contained in:
2020-05-10 23:46:44 +02:00
parent e2bb39006a
commit 63fd73f98c
17 changed files with 389 additions and 222 deletions

View File

@@ -24,10 +24,36 @@ class Block
}
public function valueOf(string $register): int
public function has(string $register): bool
{
foreach ($this->words as $word) {
if ($word->register === $register) {
return true;
}
}
return false;
}
public function read(string $register): int
{
foreach ($this->words as $index => $word) {
if ($word->register === $register) {
return $word->value;
}
}
throw new RuntimeException("No word in block for register '$register'");
}
public function pop(string $register): int
{
foreach ($this->words as $index => $word) {
if ($word->register === $register) {
unset($this->words[$index]);
return $word->value;
}
}
@@ -38,7 +64,7 @@ class Block
public function __toString()
{
$buffer = "$this->N\t";
$buffer = "N$this->N\t\t";
foreach ($this->words as $word) {
$buffer .= "$word\t";
}