aboutsummaryrefslogtreecommitdiff
path: root/src/js/tinyvm.ts
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-15 18:32:30 +0330
committerGravatar zinc <zinc@downsta.ir> 2026-10-15 18:32:30 +0330
commit012cbf7146f452690045dd07acd6775dbdf4f76c (patch)
treece863c4f55cf95166357fb8f1e68377016941d56 /src/js/tinyvm.ts
parentduplicate case labels are an error (b.2.15); unterminated string literal repo... (diff)
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)
Diffstat (limited to 'src/js/tinyvm.ts')
-rw-r--r--src/js/tinyvm.ts5
1 files changed, 4 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;