From: Brendan Hansen Date: Thu, 31 Dec 2020 04:22:15 +0000 (-0600) Subject: cleaning up more things X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=34b94061cd7aa1ac6348041925ad8cf49206c2ff;p=onyx.git cleaning up more things --- diff --git a/bin/onyx-js b/bin/onyx-js new file mode 100755 index 00000000..757f30f1 --- /dev/null +++ b/bin/onyx-js @@ -0,0 +1,25 @@ +#!/usr/bin/env node + +const fs = require('fs'); +const buf = fs.readFileSync(process.argv[2]); + +let wasm_memory; + +const ENV = { + host: { + print_str(ptr, len) { + const data = new Uint8Array(wasm_memory, ptr, len); + const str = new TextDecoder().decode(data); + process.stdout.write(str); + } + } +} + +WebAssembly.instantiate(new Uint8Array(buf), ENV) + .then(res => { + const lib = res.instance.exports; + wasm_memory = lib.memory.buffer; + + lib._start(); + }); + diff --git a/bin/test b/bin/test index 01d8dd6a..8de7a619 100755 --- a/bin/test +++ b/bin/test @@ -13,7 +13,7 @@ for test_file in ./tests/*.onyx ; do continue fi - if ! node onyxcmd.js "./tests/$name.wasm" > ./tmpoutput; then + if ! ./bin/onyx-js "./tests/$name.wasm" > ./tmpoutput; then echo "❌ Failed to run $name.onyx." failed=1 continue diff --git a/onyxcmd.js b/onyxcmd.js deleted file mode 100644 index cd007524..00000000 --- a/onyxcmd.js +++ /dev/null @@ -1,23 +0,0 @@ -const fs = require('fs'); -const buf = fs.readFileSync(process.argv[2]); - -let wasm_memory; - -const ENV = { - host: { - print_str(ptr, len) { - const data = new Uint8Array(wasm_memory, ptr, len); - const str = new TextDecoder().decode(data); - process.stdout.write(str); - } - } -} - -WebAssembly.instantiate(new Uint8Array(buf), ENV) - .then(res => { - const lib = res.instance.exports; - wasm_memory = lib.memory.buffer; - - lib._start(); - }); -