From 73ea5ace97f80cd93499c1eb851093e4d13129c4 Mon Sep 17 00:00:00 2001 From: David Konsumer Date: Fri, 18 Oct 2024 17:10:15 -0700 Subject: [PATCH] fixed AS passing pointers using correct runtime --- cart/as/build.js | 8 +++----- cart/as/src/main.ts | 2 +- null0_api/src/null0_api_wamr.h | 10 ++++------ 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/cart/as/build.js b/cart/as/build.js index cd33165..68c8411 100644 --- a/cart/as/build.js +++ b/cart/as/build.js @@ -18,9 +18,7 @@ await writeFile('build/tmp.ts', (await readFile('null0.ts')) + '\n// user-code:\ const { error, stdout, stderr, stats } = await asc.main([ 'build/tmp.ts', - // '--lowMemoryLimit', - '--stackSize', '2097152', - '--runtime', 'stub', + '--runtime', 'minimal', '--config', './node_modules/@assemblyscript/wasi-shim/asconfig.json', '--optimizeLevel', '3', '--shrinkLevel', '2', @@ -33,7 +31,7 @@ await unlink('build/tmp.ts') if (error) { console.error(stderr.toString()) -}else { +} else { console.log(`Creating build/${npm_package_name}.null0`) await copy('src/assets', `build/${npm_package_name}/assets`) const output = createWriteStream(`build/${npm_package_name}.null0`) @@ -41,4 +39,4 @@ if (error) { archive.directory(`build/${npm_package_name}`, false) await archive.finalize() await copy(`build/${npm_package_name}.null0`, `../../build/cart/${npm_package_name}.null0`) -} \ No newline at end of file +} diff --git a/cart/as/src/main.ts b/cart/as/src/main.ts index 2c2367e..9884951 100644 --- a/cart/as/src/main.ts +++ b/cart/as/src/main.ts @@ -11,7 +11,7 @@ export function load(): void { const t = file_read("assets/cyber.txt") trace(`WASM ArrayBuffer size: ${t.byteLength.toString()}`) - trace(String.UTF8.decode(t)) + trace(String.UTF8.decode(t, false)) } // called on every frame diff --git a/null0_api/src/null0_api_wamr.h b/null0_api/src/null0_api_wamr.h index 3338c2d..846a4f2 100755 --- a/null0_api/src/null0_api_wamr.h +++ b/null0_api/src/null0_api_wamr.h @@ -60,12 +60,10 @@ void params_from_sfx_to_wasm(SfxParams* s, SfxParams* sOut) { } // Read a file from cart (or local persistant) -// currently having issues in AS, so maybe try https://github.com/bytecodealliance/wasm-micro-runtime/issues/2751 -static void wamr_null0_file_read(wasm_exec_env_t exec_env, char* filename, uint32_t* bytesRead, char* retBytes) { - char* bytesHost = null0_file_read(filename, bytesRead); - memcpy(retBytes, bytesHost, *bytesRead); - printf("HOST bytesRead: %u\n", *bytesRead); - free(bytesHost); +// ($**) +static void wamr_null0_file_read(wasm_exec_env_t exec_env, char* filename, uint32_t* wasmBytesRead, char* wasmRetBytes) { + char* hostBytes = null0_file_read(filename, wasmBytesRead); + memcpy(wasmRetBytes, hostBytes, *wasmBytesRead); } // Get the user's writable dir (where file writes or appends go)