diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-02-26 13:21:22 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-03-03 15:27:26 +0900 |
| commit | 996259e6a1a04f91179d2b83cc19e3fbb371cd33 (patch) | |
| tree | 14ccabf37cc909c8c61899ffb84429fdeb8dfce0 /src/Execution/Allocator.php | |
| parent | 8a789bffe72e93ae24ea39648018e5fecf94c7fa (diff) | |
| download | php-waddiwasi-996259e6a1a04f91179d2b83cc19e3fbb371cd33.tar.gz php-waddiwasi-996259e6a1a04f91179d2b83cc19e3fbb371cd33.tar.zst php-waddiwasi-996259e6a1a04f91179d2b83cc19e3fbb371cd33.zip | |
feat: implement some of instructions
Diffstat (limited to 'src/Execution/Allocator.php')
| -rw-r--r-- | src/Execution/Allocator.php | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/Execution/Allocator.php b/src/Execution/Allocator.php index ad62fc7..89e1f83 100644 --- a/src/Execution/Allocator.php +++ b/src/Execution/Allocator.php @@ -29,9 +29,11 @@ final readonly class Allocator $m = new ModuleInst($module->types, [], [], [], [], [], [], []); foreach ($externVals as $externVal) { - if ($externVal instanceof ExternVals\Global_) { - $m->globalAddrs[] = $externVal->addr; - } + match ($externVal::class) { + ExternVals\Func::class => $m->funcAddrs[] = $externVal->addr, + ExternVals\Global_::class => $m->globalAddrs[] = $externVal->addr, + default => null, + }; } foreach ($module->funcs as $func) { $m->funcAddrs[] = $this->allocFunc($func, $m); @@ -57,7 +59,7 @@ final readonly class Allocator foreach ($externVals as $externVal) { match ($externVal::class) { - ExternVals\Func::class => $m->funcAddrs[] = $externVal->addr, + ExternVals\Func::class => null, // handled below. ExternVals\Table::class => $m->tableAddrs[] = $externVal->addr, ExternVals\Mem::class => $m->memAddrs[] = $externVal->addr, ExternVals\Global_::class => $m->globalAddrs[] = $externVal->addr, @@ -68,13 +70,14 @@ final readonly class Allocator foreach ($preAllocatedFuncs as $funcAddr) { $m->funcAddrs[] = $funcAddr; $funcInst = $this->store->funcs[$funcAddr->value]; - assert($funcInst instanceof FuncInsts\Wasm); - // @phpstan-ignore-next-line - $this->store->funcs[$funcAddr->value] = FuncInst::Wasm( - $funcInst->type, - $m, - $funcInst->code, - ); + if ($funcInst instanceof FuncInsts\Wasm) { + // @phpstan-ignore-next-line + $this->store->funcs[$funcAddr->value] = FuncInst::Wasm( + $funcInst->type, + $m, + $funcInst->code, + ); + } } foreach ($module->tables as $table) { $m->tableAddrs[] = $this->allocTable($table->type, Ref::RefNull($table->type->refType)); |
