diff options
| -rw-r--r-- | src/js/tinyvm.ts | 5 | ||||
| -rwxr-xr-x | tests/test.sh | 1 |
2 files changed, 5 insertions, 1 deletions
diff --git a/src/js/tinyvm.ts b/src/js/tinyvm.ts index 51b390b..5ee29c7 100644 --- a/src/js/tinyvm.ts +++ b/src/js/tinyvm.ts @@ -179,6 +179,7 @@ export class TinyVM { should resume it after its event loop has run, whether or not input came. */ public polling: boolean = false; private outputBuffer: number[] = []; + private exitCode: number | null = null; private onOutput?: (byte: number) => void; private onMessage?: (msg: string) => void; @@ -439,7 +440,8 @@ export class TinyVM { return -1n; case 6: // time return BigInt(Math.floor(Date.now() / 1000)); - case 7: // exit + case 7: // exit: the run stops here with this status, as the native core's exit() does + this.exitCode = Number(BigInt.asIntN(32, a)) & 255; return 0n; case 8: // rand return BigInt(Math.floor(Math.random() * 0x7FFFFFFF)); @@ -781,6 +783,7 @@ export class TinyVM { mem = this.mem; bytes = this.bytes; view = this.view; mw = this.mw; // a grow may have moved them mem[Number(a)] = result; s = this.rs; r = this.rr; + if (this.exitCode !== null) { const code = this.exitCode; this.exitCode = null; return code; } break; } else if (Number(a) >= 0 && Number(a) < mw) { mem[Number(a)] = b; diff --git a/tests/test.sh b/tests/test.sh index c31cfb7..45883d0 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -733,6 +733,7 @@ s_js() { chk "$(node $T/jsvm/tinyvm.js examples/primes.zc | tail -1)" "widest gap: 72, after 31397" "js vm: primes" chk "$(node $T/jsvm/tinyvm.js tests/programs/growone.zc)" "12 1" "js vm: a block past the initial heap grows the machine" chk "$(node $T/jsvm/tinyvm.js tests/programs/trace.zc 2>&1 | md5sum)" "$(md5sum < tests/programs/trace.expected)" "js vm: backtraces read the return stack through gate op 56" + node $T/jsvm/tinyvm.js tests/programs/trace.zc >/dev/null 2>&1; chk "$?" "2" "js vm: a runtime fault stops the run with exit status 2 (syscall 7), as the native core does" chk "$(node $T/jsvm/tinyvm.js tests/programs/replace_owner.zc)" "$(cat tests/programs/replace_owner.expected)" "js vm: replacement ownership and cleanup" chk "$(node $T/jsvm/tinyvm.js tests/programs/embed.zc | tr '\n' '/')" "hello/world 11 42 5 255 8 -1 0 119 15 5 255 3 98 321 63/" "js vm: embed declarations read their files through node" if sh src/tools/findcc.sh --wasm >/dev/null 2>&1 && command -v wasm-ld >/dev/null; then |
