From 012cbf7146f452690045dd07acd6775dbdf4f76c Mon Sep 17 00:00:00 2001 From: zinc Date: Thu, 15 Oct 2026 18:32:30 +0330 Subject: js vm: syscall 7 (exit) stops the run with its status, so a runtime fault no longer runs on past the fault (js vm trace check) --- src/js/tinyvm.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/js/tinyvm.ts') 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; -- cgit v1.2.3