aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Execution/Stack.php
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-05-01 23:17:58 +0900
committernsfisis <nsfisis@gmail.com>2024-05-01 23:17:58 +0900
commitabdad356462b4b84cba771af742d1b6ecfaabc2d (patch)
tree40a763ad15af318cfcbc00515a32d3c0970f0df2 /src/Execution/Stack.php
parentbd72d3c4acde3f5e79bd494d4678a6e72e92e313 (diff)
downloadphp-waddiwasi-abdad356462b4b84cba771af742d1b6ecfaabc2d.tar.gz
php-waddiwasi-abdad356462b4b84cba771af742d1b6ecfaabc2d.tar.zst
php-waddiwasi-abdad356462b4b84cba771af742d1b6ecfaabc2d.zip
test: define more trap kind
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',
+ };
+ }
}