aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/WebAssembly/Execution/Runtime.php
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-07-11 03:50:50 +0900
committernsfisis <nsfisis@gmail.com>2024-07-11 04:14:03 +0900
commit8a083ed74e9f4472441175e187208012927ed357 (patch)
tree3686a0f61f3fccc5ded3eda28b92b8bf7765fd2f /src/WebAssembly/Execution/Runtime.php
parent26f49b7e27076e689541b9e13a1b54f60a4ee5c2 (diff)
downloadphp-waddiwasi-8a083ed74e9f4472441175e187208012927ed357.tar.gz
php-waddiwasi-8a083ed74e9f4472441175e187208012927ed357.tar.zst
php-waddiwasi-8a083ed74e9f4472441175e187208012927ed357.zip
feat: simplify ValType structure
Diffstat (limited to 'src/WebAssembly/Execution/Runtime.php')
-rw-r--r--src/WebAssembly/Execution/Runtime.php16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/WebAssembly/Execution/Runtime.php b/src/WebAssembly/Execution/Runtime.php
index dbefea2..4e8f3e8 100644
--- a/src/WebAssembly/Execution/Runtime.php
+++ b/src/WebAssembly/Execution/Runtime.php
@@ -13,11 +13,9 @@ use Nsfisis\Waddiwasi\WebAssembly\Structure\Modules\ElemModes;
use Nsfisis\Waddiwasi\WebAssembly\Structure\Modules\Module;
use Nsfisis\Waddiwasi\WebAssembly\Structure\Types\FuncType;
use Nsfisis\Waddiwasi\WebAssembly\Structure\Types\Limits;
-use Nsfisis\Waddiwasi\WebAssembly\Structure\Types\NumType;
use Nsfisis\Waddiwasi\WebAssembly\Structure\Types\ResultType;
use Nsfisis\Waddiwasi\WebAssembly\Structure\Types\TableType;
use Nsfisis\Waddiwasi\WebAssembly\Structure\Types\ValType;
-use Nsfisis\Waddiwasi\WebAssembly\Structure\Types\ValTypes;
use RuntimeException;
use function abs;
use function array_map;
@@ -2639,14 +2637,12 @@ final class Runtime
private static function defaultValueFromValType(ValType $type): int|float|Ref
{
- return match ($type::class) {
- ValTypes\NumType::class => match ($type->inner) {
- NumType::I32 => 0,
- NumType::I64 => 0,
- NumType::F32 => 0.0,
- NumType::F64 => 0.0,
- },
- ValTypes\RefType::class => Ref::RefNull($type->inner),
+ return match ($type) {
+ ValType::I32 => 0,
+ ValType::I64 => 0,
+ ValType::F32 => 0.0,
+ ValType::F64 => 0.0,
+ ValType::FuncRef, ValType::ExternRef => Ref::RefNull($type),
default => throw new RuntimeException("unreachable"),
};
}