diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-07-18 02:39:36 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-07-18 02:39:36 +0900 |
| commit | c44c6f91b89508a71a838406b286d114e461ca18 (patch) | |
| tree | 8e90f3c630924f02114bdb65c01ef0ee81657d33 | |
| parent | 402d690243533cc1d1e164da1d44b8d913574aa8 (diff) | |
| download | php-waddiwasi-c44c6f91b89508a71a838406b286d114e461ca18.tar.gz php-waddiwasi-c44c6f91b89508a71a838406b286d114e461ca18.tar.zst php-waddiwasi-c44c6f91b89508a71a838406b286d114e461ca18.zip | |
refactor: simplify Runtime::instantiate()'s parameters
| -rw-r--r-- | examples/hello-world/index.php | 2 | ||||
| -rw-r--r-- | examples/php-on-wasm/php-wasm.php | 2 | ||||
| -rw-r--r-- | examples/rubyvm-on-php-on-wasm/php-wasm.php | 2 | ||||
| -rw-r--r-- | src/WebAssembly/Execution/Linker.php | 2 | ||||
| -rw-r--r-- | src/WebAssembly/Execution/Runtime.php | 9 | ||||
| -rw-r--r-- | tests/src/SpecTestsuites/SpecTestsuiteBase.php | 6 |
6 files changed, 11 insertions, 12 deletions
diff --git a/examples/hello-world/index.php b/examples/hello-world/index.php index 9b0b1bd..6129a07 100644 --- a/examples/hello-world/index.php +++ b/examples/hello-world/index.php @@ -30,6 +30,6 @@ $linker = new Linker($store); $linker->register('', 'putc', Extern::Func(FuncInst::Host(new FuncType([ValType::I32], []), function (Runtime $runtime, int $c) { printf('%c', $c); }))); -$runtime = Runtime::instantiate($store, $module, $linker->resolve($module)); +$runtime = Runtime::instantiate($module, $linker); $runtime->invoke('main', []); diff --git a/examples/php-on-wasm/php-wasm.php b/examples/php-on-wasm/php-wasm.php index 11bb5ac..78196d6 100644 --- a/examples/php-on-wasm/php-wasm.php +++ b/examples/php-on-wasm/php-wasm.php @@ -133,7 +133,7 @@ foreach ($imports as $moduleName => $moduleImports) { } } -$runtime = Runtime::instantiate($store, $module, $linker->resolve($module)); +$runtime = Runtime::instantiate($module, $linker); $codePtr = allocateStringOnWasmMemory($runtime, PHP_HELLO_WORLD); $results = $runtime->invoke("php_wasm_run", [$codePtr]); diff --git a/examples/rubyvm-on-php-on-wasm/php-wasm.php b/examples/rubyvm-on-php-on-wasm/php-wasm.php index 73c0f19..492d91e 100644 --- a/examples/rubyvm-on-php-on-wasm/php-wasm.php +++ b/examples/rubyvm-on-php-on-wasm/php-wasm.php @@ -133,7 +133,7 @@ foreach ($imports as $moduleName => $moduleImports) { } } -$runtime = Runtime::instantiate($store, $module, $linker->resolve($module)); +$runtime = Runtime::instantiate($module, $linker); $codePtr = allocateStringOnWasmMemory($runtime, strtr(PHP_HELLO_WORLD, ['%DIR%' => __DIR__])); $results = $runtime->invoke("php_wasm_run", [$codePtr]); diff --git a/src/WebAssembly/Execution/Linker.php b/src/WebAssembly/Execution/Linker.php index 3c9c1d0..89aaaba 100644 --- a/src/WebAssembly/Execution/Linker.php +++ b/src/WebAssembly/Execution/Linker.php @@ -14,7 +14,7 @@ final class Linker private array $symbols = []; public function __construct( - private Store $store, + public readonly Store $store, ) { } diff --git a/src/WebAssembly/Execution/Runtime.php b/src/WebAssembly/Execution/Runtime.php index 2604212..1bb440b 100644 --- a/src/WebAssembly/Execution/Runtime.php +++ b/src/WebAssembly/Execution/Runtime.php @@ -39,14 +39,13 @@ final class Runtime implements ExporterInterface ) { } - /** - * @param list<ExternVal> $externVals - */ public static function instantiate( - Store $store, Module $module, - array $externVals, + Linker $linker, ): self { + $store = $linker->store; + $externVals = $linker->resolve($module); + $allocator = new Allocator($store); $moduleInstInit = $allocator->allocPreInitModule($module, $externVals); diff --git a/tests/src/SpecTestsuites/SpecTestsuiteBase.php b/tests/src/SpecTestsuites/SpecTestsuiteBase.php index 341ca4b..3e3f5a1 100644 --- a/tests/src/SpecTestsuites/SpecTestsuiteBase.php +++ b/tests/src/SpecTestsuites/SpecTestsuiteBase.php @@ -89,7 +89,7 @@ abstract class SpecTestsuiteBase extends TestCase foreach (self::$registeredRuntimes as $registeredModuleName => $registeredRuntime) { $linker->registerNamespace($registeredModuleName, $registeredRuntime); } - $runtime = Runtime::instantiate(self::$store, $module, $linker->resolve($module)); + $runtime = Runtime::instantiate($module, $linker); self::$runtimes[$moduleName] = $runtime; if ($moduleName !== '_') { self::$modules['_'] = $module; @@ -187,7 +187,7 @@ abstract class SpecTestsuiteBase extends TestCase $linker->registerNamespace($registeredModuleName, $registeredRuntime); } try { - Runtime::instantiate(self::$store, $module, $linker->resolve($module)); + Runtime::instantiate($module, $linker); } catch (RuntimeException $e) { $exception = $e; } @@ -212,7 +212,7 @@ abstract class SpecTestsuiteBase extends TestCase $linker->registerNamespace($registeredModuleName, $registeredRuntime); } try { - Runtime::instantiate(self::$store, $module, $linker->resolve($module)); + Runtime::instantiate($module, $linker); } catch (RuntimeException $e) { $exception = $e; } |
