From 8d4c53ca92dc4b90571569f709d1c771d206acd8 Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Sun, 15 Mar 2026 14:26:22 +0000 Subject: [PATCH] Allow implicit zero-init for globals --- asm.js | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/asm.js b/asm.js index c60e27f..f8377a5 100644 --- a/asm.js +++ b/asm.js @@ -522,26 +522,21 @@ class Parser { token_global_init(token) { if (token == LINE_END) { - console.error( - "ERROR: Unexpected newline in .global: expected" - + " initial value"); - this.global = undefined; - this.global_name = undefined; - this.state = State.TOP; + this.global.init = 0; } else { const value = this.integer(token) ?? console.error( `ERROR: Unexpected token ${token} in .global: expected` + " initial value"); this.global.init = value; - const action = { - type: Action.GLOBAL, - global: { [this.global_name]: this.global } - }; - this.global = undefined; - this.global_name = undefined; - this.state = State.TOP; - return action; - } + } + const action = { + type: Action.GLOBAL, + global: { [this.global_name]: this.global } + }; + this.global = undefined; + this.global_name = undefined; + this.state = State.TOP; + return action; } token_at_mem(token) {