Add error message for unhandled states and actions

This commit is contained in:
2026-03-15 11:05:56 +00:00
parent d35b13fed0
commit 46a571be93

19
asm.js
View File

@@ -754,9 +754,15 @@ class Parser {
*handle(src) { *handle(src) {
let action; let action;
for (const token of this.tokenizer.handle(src)) { for (const token of this.tokenizer.handle(src)) {
if (action = this.handlers[this.state](token)) { const handler = this.handlers[this.state];
yield action; 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) { push(chunk) {
const text = this.decoder.decode(chunk, { stream: true }); const text = this.decoder.decode(chunk, { stream: true });
for (const action of this.parser.handle(text)) for (const action of this.parser.handle(text)) {
this.handlers[action.type](action); const handler = this.handlers[action.type];
if (handler == undefined)
console.error("ERROR: Unhandled action", action);
else
handler(action);
}
} }
lookup_block(symbol) { lookup_block(symbol) {