From 9fb3910a1615ee1434f15649687a4f0bcb3cbe8c Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Sat, 14 Mar 2026 15:04:13 +0000 Subject: [PATCH] Allow defs to reference other defs --- asm.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/asm.js b/asm.js index b52aede..a21bb52 100644 --- a/asm.js +++ b/asm.js @@ -560,18 +560,15 @@ class Parser { this.state = State.TOP; return; } - const value = this.integer(token); - if (value == null) { - console.error( - `ERROR: Unexpected token ${token}, expected value`); - this.def_name = undefined; - this.state = State.TOP; - return; - } const action = { type: Action.DEF, - def: { name: this.def_name, value }, + def: { name: this.def_name }, }; + const value = this.integer(token); + if (value != null) + action.def.value = value; + else + action.def.symbol = token; this.def_name = undefined; this.state = State.TOP; return action; @@ -742,7 +739,9 @@ export class Assembler { } action_def(action) { - this.defs[action.def.name] = action.def.value; + const value = action.def.value + ?? this.lookup_def(action.def.symbol); + this.defs[action.def.name] = value; } action_label(action) {