aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Execution
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-03-13 22:42:58 +0900
committernsfisis <nsfisis@gmail.com>2024-03-13 22:42:58 +0900
commit814e5197439fbf2b404e8e66f3c6dd6e5ed39776 (patch)
tree72901a7e2f1641366d2cfd57b883929989c68328 /src/Execution
parent7348999caf3ce1e0be64697319581d52f1d7f8ea (diff)
downloadphp-waddiwasi-814e5197439fbf2b404e8e66f3c6dd6e5ed39776.tar.gz
php-waddiwasi-814e5197439fbf2b404e8e66f3c6dd6e5ed39776.tar.zst
php-waddiwasi-814e5197439fbf2b404e8e66f3c6dd6e5ed39776.zip
perf: make *Addr/*Idx to primitive int
Diffstat (limited to 'src/Execution')
-rw-r--r--src/Execution/Allocator.php40
-rw-r--r--src/Execution/ControlFlowResult.php4
-rw-r--r--src/Execution/ControlFlowResults/Br.php3
-rw-r--r--src/Execution/DataAddr.php13
-rw-r--r--src/Execution/ElemAddr.php13
-rw-r--r--src/Execution/ExternAddr.php13
-rw-r--r--src/Execution/ExternVal.php8
-rw-r--r--src/Execution/ExternVals/Func.php3
-rw-r--r--src/Execution/ExternVals/Global_.php3
-rw-r--r--src/Execution/ExternVals/Mem.php3
-rw-r--r--src/Execution/ExternVals/Table.php3
-rw-r--r--src/Execution/FuncAddr.php13
-rw-r--r--src/Execution/GlobalAddr.php13
-rw-r--r--src/Execution/MemAddr.php13
-rw-r--r--src/Execution/ModuleInst.php12
-rw-r--r--src/Execution/Ref.php4
-rw-r--r--src/Execution/Refs/RefExtern.php3
-rw-r--r--src/Execution/Refs/RefFunc.php3
-rw-r--r--src/Execution/Runtime.php122
-rw-r--r--src/Execution/Stack.php4
-rw-r--r--src/Execution/TableAddr.php13
-rw-r--r--src/Execution/Val.php4
22 files changed, 103 insertions, 207 deletions
diff --git a/src/Execution/Allocator.php b/src/Execution/Allocator.php
index 23d9a06..730574b 100644
--- a/src/Execution/Allocator.php
+++ b/src/Execution/Allocator.php
@@ -46,7 +46,7 @@ final readonly class Allocator
* @param list<ExternVal> $externVals
* @param list<Val> $vals
* @param list<list<Ref>> $refsList
- * @param list<FuncAddr> $preAllocatedFuncs
+ * @param list<int> $preAllocatedFuncs
*/
public function allocModule(
Module $module,
@@ -69,10 +69,10 @@ final readonly class Allocator
foreach ($preAllocatedFuncs as $funcAddr) {
$m->funcAddrs[] = $funcAddr;
- $funcInst = $this->store->funcs[$funcAddr->value];
+ $funcInst = $this->store->funcs[$funcAddr];
if ($funcInst instanceof FuncInsts\Wasm) {
// @phpstan-ignore-next-line
- $this->store->funcs[$funcAddr->value] = FuncInst::Wasm(
+ $this->store->funcs[$funcAddr] = FuncInst::Wasm(
$funcInst->type,
$m,
$funcInst->code,
@@ -98,10 +98,10 @@ final readonly class Allocator
foreach ($module->exports as $export) {
$value = match ($export->desc::class) {
- ExportDescs\Func::class => ExternVal::Func($m->funcAddrs[$export->desc->func->value]),
- ExportDescs\Table::class => ExternVal::Table($m->tableAddrs[$export->desc->table->value]),
- ExportDescs\Mem::class => ExternVal::Mem($m->memAddrs[$export->desc->mem->value]),
- ExportDescs\Global_::class => ExternVal::Global_($m->globalAddrs[$export->desc->global->value]),
+ ExportDescs\Func::class => ExternVal::Func($m->funcAddrs[$export->desc->func]),
+ ExportDescs\Table::class => ExternVal::Table($m->tableAddrs[$export->desc->table]),
+ ExportDescs\Mem::class => ExternVal::Mem($m->memAddrs[$export->desc->mem]),
+ ExportDescs\Global_::class => ExternVal::Global_($m->globalAddrs[$export->desc->global]),
default => throw new \RuntimeException("unreachable"),
};
$m->exports[] = new ExportInst($export->name, $value);
@@ -110,54 +110,54 @@ final readonly class Allocator
return $m;
}
- private function allocFunc(Func $func, ModuleInst $moduleInst): FuncAddr
+ private function allocFunc(Func $func, ModuleInst $moduleInst): int
{
- $funcType = $moduleInst->types[$func->type->value];
+ $funcType = $moduleInst->types[$func->type];
$funcInst = FuncInst::Wasm($funcType, $moduleInst, $func);
$this->store->funcs[] = $funcInst;
- return new FuncAddr(count($this->store->funcs) - 1);
+ return count($this->store->funcs) - 1;
}
- private function allocTable(TableType $tableType, Ref $ref): TableAddr
+ private function allocTable(TableType $tableType, Ref $ref): int
{
$minSize = $tableType->limits->min;
$elem = array_fill(0, $minSize, $ref);
$tableInst = new TableInst($tableType, $elem);
$this->store->tables[] = $tableInst;
- return new TableAddr(count($this->store->tables) - 1);
+ return count($this->store->tables) - 1;
}
- private function allocMem(MemType $memType): MemAddr
+ private function allocMem(MemType $memType): int
{
$memInst = new MemInst($memType);
$this->store->mems[] = $memInst;
- return new MemAddr(count($this->store->mems) - 1);
+ return count($this->store->mems) - 1;
}
- private function allocGlobal(GlobalType $globalType, Val $val): GlobalAddr
+ private function allocGlobal(GlobalType $globalType, Val $val): int
{
$globalInst = new GlobalInst($globalType, $val);
$this->store->globals[] = $globalInst;
- return new GlobalAddr(count($this->store->globals) - 1);
+ return count($this->store->globals) - 1;
}
/**
* @param list<Ref> $elem
*/
- private function allocElem(RefType $refType, array $elem): ElemAddr
+ private function allocElem(RefType $refType, array $elem): int
{
$elemInst = new ElemInst($refType, $elem);
$this->store->elems[] = $elemInst;
- return new ElemAddr(count($this->store->elems) - 1);
+ return count($this->store->elems) - 1;
}
/**
* @param list<Byte> $data
*/
- private function allocData(array $data): DataAddr
+ private function allocData(array $data): int
{
$dataInst = new DataInst($data);
$this->store->datas[] = $dataInst;
- return new DataAddr(count($this->store->datas) - 1);
+ return count($this->store->datas) - 1;
}
}
diff --git a/src/Execution/ControlFlowResult.php b/src/Execution/ControlFlowResult.php
index 1b995d9..0bb831a 100644
--- a/src/Execution/ControlFlowResult.php
+++ b/src/Execution/ControlFlowResult.php
@@ -4,11 +4,9 @@ declare(strict_types=1);
namespace Nsfisis\Waddiwasi\Execution;
-use Nsfisis\Waddiwasi\Structure\Types\LabelIdx;
-
abstract readonly class ControlFlowResult
{
- final public static function Br(LabelIdx $label): ControlFlowResults\Br
+ final public static function Br(int $label): ControlFlowResults\Br
{
return new ControlFlowResults\Br($label);
}
diff --git a/src/Execution/ControlFlowResults/Br.php b/src/Execution/ControlFlowResults/Br.php
index 8ca7ff3..a9c78b7 100644
--- a/src/Execution/ControlFlowResults/Br.php
+++ b/src/Execution/ControlFlowResults/Br.php
@@ -5,12 +5,11 @@ declare(strict_types=1);
namespace Nsfisis\Waddiwasi\Execution\ControlFlowResults;
use Nsfisis\Waddiwasi\Execution\ControlFlowResult;
-use Nsfisis\Waddiwasi\Structure\Types\LabelIdx;
final readonly class Br extends ControlFlowResult
{
protected function __construct(
- public LabelIdx $label,
+ public int $label,
) {
}
}
diff --git a/src/Execution/DataAddr.php b/src/Execution/DataAddr.php
deleted file mode 100644
index b3c4516..0000000
--- a/src/Execution/DataAddr.php
+++ /dev/null
@@ -1,13 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace Nsfisis\Waddiwasi\Execution;
-
-final readonly class DataAddr
-{
- public function __construct(
- public int $value,
- ) {
- }
-}
diff --git a/src/Execution/ElemAddr.php b/src/Execution/ElemAddr.php
deleted file mode 100644
index e46b54f..0000000
--- a/src/Execution/ElemAddr.php
+++ /dev/null
@@ -1,13 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace Nsfisis\Waddiwasi\Execution;
-
-final readonly class ElemAddr
-{
- public function __construct(
- public int $value,
- ) {
- }
-}
diff --git a/src/Execution/ExternAddr.php b/src/Execution/ExternAddr.php
deleted file mode 100644
index 954127c..0000000
--- a/src/Execution/ExternAddr.php
+++ /dev/null
@@ -1,13 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace Nsfisis\Waddiwasi\Execution;
-
-final readonly class ExternAddr
-{
- public function __construct(
- public int $value,
- ) {
- }
-}
diff --git a/src/Execution/ExternVal.php b/src/Execution/ExternVal.php
index f095225..ead0330 100644
--- a/src/Execution/ExternVal.php
+++ b/src/Execution/ExternVal.php
@@ -6,22 +6,22 @@ namespace Nsfisis\Waddiwasi\Execution;
abstract readonly class ExternVal
{
- final public static function Func(FuncAddr $addr): ExternVals\Func
+ final public static function Func(int $addr): ExternVals\Func
{
return new ExternVals\Func($addr);
}
- final public static function Table(TableAddr $addr): ExternVals\Table
+ final public static function Table(int $addr): ExternVals\Table
{
return new ExternVals\Table($addr);
}
- final public static function Mem(MemAddr $addr): ExternVals\Mem
+ final public static function Mem(int $addr): ExternVals\Mem
{
return new ExternVals\Mem($addr);
}
- final public static function Global_(GlobalAddr $addr): ExternVals\Global_
+ final public static function Global_(int $addr): ExternVals\Global_
{
return new ExternVals\Global_($addr);
}
diff --git a/src/Execution/ExternVals/Func.php b/src/Execution/ExternVals/Func.php
index 314d44d..08d01e3 100644
--- a/src/Execution/ExternVals/Func.php
+++ b/src/Execution/ExternVals/Func.php
@@ -5,12 +5,11 @@ declare(strict_types=1);
namespace Nsfisis\Waddiwasi\Execution\ExternVals;
use Nsfisis\Waddiwasi\Execution\ExternVal;
-use Nsfisis\Waddiwasi\Execution\FuncAddr;
final readonly class Func extends ExternVal
{
protected function __construct(
- public FuncAddr $addr,
+ public int $addr,
) {
}
}
diff --git a/src/Execution/ExternVals/Global_.php b/src/Execution/ExternVals/Global_.php
index ae38c78..3142400 100644
--- a/src/Execution/ExternVals/Global_.php
+++ b/src/Execution/ExternVals/Global_.php
@@ -5,12 +5,11 @@ declare(strict_types=1);
namespace Nsfisis\Waddiwasi\Execution\ExternVals;
use Nsfisis\Waddiwasi\Execution\ExternVal;
-use Nsfisis\Waddiwasi\Execution\GlobalAddr;
final readonly class Global_ extends ExternVal
{
protected function __construct(
- public GlobalAddr $addr,
+ public int $addr,
) {
}
}
diff --git a/src/Execution/ExternVals/Mem.php b/src/Execution/ExternVals/Mem.php
index 7bded5a..4839f3b 100644
--- a/src/Execution/ExternVals/Mem.php
+++ b/src/Execution/ExternVals/Mem.php
@@ -5,12 +5,11 @@ declare(strict_types=1);
namespace Nsfisis\Waddiwasi\Execution\ExternVals;
use Nsfisis\Waddiwasi\Execution\ExternVal;
-use Nsfisis\Waddiwasi\Execution\MemAddr;
final readonly class Mem extends ExternVal
{
protected function __construct(
- public MemAddr $addr,
+ public int $addr,
) {
}
}
diff --git a/src/Execution/ExternVals/Table.php b/src/Execution/ExternVals/Table.php
index cd36bb2..6c19b89 100644
--- a/src/Execution/ExternVals/Table.php
+++ b/src/Execution/ExternVals/Table.php
@@ -5,12 +5,11 @@ declare(strict_types=1);
namespace Nsfisis\Waddiwasi\Execution\ExternVals;
use Nsfisis\Waddiwasi\Execution\ExternVal;
-use Nsfisis\Waddiwasi\Execution\TableAddr;
final readonly class Table extends ExternVal
{
protected function __construct(
- public TableAddr $addr,
+ public int $addr,
) {
}
}
diff --git a/src/Execution/FuncAddr.php b/src/Execution/FuncAddr.php
deleted file mode 100644
index 101c7c9..0000000
--- a/src/Execution/FuncAddr.php
+++ /dev/null
@@ -1,13 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace Nsfisis\Waddiwasi\Execution;
-
-final readonly class FuncAddr
-{
- public function __construct(
- public int $value,
- ) {
- }
-}
diff --git a/src/Execution/GlobalAddr.php b/src/Execution/GlobalAddr.php
deleted file mode 100644
index f9a08ff..0000000
--- a/src/Execution/GlobalAddr.php
+++ /dev/null
@@ -1,13 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace Nsfisis\Waddiwasi\Execution;
-
-final readonly class GlobalAddr
-{
- public function __construct(
- public int $value,
- ) {
- }
-}
diff --git a/src/Execution/MemAddr.php b/src/Execution/MemAddr.php
deleted file mode 100644
index 5c141cc..0000000
--- a/src/Execution/MemAddr.php
+++ /dev/null
@@ -1,13 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace Nsfisis\Waddiwasi\Execution;
-
-final readonly class MemAddr
-{
- public function __construct(
- public int $value,
- ) {
- }
-}
diff --git a/src/Execution/ModuleInst.php b/src/Execution/ModuleInst.php
index 2cd7f08..e073916 100644
--- a/src/Execution/ModuleInst.php
+++ b/src/Execution/ModuleInst.php
@@ -10,12 +10,12 @@ final class ModuleInst
{
/**
* @param list<FuncType> $types
- * @param list<FuncAddr> $funcAddrs
- * @param list<TableAddr> $tableAddrs
- * @param list<MemAddr> $memAddrs
- * @param list<GlobalAddr> $globalAddrs
- * @param list<ElemAddr> $elemAddrs
- * @param list<DataAddr> $dataAddrs
+ * @param list<int> $funcAddrs
+ * @param list<int> $tableAddrs
+ * @param list<int> $memAddrs
+ * @param list<int> $globalAddrs
+ * @param list<int> $elemAddrs
+ * @param list<int> $dataAddrs
* @param list<ExportInst> $exports
*/
public function __construct(
diff --git a/src/Execution/Ref.php b/src/Execution/Ref.php
index 4f0c3c1..a5682d3 100644
--- a/src/Execution/Ref.php
+++ b/src/Execution/Ref.php
@@ -13,12 +13,12 @@ abstract readonly class Ref
return new Refs\RefNull($type);
}
- final public static function RefFunc(FuncAddr $addr): Refs\RefFunc
+ final public static function RefFunc(int $addr): Refs\RefFunc
{
return new Refs\RefFunc($addr);
}
- final public static function RefExtern(ExternAddr $addr): Refs\RefExtern
+ final public static function RefExtern(int $addr): Refs\RefExtern
{
return new Refs\RefExtern($addr);
}
diff --git a/src/Execution/Refs/RefExtern.php b/src/Execution/Refs/RefExtern.php
index 4beccb4..8c0509d 100644
--- a/src/Execution/Refs/RefExtern.php
+++ b/src/Execution/Refs/RefExtern.php
@@ -4,13 +4,12 @@ declare(strict_types=1);
namespace Nsfisis\Waddiwasi\Execution\Refs;
-use Nsfisis\Waddiwasi\Execution\ExternAddr;
use Nsfisis\Waddiwasi\Execution\Ref;
final readonly class RefExtern extends Ref
{
public function __construct(
- public ExternAddr $addr,
+ public int $addr,
) {
}
}
diff --git a/src/Execution/Refs/RefFunc.php b/src/Execution/Refs/RefFunc.php
index 449b780..126150c 100644
--- a/src/Execution/Refs/RefFunc.php
+++ b/src/Execution/Refs/RefFunc.php
@@ -4,13 +4,12 @@ declare(strict_types=1);
namespace Nsfisis\Waddiwasi\Execution\Refs;
-use Nsfisis\Waddiwasi\Execution\FuncAddr;
use Nsfisis\Waddiwasi\Execution\Ref;
final readonly class RefFunc extends Ref
{
public function __construct(
- public FuncAddr $addr,
+ public int $addr,
) {
}
}
diff --git a/src/Execution/Runtime.php b/src/Execution/Runtime.php
index 3617de2..5e205b1 100644
--- a/src/Execution/Runtime.php
+++ b/src/Execution/Runtime.php
@@ -11,13 +11,9 @@ use Nsfisis\Waddiwasi\Structure\Instructions\Instrs\Control\BlockTypes;
use Nsfisis\Waddiwasi\Structure\Modules\DataModes;
use Nsfisis\Waddiwasi\Structure\Modules\ElemModes;
use Nsfisis\Waddiwasi\Structure\Modules\Module;
-use Nsfisis\Waddiwasi\Structure\Types\DataIdx;
-use Nsfisis\Waddiwasi\Structure\Types\ElemIdx;
use Nsfisis\Waddiwasi\Structure\Types\FuncType;
-use Nsfisis\Waddiwasi\Structure\Types\LabelIdx;
use Nsfisis\Waddiwasi\Structure\Types\NumType;
use Nsfisis\Waddiwasi\Structure\Types\ResultType;
-use Nsfisis\Waddiwasi\Structure\Types\TableIdx;
use Nsfisis\Waddiwasi\Structure\Types\ValType;
use Nsfisis\Waddiwasi\Structure\Types\ValTypes;
@@ -97,23 +93,23 @@ final class Runtime
array_pop($instrs); // drop "end"
$instrs[] = Instr::I32Const(0);
$instrs[] = Instr::I32Const($n);
- $instrs[] = Instr::TableInit($elem->mode->table, new ElemIdx($i));
- $instrs[] = Instr::ElemDrop(new ElemIdx($i));
+ $instrs[] = Instr::TableInit($elem->mode->table, $i);
+ $instrs[] = Instr::ElemDrop($i);
$runtime->execInstrsForInit($instrs);
} elseif ($elem->mode instanceof ElemModes\Declarative) {
- $runtime->execInstrsForInit([Instr::ElemDrop(new ElemIdx($i))]);
+ $runtime->execInstrsForInit([Instr::ElemDrop($i)]);
}
}
foreach ($module->datas as $i => $data) {
if ($data->mode instanceof DataModes\Active) {
- assert($data->mode->memory->value === 0);
+ assert($data->mode->memory === 0);
$n = count($data->init);
$instrs = $data->mode->offset->instrs;
array_pop($instrs); // drop "end"
$instrs[] = Instr::I32Const(0);
$instrs[] = Instr::I32Const($n);
- $instrs[] = Instr::MemoryInit(new DataIdx($i));
- $instrs[] = Instr::DataDrop(new DataIdx($i));
+ $instrs[] = Instr::MemoryInit($i);
+ $instrs[] = Instr::DataDrop($i);
$runtime->execInstrsForInit($instrs);
}
}
@@ -142,7 +138,7 @@ final class Runtime
{
$export = $this->getExport($name);
if ($export instanceof ExternVals\Table) {
- return $this->store->tables[$export->addr->value];
+ return $this->store->tables[$export->addr];
}
return null;
}
@@ -151,7 +147,7 @@ final class Runtime
{
$export = $this->getExport($name);
if ($export instanceof ExternVals\Mem) {
- return $this->store->mems[$export->addr->value];
+ return $this->store->mems[$export->addr];
}
return null;
}
@@ -175,7 +171,7 @@ final class Runtime
assert($export instanceof ExternVals\Func);
$funcAddr = $export->addr;
- $funcInst = $this->store->funcs[$funcAddr->value];
+ $funcInst = $this->store->funcs[$funcAddr];
assert($funcInst instanceof FuncInsts\Wasm);
$paramTypes = $funcInst->type->params->types;
$resultTypes = $funcInst->type->results->types;
@@ -196,15 +192,15 @@ final class Runtime
return $results;
}
- public function invokeByFuncAddr(FuncAddr $funcAddr): void
+ public function invokeByFuncAddr(int $funcAddr): void
{
$this->doInvokeFunc($funcAddr);
}
- private function doInvokeFunc(FuncAddr $funcAddr): void
+ private function doInvokeFunc(int $funcAddr): void
{
- // echo "Invoke: $funcAddr->value\n";
- $fn = $this->store->funcs[$funcAddr->value];
+ // echo "Invoke: $funcAddr\n";
+ $fn = $this->store->funcs[$funcAddr];
if ($fn instanceof FuncInsts\Wasm) {
$this->doInvokeWasmFunc($fn, $funcAddr);
} elseif ($fn instanceof FuncInsts\Host) {
@@ -212,10 +208,10 @@ final class Runtime
} else {
throw new \RuntimeException("doInvokeFunc: unreachable");
}
- // echo "Return: $funcAddr->value\n";
+ // echo "Return: $funcAddr\n";
}
- private function doInvokeWasmFunc(FuncInsts\Wasm $fn, FuncAddr $funcAddr): void
+ private function doInvokeWasmFunc(FuncInsts\Wasm $fn, int $funcAddr): void
{
$paramTypes = $fn->type->params->types;
$n = count($paramTypes);
@@ -235,7 +231,7 @@ final class Runtime
array_map(fn ($local) => self::defaultValueFromValType($local->type), $ts),
),
$fn->module,
- "wasm: $funcAddr->value",
+ "wasm: $funcAddr",
);
$this->activateFrame($f);
$l = StackEntry::Label($m);
@@ -1517,7 +1513,7 @@ final class Runtime
{
$x = $instr->func;
$f = $this->stack->currentFrame();
- $a = $f->module->funcAddrs[$x->value];
+ $a = $f->module->funcAddrs[$x];
$this->stack->pushRefFunc($a);
}
@@ -1554,8 +1550,8 @@ final class Runtime
{
$x = $instr->var;
$f = $this->stack->currentFrame();
- $a = $f->module->globalAddrs[$x->value];
- $glob = $this->store->globals[$a->value];
+ $a = $f->module->globalAddrs[$x];
+ $glob = $this->store->globals[$a];
$val = $glob->value;
$this->stack->pushValue($val);
}
@@ -1564,8 +1560,8 @@ final class Runtime
{
$x = $instr->var;
$f = $this->stack->currentFrame();
- $a = $f->module->globalAddrs[$x->value];
- $glob = $this->store->globals[$a->value];
+ $a = $f->module->globalAddrs[$x];
+ $glob = $this->store->globals[$a];
$val = $this->stack->popValue();
$glob->value = $val;
}
@@ -1574,9 +1570,9 @@ final class Runtime
{
$x = $instr->var;
$f = $this->stack->currentFrame();
- $val = $f->locals[$x->value] ?? null;
+ $val = $f->locals[$x] ?? null;
if ($val === null) {
- throw new \RuntimeException("local.get: local $x->value not found in [$f->debugName]");
+ throw new \RuntimeException("local.get: local $x not found in [$f->debugName]");
}
$this->stack->pushValue($val);
}
@@ -1587,7 +1583,7 @@ final class Runtime
$f = $this->stack->currentFrame();
$val = $this->stack->popValue();
// @phpstan-ignore-next-line
- $f->locals[$x->value] = $val;
+ $f->locals[$x] = $val;
}
private function execInstrVariableLocalTee(Instrs\Variable\LocalTee $instr): void
@@ -1596,7 +1592,7 @@ final class Runtime
$f = $this->stack->currentFrame();
$val = $this->stack->popValue();
// @phpstan-ignore-next-line
- $f->locals[$x->value] = $val;
+ $f->locals[$x] = $val;
$this->stack->pushValue($val);
}
@@ -1604,10 +1600,10 @@ final class Runtime
{
$x = $instr->elem;
$f = $this->stack->currentFrame();
- $a = $f->module->elemAddrs[$x->value];
- $elem = $this->store->elems[$a->value];
+ $a = $f->module->elemAddrs[$x];
+ $elem = $this->store->elems[$a];
// @phpstan-ignore-next-line
- $this->store->elems[$a->value] = new ElemInst($elem->type, []);
+ $this->store->elems[$a] = new ElemInst($elem->type, []);
}
private function execInstrTableTableCopy(Instrs\Table\TableCopy $instr): void
@@ -1635,10 +1631,10 @@ final class Runtime
$x = $instr->to;
$y = $instr->from;
$f = $this->stack->currentFrame();
- $ta = $f->module->tableAddrs[$x->value];
- $tab = $this->store->tables[$ta->value];
- $ea = $f->module->elemAddrs[$y->value];
- $elem = $this->store->elems[$ea->value];
+ $ta = $f->module->tableAddrs[$x];
+ $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();
@@ -1652,7 +1648,7 @@ final class Runtime
$val = $elem->elem[$s];
$this->stack->pushI32($d);
$this->stack->pushValue(Val::Ref($val));
- $this->execInstr(Instr::TableSet(new TableIdx($x->value)));
+ $this->execInstr(Instr::TableSet($x));
$d++;
$s++;
}
@@ -1662,8 +1658,8 @@ final class Runtime
{
$x = $instr->table;
$f = $this->stack->currentFrame();
- $a = $f->module->tableAddrs[$x->value];
- $tab = $this->store->tables[$a->value];
+ $a = $f->module->tableAddrs[$x];
+ $tab = $this->store->tables[$a];
$val = $this->stack->popRef();
$i = $this->stack->popI32();
if (count($tab->elem) <= $i) {
@@ -1682,9 +1678,9 @@ final class Runtime
{
$x = $instr->data;
$f = $this->stack->currentFrame();
- $a = $f->module->dataAddrs[$x->value];
+ $a = $f->module->dataAddrs[$x];
// @phpstan-ignore-next-line
- $this->store->datas[$a->value] = new DataInst([]);
+ $this->store->datas[$a] = new DataInst([]);
}
private function execInstrMemoryF32Load(Instrs\Memory\F32Load $instr): void
@@ -1822,9 +1818,9 @@ final class Runtime
$x = $instr->data;
$f = $this->stack->currentFrame();
$ma = $f->module->memAddrs[0];
- $mem = $this->store->mems[$ma->value];
- $da = $f->module->dataAddrs[$x->value];
- $data = $this->store->datas[$da->value];
+ $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();
@@ -1848,7 +1844,7 @@ final class Runtime
{
$f = $this->stack->currentFrame();
$a = $f->module->memAddrs[0];
- $mem = $this->store->mems[$a->value];
+ $mem = $this->store->mems[$a];
$szInByte = $mem->size();
assert(is_int($szInByte / (64 * 1024)));
$sz = $szInByte / (64 * 1024);
@@ -1870,11 +1866,11 @@ final class Runtime
} elseif ($result instanceof ControlFlowResults\Return_) {
return $result;
} elseif ($result instanceof ControlFlowResults\Br) {
- if ($result->label->value === 0) {
+ if ($result->label === 0) {
$this->deactivateLabel($n);
} else {
$this->deactivateLabel($n);
- return ControlFlowResult::Br(new LabelIdx($result->label->value - 1));
+ return ControlFlowResult::Br($result->label - 1);
}
} else {
throw new \RuntimeException("block: unreachable");
@@ -1915,7 +1911,7 @@ final class Runtime
{
$x = $instr->func;
$f = $this->stack->currentFrame();
- $a = $f->module->funcAddrs[$x->value];
+ $a = $f->module->funcAddrs[$x];
$this->doInvokeFunc($a);
}
@@ -1924,9 +1920,9 @@ final class Runtime
$x = $instr->funcTable;
$y = $instr->type;
$f = $this->stack->currentFrame();
- $ta = $f->module->tableAddrs[$x->value];
- $tab = $this->store->tables[$ta->value];
- $ftExpect = $f->module->types[$y->value];
+ $ta = $f->module->tableAddrs[$x];
+ $tab = $this->store->tables[$ta];
+ $ftExpect = $f->module->types[$y];
$i = self::wasmI32ToPhpInt($this->stack->popI32());
if (count($tab->elem) <= $i) {
throw new TrapException("call_indirect: out of bounds");
@@ -1937,7 +1933,7 @@ final class Runtime
}
assert($r instanceof Refs\RefFunc);
$a = $r->addr;
- $fn = $this->store->funcs[$a->value];
+ $fn = $this->store->funcs[$a];
assert($fn instanceof FuncInsts\Wasm || $fn instanceof FuncInsts\Host);
$ftActual = $fn->type;
if (!$ftExpect->equals($ftActual)) {
@@ -1985,7 +1981,7 @@ final class Runtime
} elseif ($result instanceof ControlFlowResults\Return_) {
return $result;
} elseif ($result instanceof ControlFlowResults\Br) {
- if ($result->label->value === 0) {
+ if ($result->label === 0) {
if ($n === 1) {
if ($this->stack->top() instanceof StackEntries\Label) {
// echo "loop: top is label\n";
@@ -2001,7 +1997,7 @@ final class Runtime
continue;
} else {
$this->deactivateLabel($n);
- return ControlFlowResult::Br(new LabelIdx($result->label->value - 1));
+ return ControlFlowResult::Br($result->label - 1);
}
} else {
throw new \RuntimeException("loop: unreachable");
@@ -2028,7 +2024,7 @@ final class Runtime
{
$f = $this->stack->currentFrame();
$a = $f->module->memAddrs[0];
- $mem = $this->store->mems[$a->value];
+ $mem = $this->store->mems[$a];
$i = $this->stack->popI32();
$ea = $i + $offset;
$c = $mem->loadI32($ea, $n, $signed);
@@ -2042,7 +2038,7 @@ final class Runtime
{
$f = $this->stack->currentFrame();
$a = $f->module->memAddrs[0];
- $mem = $this->store->mems[$a->value];
+ $mem = $this->store->mems[$a];
$i = $this->stack->popI32();
$ea = $i + $offset;
$c = $mem->loadI64($ea, $n, $signed);
@@ -2056,7 +2052,7 @@ final class Runtime
{
$f = $this->stack->currentFrame();
$a = $f->module->memAddrs[0];
- $mem = $this->store->mems[$a->value];
+ $mem = $this->store->mems[$a];
$i = $this->stack->popI32();
$ea = $i + $offset;
$c = $mem->loadF32($ea);
@@ -2070,7 +2066,7 @@ final class Runtime
{
$f = $this->stack->currentFrame();
$a = $f->module->memAddrs[0];
- $mem = $this->store->mems[$a->value];
+ $mem = $this->store->mems[$a];
$i = $this->stack->popI32();
$ea = $i + $offset;
$c = $mem->loadF64($ea);
@@ -2084,7 +2080,7 @@ final class Runtime
{
$f = $this->stack->currentFrame();
$a = $f->module->memAddrs[0];
- $mem = $this->store->mems[$a->value];
+ $mem = $this->store->mems[$a];
$c = $this->stack->popI32();
$i = $this->stack->popI32();
$ea = $i + $offset;
@@ -2098,7 +2094,7 @@ final class Runtime
{
$f = $this->stack->currentFrame();
$a = $f->module->memAddrs[0];
- $mem = $this->store->mems[$a->value];
+ $mem = $this->store->mems[$a];
$c = $this->stack->popI64();
$i = $this->stack->popI32();
$ea = $i + $offset;
@@ -2112,7 +2108,7 @@ final class Runtime
{
$f = $this->stack->currentFrame();
$a = $f->module->memAddrs[0];
- $mem = $this->store->mems[$a->value];
+ $mem = $this->store->mems[$a];
$c = $this->stack->popF32();
$i = $this->stack->popI32();
$ea = $i + $offset;
@@ -2126,7 +2122,7 @@ final class Runtime
{
$f = $this->stack->currentFrame();
$a = $f->module->memAddrs[0];
- $mem = $this->store->mems[$a->value];
+ $mem = $this->store->mems[$a];
$c = $this->stack->popF64();
$i = $this->stack->popI32();
$ea = $i + $offset;
@@ -2153,7 +2149,7 @@ final class Runtime
private static function expandBlockType(BlockType $bt, ModuleInst $module): FuncType
{
if ($bt instanceof BlockTypes\TypeIdx) {
- return $module->types[$bt->inner->value];
+ return $module->types[$bt->inner];
} elseif ($bt instanceof BlockTypes\ValType) {
$t = $bt->inner;
return new FuncType(
diff --git a/src/Execution/Stack.php b/src/Execution/Stack.php
index 3a40764..467bd9b 100644
--- a/src/Execution/Stack.php
+++ b/src/Execution/Stack.php
@@ -79,12 +79,12 @@ final class Stack
$this->pushValue(Val::RefNull($type));
}
- public function pushRefFunc(FuncAddr $addr): void
+ public function pushRefFunc(int $addr): void
{
$this->pushValue(Val::RefFunc($addr));
}
- public function pushRefExtern(ExternAddr $addr): void
+ public function pushRefExtern(int $addr): void
{
$this->pushValue(Val::RefExtern($addr));
}
diff --git a/src/Execution/TableAddr.php b/src/Execution/TableAddr.php
deleted file mode 100644
index e41eef1..0000000
--- a/src/Execution/TableAddr.php
+++ /dev/null
@@ -1,13 +0,0 @@
-<?php
-
-declare(strict_types=1);
-
-namespace Nsfisis\Waddiwasi\Execution;
-
-final readonly class TableAddr
-{
- public function __construct(
- public int $value,
- ) {
- }
-}
diff --git a/src/Execution/Val.php b/src/Execution/Val.php
index 0f9ce42..1746cae 100644
--- a/src/Execution/Val.php
+++ b/src/Execution/Val.php
@@ -55,12 +55,12 @@ abstract readonly class Val
return self::Ref(Ref::RefNull($type));
}
- final public static function RefFunc(FuncAddr $addr): Vals\Ref
+ final public static function RefFunc(int $addr): Vals\Ref
{
return self::Ref(Ref::RefFunc($addr));
}
- final public static function RefExtern(ExternAddr $addr): Vals\Ref
+ final public static function RefExtern(int $addr): Vals\Ref
{
return self::Ref(Ref::RefExtern($addr));
}