Add .zero directive

This commit is contained in:
2026-03-15 21:28:25 +00:00
parent 02ee4c3c88
commit e7affbf8b7

23
asm.js
View File

@@ -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,