Initial implementation of instruction set
This commit is contained in:
@@ -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";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user