diff --git a/asm.js b/asm.js index 9699496..e727a6d 100644 --- a/asm.js +++ b/asm.js @@ -106,6 +106,7 @@ const State = Object.freeze({ ELEM_TABLE: 33, ELEM_ELEM: 34, ELEM_LABEL: 35, + ZERO: 36, }); const Action = Object.freeze({ @@ -228,6 +229,7 @@ class Parser { ".type": State.TYPE_NAME, ".table": State.TABLE_NAME, ".elem": State.ELEM_TABLE, + ".zero": State.ZERO, }; this.blocks = new Set(["block", "loop", "if"]); this.handlers = { @@ -267,6 +269,7 @@ class Parser { [State.ELEM_TABLE]: (token) => this.token_elem_table(token), [State.ELEM_ELEM]: (token) => this.token_elem_elem(token), [State.ELEM_LABEL]: (token) => this.token_elem_label(token), + [State.ZERO]: (token) => this.token_zero(token), }; this.results = []; @@ -821,6 +824,26 @@ class Parser { return action; } + token_zero(token) { + if (token == LINE_END) { + console.error( + "ERROR: Unexpected newline in .zero, expected count") + this.state = State.TOP; + return; + } + + const count = this.integer(token); + if (count == null) { + console.error( + `ERROR: Unexpected token ${token} in .zero, expected count`); + this.state = State.TOP; + return; + } + + this.state = State.TOP; + return { type: Action.DATA, size: count, value: 0 } + } + mem_action() { const action = { type: Action.MEM,