Compare commits

..

3 Commits

Author SHA1 Message Date
9fb3910a16 Allow defs to reference other defs 2026-03-14 15:04:25 +00:00
22dc1fc0ca Add support for labels 2026-03-14 14:52:44 +00:00
cc51b2d7be Fix data word size 2026-03-14 14:50:40 +00:00

29
asm.js
View File

@@ -112,6 +112,7 @@ const Action = Object.freeze({
DATA: 11,
ALIGN: 12,
DEF: 13,
LABEL: 14,
});
const types = {
@@ -224,6 +225,8 @@ class Parser {
this.state = state;
return;
}
if (token.endsWith(":"))
return { type: Action.LABEL, name: token.slice(0, -1) };
const code = this.translate_code(token);
if (code)
return { type: Action.APPEND, code };
@@ -497,7 +500,7 @@ class Parser {
this.state = State.TOP;
return;
}
const action = { type: Action.DATA, size: 2 };
const action = { type: Action.DATA, size: 4 };
const value = this.integer(token);
if (value == null) {
action.symbol = token;
@@ -557,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;
@@ -630,6 +630,7 @@ export class Assembler {
[Action.DATA]: (action) => this.action_data(action),
[Action.ALIGN]: (action) => this.action_align(action),
[Action.DEF]: (action) => this.action_def(action),
[Action.LABEL]: (action) => this.action_label(action),
};
this.exports = [];
@@ -738,7 +739,13 @@ 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) {
this.defs[action.name] = this.pos.addr;
}
push(chunk) {