aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-05-19 11:36:04 +0900
committernsfisis <nsfisis@gmail.com>2024-05-19 11:36:04 +0900
commit07b375c2c5ae968735f2390b523dbcc088b03ee5 (patch)
tree96ba2641b3382ace2c5a6f7ede5f89cd596d05b0
parent829f6e531525fa82c5fa948e6bb96bb6469685a2 (diff)
downloadphp-waddiwasi-07b375c2c5ae968735f2390b523dbcc088b03ee5.tar.gz
php-waddiwasi-07b375c2c5ae968735f2390b523dbcc088b03ee5.tar.zst
php-waddiwasi-07b375c2c5ae968735f2390b523dbcc088b03ee5.zip
test: UnreachableTest passed
-rw-r--r--src/Execution/Runtime.php2
-rw-r--r--src/Execution/TrapKind.php1
-rw-r--r--tests/src/SpecTestsuites/SpecTestsuiteBase.php9
3 files changed, 8 insertions, 4 deletions
diff --git a/src/Execution/Runtime.php b/src/Execution/Runtime.php
index bf010c9..9987118 100644
--- a/src/Execution/Runtime.php
+++ b/src/Execution/Runtime.php
@@ -2449,7 +2449,7 @@ final class Runtime
private function execInstrControlUnreachable(Instrs\Control\Unreachable $instr): void
{
- throw new TrapException("unreachable");
+ throw new TrapException("unreachable", trapKind: TrapKind::Unreachable);
}
private function doLoadF32(int $offset, string $instrOpName): void
diff --git a/src/Execution/TrapKind.php b/src/Execution/TrapKind.php
index b33e4df..c44747d 100644
--- a/src/Execution/TrapKind.php
+++ b/src/Execution/TrapKind.php
@@ -7,6 +7,7 @@ namespace Nsfisis\Waddiwasi\Execution;
enum TrapKind
{
case Unknown;
+ case Unreachable;
case OutOfBoundsMemoryAccess;
case OutOfBoundsTableAccess;
case UninitializedElement;
diff --git a/tests/src/SpecTestsuites/SpecTestsuiteBase.php b/tests/src/SpecTestsuites/SpecTestsuiteBase.php
index 0fc7e2e..2fc1998 100644
--- a/tests/src/SpecTestsuites/SpecTestsuiteBase.php
+++ b/tests/src/SpecTestsuites/SpecTestsuiteBase.php
@@ -14,7 +14,9 @@ use Nsfisis\Waddiwasi\Execution\Store;
use Nsfisis\Waddiwasi\Execution\TrapException;
use Nsfisis\Waddiwasi\Execution\TrapKind;
use PHPUnit\Framework\TestCase;
+use RuntimeException;
use function count;
+use function is_float;
abstract class SpecTestsuiteBase extends TestCase
{
@@ -157,7 +159,7 @@ abstract class SpecTestsuiteBase extends TestCase
'f32' => unpack('g', pack('l', (int)$value))[1],
'f64' => unpack('e', self::convertInt64ToBinary($value))[1],
'externref' => Ref::RefExtern((int)$value),
- default => throw new \RuntimeException("unknown type: $type"),
+ default => throw new RuntimeException("unknown type: $type"),
};
}
@@ -209,7 +211,7 @@ abstract class SpecTestsuiteBase extends TestCase
is_nan($actualResult),
"result $i is not NaN" . $message,
);
- } else if ($expectedValue instanceof RefExtern) {
+ } elseif ($expectedValue instanceof RefExtern) {
$this->assertInstanceOf(
RefExtern::class,
$actualResult,
@@ -240,6 +242,7 @@ abstract class SpecTestsuiteBase extends TestCase
}
$actualErrorMessage = match ($kind) {
TrapKind::Unknown => 'unknown',
+ TrapKind::Unreachable => 'unreachable',
TrapKind::OutOfBoundsMemoryAccess => 'out of bounds memory access',
TrapKind::OutOfBoundsTableAccess => 'out of bounds table access',
TrapKind::UninitializedElement => 'uninitialized element',
@@ -253,7 +256,7 @@ abstract class SpecTestsuiteBase extends TestCase
);
}
- static private function convertInt64ToBinary(string $value): string
+ private static function convertInt64ToBinary(string $value): string
{
// 2^63-1 < $value
if (bccomp(bcsub(bcpow('2', '63'), '1'), $value) < 0) {