diff options
| author | nsfisis <nsfisis@gmail.com> | 2024-07-07 14:44:45 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2024-07-07 14:44:45 +0900 |
| commit | e79241c1988e7c0b3d422cdb99c9a105d0cfa903 (patch) | |
| tree | 6d341707f561a13c36bc376c623b034c2d9b551a | |
| parent | 378a315f15a26158885d4e1b14cb97cf04676ba9 (diff) | |
| download | php-waddiwasi-e79241c1988e7c0b3d422cdb99c9a105d0cfa903.tar.gz php-waddiwasi-e79241c1988e7c0b3d422cdb99c9a105d0cfa903.tar.zst php-waddiwasi-e79241c1988e7c0b3d422cdb99c9a105d0cfa903.zip | |
refactor: add Store::registerFunc()
| -rw-r--r-- | examples/php-on-wasm/php-wasm.php | 4 | ||||
| -rw-r--r-- | examples/rubyvm-on-php-on-wasm/php-wasm.php | 4 | ||||
| -rw-r--r-- | src/Execution/Store.php | 8 |
3 files changed, 10 insertions, 6 deletions
diff --git a/examples/php-on-wasm/php-wasm.php b/examples/php-on-wasm/php-wasm.php index 9072bf0..1faebe6 100644 --- a/examples/php-on-wasm/php-wasm.php +++ b/examples/php-on-wasm/php-wasm.php @@ -6,7 +6,6 @@ require_once __DIR__ . '/../../vendor/autoload.php'; use Nsfisis\Waddiwasi\BinaryFormat\Decoder; use Nsfisis\Waddiwasi\BinaryFormat\InvalidBinaryFormatException; -use Nsfisis\Waddiwasi\Execution\ExternVal; use Nsfisis\Waddiwasi\Execution\FuncInst; use Nsfisis\Waddiwasi\Execution\Refs; use Nsfisis\Waddiwasi\Execution\Runtime; @@ -130,8 +129,7 @@ $hostFuncs = [ $store = Store::empty(); $externVals = []; foreach ($hostFuncs as $hostFunc) { - $store->funcs[] = $hostFunc; - $externVals[] = ExternVal::Func(\count($store->funcs) - 1); + $externVals[] = $store->registerFunc($hostFunc); } $runtime = Runtime::instantiate($store, $module, $externVals); $codePtr = allocateStringOnWasmMemory($runtime, PHP_HELLO_WORLD); diff --git a/examples/rubyvm-on-php-on-wasm/php-wasm.php b/examples/rubyvm-on-php-on-wasm/php-wasm.php index 704254f..fa17f27 100644 --- a/examples/rubyvm-on-php-on-wasm/php-wasm.php +++ b/examples/rubyvm-on-php-on-wasm/php-wasm.php @@ -6,7 +6,6 @@ require_once __DIR__ . '/vendor/autoload.php'; use Nsfisis\Waddiwasi\BinaryFormat\Decoder; use Nsfisis\Waddiwasi\BinaryFormat\InvalidBinaryFormatException; -use Nsfisis\Waddiwasi\Execution\ExternVal; use Nsfisis\Waddiwasi\Execution\FuncInst; use Nsfisis\Waddiwasi\Execution\MemInst; use Nsfisis\Waddiwasi\Execution\Refs; @@ -131,8 +130,7 @@ $hostFuncs = [ $store = Store::empty(); $externVals = []; foreach ($hostFuncs as $hostFunc) { - $store->funcs[] = $hostFunc; - $externVals[] = ExternVal::Func(\count($store->funcs) - 1); + $externVals[] = $store->registerFunc($hostFunc); } $runtime = Runtime::instantiate($store, $module, $externVals); $codePtr = allocateStringOnWasmMemory($runtime, strtr(PHP_HELLO_WORLD, ['%DIR%' => __DIR__])); diff --git a/src/Execution/Store.php b/src/Execution/Store.php index b7b0dfc..2b1a26d 100644 --- a/src/Execution/Store.php +++ b/src/Execution/Store.php @@ -4,6 +4,8 @@ declare(strict_types=1); namespace Nsfisis\Waddiwasi\Execution; +use function count; + final class Store { /** @@ -28,4 +30,10 @@ final class Store { return new self([], [], [], [], [], []); } + + public function registerFunc(FuncInst $func): ExternVals\Func + { + $this->funcs[] = $func; + return ExternVal::Func(count($this->funcs) - 1); + } } |
