From e94a046a548795b8675bc109c87413de6bca53e7 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Fri, 12 Jul 2024 22:39:20 +0900 Subject: feat: add Linker class --- examples/php-on-wasm/php-wasm.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'examples/php-on-wasm') 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]); -- cgit v1.2.3-70-g09d2