diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-07-12 22:39:20 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-07-13 08:23:06 +0900 |
| commit | e94a046a548795b8675bc109c87413de6bca53e7 (patch) | |
| tree | 9958efead32039de87f3564c77a7b09f978a13ef /examples | |
| parent | d1c268b76f65e69ea708096d5023c4d731cff594 (diff) | |
| download | php-waddiwasi-e94a046a548795b8675bc109c87413de6bca53e7.tar.gz php-waddiwasi-e94a046a548795b8675bc109c87413de6bca53e7.tar.zst php-waddiwasi-e94a046a548795b8675bc109c87413de6bca53e7.zip | |
feat: add Linker class
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/php-on-wasm/php-wasm.php | 12 | ||||
| -rw-r--r-- | examples/rubyvm-on-php-on-wasm/php-wasm.php | 12 |
2 files changed, 22 insertions, 2 deletions
diff --git a/examples/php-on-wasm/php-wasm.php b/examples/php-on-wasm/php-wasm.php index fe1d327..11bb5ac 100644 --- a/examples/php-on-wasm/php-wasm.php +++ b/examples/php-on-wasm/php-wasm.php @@ -9,6 +9,7 @@ use Nsfisis\Waddiwasi\WebAssembly\BinaryFormat\Decoder; use Nsfisis\Waddiwasi\WebAssembly\Execution\Extern; use Nsfisis\Waddiwasi\WebAssembly\Execution\Externs; use Nsfisis\Waddiwasi\WebAssembly\Execution\FuncInst; +use Nsfisis\Waddiwasi\WebAssembly\Execution\Linker; use Nsfisis\Waddiwasi\WebAssembly\Execution\Refs; use Nsfisis\Waddiwasi\WebAssembly\Execution\Runtime; use Nsfisis\Waddiwasi\WebAssembly\Execution\Store; @@ -123,7 +124,16 @@ $imports = [ ], ]; -$runtime = Runtime::instantiate(Store::empty(), $module, $imports); +$store = Store::empty(); +$linker = new Linker($store); + +foreach ($imports as $moduleName => $moduleImports) { + foreach ($moduleImports as $importName => $import) { + $linker->register($moduleName, $importName, $import); + } +} + +$runtime = Runtime::instantiate($store, $module, $linker->resolve($module)); $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 726f6d1..b86c6a2 100644 --- a/examples/rubyvm-on-php-on-wasm/php-wasm.php +++ b/examples/rubyvm-on-php-on-wasm/php-wasm.php @@ -9,6 +9,7 @@ use Nsfisis\Waddiwasi\WebAssembly\BinaryFormat\Decoder; use Nsfisis\Waddiwasi\WebAssembly\Execution\Extern; use Nsfisis\Waddiwasi\WebAssembly\Execution\Externs; use Nsfisis\Waddiwasi\WebAssembly\Execution\FuncInst; +use Nsfisis\Waddiwasi\WebAssembly\Execution\Linker; use Nsfisis\Waddiwasi\WebAssembly\Execution\Refs; use Nsfisis\Waddiwasi\WebAssembly\Execution\Runtime; use Nsfisis\Waddiwasi\WebAssembly\Execution\Store; @@ -123,7 +124,16 @@ $imports = [ ], ]; -$runtime = Runtime::instantiate(Store::empty(), $module, $imports); +$store = Store::empty(); +$linker = new Linker($store); + +foreach ($imports as $moduleName => $moduleImports) { + foreach ($moduleImports as $importName => $import) { + $linker->register($moduleName, $importName, $import); + } +} + +$runtime = Runtime::instantiate($store, $module, $linker->resolve($module)); $codePtr = allocateStringOnWasmMemory($runtime, strtr(PHP_HELLO_WORLD, ['%DIR%' => __DIR__])); $results = $runtime->invoke("php_wasm_run", [$codePtr]); |
