aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/WebAssembly/Structure
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/Structure
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/Structure')
-rw-r--r--src/WebAssembly/Structure/Instructions/Instr.php6
-rw-r--r--src/WebAssembly/Structure/Instructions/Instrs/Reference/RefNull.php7
-rw-r--r--src/WebAssembly/Structure/Modules/Elem.php5
-rw-r--r--src/WebAssembly/Structure/Types/NumType.php13
-rw-r--r--src/WebAssembly/Structure/Types/RefType.php11
-rw-r--r--src/WebAssembly/Structure/Types/ResultType.php2
-rw-r--r--src/WebAssembly/Structure/Types/TableType.php5
-rw-r--r--src/WebAssembly/Structure/Types/ValType.php25
-rw-r--r--src/WebAssembly/Structure/Types/ValTypes/NumType.php21
-rw-r--r--src/WebAssembly/Structure/Types/ValTypes/RefType.php21
-rw-r--r--src/WebAssembly/Structure/Types/ValTypes/VecType.php21
-rw-r--r--src/WebAssembly/Structure/Types/VecType.php10
12 files changed, 25 insertions, 122 deletions
diff --git a/src/WebAssembly/Structure/Instructions/Instr.php b/src/WebAssembly/Structure/Instructions/Instr.php
index 18531c6..5f9cf29 100644
--- a/src/WebAssembly/Structure/Instructions/Instr.php
+++ b/src/WebAssembly/Structure/Instructions/Instr.php
@@ -12,7 +12,6 @@ use Nsfisis\Waddiwasi\WebAssembly\Structure\Instructions\Instrs\Parametric;
use Nsfisis\Waddiwasi\WebAssembly\Structure\Instructions\Instrs\Reference;
use Nsfisis\Waddiwasi\WebAssembly\Structure\Instructions\Instrs\Table;
use Nsfisis\Waddiwasi\WebAssembly\Structure\Instructions\Instrs\Variable;
-use Nsfisis\Waddiwasi\WebAssembly\Structure\Types\RefType;
use Nsfisis\Waddiwasi\WebAssembly\Structure\Types\ValType;
abstract readonly class Instr
@@ -616,7 +615,10 @@ abstract readonly class Instr
{
return new Reference\RefIsNull();
}
- final public static function RefNull(RefType $type): Reference\RefNull
+ /**
+ * @param ValType::FuncRef|ValType::ExternRef $type
+ */
+ final public static function RefNull(ValType $type): Reference\RefNull
{
return new Reference\RefNull($type);
}
diff --git a/src/WebAssembly/Structure/Instructions/Instrs/Reference/RefNull.php b/src/WebAssembly/Structure/Instructions/Instrs/Reference/RefNull.php
index 39d0f8f..ed5afff 100644
--- a/src/WebAssembly/Structure/Instructions/Instrs/Reference/RefNull.php
+++ b/src/WebAssembly/Structure/Instructions/Instrs/Reference/RefNull.php
@@ -5,12 +5,15 @@ declare(strict_types=1);
namespace Nsfisis\Waddiwasi\WebAssembly\Structure\Instructions\Instrs\Reference;
use Nsfisis\Waddiwasi\WebAssembly\Structure\Instructions\Instr;
-use Nsfisis\Waddiwasi\WebAssembly\Structure\Types\RefType;
+use Nsfisis\Waddiwasi\WebAssembly\Structure\Types\ValType;
final readonly class RefNull extends Instr
{
+ /**
+ * @param ValType::FuncRef|ValType::ExternRef $type
+ */
protected function __construct(
- public RefType $type,
+ public ValType $type,
) {
}
diff --git a/src/WebAssembly/Structure/Modules/Elem.php b/src/WebAssembly/Structure/Modules/Elem.php
index 1b9831f..646315d 100644
--- a/src/WebAssembly/Structure/Modules/Elem.php
+++ b/src/WebAssembly/Structure/Modules/Elem.php
@@ -5,15 +5,16 @@ declare(strict_types=1);
namespace Nsfisis\Waddiwasi\WebAssembly\Structure\Modules;
use Nsfisis\Waddiwasi\WebAssembly\Structure\Instructions\Instr;
-use Nsfisis\Waddiwasi\WebAssembly\Structure\Types\RefType;
+use Nsfisis\Waddiwasi\WebAssembly\Structure\Types\ValType;
final readonly class Elem
{
/**
+ * @param ValType::FuncRef|ValType::ExternRef $type
* @param list<list<Instr>> $init
*/
public function __construct(
- public RefType $type,
+ public ValType $type,
public array $init,
public ElemMode $mode,
) {
diff --git a/src/WebAssembly/Structure/Types/NumType.php b/src/WebAssembly/Structure/Types/NumType.php
deleted file mode 100644
index 2d5a3b1..0000000
--- a/src/WebAssembly/Structure/Types/NumType.php
+++ /dev/null
@@ -1,13 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace Nsfisis\Waddiwasi\WebAssembly\Structure\Types;
-
-enum NumType
-{
- case I32;
- case I64;
- case F32;
- case F64;
-}
diff --git a/src/WebAssembly/Structure/Types/RefType.php b/src/WebAssembly/Structure/Types/RefType.php
deleted file mode 100644
index 2225f56..0000000
--- a/src/WebAssembly/Structure/Types/RefType.php
+++ /dev/null
@@ -1,11 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace Nsfisis\Waddiwasi\WebAssembly\Structure\Types;
-
-enum RefType
-{
- case FuncRef;
- case ExternRef;
-}
diff --git a/src/WebAssembly/Structure/Types/ResultType.php b/src/WebAssembly/Structure/Types/ResultType.php
index dff2e59..9f44e81 100644
--- a/src/WebAssembly/Structure/Types/ResultType.php
+++ b/src/WebAssembly/Structure/Types/ResultType.php
@@ -22,7 +22,7 @@ final readonly class ResultType
return false;
}
foreach ($this->types as $i => $type) {
- if (!$type->equals($other->types[$i])) {
+ if ($type !== $other->types[$i]) {
return false;
}
}
diff --git a/src/WebAssembly/Structure/Types/TableType.php b/src/WebAssembly/Structure/Types/TableType.php
index 7e4b957..b812de4 100644
--- a/src/WebAssembly/Structure/Types/TableType.php
+++ b/src/WebAssembly/Structure/Types/TableType.php
@@ -6,9 +6,12 @@ namespace Nsfisis\Waddiwasi\WebAssembly\Structure\Types;
final readonly class TableType
{
+ /**
+ * @param ValType::FuncRef|ValType::ExternRef $refType
+ */
public function __construct(
public Limits $limits,
- public RefType $refType,
+ public ValType $refType,
) {
}
}
diff --git a/src/WebAssembly/Structure/Types/ValType.php b/src/WebAssembly/Structure/Types/ValType.php
index f6f3111..ace4604 100644
--- a/src/WebAssembly/Structure/Types/ValType.php
+++ b/src/WebAssembly/Structure/Types/ValType.php
@@ -4,22 +4,13 @@ declare(strict_types=1);
namespace Nsfisis\Waddiwasi\WebAssembly\Structure\Types;
-abstract readonly class ValType
+enum ValType
{
- final public static function NumType(NumType $type): ValTypes\NumType
- {
- return new ValTypes\NumType($type);
- }
-
- final public static function VecType(VecType $type): ValTypes\VecType
- {
- return new ValTypes\VecType($type);
- }
-
- final public static function RefType(RefType $type): ValTypes\RefType
- {
- return new ValTypes\RefType($type);
- }
-
- abstract public function equals(ValType $other): bool;
+ case I32;
+ case I64;
+ case F32;
+ case F64;
+ case V128;
+ case FuncRef;
+ case ExternRef;
}
diff --git a/src/WebAssembly/Structure/Types/ValTypes/NumType.php b/src/WebAssembly/Structure/Types/ValTypes/NumType.php
deleted file mode 100644
index 1836679..0000000
--- a/src/WebAssembly/Structure/Types/ValTypes/NumType.php
+++ /dev/null
@@ -1,21 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace Nsfisis\Waddiwasi\WebAssembly\Structure\Types\ValTypes;
-
-use Nsfisis\Waddiwasi\WebAssembly\Structure\Types\NumType as OrigNumType;
-use Nsfisis\Waddiwasi\WebAssembly\Structure\Types\ValType;
-
-final readonly class NumType extends ValType
-{
- protected function __construct(public OrigNumType $inner)
- {
- }
-
- public function equals(ValType $other): bool
- {
- return $other instanceof self
- && $this->inner === $other->inner;
- }
-}
diff --git a/src/WebAssembly/Structure/Types/ValTypes/RefType.php b/src/WebAssembly/Structure/Types/ValTypes/RefType.php
deleted file mode 100644
index a31b7c3..0000000
--- a/src/WebAssembly/Structure/Types/ValTypes/RefType.php
+++ /dev/null
@@ -1,21 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace Nsfisis\Waddiwasi\WebAssembly\Structure\Types\ValTypes;
-
-use Nsfisis\Waddiwasi\WebAssembly\Structure\Types\RefType as OrigRefType;
-use Nsfisis\Waddiwasi\WebAssembly\Structure\Types\ValType;
-
-final readonly class RefType extends ValType
-{
- protected function __construct(public OrigRefType $inner)
- {
- }
-
- public function equals(ValType $other): bool
- {
- return $other instanceof self
- && $this->inner === $other->inner;
- }
-}
diff --git a/src/WebAssembly/Structure/Types/ValTypes/VecType.php b/src/WebAssembly/Structure/Types/ValTypes/VecType.php
deleted file mode 100644
index 03cc95e..0000000
--- a/src/WebAssembly/Structure/Types/ValTypes/VecType.php
+++ /dev/null
@@ -1,21 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace Nsfisis\Waddiwasi\WebAssembly\Structure\Types\ValTypes;
-
-use Nsfisis\Waddiwasi\WebAssembly\Structure\Types\ValType;
-use Nsfisis\Waddiwasi\WebAssembly\Structure\Types\VecType as OrigVecType;
-
-final readonly class VecType extends ValType
-{
- protected function __construct(public OrigVecType $inner)
- {
- }
-
- public function equals(ValType $other): bool
- {
- return $other instanceof self
- && $this->inner === $other->inner; // @phpstan-ignore-line
- }
-}
diff --git a/src/WebAssembly/Structure/Types/VecType.php b/src/WebAssembly/Structure/Types/VecType.php
deleted file mode 100644
index dcf7d68..0000000
--- a/src/WebAssembly/Structure/Types/VecType.php
+++ /dev/null
@@ -1,10 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace Nsfisis\Waddiwasi\WebAssembly\Structure\Types;
-
-enum VecType
-{
- case V128;
-}