aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Execution/Store.php
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-07-10 19:30:09 +0900
committernsfisis <nsfisis@gmail.com>2024-07-10 19:30:20 +0900
commit2984d445831ebf0cd8c909f589dc203018ae2b0b (patch)
tree465c6e304b85fcd322389dd8b530cea5acabd929 /src/Execution/Store.php
parent1011da8798ba7370d914dbce9feac1b06ab81ed5 (diff)
downloadphp-waddiwasi-2984d445831ebf0cd8c909f589dc203018ae2b0b.tar.gz
php-waddiwasi-2984d445831ebf0cd8c909f589dc203018ae2b0b.tar.zst
php-waddiwasi-2984d445831ebf0cd8c909f589dc203018ae2b0b.zip
test: implement "register" action of WAST
Diffstat (limited to 'src/Execution/Store.php')
-rw-r--r--src/Execution/Store.php19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/Execution/Store.php b/src/Execution/Store.php
index 2b1a26d..52a8ce1 100644
--- a/src/Execution/Store.php
+++ b/src/Execution/Store.php
@@ -4,6 +4,7 @@ declare(strict_types=1);
namespace Nsfisis\Waddiwasi\Execution;
+use RuntimeException;
use function count;
final class Store
@@ -31,9 +32,21 @@ final class Store
return new self([], [], [], [], [], []);
}
- public function registerFunc(FuncInst $func): ExternVals\Func
+ public function register(Extern $extern): ExternVal
{
- $this->funcs[] = $func;
- return ExternVal::Func(count($this->funcs) - 1);
+ 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"),
+ };
}
}