aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-03-13 23:11:23 +0900
committernsfisis <nsfisis@gmail.com>2024-03-13 23:11:23 +0900
commit3702e772d72cb46c6cb13e21d570427bd0b4e493 (patch)
tree61949354c5c546200797cad9f1ad520e258b93a6
parent804dea0ddefe826f535738cda9cc5ad900c083c4 (diff)
downloadphp-waddiwasi-3702e772d72cb46c6cb13e21d570427bd0b4e493.tar.gz
php-waddiwasi-3702e772d72cb46c6cb13e21d570427bd0b4e493.tar.zst
php-waddiwasi-3702e772d72cb46c6cb13e21d570427bd0b4e493.zip
perf: make Val to primitive
-rw-r--r--benchmarks/20240313-2308.log4
-rw-r--r--examples/php-on-wasm/php-wasm.php335
-rw-r--r--src/Execution/Allocator.php4
-rw-r--r--src/Execution/GlobalInst.php2
-rw-r--r--src/Execution/Num.php40
-rw-r--r--src/Execution/Nums/F32_.php18
-rw-r--r--src/Execution/Nums/F64_.php18
-rw-r--r--src/Execution/Nums/I32.php18
-rw-r--r--src/Execution/Nums/I64.php18
-rw-r--r--src/Execution/Result.php2
-rw-r--r--src/Execution/Results/Values.php4
-rw-r--r--src/Execution/Runtime.php530
-rw-r--r--src/Execution/Stack.php91
-rw-r--r--src/Execution/StackEntries/Frame.php4
-rw-r--r--src/Execution/StackEntries/Value.php4
-rw-r--r--src/Execution/StackEntry.php4
-rw-r--r--src/Execution/Val.php67
-rw-r--r--src/Execution/Vals/Num.php16
-rw-r--r--src/Execution/Vals/Ref.php16
-rw-r--r--traces/20240313-2308.stderr.log8
20 files changed, 469 insertions, 734 deletions
diff --git a/benchmarks/20240313-2308.log b/benchmarks/20240313-2308.log
new file mode 100644
index 0000000..fe1948d
--- /dev/null
+++ b/benchmarks/20240313-2308.log
@@ -0,0 +1,4 @@
+Benchmark 1: make run
+ Time (mean ± σ): 8.300 s ± 0.040 s [User: 8.230 s, System: 0.070 s]
+ Range (min … max): 8.232 s … 8.354 s 10 runs
+
diff --git a/examples/php-on-wasm/php-wasm.php b/examples/php-on-wasm/php-wasm.php
index 7279730..6443107 100644
--- a/examples/php-on-wasm/php-wasm.php
+++ b/examples/php-on-wasm/php-wasm.php
@@ -9,12 +9,9 @@ use Nsfisis\Waddiwasi\BinaryFormat\InvalidBinaryFormatException;
use Nsfisis\Waddiwasi\Debug\Debug;
use Nsfisis\Waddiwasi\Execution\ExternVal;
use Nsfisis\Waddiwasi\Execution\FuncInst;
-use Nsfisis\Waddiwasi\Execution\Nums;
use Nsfisis\Waddiwasi\Execution\Refs;
use Nsfisis\Waddiwasi\Execution\Runtime;
use Nsfisis\Waddiwasi\Execution\Store;
-use Nsfisis\Waddiwasi\Execution\Val;
-use Nsfisis\Waddiwasi\Execution\Vals;
use Nsfisis\Waddiwasi\Structure\Types\FuncType;
use Nsfisis\Waddiwasi\Structure\Types\NumType;
use Nsfisis\Waddiwasi\Structure\Types\ResultType;
@@ -144,12 +141,10 @@ $runtime = Runtime::instantiate($store, $module, $externVals);
$codePtr = allocateStringOnWasmMemory($runtime, PHP_HELLO_WORLD);
fprintf(STDERR, "Executing...\n");
-$results = $runtime->invoke("php_wasm_run", [Val::NumI32($codePtr)]);
+$results = $runtime->invoke("php_wasm_run", [$codePtr]);
assert(count($results) === 1);
-$result = $results[0];
-assert($result instanceof Vals\Num);
-assert($result->inner instanceof Nums\I32);
-$exitCode = $result->inner->value;
+$exitCode = $results[0];
+assert(is_int($exitCode));
fprintf(STDERR, "Exit code: $exitCode\n");
fprintf(STDERR, "Memory peak usage: %s\n", memory_get_peak_usage());
@@ -167,21 +162,19 @@ function allocateStringOnWasmMemory(Runtime $runtime, string $str): int {
}
function wasm_stackAlloc(Runtime $runtime, int $size): int {
- $results = $runtime->invoke("stackAlloc", [Val::NumI32($size)]);
+ $results = $runtime->invoke("stackAlloc", [$size]);
assert(count($results) === 1);
$result = $results[0];
- assert($result instanceof Vals\Num);
- assert($result->inner instanceof Nums\I32);
- return $result->inner->value;
+ assert(is_int($result));
+ return $result;
}
function wasm_stackSave(Runtime $runtime): int {
$results = $runtime->invoke("stackSave", []);
assert(count($results) === 1);
$result = $results[0];
- assert($result instanceof Vals\Num);
- assert($result->inner instanceof Nums\I32);
- return $result->inner->value;
+ assert(is_int($result));
+ return $result;
}
function copyStringToWasmMemory(Runtime $runtime, int $dst, string $src): void {
@@ -257,35 +250,35 @@ function syscallCalculateAt(Runtime $runtime, int $dirfd, string $path): string
// Type: (i32, i32, i32) -> (i32)
function hostFunc__env__invoke_iii(Runtime $runtime): void {
- $a2 = $runtime->stack->popI32();
- $a1 = $runtime->stack->popI32();
- $index = $runtime->stack->popI32();
+ $a2 = $runtime->stack->popInt();
+ $a1 = $runtime->stack->popInt();
+ $index = $runtime->stack->popInt();
$sp = wasm_stackSave($runtime);
$func = getWasmTableEntry($runtime, $index);
- $runtime->stack->pushI32($a1);
- $runtime->stack->pushI32($a2);
+ $runtime->stack->pushValue($a1);
+ $runtime->stack->pushValue($a2);
$runtime->invokeByFuncAddr($func);
}
// Type: (i32, i32, i32, i32, i32) -> (i32)
function hostFunc__env__invoke_iiiii(Runtime $runtime): void {
- $a4 = $runtime->stack->popI32();
- $a3 = $runtime->stack->popI32();
- $a2 = $runtime->stack->popI32();
- $a1 = $runtime->stack->popI32();
- $index = $runtime->stack->popI32();
+ $a4 = $runtime->stack->popInt();
+ $a3 = $runtime->stack->popInt();
+ $a2 = $runtime->stack->popInt();
+ $a1 = $runtime->stack->popInt();
+ $index = $runtime->stack->popInt();
$sp = wasm_stackSave($runtime);
$func = getWasmTableEntry($runtime, $index);
- $runtime->stack->pushI32($a1);
- $runtime->stack->pushI32($a2);
- $runtime->stack->pushI32($a3);
- $runtime->stack->pushI32($a4);
+ $runtime->stack->pushValue($a1);
+ $runtime->stack->pushValue($a2);
+ $runtime->stack->pushValue($a3);
+ $runtime->stack->pushValue($a4);
$runtime->invokeByFuncAddr($func);
}
// Type: (i32) -> ()
function hostFunc__env__invoke_v(Runtime $runtime): void {
- $index = $runtime->stack->popI32();
+ $index = $runtime->stack->popInt();
$sp = wasm_stackSave($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->invokeByFuncAddr($func);
@@ -293,25 +286,25 @@ function hostFunc__env__invoke_v(Runtime $runtime): void {
// Type: (i32, i32, i32, i32) -> (i32)
function hostFunc__env__invoke_iiii(Runtime $runtime): void {
- $a3 = $runtime->stack->popI32();
- $a2 = $runtime->stack->popI32();
- $a1 = $runtime->stack->popI32();
- $index = $runtime->stack->popI32();
+ $a3 = $runtime->stack->popInt();
+ $a2 = $runtime->stack->popInt();
+ $a1 = $runtime->stack->popInt();
+ $index = $runtime->stack->popInt();
$sp = wasm_stackSave($runtime);
$func = getWasmTableEntry($runtime, $index);
- $runtime->stack->pushI32($a1);
- $runtime->stack->pushI32($a2);
- $runtime->stack->pushI32($a3);
+ $runtime->stack->pushValue($a1);
+ $runtime->stack->pushValue($a2);
+ $runtime->stack->pushValue($a3);
$runtime->invokeByFuncAddr($func);
}
// Type: (i32, i32) -> (i32)
function hostFunc__env__invoke_ii(Runtime $runtime): void {
- $a1 = $runtime->stack->popI32();
- $index = $runtime->stack->popI32();
+ $a1 = $runtime->stack->popInt();
+ $index = $runtime->stack->popInt();
$sp = wasm_stackSave($runtime);
$func = getWasmTableEntry($runtime, $index);
- $runtime->stack->pushI32($a1);
+ $runtime->stack->pushValue($a1);
$runtime->invokeByFuncAddr($func);
}
@@ -327,43 +320,43 @@ function hostFunc__env__exit(Runtime $runtime): void {
// Type: (i32, i32, i32, i32) -> ()
function hostFunc__env__invoke_viii(Runtime $runtime): void {
- $a3 = $runtime->stack->popI32();
- $a2 = $runtime->stack->popI32();
- $a1 = $runtime->stack->popI32();
- $index = $runtime->stack->popI32();
+ $a3 = $runtime->stack->popInt();
+ $a2 = $runtime->stack->popInt();
+ $a1 = $runtime->stack->popInt();
+ $index = $runtime->stack->popInt();
$sp = wasm_stackSave($runtime);
$func = getWasmTableEntry($runtime, $index);
- $runtime->stack->pushI32($a1);
- $runtime->stack->pushI32($a2);
- $runtime->stack->pushI32($a3);
+ $runtime->stack->pushValue($a1);
+ $runtime->stack->pushValue($a2);
+ $runtime->stack->pushValue($a3);
$runtime->invokeByFuncAddr($func);
}
// Type: (i32, i32, i32) -> ()
function hostFunc__env__invoke_vii(Runtime $runtime): void {
- $a2 = $runtime->stack->popI32();
- $a1 = $runtime->stack->popI32();
- $index = $runtime->stack->popI32();
+ $a2 = $runtime->stack->popInt();
+ $a1 = $runtime->stack->popInt();
+ $index = $runtime->stack->popInt();
$sp = wasm_stackSave($runtime);
$func = getWasmTableEntry($runtime, $index);
- $runtime->stack->pushI32($a1);
- $runtime->stack->pushI32($a2);
+ $runtime->stack->pushValue($a1);
+ $runtime->stack->pushValue($a2);
$runtime->invokeByFuncAddr($func);
}
// Type: (i32, i32) -> ()
function hostFunc__env__invoke_vi(Runtime $runtime): void {
- $a1 = $runtime->stack->popI32();
- $index = $runtime->stack->popI32();
+ $a1 = $runtime->stack->popInt();
+ $index = $runtime->stack->popInt();
$sp = wasm_stackSave($runtime);
$func = getWasmTableEntry($runtime, $index);
- $runtime->stack->pushI32($a1);
+ $runtime->stack->pushValue($a1);
$runtime->invokeByFuncAddr($func);
}
// Type: (i32) -> (i32)
function hostFunc__env__invoke_i(Runtime $runtime): void {
- $index = $runtime->stack->popI32();
+ $index = $runtime->stack->popInt();
$sp = wasm_stackSave($runtime);
$func = getWasmTableEntry($runtime, $index);
$runtime->invokeByFuncAddr($func);
@@ -371,113 +364,113 @@ function hostFunc__env__invoke_i(Runtime $runtime): void {
// Type: (i32, i32, i32, i32, i32, i32, i32) -> (i32)
function hostFunc__env__invoke_iiiiiii(Runtime $runtime): void {
- $a6 = $runtime->stack->popI32();
- $a5 = $runtime->stack->popI32();
- $a4 = $runtime->stack->popI32();
- $a3 = $runtime->stack->popI32();
- $a2 = $runtime->stack->popI32();
- $a1 = $runtime->stack->popI32();
- $index = $runtime->stack->popI32();
+ $a6 = $runtime->stack->popInt();
+ $a5 = $runtime->stack->popInt();
+ $a4 = $runtime->stack->popInt();
+ $a3 = $runtime->stack->popInt();
+ $a2 = $runtime->stack->popInt();
+ $a1 = $runtime->stack->popInt();
+ $index = $runtime->stack->popInt();
$sp = wasm_stackSave($runtime);
$func = getWasmTableEntry($runtime, $index);
- $runtime->stack->pushI32($a1);
- $runtime->stack->pushI32($a2);
- $runtime->stack->pushI32($a3);
- $runtime->stack->pushI32($a4);
- $runtime->stack->pushI32($a5);
- $runtime->stack->pushI32($a6);
+ $runtime->stack->pushValue($a1);
+ $runtime->stack->pushValue($a2);
+ $runtime->stack->pushValue($a3);
+ $runtime->stack->pushValue($a4);
+ $runtime->stack->pushValue($a5);
+ $runtime->stack->pushValue($a6);
$runtime->invokeByFuncAddr($func);
}
// Type: (i32, i32, i32, i32) -> ()
function hostFunc__env____assert_fail(Runtime $runtime): void {
- $a3 = $runtime->stack->popI32();
- $a2 = $runtime->stack->popI32();
- $a1 = $runtime->stack->popI32();
- $index = $runtime->stack->popI32();
+ $a3 = $runtime->stack->popInt();
+ $a2 = $runtime->stack->popInt();
+ $a1 = $runtime->stack->popInt();
+ $index = $runtime->stack->popInt();
$sp = wasm_stackSave($runtime);
$func = getWasmTableEntry($runtime, $index);
- $runtime->stack->pushI32($a1);
- $runtime->stack->pushI32($a2);
- $runtime->stack->pushI32($a3);
+ $runtime->stack->pushValue($a1);
+ $runtime->stack->pushValue($a2);
+ $runtime->stack->pushValue($a3);
$runtime->invokeByFuncAddr($func);
}
// Type: (i32, i32, i32, i32, i32) -> ()
function hostFunc__env__invoke_viiii(Runtime $runtime): void {
- $a4 = $runtime->stack->popI32();
- $a3 = $runtime->stack->popI32();
- $a2 = $runtime->stack->popI32();
- $a1 = $runtime->stack->popI32();
- $index = $runtime->stack->popI32();
+ $a4 = $runtime->stack->popInt();
+ $a3 = $runtime->stack->popInt();
+ $a2 = $runtime->stack->popInt();
+ $a1 = $runtime->stack->popInt();
+ $index = $runtime->stack->popInt();
$sp = wasm_stackSave($runtime);
$func = getWasmTableEntry($runtime, $index);
- $runtime->stack->pushI32($a1);
- $runtime->stack->pushI32($a2);
- $runtime->stack->pushI32($a3);
- $runtime->stack->pushI32($a4);
+ $runtime->stack->pushValue($a1);
+ $runtime->stack->pushValue($a2);
+ $runtime->stack->pushValue($a3);
+ $runtime->stack->pushValue($a4);
$runtime->invokeByFuncAddr($func);
}
// Type: (i32, i32, i32, i32, i32, i32) -> ()
function hostFunc__env__invoke_viiiii(Runtime $runtime): void {
- $a5 = $runtime->stack->popI32();
- $a4 = $runtime->stack->popI32();
- $a3 = $runtime->stack->popI32();
- $a2 = $runtime->stack->popI32();
- $a1 = $runtime->stack->popI32();
- $index = $runtime->stack->popI32();
+ $a5 = $runtime->stack->popInt();
+ $a4 = $runtime->stack->popInt();
+ $a3 = $runtime->stack->popInt();
+ $a2 = $runtime->stack->popInt();
+ $a1 = $runtime->stack->popInt();
+ $index = $runtime->stack->popInt();
$sp = wasm_stackSave($runtime);
$func = getWasmTableEntry($runtime, $index);
- $runtime->stack->pushI32($a1);
- $runtime->stack->pushI32($a2);
- $runtime->stack->pushI32($a3);
- $runtime->stack->pushI32($a4);
- $runtime->stack->pushI32($a5);
+ $runtime->stack->pushValue($a1);
+ $runtime->stack->pushValue($a2);
+ $runtime->stack->pushValue($a3);
+ $runtime->stack->pushValue($a4);
+ $runtime->stack->pushValue($a5);
$runtime->invokeByFuncAddr($func);
}
// Type: (i32, i32, i32, i32, i32, i32) -> (i32)
function hostFunc__env__invoke_iiiiii(Runtime $runtime): void {
- $a5 = $runtime->stack->popI32();
- $a4 = $runtime->stack->popI32();
- $a3 = $runtime->stack->popI32();
- $a2 = $runtime->stack->popI32();
- $a1 = $runtime->stack->popI32();
- $index = $runtime->stack->popI32();
+ $a5 = $runtime->stack->popInt();
+ $a4 = $runtime->stack->popInt();
+ $a3 = $runtime->stack->popInt();
+ $a2 = $runtime->stack->popInt();
+ $a1 = $runtime->stack->popInt();
+ $index = $runtime->stack->popInt();
$sp = wasm_stackSave($runtime);
$func = getWasmTableEntry($runtime, $index);
- $runtime->stack->pushI32($a1);
- $runtime->stack->pushI32($a2);
- $runtime->stack->pushI32($a3);
- $runtime->stack->pushI32($a4);
- $runtime->stack->pushI32($a5);
+ $runtime->stack->pushValue($a1);
+ $runtime->stack->pushValue($a2);
+ $runtime->stack->pushValue($a3);
+ $runtime->stack->pushValue($a4);
+ $runtime->stack->pushValue($a5);
$runtime->invokeByFuncAddr($func);
}
// Type: (i32, i32, i32, i32, i32, i32, i32, i32, i32, i32) -> (i32)
function hostFunc__env__invoke_iiiiiiiiii(Runtime $runtime): void {
- $a9 = $runtime->stack->popI32();
- $a8 = $runtime->stack->popI32();
- $a7 = $runtime->stack->popI32();
- $a6 = $runtime->stack->popI32();
- $a5 = $runtime->stack->popI32();
- $a4 = $runtime->stack->popI32();
- $a3 = $runtime->stack->popI32();
- $a2 = $runtime->stack->popI32();
- $a1 = $runtime->stack->popI32();
- $index = $runtime->stack->popI32();
+ $a9 = $runtime->stack->popInt();
+ $a8 = $runtime->stack->popInt();
+ $a7 = $runtime->stack->popInt();
+ $a6 = $runtime->stack->popInt();
+ $a5 = $runtime->stack->popInt();
+ $a4 = $runtime->stack->popInt();
+ $a3 = $runtime->stack->popInt();
+ $a2 = $runtime->stack->popInt();
+ $a1 = $runtime->stack->popInt();
+ $index = $runtime->stack->popInt();
$sp = wasm_stackSave($runtime);
$func = getWasmTableEntry($runtime, $index);
- $runtime->stack->pushI32($a1);
- $runtime->stack->pushI32($a2);
- $runtime->stack->pushI32($a3);
- $runtime->stack->pushI32($a4);
- $runtime->stack->pushI32($a5);
- $runtime->stack->pushI32($a6);
- $runtime->stack->pushI32($a7);
- $runtime->stack->pushI32($a8);
- $runtime->stack->pushI32($a9);
+ $runtime->stack->pushValue($a1);
+ $runtime->stack->pushValue($a2);
+ $runtime->stack->pushValue($a3);
+ $runtime->stack->pushValue($a4);
+ $runtime->stack->pushValue($a5);
+ $runtime->stack->pushValue($a6);
+ $runtime->stack->pushValue($a7);
+ $runtime->stack->pushValue($a8);
+ $runtime->stack->pushValue($a9);
$runtime->invokeByFuncAddr($func);
}
@@ -523,39 +516,39 @@ function hostFunc__env__getnameinfo(Runtime $runtime): void {
// Type: (i32, i32, i32, i32, i32, i32, i32) -> ()
function hostFunc__env__invoke_viiiiii(Runtime $runtime): void {
- $a6 = $runtime->stack->popI32();
- $a5 = $runtime->stack->popI32();
- $a4 = $runtime->stack->popI32();
- $a3 = $runtime->stack->popI32();
- $a2 = $runtime->stack->popI32();
- $a1 = $runtime->stack->popI32();
- $index = $runtime->stack->popI32();
+ $a6 = $runtime->stack->popInt();
+ $a5 = $runtime->stack->popInt();
+ $a4 = $runtime->stack->popInt();
+ $a3 = $runtime->stack->popInt();
+ $a2 = $runtime->stack->popInt();
+ $a1 = $runtime->stack->popInt();
+ $index = $runtime->stack->popInt();
$sp = wasm_stackSave($runtime);
$func = getWasmTableEntry($runtime, $index);
- $runtime->stack->pushI32($a1);
- $runtime->stack->pushI32($a2);
- $runtime->stack->pushI32($a3);
- $runtime->stack->pushI32($a4);
- $runtime->stack->pushI32($a5);
- $runtime->stack->pushI32($a6);
+ $runtime->stack->pushValue($a1);
+ $runtime->stack->pushValue($a2);
+ $runtime->stack->pushValue($a3);
+ $runtime->stack->pushValue($a4);
+ $runtime->stack->pushValue($a5);
+ $runtime->stack->pushValue($a6);
$runtime->invokeByFuncAddr($func);
}
// Type: (i32, i32, i32, f64, i32, i32) -> ()
function hostFunc__env__invoke_viidii(Runtime $runtime): void {
- $a5 = $runtime->stack->popI32();
- $a4 = $runtime->stack->popI32();
- $a3 = $runtime->stack->popF64();
- $a2 = $runtime->stack->popI32();
- $a1 = $runtime->stack->popI32();
- $index = $runtime->stack->popI32();
+ $a5 = $runtime->stack->popInt();
+ $a4 = $runtime->stack->popInt();
+ $a3 = $runtime->stack->popFloat();
+ $a2 = $runtime->stack->popInt();
+ $a1 = $runtime->stack->popInt();
+ $index = $runtime->stack->popInt();
$sp = wasm_stackSave($runtime);
$func = getWasmTableEntry($runtime, $index);
- $runtime->stack->pushI32($a1);
- $runtime->stack->pushI32($a2);
- $runtime->stack->pushF64($a3);
- $runtime->stack->pushI32($a4);
- $runtime->stack->pushI32($a5);
+ $runtime->stack->pushValue($a1);
+ $runtime->stack->pushValue($a2);
+ $runtime->stack->pushValue($a3);
+ $runtime->stack->pushValue($a4);
+ $runtime->stack->pushValue($a5);
$runtime->invokeByFuncAddr($func);
}
@@ -607,13 +600,13 @@ function hostFunc__wasi_snapshot_preview1__fd_read(Runtime $runtime): void {
// Type: (i32, i32, i32, i32) -> (i32)
function hostFunc__wasi_snapshot_preview1__fd_write(Runtime $runtime): void {
// Output pointer to the number of bytes written.
- $pnum = $runtime->stack->popI32();
+ $pnum = $runtime->stack->popInt();
// Length of the array of iov structs.
- $iovcnt = $runtime->stack->popI32();
+ $iovcnt = $runtime->stack->popInt();
// Pointer to the array of iov structs.
- $iov = $runtime->stack->popI32();
+ $iov = $runtime->stack->popInt();
// File descripter.
- $fd = $runtime->stack->popI32();
+ $fd = $runtime->stack->popInt();
// struct iov {
// ptr: u32, pointer to the data
@@ -645,7 +638,7 @@ function hostFunc__wasi_snapshot_preview1__fd_write(Runtime $runtime): void {
}
$mem->storeI32($pnum, $nWritten, 4);
- $runtime->stack->pushI32(0);
+ $runtime->stack->pushValue(0);
}
// Type: (i32) -> ()
@@ -685,9 +678,9 @@ function hostFunc__env____syscall_dup3(Runtime $runtime): void {
// Type: (i32, i32, i32) -> ()
function hostFunc__env__emscripten_memcpy_js(Runtime $runtime): void {
- $num = $runtime->stack->popI32();
- $src = $runtime->stack->popI32();
- $dest = $runtime->stack->popI32();
+ $num = $runtime->stack->popInt();
+ $src = $runtime->stack->popInt();
+ $dest = $runtime->stack->popInt();
$mem = $runtime->getExportedMemory('memory');
assert($mem !== null);
for ($i = 0; $i < $num; $i++) {
@@ -719,10 +712,10 @@ function hostFunc__env____syscall_fdatasync(Runtime $runtime): void {
// Type: (i32, i32, i32, i32) -> (i32)
function hostFunc__env____syscall_openat(Runtime $runtime): void {
- $varargs = $runtime->stack->popI32();
- $flags = $runtime->stack->popI32();
- $path = $runtime->stack->popI32();
- $dirfd = $runtime->stack->popI32();
+ $varargs = $runtime->stack->popInt();
+ $flags = $runtime->stack->popInt();
+ $path = $runtime->stack->popInt();
+ $dirfd = $runtime->stack->popInt();
$path = syscallGetStr($runtime, $path);
$path = syscallCalculateAt($runtime, $dirfd, $path);
@@ -740,7 +733,7 @@ function hostFunc__env____syscall_openat(Runtime $runtime): void {
// echo "syscall_openat: $path, $flags, $mode\n";
// no such file
- $runtime->stack->pushI32(-44);
+ $runtime->stack->pushValue(-44);
}
// Type: (i32, i32) -> (i32)
@@ -770,21 +763,21 @@ function hostFunc__wasi_snapshot_preview1__fd_sync(Runtime $runtime): void {
// Type: (i32, i32) -> (i32)
function hostFunc__env____syscall_getcwd(Runtime $runtime): void {
- $size = $runtime->stack->popI32();
- $bufPtr = $runtime->stack->popI32();
+ $size = $runtime->stack->popInt();
+ $bufPtr = $runtime->stack->popInt();
if ($size === 0) {
- $runtime->stack->pushI32(-28);
+ $runtime->stack->pushValue(-28);
return;
}
$cwd = getcwd();
assert($cwd !== false);
$cwdLen = strlen($cwd) + 1;
if ($size < $cwdLen) {
- $runtime->stack->pushI32(-68);
+ $runtime->stack->pushValue(-68);
return;
}
copyStringToWasmMemory($runtime, $bufPtr, $cwd);
- $runtime->stack->pushI32($cwdLen);
+ $runtime->stack->pushValue($cwdLen);
}
// Type: (i32) -> ()
@@ -864,9 +857,9 @@ function hostFunc__env__emscripten_get_heap_max(Runtime $runtime): void {
// Type: (i32, i32, i32) -> ()
function hostFunc__env___tzset_js(Runtime $runtime): void {
- $tzname = $runtime->stack->popI32();
- $daylight = $runtime->stack->popI32();
- $timezone = $runtime->stack->popI32();
+ $tzname = $runtime->stack->popInt();
+ $daylight = $runtime->stack->popInt();
+ $timezone = $runtime->stack->popInt();
// Do nothing ;)
}
diff --git a/src/Execution/Allocator.php b/src/Execution/Allocator.php
index 730574b..299e761 100644
--- a/src/Execution/Allocator.php
+++ b/src/Execution/Allocator.php
@@ -44,7 +44,7 @@ final readonly class Allocator
/**
* @param list<ExternVal> $externVals
- * @param list<Val> $vals
+ * @param list<int|float|Ref> $vals
* @param list<list<Ref>> $refsList
* @param list<int> $preAllocatedFuncs
*/
@@ -134,7 +134,7 @@ final readonly class Allocator
return count($this->store->mems) - 1;
}
- private function allocGlobal(GlobalType $globalType, Val $val): int
+ private function allocGlobal(GlobalType $globalType, int|float|Ref $val): int
{
$globalInst = new GlobalInst($globalType, $val);
$this->store->globals[] = $globalInst;
diff --git a/src/Execution/GlobalInst.php b/src/Execution/GlobalInst.php
index 5595b45..08b621e 100644
--- a/src/Execution/GlobalInst.php
+++ b/src/Execution/GlobalInst.php
@@ -10,7 +10,7 @@ final class GlobalInst
{
public function __construct(
public readonly GlobalType $type,
- public Val $value,
+ public int|float|Ref $value,
) {
}
}
diff --git a/src/Execution/Num.php b/src/Execution/Num.php
deleted file mode 100644
index 03fec4f..0000000
--- a/src/Execution/Num.php
+++ /dev/null
@@ -1,40 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace Nsfisis\Waddiwasi\Execution;
-
-abstract readonly class Num
-{
- /**
- * @param S32 $value
- */
- final public static function I32(int $value): Nums\I32
- {
- return new Nums\I32($value);
- }
-
- /**
- * @param S64 $value
- */
- final public static function I64(int $value): Nums\I64
- {
- return new Nums\I64($value);
- }
-
- /**
- * @param F32 $value
- */
- final public static function F32(float $value): Nums\F32_
- {
- return new Nums\F32_($value);
- }
-
- /**
- * @param F64 $value
- */
- final public static function F64(float $value): Nums\F64_
- {
- return new Nums\F64_($value);
- }
-}
diff --git a/src/Execution/Nums/F32_.php b/src/Execution/Nums/F32_.php
deleted file mode 100644
index 5c7b749..0000000
--- a/src/Execution/Nums/F32_.php
+++ /dev/null
@@ -1,18 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace Nsfisis\Waddiwasi\Execution\Nums;
-
-use Nsfisis\Waddiwasi\Execution\Num;
-
-final readonly class F32_ extends Num
-{
- /**
- * @param F32 $value
- */
- public function __construct(
- public float $value,
- ) {
- }
-}
diff --git a/src/Execution/Nums/F64_.php b/src/Execution/Nums/F64_.php
deleted file mode 100644
index c24709e..0000000
--- a/src/Execution/Nums/F64_.php
+++ /dev/null
@@ -1,18 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace Nsfisis\Waddiwasi\Execution\Nums;
-
-use Nsfisis\Waddiwasi\Execution\Num;
-
-final readonly class F64_ extends Num
-{
- /**
- * @param F64 $value
- */
- public function __construct(
- public float $value,
- ) {
- }
-}
diff --git a/src/Execution/Nums/I32.php b/src/Execution/Nums/I32.php
deleted file mode 100644
index fbc6fab..0000000
--- a/src/Execution/Nums/I32.php
+++ /dev/null
@@ -1,18 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace Nsfisis\Waddiwasi\Execution\Nums;
-
-use Nsfisis\Waddiwasi\Execution\Num;
-
-final readonly class I32 extends Num
-{
- /**
- * @param S32 $value
- */
- public function __construct(
- public int $value,
- ) {
- }
-}
diff --git a/src/Execution/Nums/I64.php b/src/Execution/Nums/I64.php
deleted file mode 100644
index 889b863..0000000
--- a/src/Execution/Nums/I64.php
+++ /dev/null
@@ -1,18 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace Nsfisis\Waddiwasi\Execution\Nums;
-
-use Nsfisis\Waddiwasi\Execution\Num;
-
-final readonly class I64 extends Num
-{
- /**
- * @param S64 $value
- */
- public function __construct(
- public int $value,
- ) {
- }
-}
diff --git a/src/Execution/Result.php b/src/Execution/Result.php
index e07752c..c3cc64a 100644
--- a/src/Execution/Result.php
+++ b/src/Execution/Result.php
@@ -7,7 +7,7 @@ namespace Nsfisis\Waddiwasi\Execution;
abstract readonly class Result
{
/**
- * @param list<Val> $values
+ * @param list<int|float|Ref> $values
*/
final public static function Values(array $values): Results\Values
{
diff --git a/src/Execution/Results/Values.php b/src/Execution/Results/Values.php
index c3a9e36..61cb27f 100644
--- a/src/Execution/Results/Values.php
+++ b/src/Execution/Results/Values.php
@@ -4,13 +4,13 @@ declare(strict_types=1);
namespace Nsfisis\Waddiwasi\Execution\Results;
+use Nsfisis\Waddiwasi\Execution\Ref;
use Nsfisis\Waddiwasi\Execution\Result;
-use Nsfisis\Waddiwasi\Execution\Val;
final readonly class Values extends Result
{
/**
- * @param list<Val> $values
+ * @param list<int|float|Ref> $values
*/
protected function __construct(
public array $values,
diff --git a/src/Execution/Runtime.php b/src/Execution/Runtime.php
index 5e205b1..162c8b5 100644
--- a/src/Execution/Runtime.php
+++ b/src/Execution/Runtime.php
@@ -64,8 +64,8 @@ final class Runtime
$instrs = $expr->instrs;
array_pop($instrs); // drop "end"
$result = $runtimeInit->evalInstrsForInit($instrs);
- assert($result instanceof Vals\Ref);
- $refs[] = $result->inner;
+ assert($result instanceof Ref);
+ $refs[] = $result;
}
$refsList[] = $refs;
}
@@ -162,8 +162,8 @@ final class Runtime
}
/**
- * @param list<Val> $vals
- * @return list<Val>
+ * @param list<int|float|Ref> $vals
+ * @return list<int|float|Ref>
*/
public function invoke(string $name, array $vals): array
{
@@ -312,7 +312,7 @@ final class Runtime
/**
* @param list<Instr> $instrs
*/
- private function evalInstrsForInit(array $instrs): Val
+ private function evalInstrsForInit(array $instrs): int|float|Ref
{
$this->execInstrsForInit($instrs);
$result = $this->stack->popValue();
@@ -538,26 +538,26 @@ final class Runtime
private function execInstrNumericF32Abs(Instrs\Numeric\F32Abs $instr): void
{
- $v = $this->stack->popF32();
- $this->stack->pushF32(abs($v));
+ $v = $this->stack->popFloat();
+ $this->stack->pushValue(abs($v));
}
private function execInstrNumericF32Add(Instrs\Numeric\F32Add $instr): void
{
- $c2 = $this->stack->popF32();
- $c1 = $this->stack->popF32();
- $this->stack->pushF32($c1 + $c2);
+ $c2 = $this->stack->popFloat();
+ $c1 = $this->stack->popFloat();
+ $this->stack->pushValue($c1 + $c2);
}
private function execInstrNumericF32Ceil(Instrs\Numeric\F32Ceil $instr): void
{
- $v = $this->stack->popF32();
- $this->stack->pushF32(ceil($v));
+ $v = $this->stack->popFloat();
+ $this->stack->pushValue(ceil($v));
}
private function execInstrNumericF32Const(Instrs\Numeric\F32Const $instr): void
{
- $this->stack->pushValue(Val::NumF32($instr->value));
+ $this->stack->pushValue($instr->value);
}
private function execInstrNumericF32ConvertI32S(Instrs\Numeric\F32ConvertI32S $instr): void
@@ -592,9 +592,9 @@ final class Runtime
private function execInstrNumericF32Div(Instrs\Numeric\F32Div $instr): void
{
- $c2 = $this->stack->popF32();
- $c1 = $this->stack->popF32();
- $this->stack->pushF32($c1 / $c2);
+ $c2 = $this->stack->popFloat();
+ $c1 = $this->stack->popFloat();
+ $this->stack->pushValue($c1 / $c2);
}
private function execInstrNumericF32Eq(Instrs\Numeric\F32Eq $instr): void
@@ -609,51 +609,51 @@ final class Runtime
private function execInstrNumericF32Ge(Instrs\Numeric\F32Ge $instr): void
{
- $c2 = $this->stack->popF32();
- $c1 = $this->stack->popF32();
+ $c2 = $this->stack->popFloat();
+ $c1 = $this->stack->popFloat();
$this->stack->pushBool($c1 >= $c2);
}
private function execInstrNumericF32Gt(Instrs\Numeric\F32Gt $instr): void
{
- $c2 = $this->stack->popF32();
- $c1 = $this->stack->popF32();
+ $c2 = $this->stack->popFloat();
+ $c1 = $this->stack->popFloat();
$this->stack->pushBool($c1 > $c2);
}
private function execInstrNumericF32Le(Instrs\Numeric\F32Le $instr): void
{
- $c2 = $this->stack->popF32();
- $c1 = $this->stack->popF32();
+ $c2 = $this->stack->popFloat();
+ $c1 = $this->stack->popFloat();
$this->stack->pushBool($c1 <= $c2);
}
private function execInstrNumericF32Lt(Instrs\Numeric\F32Lt $instr): void
{
- $c2 = $this->stack->popF32();
- $c1 = $this->stack->popF32();
+ $c2 = $this->stack->popFloat();
+ $c1 = $this->stack->popFloat();
$this->stack->pushBool($c1 < $c2);
}
private function execInstrNumericF32Max(Instrs\Numeric\F32Max $instr): void
{
- $c2 = $this->stack->popF32();
- $c1 = $this->stack->popF32();
- $this->stack->pushF32(max($c1, $c2));
+ $c2 = $this->stack->popFloat();
+ $c1 = $this->stack->popFloat();
+ $this->stack->pushValue(max($c1, $c2));
}
private function execInstrNumericF32Min(Instrs\Numeric\F32Min $instr): void
{
- $c2 = $this->stack->popF32();
- $c1 = $this->stack->popF32();
- $this->stack->pushF32(min($c1, $c2));
+ $c2 = $this->stack->popFloat();
+ $c1 = $this->stack->popFloat();
+ $this->stack->pushValue(min($c1, $c2));
}
private function execInstrNumericF32Mul(Instrs\Numeric\F32Mul $instr): void
{
- $c2 = $this->stack->popF32();
- $c1 = $this->stack->popF32();
- $this->stack->pushF32($c1 * $c2);
+ $c2 = $this->stack->popFloat();
+ $c1 = $this->stack->popFloat();
+ $this->stack->pushValue($c1 * $c2);
}
private function execInstrNumericF32Ne(Instrs\Numeric\F32Ne $instr): void
@@ -668,8 +668,8 @@ final class Runtime
private function execInstrNumericF32Neg(Instrs\Numeric\F32Neg $instr): void
{
- $c1 = $this->stack->popF32();
- $this->stack->pushF32(-$c1);
+ $c1 = $this->stack->popFloat();
+ $this->stack->pushValue(-$c1);
}
private function execInstrNumericF32ReinterpretI32(Instrs\Numeric\F32ReinterpretI32 $instr): void
@@ -684,15 +684,15 @@ final class Runtime
private function execInstrNumericF32Sqrt(Instrs\Numeric\F32Sqrt $instr): void
{
- $c1 = $this->stack->popF32();
- $this->stack->pushF32(sqrt($c1));
+ $c1 = $this->stack->popFloat();
+ $this->stack->pushValue(sqrt($c1));
}
private function execInstrNumericF32Sub(Instrs\Numeric\F32Sub $instr): void
{
- $c2 = $this->stack->popF32();
- $c1 = $this->stack->popF32();
- $this->stack->pushF32($c1 - $c2);
+ $c2 = $this->stack->popFloat();
+ $c1 = $this->stack->popFloat();
+ $this->stack->pushValue($c1 - $c2);
}
private function execInstrNumericF32Trunc(Instrs\Numeric\F32Trunc $instr): void
@@ -702,50 +702,50 @@ final class Runtime
private function execInstrNumericF64Abs(Instrs\Numeric\F64Abs $instr): void
{
- $c1 = $this->stack->popF64();
- $this->stack->pushF64(abs($c1));
+ $c1 = $this->stack->popFloat();
+ $this->stack->pushValue(abs($c1));
}
private function execInstrNumericF64Add(Instrs\Numeric\F64Add $instr): void
{
- $c2 = $this->stack->popF64();
- $c1 = $this->stack->popF64();
- $this->stack->pushF64($c1 + $c2);
+ $c2 = $this->stack->popFloat();
+ $c1 = $this->stack->popFloat();
+ $this->stack->pushValue($c1 + $c2);
}
private function execInstrNumericF64Ceil(Instrs\Numeric\F64Ceil $instr): void
{
- $c1 = $this->stack->popF64();
- $this->stack->pushF64(ceil($c1));
+ $c1 = $this->stack->popFloat();
+ $this->stack->pushValue(ceil($c1));
}
private function execInstrNumericF64Const(Instrs\Numeric\F64Const $instr): void
{
- $this->stack->pushValue(Val::NumF64($instr->value));
+ $this->stack->pushValue($instr->value);
}
private function execInstrNumericF64ConvertI32S(Instrs\Numeric\F64ConvertI32S $instr): void
{
- $c = $this->stack->popI32();
- $this->stack->pushF64((float) $c);
+ $c = $this->stack->popInt();
+ $this->stack->pushValue((float) $c);
}
private function execInstrNumericF64ConvertI32U(Instrs\Numeric\F64ConvertI32U $instr): void
{
- $c = $this->stack->popI32();
- $this->stack->pushF64((float) $c);
+ $c = $this->stack->popInt();
+ $this->stack->pushValue((float) $c);
}
private function execInstrNumericF64ConvertI64S(Instrs\Numeric\F64ConvertI64S $instr): void
{
- $c = $this->stack->popI64();
- $this->stack->pushF64((float) $c);
+ $c = $this->stack->popInt();
+ $this->stack->pushValue((float) $c);
}
private function execInstrNumericF64ConvertI64U(Instrs\Numeric\F64ConvertI64U $instr): void
{
- $c = $this->stack->popI64();
- $this->stack->pushF64((float) $c);
+ $c = $this->stack->popInt();
+ $this->stack->pushValue((float) $c);
}
private function execInstrNumericF64CopySign(Instrs\Numeric\F64CopySign $instr): void
@@ -755,9 +755,9 @@ final class Runtime
private function execInstrNumericF64Div(Instrs\Numeric\F64Div $instr): void
{
- $c2 = $this->stack->popF64();
- $c1 = $this->stack->popF64();
- $this->stack->pushF64($c1 / $c2);
+ $c2 = $this->stack->popFloat();
+ $c1 = $this->stack->popFloat();
+ $this->stack->pushValue($c1 / $c2);
}
private function execInstrNumericF64Eq(Instrs\Numeric\F64Eq $instr): void
@@ -772,51 +772,51 @@ final class Runtime
private function execInstrNumericF64Ge(Instrs\Numeric\F64Ge $instr): void
{
- $c2 = $this->stack->popF64();
- $c1 = $this->stack->popF64();
+ $c2 = $this->stack->popFloat();
+ $c1 = $this->stack->popFloat();
$this->stack->pushBool($c1 >= $c2);
}
private function execInstrNumericF64Gt(Instrs\Numeric\F64Gt $instr): void
{
- $c2 = $this->stack->popF64();
- $c1 = $this->stack->popF64();
+ $c2 = $this->stack->popFloat();
+ $c1 = $this->stack->popFloat();
$this->stack->pushBool($c1 > $c2);
}
private function execInstrNumericF64Le(Instrs\Numeric\F64Le $instr): void
{
- $c2 = $this->stack->popF64();
- $c1 = $this->stack->popF64();
+ $c2 = $this->stack->popFloat();
+ $c1 = $this->stack->popFloat();
$this->stack->pushBool($c1 <= $c2);
}
private function execInstrNumericF64Lt(Instrs\Numeric\F64Lt $instr): void
{
- $c2 = $this->stack->popF64();
- $c1 = $this->stack->popF64();
+ $c2 = $this->stack->popFloat();
+ $c1 = $this->stack->popFloat();
$this->stack->pushBool($c1 < $c2);
}
private function execInstrNumericF64Max(Instrs\Numeric\F64Max $instr): void
{
- $c2 = $this->stack->popF64();
- $c1 = $this->stack->popF64();
- $this->stack->pushF64(max($c1, $c2));
+ $c2 = $this->stack->popFloat();
+ $c1 = $this->stack->popFloat();
+ $this->stack->pushValue(max($c1, $c2));
}
private function execInstrNumericF64Min(Instrs\Numeric\F64Min $instr): void
{
- $c2 = $this->stack->popF64();
- $c1 = $this->stack->popF64();
- $this->stack->pushF64(min($c1, $c2));
+ $c2 = $this->stack->popFloat();
+ $c1 = $this->stack->popFloat();
+ $this->stack->pushValue(min($c1, $c2));
}
private function execInstrNumericF64Mul(Instrs\Numeric\F64Mul $instr): void
{
- $c2 = $this->stack->popF64();
- $c1 = $this->stack->popF64();
- $this->stack->pushF64($c1 * $c2);
+ $c2 = $this->stack->popFloat();
+ $c1 = $this->stack->popFloat();
+ $this->stack->pushValue($c1 * $c2);
}
private function execInstrNumericF64Ne(Instrs\Numeric\F64Ne $instr): void
@@ -831,8 +831,8 @@ final class Runtime
private function execInstrNumericF64Neg(Instrs\Numeric\F64Neg $instr): void
{
- $c1 = $this->stack->popF64();
- $this->stack->pushF64(-$c1);
+ $c1 = $this->stack->popFloat();
+ $this->stack->pushValue(-$c1);
}
private function execInstrNumericF64PromoteF32(Instrs\Numeric\F64PromoteF32 $instr): void
@@ -852,15 +852,15 @@ final class Runtime
private function execInstrNumericF64Sqrt(Instrs\Numeric\F64Sqrt $instr): void
{
- $c1 = $this->stack->popF64();
- $this->stack->pushF64(sqrt($c1));
+ $c1 = $this->stack->popFloat();
+ $this->stack->pushValue(sqrt($c1));
}
private function execInstrNumericF64Sub(Instrs\Numeric\F64Sub $instr): void
{
- $c2 = $this->stack->popF64();
- $c1 = $this->stack->popF64();
- $this->stack->pushF64($c1 - $c2);
+ $c2 = $this->stack->popFloat();
+ $c1 = $this->stack->popFloat();
+ $this->stack->pushValue($c1 - $c2);
}
private function execInstrNumericF64Trunc(Instrs\Numeric\F64Trunc $instr): void
@@ -870,21 +870,21 @@ final class Runtime
private function execInstrNumericI32Add(Instrs\Numeric\I32Add $instr): void
{
- $c2 = $this->stack->popI32();
- $c1 = $this->stack->popI32();
- $this->stack->pushI32(($c1 + $c2) % 0x100000000);
+ $c2 = $this->stack->popInt();
+ $c1 = $this->stack->popInt();
+ $this->stack->pushValue(($c1 + $c2) % 0x100000000);
}
private function execInstrNumericI32And(Instrs\Numeric\I32And $instr): void
{
- $c2 = self::wasmI32ToPhpInt($this->stack->popI32());
- $c1 = self::wasmI32ToPhpInt($this->stack->popI32());
- $this->stack->pushI32(self::phpIntToWasmI32(($c1 & $c2) & 0xFFFFFFFF));
+ $c2 = self::wasmI32ToPhpInt($this->stack->popInt());
+ $c1 = self::wasmI32ToPhpInt($this->stack->popInt());
+ $this->stack->pushValue(self::phpIntToWasmI32(($c1 & $c2) & 0xFFFFFFFF));
}
private function execInstrNumericI32Clz(Instrs\Numeric\I32Clz $instr): void
{
- $i = self::wasmI32ToPhpInt($this->stack->popI32());
+ $i = self::wasmI32ToPhpInt($this->stack->popInt());
$leadingZeros = 0;
for ($j = 31; 0 <= $j; $j--) {
if (($i & (1 << $j)) === 0) {
@@ -893,17 +893,17 @@ final class Runtime
break;
}
}
- $this->stack->pushI32($leadingZeros);
+ $this->stack->pushValue($leadingZeros);
}
private function execInstrNumericI32Const(Instrs\Numeric\I32Const $instr): void
{
- $this->stack->pushValue(Val::NumI32($instr->value));
+ $this->stack->pushValue($instr->value);
}
private function execInstrNumericI32Ctz(Instrs\Numeric\I32Ctz $instr): void
{
- $i = self::wasmI32ToPhpInt($this->stack->popI32());
+ $i = self::wasmI32ToPhpInt($this->stack->popInt());
$trailingZeros = 0;
for ($j = 0; $j < 32; $j++) {
if (($i & (1 << $j)) === 0) {
@@ -912,7 +912,7 @@ final class Runtime
break;
}
}
- $this->stack->pushI32($trailingZeros);
+ $this->stack->pushValue($trailingZeros);
}
private function execInstrNumericI32DivS(Instrs\Numeric\I32DivS $instr): void
@@ -922,120 +922,120 @@ final class Runtime
private function execInstrNumericI32DivU(Instrs\Numeric\I32DivU $instr): void
{
- $c2 = $this->stack->popI32();
- $c1 = $this->stack->popI32();
+ $c2 = $this->stack->popInt();
+ $c1 = $this->stack->popInt();
if ($c2 === 0) {
throw new TrapException("i32.div_u: divide by zero");
}
- $this->stack->pushI32(intdiv($c1, $c2));
+ $this->stack->pushValue(intdiv($c1, $c2));
}
private function execInstrNumericI32Eq(Instrs\Numeric\I32Eq $instr): void
{
- $c2 = $this->stack->popI32();
- $c1 = $this->stack->popI32();
+ $c2 = $this->stack->popInt();
+ $c1 = $this->stack->popInt();
$this->stack->pushBool($c1 === $c2);
}
private function execInstrNumericI32Eqz(Instrs\Numeric\I32Eqz $instr): void
{
- $c1 = $this->stack->popI32();
+ $c1 = $this->stack->popInt();
$this->stack->pushBool($c1 === 0);
}
private function execInstrNumericI32Extend16S(Instrs\Numeric\I32Extend16S $instr): void
{
- $c1 = self::wasmI32ToPhpInt($this->stack->popI32());
+ $c1 = self::wasmI32ToPhpInt($this->stack->popInt());
$c2 = $c1 & 0xFFFF;
$result = unpack('s', pack('S', $c2));
assert($result !== false);
- $this->stack->pushI32($result[1]);
+ $this->stack->pushValue($result[1]);
}
private function execInstrNumericI32Extend8S(Instrs\Numeric\I32Extend8S $instr): void
{
- $c1 = self::wasmI32ToPhpInt($this->stack->popI32());
+ $c1 = self::wasmI32ToPhpInt($this->stack->popInt());
$c2 = $c1 & 0xFF;
$result = unpack('c', pack('C', $c2));
assert($result !== false);
- $this->stack->pushI32($result[1]);
+ $this->stack->pushValue($result[1]);
}
private function execInstrNumericI32GeS(Instrs\Numeric\I32GeS $instr): void
{
- $c2 = $this->stack->popI32();
- $c1 = $this->stack->popI32();
+ $c2 = $this->stack->popInt();
+ $c1 = $this->stack->popInt();
$this->stack->pushBool($c1 >= $c2);
}
private function execInstrNumericI32GeU(Instrs\Numeric\I32GeU $instr): void
{
- $c2 = self::wasmI32ToPhpInt($this->stack->popI32());
- $c1 = self::wasmI32ToPhpInt($this->stack->popI32());
+ $c2 = self::wasmI32ToPhpInt($this->stack->popInt());
+ $c1 = self::wasmI32ToPhpInt($this->stack->popInt());
$this->stack->pushBool($c1 >= $c2);
}
private function execInstrNumericI32GtS(Instrs\Numeric\I32GtS $instr): void
{
- $c2 = $this->stack->popI32();
- $c1 = $this->stack->popI32();
+ $c2 = $this->stack->popInt();
+ $c1 = $this->stack->popInt();
$this->stack->pushBool($c1 > $c2);
}
private function execInstrNumericI32GtU(Instrs\Numeric\I32GtU $instr): void
{
- $c2 = self::wasmI32ToPhpInt($this->stack->popI32());
- $c1 = self::wasmI32ToPhpInt($this->stack->popI32());
+ $c2 = self::wasmI32ToPhpInt($this->stack->popInt());
+ $c1 = self::wasmI32ToPhpInt($this->stack->popInt());
$this->stack->pushBool($c1 > $c2);
}
private function execInstrNumericI32LeS(Instrs\Numeric\I32LeS $instr): void
{
- $c2 = $this->stack->popI32();
- $c1 = $this->stack->popI32();
+ $c2 = $this->stack->popInt();
+ $c1 = $this->stack->popInt();
$this->stack->pushBool($c1 <= $c2);
}
private function execInstrNumericI32LeU(Instrs\Numeric\I32LeU $instr): void
{
- $c2 = self::wasmI32ToPhpInt($this->stack->popI32());
- $c1 = self::wasmI32ToPhpInt($this->stack->popI32());
+ $c2 = self::wasmI32ToPhpInt($this->stack->popInt());
+ $c1 = self::wasmI32ToPhpInt($this->stack->popInt());
$this->stack->pushBool($c1 <= $c2);
}
private function execInstrNumericI32LtS(Instrs\Numeric\I32LtS $instr): void
{
- $c2 = $this->stack->popI32();
- $c1 = $this->stack->popI32();
+ $c2 = $this->stack->popInt();
+ $c1 = $this->stack->popInt();
$this->stack->pushBool($c1 < $c2);
}
private function execInstrNumericI32LtU(Instrs\Numeric\I32LtU $instr): void
{
- $c2 = self::wasmI32ToPhpInt($this->stack->popI32());
- $c1 = self::wasmI32ToPhpInt($this->stack->popI32());
+ $c2 = self::wasmI32ToPhpInt($this->stack->popInt());
+ $c1 = self::wasmI32ToPhpInt($this->stack->popInt());
$this->stack->pushBool($c1 < $c2);
}
private function execInstrNumericI32Mul(Instrs\Numeric\I32Mul $instr): void
{
- $c2 = $this->stack->popI32();
- $c1 = $this->stack->popI32();
- $this->stack->pushI32(self::phpIntToWasmI32(($c1 * $c2) & 0xFFFFFFFF));
+ $c2 = $this->stack->popInt();
+ $c1 = $this->stack->popInt();
+ $this->stack->pushValue(self::phpIntToWasmI32(($c1 * $c2) & 0xFFFFFFFF));
}
private function execInstrNumericI32Ne(Instrs\Numeric\I32Ne $instr): void
{
- $c2 = $this->stack->popI32();
- $c1 = $this->stack->popI32();
+ $c2 = $this->stack->popInt();
+ $c1 = $this->stack->popInt();
$this->stack->pushBool($c1 !== $c2);
}
private function execInstrNumericI32Or(Instrs\Numeric\I32Or $instr): void
{
- $c2 = self::wasmI32ToPhpInt($this->stack->popI32());
- $c1 = self::wasmI32ToPhpInt($this->stack->popI32());
- $this->stack->pushI32(self::phpIntToWasmI32(($c1 | $c2) & 0xFFFFFFFF));
+ $c2 = self::wasmI32ToPhpInt($this->stack->popInt());
+ $c1 = self::wasmI32ToPhpInt($this->stack->popInt());
+ $this->stack->pushValue(self::phpIntToWasmI32(($c1 | $c2) & 0xFFFFFFFF));
}
private function execInstrNumericI32Popcnt(Instrs\Numeric\I32Popcnt $instr): void
@@ -1060,20 +1060,20 @@ final class Runtime
private function execInstrNumericI32RemU(Instrs\Numeric\I32RemU $instr): void
{
- $c2 = $this->stack->popI32();
- $c1 = $this->stack->popI32();
+ $c2 = $this->stack->popInt();
+ $c1 = $this->stack->popInt();
if ($c2 === 0) {
throw new TrapException("i32.rem_u: divide by zero");
}
- $this->stack->pushI32($c1 % $c2);
+ $this->stack->pushValue($c1 % $c2);
}
private function execInstrNumericI32RotL(Instrs\Numeric\I32RotL $instr): void
{
- $i2 = self::wasmI32ToPhpInt($this->stack->popI32());
- $i1 = self::wasmI32ToPhpInt($this->stack->popI32());
+ $i2 = self::wasmI32ToPhpInt($this->stack->popInt());
+ $i1 = self::wasmI32ToPhpInt($this->stack->popInt());
$k = $i2 % 32;
- $this->stack->pushI32(self::phpIntToWasmI32((($i1 << $k) | ($i1 >> (32 - $k))) & 0xFFFFFFFF));
+ $this->stack->pushValue(self::phpIntToWasmI32((($i1 << $k) | ($i1 >> (32 - $k))) & 0xFFFFFFFF));
}
private function execInstrNumericI32RotR(Instrs\Numeric\I32RotR $instr): void
@@ -1083,38 +1083,38 @@ final class Runtime
private function execInstrNumericI32Shl(Instrs\Numeric\I32Shl $instr): void
{
- $c2 = self::wasmI32ToPhpInt($this->stack->popI32());
+ $c2 = self::wasmI32ToPhpInt($this->stack->popInt());
$k = $c2 % 32;
- $c1 = $this->stack->popI32();
- $this->stack->pushI32(self::phpIntToWasmI32(($c1 << $k) & 0xFFFFFFFF));
+ $c1 = $this->stack->popInt();
+ $this->stack->pushValue(self::phpIntToWasmI32(($c1 << $k) & 0xFFFFFFFF));
}
private function execInstrNumericI32ShrS(Instrs\Numeric\I32ShrS $instr): void
{
- $c2 = self::wasmI32ToPhpInt($this->stack->popI32());
+ $c2 = self::wasmI32ToPhpInt($this->stack->popInt());
$k = $c2 % 32;
- $c1 = self::wasmI32ToPhpInt($this->stack->popI32());
+ $c1 = self::wasmI32ToPhpInt($this->stack->popInt());
$signed = $c1 & 0x80000000;
if ($signed !== 0) {
- $this->stack->pushI32(self::phpIntToWasmI32(($c1 >> $k) & 0x80000000));
+ $this->stack->pushValue(self::phpIntToWasmI32(($c1 >> $k) & 0x80000000));
} else {
- $this->stack->pushI32($c1 >> $k);
+ $this->stack->pushValue($c1 >> $k);
}
}
private function execInstrNumericI32ShrU(Instrs\Numeric\I32ShrU $instr): void
{
- $c2 = self::wasmI32ToPhpInt($this->stack->popI32());
+ $c2 = self::wasmI32ToPhpInt($this->stack->popInt());
$k = $c2 % 32;
- $c1 = self::wasmI32ToPhpInt($this->stack->popI32());
- $this->stack->pushI32($c1 >> $k);
+ $c1 = self::wasmI32ToPhpInt($this->stack->popInt());
+ $this->stack->pushValue($c1 >> $k);
}
private function execInstrNumericI32Sub(Instrs\Numeric\I32Sub $instr): void
{
- $c2 = $this->stack->popI32();
- $c1 = $this->stack->popI32();
- $this->stack->pushI32(($c1 - $c2) % 0x100000000);
+ $c2 = $this->stack->popInt();
+ $c1 = $this->stack->popInt();
+ $this->stack->pushValue(($c1 - $c2) % 0x100000000);
}
private function execInstrNumericI32TruncF32S(Instrs\Numeric\I32TruncF32S $instr): void
@@ -1159,34 +1159,34 @@ final class Runtime
private function execInstrNumericI32WrapI64(Instrs\Numeric\I32WrapI64 $instr): void
{
- $c1 = $this->stack->popI64();
- $this->stack->pushI32($c1 & 0xFFFFFFFF);
+ $c1 = $this->stack->popInt();
+ $this->stack->pushValue($c1 & 0xFFFFFFFF);
}
private function execInstrNumericI32Xor(Instrs\Numeric\I32Xor $instr): void
{
- $c2 = self::wasmI32ToPhpInt($this->stack->popI32());
- $c1 = self::wasmI32ToPhpInt($this->stack->popI32());
- $this->stack->pushI32(self::phpIntToWasmI32(($c1 ^ $c2) & 0xFFFFFFFF));
+ $c2 = self::wasmI32ToPhpInt($this->stack->popInt());
+ $c1 = self::wasmI32ToPhpInt($this->stack->popInt());
+ $this->stack->pushValue(self::phpIntToWasmI32(($c1 ^ $c2) & 0xFFFFFFFF));
}
private function execInstrNumericI64Add(Instrs\Numeric\I64Add $instr): void
{
- $c2 = $this->stack->popI64();
- $c1 = $this->stack->popI64();
- $this->stack->pushI64($c1 + $c2);
+ $c2 = $this->stack->popInt();
+ $c1 = $this->stack->popInt();
+ $this->stack->pushValue($c1 + $c2);
}
private function execInstrNumericI64And(Instrs\Numeric\I64And $instr): void
{
- $c2 = $this->stack->popI64();
- $c1 = $this->stack->popI64();
- $this->stack->pushI64($c1 & $c2);
+ $c2 = $this->stack->popInt();
+ $c1 = $this->stack->popInt();
+ $this->stack->pushValue($c1 & $c2);
}
private function execInstrNumericI64Clz(Instrs\Numeric\I64Clz $instr): void
{
- $i = $this->stack->popI64();
+ $i = $this->stack->popInt();
$leadingZeros = 0;
for ($j = 63; 0 <= $j; $j--) {
if ($j === 63) {
@@ -1203,17 +1203,17 @@ final class Runtime
}
}
}
- $this->stack->pushI64($leadingZeros);
+ $this->stack->pushValue($leadingZeros);
}
private function execInstrNumericI64Const(Instrs\Numeric\I64Const $instr): void
{
- $this->stack->pushValue(Val::NumI64($instr->value));
+ $this->stack->pushValue($instr->value);
}
private function execInstrNumericI64Ctz(Instrs\Numeric\I64Ctz $instr): void
{
- $i = $this->stack->popI64();
+ $i = $this->stack->popInt();
$trailingZeros = 0;
for ($j = 0; $j < 64; $j++) {
if ($j === 63) {
@@ -1228,169 +1228,169 @@ final class Runtime
}
}
}
- $this->stack->pushI64($trailingZeros);
+ $this->stack->pushValue($trailingZeros);
}
private function execInstrNumericI64DivS(Instrs\Numeric\I64DivS $instr): void
{
- $c2 = $this->stack->popI64();
- $c1 = $this->stack->popI64();
+ $c2 = $this->stack->popInt();
+ $c1 = $this->stack->popInt();
if ($c2 === 0) {
throw new TrapException("i64.div_s: divide by zero");
}
- $this->stack->pushI64(intdiv($c1, $c2));
+ $this->stack->pushValue(intdiv($c1, $c2));
}
private function execInstrNumericI64DivU(Instrs\Numeric\I64DivU $instr): void
{
- $c2 = $this->stack->popI64();
- $c1 = $this->stack->popI64();
+ $c2 = $this->stack->popInt();
+ $c1 = $this->stack->popInt();
if ($c2 === 0) {
throw new TrapException("i64.div_u: divide by zero");
}
- $this->stack->pushI64(intdiv($c1, $c2));
+ $this->stack->pushValue(intdiv($c1, $c2));
}
private function execInstrNumericI64Eq(Instrs\Numeric\I64Eq $instr): void
{
- $c2 = $this->stack->popI64();
- $c1 = $this->stack->popI64();
+ $c2 = $this->stack->popInt();
+ $c1 = $this->stack->popInt();
$this->stack->pushBool($c1 === $c2);
}
private function execInstrNumericI64Eqz(Instrs\Numeric\I64Eqz $instr): void
{
- $c1 = $this->stack->popI64();
+ $c1 = $this->stack->popInt();
$this->stack->pushBool($c1 === 0);
}
private function execInstrNumericI64Extend16S(Instrs\Numeric\I64Extend16S $instr): void
{
- $c1 = $this->stack->popI64();
+ $c1 = $this->stack->popInt();
$c2 = $c1 & 0xFFFF;
$result = unpack('s', pack('S', $c2));
assert($result !== false);
- $this->stack->pushI64($result[1]);
+ $this->stack->pushValue($result[1]);
}
private function execInstrNumericI64Extend32S(Instrs\Numeric\I64Extend32S $instr): void
{
- $c1 = $this->stack->popI64();
+ $c1 = $this->stack->popInt();
$c2 = $c1 & 0xFFFFFFFF;
$result = unpack('l', pack('L', $c2));
assert($result !== false);
- $this->stack->pushI64($result[1]);
+ $this->stack->pushValue($result[1]);
}
private function execInstrNumericI64Extend8S(Instrs\Numeric\I64Extend8S $instr): void
{
- $c1 = $this->stack->popI64();
+ $c1 = $this->stack->popInt();
$c2 = $c1 & 0xFF;
$result = unpack('c', pack('C', $c2));
assert($result !== false);
- $this->stack->pushI64($result[1]);
+ $this->stack->pushValue($result[1]);
}
private function execInstrNumericI64ExtendI32S(Instrs\Numeric\I64ExtendI32S $instr): void
{
- $c1 = $this->stack->popI32();
- $this->stack->pushI64($c1);
+ $c1 = $this->stack->popInt();
+ $this->stack->pushValue($c1);
}
private function execInstrNumericI64ExtendI32U(Instrs\Numeric\I64ExtendI32U $instr): void
{
- $c1 = self::wasmI32ToPhpInt($this->stack->popI32());
+ $c1 = self::wasmI32ToPhpInt($this->stack->popInt());
$c2 = $c1 & 0xFFFFFFFF;
- $this->stack->pushI64($c2);
+ $this->stack->pushValue($c2);
}
private function execInstrNumericI64GeS(Instrs\Numeric\I64GeS $instr): void
{
- $c2 = $this->stack->popI64();
- $c1 = $this->stack->popI64();
+ $c2 = $this->stack->popInt();
+ $c1 = $this->stack->popInt();
$this->stack->pushBool($c1 >= $c2);
}
private function execInstrNumericI64GeU(Instrs\Numeric\I64GeU $instr): void
{
- $c2 = $this->stack->popI64();
+ $c2 = $this->stack->popInt();
$c2Packed = pack('J', $c2);
- $c1 = $this->stack->popI64();
+ $c1 = $this->stack->popInt();
$c1Packed = pack('J', $c1);
$this->stack->pushBool($c1Packed >= $c2Packed);
}
private function execInstrNumericI64GtS(Instrs\Numeric\I64GtS $instr): void
{
- $c2 = $this->stack->popI64();
- $c1 = $this->stack->popI64();
+ $c2 = $this->stack->popInt();
+ $c1 = $this->stack->popInt();
$this->stack->pushBool($c1 > $c2);
}
private function execInstrNumericI64GtU(Instrs\Numeric\I64GtU $instr): void
{
- $c2 = $this->stack->popI64();
+ $c2 = $this->stack->popInt();
$c2Packed = pack('J', $c2);
- $c1 = $this->stack->popI64();
+ $c1 = $this->stack->popInt();
$c1Packed = pack('J', $c1);
$this->stack->pushBool($c1Packed > $c2Packed);
}
private function execInstrNumericI64LeS(Instrs\Numeric\I64LeS $instr): void
{
- $c2 = $this->stack->popI64();
- $c1 = $this->stack->popI64();
+ $c2 = $this->stack->popInt();
+ $c1 = $this->stack->popInt();
$this->stack->pushBool($c1 <= $c2);
}
private function execInstrNumericI64LeU(Instrs\Numeric\I64LeU $instr): void
{
- $c2 = $this->stack->popI64();
+ $c2 = $this->stack->popInt();
$c2Packed = pack('J', $c2);
- $c1 = $this->stack->popI64();
+ $c1 = $this->stack->popInt();
$c1Packed = pack('J', $c1);
$this->stack->pushBool($c1Packed <= $c2Packed);
}
private function execInstrNumericI64LtS(Instrs\Numeric\I64LtS $instr): void
{
- $c2 = $this->stack->popI64();
- $c1 = $this->stack->popI64();
+ $c2 = $this->stack->popInt();
+ $c1 = $this->stack->popInt();
$this->stack->pushBool($c1 < $c2);
}
private function execInstrNumericI64LtU(Instrs\Numeric\I64LtU $instr): void
{
- $c2 = $this->stack->popI64();
+ $c2 = $this->stack->popInt();
$c2Packed = pack('J', $c2);
- $c1 = $this->stack->popI64();
+ $c1 = $this->stack->popInt();
$c1Packed = pack('J', $c1);
$this->stack->pushBool($c1Packed < $c2Packed);
}
private function execInstrNumericI64Mul(Instrs\Numeric\I64Mul $instr): void
{
- $c2 = $this->stack->popI64();
- $c1 = $this->stack->popI64();
+ $c2 = $this->stack->popInt();
+ $c1 = $this->stack->popInt();
if ($c1 === (1 << 32) - 1 && $c2 === (1 << 32) + 1) {
- $this->stack->pushI64(-1);
+ $this->stack->pushValue(-1);
} else {
- $this->stack->pushI64($c1 * $c2);
+ $this->stack->pushValue($c1 * $c2);
}
}
private function execInstrNumericI64Ne(Instrs\Numeric\I64Ne $instr): void
{
- $c2 = $this->stack->popI64();
- $c1 = $this->stack->popI64();
+ $c2 = $this->stack->popInt();
+ $c1 = $this->stack->popInt();
$this->stack->pushBool($c1 !== $c2);
}
private function execInstrNumericI64Or(Instrs\Numeric\I64Or $instr): void
{
- $c2 = $this->stack->popI64();
- $c1 = $this->stack->popI64();
- $this->stack->pushI64($c1 | $c2);
+ $c2 = $this->stack->popInt();
+ $c1 = $this->stack->popInt();
+ $this->stack->pushValue($c1 | $c2);
}
private function execInstrNumericI64Popcnt(Instrs\Numeric\I64Popcnt $instr): void
@@ -1420,10 +1420,10 @@ final class Runtime
private function execInstrNumericI64RotL(Instrs\Numeric\I64RotL $instr): void
{
- $i2 = $this->stack->popI64();
- $i1 = $this->stack->popI64();
+ $i2 = $this->stack->popInt();
+ $i1 = $this->stack->popInt();
$k = $i2 % 64;
- $this->stack->pushI64(($i1 << $k) | ($i1 >> (64 - $k)));
+ $this->stack->pushValue(($i1 << $k) | ($i1 >> (64 - $k)));
}
private function execInstrNumericI64RotR(Instrs\Numeric\I64RotR $instr): void
@@ -1433,33 +1433,33 @@ final class Runtime
private function execInstrNumericI64Shl(Instrs\Numeric\I64Shl $instr): void
{
- $c2 = $this->stack->popI64();
+ $c2 = $this->stack->popInt();
$k = $c2 % 64;
- $c1 = $this->stack->popI64();
- $this->stack->pushI64($c1 << $k);
+ $c1 = $this->stack->popInt();
+ $this->stack->pushValue($c1 << $k);
}
private function execInstrNumericI64ShrS(Instrs\Numeric\I64ShrS $instr): void
{
- $c2 = $this->stack->popI64();
+ $c2 = $this->stack->popInt();
$k = $c2 % 64;
- $c1 = $this->stack->popI64();
- $this->stack->pushI64($c1 >> $k);
+ $c1 = $this->stack->popInt();
+ $this->stack->pushValue($c1 >> $k);
}
private function execInstrNumericI64ShrU(Instrs\Numeric\I64ShrU $instr): void
{
- $c2 = $this->stack->popI64();
+ $c2 = $this->stack->popInt();
$k = $c2 % 64;
- $c1 = $this->stack->popI64();
- $this->stack->pushI64($c1 >> $k);
+ $c1 = $this->stack->popInt();
+ $this->stack->pushValue($c1 >> $k);
}
private function execInstrNumericI64Sub(Instrs\Numeric\I64Sub $instr): void
{
- $c2 = $this->stack->popI64();
- $c1 = $this->stack->popI64();
- $this->stack->pushI64($c1 - $c2);
+ $c2 = $this->stack->popInt();
+ $c1 = $this->stack->popInt();
+ $this->stack->pushValue($c1 - $c2);
}
private function execInstrNumericI64TruncF32S(Instrs\Numeric\I64TruncF32S $instr): void
@@ -1504,9 +1504,9 @@ final class Runtime
private function execInstrNumericI64Xor(Instrs\Numeric\I64Xor $instr): void
{
- $c2 = $this->stack->popI64();
- $c1 = $this->stack->popI64();
- $this->stack->pushI64($c1 ^ $c2);
+ $c2 = $this->stack->popInt();
+ $c1 = $this->stack->popInt();
+ $this->stack->pushValue($c1 ^ $c2);
}
private function execInstrReferenceRefFunc(Instrs\Reference\RefFunc $instr): void
@@ -1536,7 +1536,7 @@ final class Runtime
private function execInstrParametricSelect(Instrs\Parametric\Select $instr): void
{
- $c = $this->stack->popI32();
+ $c = $this->stack->popInt();
$val2 = $this->stack->popValue();
$val1 = $this->stack->popValue();
if ($c !== 0) {
@@ -1635,9 +1635,9 @@ final class Runtime
$tab = $this->store->tables[$ta];
$ea = $f->module->elemAddrs[$y];
$elem = $this->store->elems[$ea];
- $n = $this->stack->popI32();
- $s = $this->stack->popI32();
- $d = $this->stack->popI32();
+ $n = $this->stack->popInt();
+ $s = $this->stack->popInt();
+ $d = $this->stack->popInt();
if (count($elem->elem) < $s + $n) {
throw new TrapException("table.init: out of bounds");
}
@@ -1646,8 +1646,8 @@ final class Runtime
}
for ($i = 0; $i < $n; $i++) {
$val = $elem->elem[$s];
- $this->stack->pushI32($d);
- $this->stack->pushValue(Val::Ref($val));
+ $this->stack->pushValue($d);
+ $this->stack->pushValue($val);
$this->execInstr(Instr::TableSet($x));
$d++;
$s++;
@@ -1661,7 +1661,7 @@ final class Runtime
$a = $f->module->tableAddrs[$x];
$tab = $this->store->tables[$a];
$val = $this->stack->popRef();
- $i = $this->stack->popI32();
+ $i = $this->stack->popInt();
if (count($tab->elem) <= $i) {
throw new TrapException("table.set: out of bounds");
}
@@ -1821,9 +1821,9 @@ final class Runtime
$mem = $this->store->mems[$ma];
$da = $f->module->dataAddrs[$x];
$data = $this->store->datas[$da];
- $n = $this->stack->popI32();
- $s = $this->stack->popI32();
- $d = $this->stack->popI32();
+ $n = $this->stack->popInt();
+ $s = $this->stack->popInt();
+ $d = $this->stack->popInt();
if (count($data->data) < $s + $n) {
throw new TrapException("memory.init: out of bounds");
}
@@ -1832,8 +1832,8 @@ final class Runtime
}
for ($i = 0; $i < $n; $i++) {
$b = $data->data[$s];
- $this->stack->pushI32($d);
- $this->stack->pushI32($b);
+ $this->stack->pushValue($d);
+ $this->stack->pushValue($b);
$this->execInstr(Instr::I32Store8(0, 0));
$d++;
$s++;
@@ -1848,7 +1848,7 @@ final class Runtime
$szInByte = $mem->size();
assert(is_int($szInByte / (64 * 1024)));
$sz = $szInByte / (64 * 1024);
- $this->stack->pushI32($sz);
+ $this->stack->pushValue($sz);
}
private function execInstrControlBlock(Instrs\Control\Block $instr): ?ControlFlowResult
@@ -1887,7 +1887,7 @@ final class Runtime
private function execInstrControlBrIf(Instrs\Control\BrIf $instr): ?ControlFlowResult
{
$l = $instr->label;
- $c = $this->stack->popI32();
+ $c = $this->stack->popInt();
if ($c !== 0) {
return $this->execInstr(Instr::Br($l));
} else {
@@ -1899,7 +1899,7 @@ final class Runtime
{
$ls = $instr->labelTable;
$ln = $instr->defaultLabel;
- $i = self::wasmI32ToPhpInt($this->stack->popI32());
+ $i = self::wasmI32ToPhpInt($this->stack->popInt());
if ($i < count($ls)) {
return $this->execInstr(Instr::Br($ls[$i]));
} else {
@@ -1923,7 +1923,7 @@ final class Runtime
$ta = $f->module->tableAddrs[$x];
$tab = $this->store->tables[$ta];
$ftExpect = $f->module->types[$y];
- $i = self::wasmI32ToPhpInt($this->stack->popI32());
+ $i = self::wasmI32ToPhpInt($this->stack->popInt());
if (count($tab->elem) <= $i) {
throw new TrapException("call_indirect: out of bounds");
}
@@ -1957,7 +1957,7 @@ final class Runtime
$blockType = $instr->type;
$instrs1 = $instr->thenBody;
$instrs2 = $instr->elseBody;
- $c = $this->stack->popI32();
+ $c = $this->stack->popInt();
if ($c !== 0) {
return $this->execInstr(Instr::Block($blockType, $instrs1));
} else {
@@ -1990,7 +1990,7 @@ final class Runtime
// echo " " . $instr::opName() . "\n";
// }
// WORKAROUND:
- $this->stack->pushI32(0);
+ $this->stack->pushValue(0);
}
}
$this->deactivateLabel($n);
@@ -2025,13 +2025,13 @@ final class Runtime
$f = $this->stack->currentFrame();
$a = $f->module->memAddrs[0];
$mem = $this->store->mems[$a];
- $i = $this->stack->popI32();
+ $i = $this->stack->popInt();
$ea = $i + $offset;
$c = $mem->loadI32($ea, $n, $signed);
if ($c === null) {
throw new TrapException("$instrOpName: out of bounds");
}
- $this->stack->pushI32($c);
+ $this->stack->pushValue($c);
}
private function doLoadI64(int $offset, int $n, bool $signed, string $instrOpName): void
@@ -2039,13 +2039,13 @@ final class Runtime
$f = $this->stack->currentFrame();
$a = $f->module->memAddrs[0];
$mem = $this->store->mems[$a];
- $i = $this->stack->popI32();
+ $i = $this->stack->popInt();
$ea = $i + $offset;
$c = $mem->loadI64($ea, $n, $signed);
if ($c === null) {
throw new TrapException("$instrOpName: out of bounds");
}
- $this->stack->pushI64($c);
+ $this->stack->pushValue($c);
}
private function doLoadF32(int $offset, string $instrOpName): void
@@ -2053,13 +2053,13 @@ final class Runtime
$f = $this->stack->currentFrame();
$a = $f->module->memAddrs[0];
$mem = $this->store->mems[$a];
- $i = $this->stack->popI32();
+ $i = $this->stack->popInt();
$ea = $i + $offset;
$c = $mem->loadF32($ea);
if ($c === null) {
throw new TrapException("$instrOpName: out of bounds");
}
- $this->stack->pushF64($c);
+ $this->stack->pushValue($c);
}
private function doLoadF64(int $offset, string $instrOpName): void
@@ -2067,13 +2067,13 @@ final class Runtime
$f = $this->stack->currentFrame();
$a = $f->module->memAddrs[0];
$mem = $this->store->mems[$a];
- $i = $this->stack->popI32();
+ $i = $this->stack->popInt();
$ea = $i + $offset;
$c = $mem->loadF64($ea);
if ($c === null) {
throw new TrapException("$instrOpName: out of bounds");
}
- $this->stack->pushF64($c);
+ $this->stack->pushValue($c);
}
private function doStoreI32(int $offset, int $n, string $instrOpName): void
@@ -2081,8 +2081,8 @@ final class Runtime
$f = $this->stack->currentFrame();
$a = $f->module->memAddrs[0];
$mem = $this->store->mems[$a];
- $c = $this->stack->popI32();
- $i = $this->stack->popI32();
+ $c = $this->stack->popInt();
+ $i = $this->stack->popInt();
$ea = $i + $offset;
$ok = $mem->storeI32($ea, $c, $n);
if (!$ok) {
@@ -2095,8 +2095,8 @@ final class Runtime
$f = $this->stack->currentFrame();
$a = $f->module->memAddrs[0];
$mem = $this->store->mems[$a];
- $c = $this->stack->popI64();
- $i = $this->stack->popI32();
+ $c = $this->stack->popInt();
+ $i = $this->stack->popInt();
$ea = $i + $offset;
$ok = $mem->storeI64($ea, $c, $n);
if (!$ok) {
@@ -2109,8 +2109,8 @@ final class Runtime
$f = $this->stack->currentFrame();
$a = $f->module->memAddrs[0];
$mem = $this->store->mems[$a];
- $c = $this->stack->popF32();
- $i = $this->stack->popI32();
+ $c = $this->stack->popFloat();
+ $i = $this->stack->popInt();
$ea = $i + $offset;
$ok = $mem->storeF32($ea, $c);
if (!$ok) {
@@ -2123,8 +2123,8 @@ final class Runtime
$f = $this->stack->currentFrame();
$a = $f->module->memAddrs[0];
$mem = $this->store->mems[$a];
- $c = $this->stack->popF64();
- $i = $this->stack->popI32();
+ $c = $this->stack->popFloat();
+ $i = $this->stack->popInt();
$ea = $i + $offset;
$ok = $mem->storeF64($ea, $c);
if (!$ok) {
@@ -2132,16 +2132,16 @@ final class Runtime
}
}
- private static function defaultValueFromValType(ValType $type): Val
+ private static function defaultValueFromValType(ValType $type): int|float|Ref
{
return match ($type::class) {
ValTypes\NumType::class => match ($type->inner) {
- NumType::I32 => Val::NumI32(0),
- NumType::I64 => Val::NumI64(0),
- NumType::F32 => Val::NumF32(0),
- NumType::F64 => Val::NumF64(0),
+ NumType::I32 => 0,
+ NumType::I64 => 0,
+ NumType::F32 => 0.0,
+ NumType::F64 => 0.0,
},
- ValTypes\RefType::class => Val::RefNull($type->inner),
+ ValTypes\RefType::class => Ref::RefNull($type->inner),
default => throw new \RuntimeException("unreachable"),
};
}
diff --git a/src/Execution/Stack.php b/src/Execution/Stack.php
index 467bd9b..ab118c5 100644
--- a/src/Execution/Stack.php
+++ b/src/Execution/Stack.php
@@ -32,61 +32,29 @@ final class Stack
$this->push($label);
}
- public function pushValue(Val $val): void
+ public function pushValue(int|float|Ref $val): void
{
$this->push(StackEntry::Value($val));
}
public function pushBool(bool $value): void
{
- $this->pushValue(Val::NumI32((int)$value));
- }
-
- /**
- * @param S32 $value
- */
- public function pushI32(int $value): void
- {
- $this->pushValue(Val::NumI32($value));
- }
-
- /**
- * @param S64 $value
- */
- public function pushI64(int $value): void
- {
- $this->pushValue(Val::NumI64($value));
- }
-
- /**
- * @param F32 $value
- */
- public function pushF32(float $value): void
- {
- $this->pushValue(Val::NumF32($value));
- }
-
- /**
- * @param F64 $value
- */
- public function pushF64(float $value): void
- {
- $this->pushValue(Val::NumF64($value));
+ $this->pushValue((int)$value);
}
public function pushRefNull(RefType $type): void
{
- $this->pushValue(Val::RefNull($type));
+ $this->pushValue(Ref::RefNull($type));
}
public function pushRefFunc(int $addr): void
{
- $this->pushValue(Val::RefFunc($addr));
+ $this->pushValue(Ref::RefFunc($addr));
}
public function pushRefExtern(int $addr): void
{
- $this->pushValue(Val::RefExtern($addr));
+ $this->pushValue(Ref::RefExtern($addr));
}
public function popFrame(): StackEntries\Frame
@@ -97,7 +65,7 @@ final class Stack
return $result;
}
- public function popValue(): Val
+ public function popValue(): int|float|Ref
{
$result = $this->pop();
assert($result instanceof StackEntries\Value, 'Expected a value on the stack, but got ' . print_r($result, true));
@@ -105,7 +73,7 @@ final class Stack
}
/**
- * @return list<Val>
+ * @return list<int|float|Ref>
*/
public function popNValues(int $n): array
{
@@ -116,59 +84,32 @@ final class Stack
return $results;
}
- /**
- * @return S32
- */
- public function popI32(): int
+ public function popInt(): int
{
$v = $this->popValue();
- assert($v instanceof Vals\Num);
- assert($v->inner instanceof Nums\I32);
- return $v->inner->value;
- }
-
- /**
- * @return S64
- */
- public function popI64(): int
- {
- $v = $this->popValue();
- assert($v instanceof Vals\Num);
- assert($v->inner instanceof Nums\I64);
- return $v->inner->value;
+ assert(is_int($v));
+ return $v;
}
/**
* @return F32
*/
- public function popF32(): float
- {
- $v = $this->popValue();
- assert($v instanceof Vals\Num);
- assert($v->inner instanceof Nums\F32_);
- return $v->inner->value;
- }
-
- /**
- * @return F64
- */
- public function popF64(): float
+ public function popFloat(): float
{
$v = $this->popValue();
- assert($v instanceof Vals\Num);
- assert($v->inner instanceof Nums\F64_);
- return $v->inner->value;
+ assert(is_float($v));
+ return $v;
}
public function popRef(): Ref
{
$v = $this->popValue();
- assert($v instanceof Vals\Ref);
- return $v->inner;
+ assert($v instanceof Ref);
+ return $v;
}
/**
- * @return list<Val>
+ * @return list<int|float|Ref>
*/
public function popValuesToLabel(): array
{
diff --git a/src/Execution/StackEntries/Frame.php b/src/Execution/StackEntries/Frame.php
index 955548a..298feb6 100644
--- a/src/Execution/StackEntries/Frame.php
+++ b/src/Execution/StackEntries/Frame.php
@@ -5,14 +5,14 @@ declare(strict_types=1);
namespace Nsfisis\Waddiwasi\Execution\StackEntries;
use Nsfisis\Waddiwasi\Execution\ModuleInst;
+use Nsfisis\Waddiwasi\Execution\Ref;
use Nsfisis\Waddiwasi\Execution\StackEntry;
-use Nsfisis\Waddiwasi\Execution\Val;
final class Frame extends StackEntry
{
/**
* @param int<0, max> $arity
- * @param list<Val> $locals
+ * @param list<int|float|Ref> $locals
*/
public function __construct(
public readonly int $arity,
diff --git a/src/Execution/StackEntries/Value.php b/src/Execution/StackEntries/Value.php
index a0f621a..32244d6 100644
--- a/src/Execution/StackEntries/Value.php
+++ b/src/Execution/StackEntries/Value.php
@@ -4,13 +4,13 @@ declare(strict_types=1);
namespace Nsfisis\Waddiwasi\Execution\StackEntries;
+use Nsfisis\Waddiwasi\Execution\Ref;
use Nsfisis\Waddiwasi\Execution\StackEntry;
-use Nsfisis\Waddiwasi\Execution\Val;
final class Value extends StackEntry
{
public function __construct(
- public readonly Val $inner,
+ public readonly int|float|Ref $inner,
) {
}
}
diff --git a/src/Execution/StackEntry.php b/src/Execution/StackEntry.php
index bba31df..4260830 100644
--- a/src/Execution/StackEntry.php
+++ b/src/Execution/StackEntry.php
@@ -6,7 +6,7 @@ namespace Nsfisis\Waddiwasi\Execution;
abstract class StackEntry
{
- final public static function Value(Val $inner): StackEntries\Value
+ final public static function Value(int|float|Ref $inner): StackEntries\Value
{
return new StackEntries\Value($inner);
}
@@ -22,7 +22,7 @@ abstract class StackEntry
/**
* @param int<0, max> $arity
- * @param list<Val> $locals
+ * @param list<int|float|Ref> $locals
*/
final public static function Frame(
int $arity,
diff --git a/src/Execution/Val.php b/src/Execution/Val.php
deleted file mode 100644
index 1746cae..0000000
--- a/src/Execution/Val.php
+++ /dev/null
@@ -1,67 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace Nsfisis\Waddiwasi\Execution;
-
-use Nsfisis\Waddiwasi\Structure\Types\RefType;
-
-abstract readonly class Val
-{
- final public static function Num(Num $inner): Vals\Num
- {
- return new Vals\Num($inner);
- }
-
- /**
- * @param S32 $value
- */
- final public static function NumI32(int $value): Vals\Num
- {
- return self::Num(Num::I32($value));
- }
-
- /**
- * @param S64 $value
- */
- final public static function NumI64(int $value): Vals\Num
- {
- return self::Num(Num::I64($value));
- }
-
- /**
- * @param F32 $value
- */
- final public static function NumF32(float $value): Vals\Num
- {
- return self::Num(Num::F32($value));
- }
-
- /**
- * @param F64 $value
- */
- final public static function NumF64(float $value): Vals\Num
- {
- return self::Num(Num::F64($value));
- }
-
- final public static function Ref(Ref $inner): Vals\Ref
- {
- return new Vals\Ref($inner);
- }
-
- final public static function RefNull(RefType $type): Vals\Ref
- {
- return self::Ref(Ref::RefNull($type));
- }
-
- final public static function RefFunc(int $addr): Vals\Ref
- {
- return self::Ref(Ref::RefFunc($addr));
- }
-
- final public static function RefExtern(int $addr): Vals\Ref
- {
- return self::Ref(Ref::RefExtern($addr));
- }
-}
diff --git a/src/Execution/Vals/Num.php b/src/Execution/Vals/Num.php
deleted file mode 100644
index 15b4433..0000000
--- a/src/Execution/Vals/Num.php
+++ /dev/null
@@ -1,16 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace Nsfisis\Waddiwasi\Execution\Vals;
-
-use Nsfisis\Waddiwasi\Execution\Num as OrigNum;
-use Nsfisis\Waddiwasi\Execution\Val;
-
-final readonly class Num extends Val
-{
- public function __construct(
- public OrigNum $inner,
- ) {
- }
-}
diff --git a/src/Execution/Vals/Ref.php b/src/Execution/Vals/Ref.php
deleted file mode 100644
index 8ea8a94..0000000
--- a/src/Execution/Vals/Ref.php
+++ /dev/null
@@ -1,16 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace Nsfisis\Waddiwasi\Execution\Vals;
-
-use Nsfisis\Waddiwasi\Execution\Ref as OrigRef;
-use Nsfisis\Waddiwasi\Execution\Val;
-
-final readonly class Ref extends Val
-{
- public function __construct(
- public OrigRef $inner,
- ) {
- }
-}
diff --git a/traces/20240313-2308.stderr.log b/traces/20240313-2308.stderr.log
new file mode 100644
index 0000000..ad0d1ea
--- /dev/null
+++ b/traces/20240313-2308.stderr.log
@@ -0,0 +1,8 @@
+Decoding...
+Instantiating...
+Executing...
+
+Exit code: 0
+Memory peak usage: 195919208
+
+