diff --git a/asm.js b/asm.js index 9297868..5036c66 100644 --- a/asm.js +++ b/asm.js @@ -754,9 +754,15 @@ class Parser { *handle(src) { let action; for (const token of this.tokenizer.handle(src)) { - if (action = this.handlers[this.state](token)) { - yield action; + const handler = this.handlers[this.state]; + if (handler == undefined) { + console.error(`ERROR: Unhandled state ${this.state}`); + this.state = State.TOP; + continue; } + + if (action = handler(token)) + yield action; } } } @@ -955,8 +961,13 @@ export class Assembler { push(chunk) { const text = this.decoder.decode(chunk, { stream: true }); - for (const action of this.parser.handle(text)) - this.handlers[action.type](action); + for (const action of this.parser.handle(text)) { + const handler = this.handlers[action.type]; + if (handler == undefined) + console.error("ERROR: Unhandled action", action); + else + handler(action); + } } lookup_block(symbol) {