Allow defs to reference other defs

This commit is contained in:
2026-03-14 15:04:13 +00:00
parent 22dc1fc0ca
commit 9fb3910a16

19
asm.js
View File

@@ -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) {