aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Execution/Stack.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/Execution/Stack.php')
-rw-r--r--src/Execution/Stack.php19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/Execution/Stack.php b/src/Execution/Stack.php
index be4e7ec..424f8c6 100644
--- a/src/Execution/Stack.php
+++ b/src/Execution/Stack.php
@@ -9,6 +9,7 @@ use function assert;
use function count;
use function is_float;
use function is_int;
+use function is_null;
final class Stack
{
@@ -102,7 +103,7 @@ final class Stack
public function popInt(): int
{
$v = $this->popValue();
- assert(is_int($v));
+ assert(is_int($v), "Expected an int on top of the stack, but got " . self::getValueTypeName($v));
return $v;
}
@@ -112,14 +113,14 @@ final class Stack
public function popFloat(): float
{
$v = $this->popValue();
- assert(is_float($v));
+ assert(is_float($v), "Expected a float on top of the stack, but got " . self::getValueTypeName($v));
return $v;
}
public function popRef(): Ref
{
$v = $this->popValue();
- assert($v instanceof Ref);
+ assert($v instanceof Ref, "Expected a Ref on top of the stack, but got " . self::getValueTypeName($v));
return $v;
}
@@ -187,4 +188,16 @@ final class Stack
{
return array_pop($this->entries);
}
+
+ private static function getValueTypeName(int|float|Ref|Frame|Label|null $value): string
+ {
+ return match (true) {
+ is_null($value) => 'null',
+ is_int($value) => 'int',
+ is_float($value) => 'float',
+ $value instanceof Ref => 'Ref',
+ $value instanceof Frame => 'Frame',
+ $value instanceof Label => 'Label',
+ };
+ }
}