aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples/rubyvm-on-php-on-wasm
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-07-12 22:39:20 +0900
committernsfisis <nsfisis@gmail.com>2024-07-13 08:23:06 +0900
commite94a046a548795b8675bc109c87413de6bca53e7 (patch)
tree9958efead32039de87f3564c77a7b09f978a13ef /examples/rubyvm-on-php-on-wasm
parentd1c268b76f65e69ea708096d5023c4d731cff594 (diff)
downloadphp-waddiwasi-e94a046a548795b8675bc109c87413de6bca53e7.tar.gz
php-waddiwasi-e94a046a548795b8675bc109c87413de6bca53e7.tar.zst
php-waddiwasi-e94a046a548795b8675bc109c87413de6bca53e7.zip
feat: add Linker class
Diffstat (limited to 'examples/rubyvm-on-php-on-wasm')
-rw-r--r--examples/rubyvm-on-php-on-wasm/php-wasm.php12
1 files changed, 11 insertions, 1 deletions
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]);