aboutsummaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2024-03-11 22:44:57 +0900
committernsfisis <nsfisis@gmail.com>2024-03-11 22:44:57 +0900
commit75e14575b4ae1a0cc428ccf2944c314b0c908f93 (patch)
tree1b3a4a866f833a523c49412df5d180d6ba68180f /examples
parent3a667844e177dcc2dd7729df00d7368d4a21b84f (diff)
downloadphp-waddiwasi-75e14575b4ae1a0cc428ccf2944c314b0c908f93.tar.gz
php-waddiwasi-75e14575b4ae1a0cc428ccf2944c314b0c908f93.tar.zst
php-waddiwasi-75e14575b4ae1a0cc428ccf2944c314b0c908f93.zip
feat: add minimum test
Diffstat (limited to 'examples')
-rw-r--r--examples/php-on-wasm/php-wasm.php11
1 files changed, 6 insertions, 5 deletions
diff --git a/examples/php-on-wasm/php-wasm.php b/examples/php-on-wasm/php-wasm.php
index 32c375e..f1a26fb 100644
--- a/examples/php-on-wasm/php-wasm.php
+++ b/examples/php-on-wasm/php-wasm.php
@@ -29,15 +29,16 @@ const PHP_HELLO_WORLD = <<<'EOS'
echo "Hello, World!\n";
EOS;
-echo "Decoding...\n";
+fprintf(STDERR, "Decoding...\n");
try {
$module = (new Decoder($wasmBinary))->decode();
// Debug::printImports($module);
} catch (InvalidBinaryFormatException $e) {
- echo $e->getMessage() . PHP_EOL;
+ fprintf(STDERR, $e->getMessage() . "\n");
+ exit(1);
}
-echo "Instantiating...\n";
+fprintf(STDERR, "Instantiating...\n");
$hostFuncs = [
makeHostFunc('(i32, i32, i32) -> (i32)', hostFunc__env__invoke_iii(...)),
makeHostFunc('(i32, i32, i32, i32, i32) -> (i32)', hostFunc__env__invoke_iiiii(...)),
@@ -142,7 +143,7 @@ foreach ($hostFuncs as $hostFunc) {
$runtime = Runtime::instantiate($store, $module, $externVals);
$codePtr = allocateStringOnWasmMemory($runtime, PHP_HELLO_WORLD);
-echo "Executing...\n";
+fprintf(STDERR, "Executing...\n");
$results = $runtime->invoke("php_wasm_run", [Val::NumI32($codePtr)]);
assert(count($results) === 1);
$result = $results[0];
@@ -150,7 +151,7 @@ assert($result instanceof Vals\Num);
assert($result->inner instanceof Nums\I32);
$exitCode = $result->inner->value;
-echo "Exit code: $exitCode\n";
+fprintf(STDERR, "Exit code: $exitCode\n");
function allocateStringOnWasmMemory(Runtime $runtime, string $str): int {
// Plus 1 for the null terminator in C.