blob: c66b79cc20b3414709b1dee26c6aec8a44705467 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
<?php
declare(strict_types=1);
require_once __DIR__ . '/../../vendor/autoload.php';
use Nsfisis\Waddiwasi\Stream\FileStream;
use Nsfisis\Waddiwasi\WebAssembly\Execution\Runtime;
const PHP_HELLO_WORLD = <<<'EOS'
echo "Hello, World!\n";
EOS;
$linker = (require_once __DIR__ . '/emscripten_bridge.php');
$wasmBinaryStream = new FileStream(__DIR__ . '/php-wasm.wasm');
$runtime = Runtime::instantiateFromStream($wasmBinaryStream, $linker);
$codePtr = allocateStringOnWasmMemory($runtime, PHP_HELLO_WORLD);
$results = $runtime->invoke("php_wasm_run", [$codePtr]);
\assert(\count($results) === 1);
$exitCode = $results[0];
\assert(\is_int($exitCode));
|