diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-07-11 20:02:34 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-07-11 20:02:34 +0900 |
| commit | d1c268b76f65e69ea708096d5023c4d731cff594 (patch) | |
| tree | e48836287272388df613a370fda7a46598c517f8 /src/WebAssembly/Execution/Store.php | |
| parent | e4324d3d1d3bf3568d4e2f3b80c9cc324d324f83 (diff) | |
| download | php-waddiwasi-d1c268b76f65e69ea708096d5023c4d731cff594.tar.gz php-waddiwasi-d1c268b76f65e69ea708096d5023c4d731cff594.tar.zst php-waddiwasi-d1c268b76f65e69ea708096d5023c4d731cff594.zip | |
fix: various spectests
Diffstat (limited to 'src/WebAssembly/Execution/Store.php')
| -rw-r--r-- | src/WebAssembly/Execution/Store.php | 50 |
1 files changed, 36 insertions, 14 deletions
diff --git a/src/WebAssembly/Execution/Store.php b/src/WebAssembly/Execution/Store.php index 5bef648..18f8626 100644 --- a/src/WebAssembly/Execution/Store.php +++ b/src/WebAssembly/Execution/Store.php @@ -34,19 +34,41 @@ final class Store public function register(Extern $extern): ExternVal { - match ($extern::class) { - Externs\Func::class => $this->funcs[] = $extern->func, - Externs\Table::class => $this->tables[] = $extern->table, - Externs\Mem::class => $this->mems[] = $extern->mem, - Externs\Global_::class => $this->globals[] = $extern->global, - default => throw new RuntimeException("unreachable"), - }; - return match ($extern::class) { - Externs\Func::class => ExternVal::Func(count($this->funcs) - 1), - Externs\Table::class => ExternVal::Table(count($this->tables) - 1), - Externs\Mem::class => ExternVal::Mem(count($this->mems) - 1), - Externs\Global_::class => ExternVal::Global_(count($this->globals) - 1), - default => throw new RuntimeException("unreachable"), - }; + switch ($extern::class) { + case Externs\Func::class: + foreach ($this->funcs as $i => $f) { + if ($f === $extern->func) { + return ExternVal::Func($i); + } + } + $this->funcs[] = $extern->func; + return ExternVal::Func(count($this->funcs) - 1); + case Externs\Table::class: + foreach ($this->tables as $i => $t) { + if ($t === $extern->table) { + return ExternVal::Table($i); + } + } + $this->tables[] = $extern->table; + return ExternVal::Table(count($this->tables) - 1); + case Externs\Mem::class: + foreach ($this->mems as $i => $m) { + if ($m === $extern->mem) { + return ExternVal::Mem($i); + } + } + $this->mems[] = $extern->mem; + return ExternVal::Mem(count($this->mems) - 1); + case Externs\Global_::class: + foreach ($this->globals as $i => $g) { + if ($g === $extern->global) { + return ExternVal::Global_($i); + } + } + $this->globals[] = $extern->global; + return ExternVal::Global_(count($this->globals) - 1); + default: + throw new RuntimeException("unreachable"); + } } } |
