diff --git a/asm.js b/asm.js index d04a423..b52aede 100644 --- a/asm.js +++ b/asm.js @@ -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 }; @@ -630,6 +633,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 = []; @@ -741,6 +745,10 @@ export class Assembler { this.defs[action.def.name] = action.def.value; } + action_label(action) { + this.defs[action.name] = this.pos.addr; + } + push(chunk) { const text = this.decoder.decode(chunk, { stream: true }); for (const action of this.parser.handle(text))