From 72c5f643122cec628c55897ec6cdb0c38241c3cd Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Sun, 15 Mar 2026 13:42:02 +0000 Subject: [PATCH] Handle global init value encoding in Assembler --- asm.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/asm.js b/asm.js index 7db3575..9fce033 100644 --- a/asm.js +++ b/asm.js @@ -531,8 +531,7 @@ class Parser { const value = this.integer(token) ?? console.error( `ERROR: Unexpected token ${token} in .global: expected` + " initial value"); - const const_opcode = const_opcodes[this.global.type]; - this.global.init = [ const_opcode, value, opcodes["end"] ]; + this.global.init = value; const action = { type: Action.GLOBAL, global: { [this.global_name]: this.global } @@ -1222,8 +1221,13 @@ export class Assembler { const globals = Object.values(this.globals); if (globals.length == 0) return null; - const contents = globals.map( - ({ type, init }) => [ type, 1, ...init ]); + const contents = globals.map(({ type, init }) => [ + type, + 1, + const_opcodes[type], + ...this.leb128(init), + opcodes["end"], + ]); return [ globals.length ].concat(...contents); }