diff options
Diffstat (limited to 'src/js')
| -rw-r--r-- | src/js/tinyvm.ts | 5 |
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; |
