diff options
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/php-on-wasm/php-wasm.php | 15 | ||||
| -rw-r--r-- | examples/rubyvm-on-php-on-wasm/php-wasm.php | 32 |
2 files changed, 6 insertions, 41 deletions
diff --git a/examples/php-on-wasm/php-wasm.php b/examples/php-on-wasm/php-wasm.php index 92871cd..697b5b3 100644 --- a/examples/php-on-wasm/php-wasm.php +++ b/examples/php-on-wasm/php-wasm.php @@ -5,33 +5,24 @@ declare(strict_types=1); require_once __DIR__ . '/../../vendor/autoload.php'; use Nsfisis\Waddiwasi\BinaryFormat\Decoder; -use Nsfisis\Waddiwasi\BinaryFormat\InvalidBinaryFormatException; use Nsfisis\Waddiwasi\Execution\Extern; use Nsfisis\Waddiwasi\Execution\Externs; use Nsfisis\Waddiwasi\Execution\FuncInst; use Nsfisis\Waddiwasi\Execution\Refs; use Nsfisis\Waddiwasi\Execution\Runtime; use Nsfisis\Waddiwasi\Execution\Store; +use Nsfisis\Waddiwasi\Stream\FileStream; use Nsfisis\Waddiwasi\Structure\Types\FuncType; use Nsfisis\Waddiwasi\Structure\Types\NumType; use Nsfisis\Waddiwasi\Structure\Types\ResultType; use Nsfisis\Waddiwasi\Structure\Types\ValType; -const PHP_EMPTY = ''; - const PHP_HELLO_WORLD = <<<'EOS' echo "Hello, World!\n"; EOS; -$wasmBinary = file_get_contents(__DIR__ . '/php-wasm.wasm'); -\assert($wasmBinary !== false); - -try { - $module = (new Decoder($wasmBinary))->decode(); -} catch (InvalidBinaryFormatException $e) { - fprintf(STDERR, $e->getMessage() . "\n"); - exit(1); -} +$wasmBinaryStream = new FileStream(__DIR__ . '/php-wasm.wasm'); +$module = (new Decoder($wasmBinaryStream))->decode(); $imports = [ 'env' => [ diff --git a/examples/rubyvm-on-php-on-wasm/php-wasm.php b/examples/rubyvm-on-php-on-wasm/php-wasm.php index b24641d..723e210 100644 --- a/examples/rubyvm-on-php-on-wasm/php-wasm.php +++ b/examples/rubyvm-on-php-on-wasm/php-wasm.php @@ -5,34 +5,24 @@ declare(strict_types=1); require_once __DIR__ . '/vendor/autoload.php'; use Nsfisis\Waddiwasi\BinaryFormat\Decoder; -use Nsfisis\Waddiwasi\BinaryFormat\InvalidBinaryFormatException; use Nsfisis\Waddiwasi\Execution\Extern; use Nsfisis\Waddiwasi\Execution\Externs; use Nsfisis\Waddiwasi\Execution\FuncInst; -use Nsfisis\Waddiwasi\Execution\MemInst; use Nsfisis\Waddiwasi\Execution\Refs; use Nsfisis\Waddiwasi\Execution\Runtime; use Nsfisis\Waddiwasi\Execution\Store; +use Nsfisis\Waddiwasi\Stream\FileStream; use Nsfisis\Waddiwasi\Structure\Types\FuncType; use Nsfisis\Waddiwasi\Structure\Types\NumType; use Nsfisis\Waddiwasi\Structure\Types\ResultType; use Nsfisis\Waddiwasi\Structure\Types\ValType; -const PHP_EMPTY = ''; - const PHP_HELLO_WORLD = <<<'EOS' require_once '%DIR%/HelloWorld.php'; EOS; -$wasmBinary = file_get_contents(__DIR__ . '/php-wasm.wasm'); -\assert($wasmBinary !== false); - -try { - $module = (new Decoder($wasmBinary))->decode(); -} catch (InvalidBinaryFormatException $e) { - fprintf(STDERR, $e->getMessage() . "\n"); - exit(1); -} +$wasmBinaryStream = new FileStream(__DIR__ . '/php-wasm.wasm'); +$module = (new Decoder($wasmBinaryStream))->decode(); $imports = [ 'env' => [ @@ -142,22 +132,6 @@ $results = $runtime->invoke("php_wasm_run", [$codePtr]); $exitCode = $results[0]; \assert(\is_int($exitCode)); -function dumpMemory(MemInst $mem): void -{ - $buf = ''; - $s = $mem->size(); - for ($j = 0; $j < $s; $j++) { - $c = $mem->loadByte($j); - \assert($c !== null); - $buf .= \chr($c); - if ($j % 1024 === 1023) { - fputs(STDOUT, $buf); - $buf = ""; - } - } - fputs(STDOUT, $buf); -} - function allocateStringOnWasmMemory(Runtime $runtime, string $str): int { // Plus 1 for the null terminator in C. |
