Assemble kernel on the client #1

Merged
cdo merged 72 commits from client-side-assembler into main 2026-03-18 15:21:33 +00:00
Showing only changes of commit 0dd2a925d8 - Show all commits

16
asm.js
View File

@@ -104,6 +104,7 @@ const State = Object.freeze({
TABLE_SIZE: 32,
ELEM_TABLE: 33,
ELEM_ELEM: 34,
ELEM_LABEL: 35,
});
const Action = Object.freeze({
@@ -260,6 +261,7 @@ class Parser {
[State.TABLE_SIZE]: (token) => this.token_table_size(token),
[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),
};
this.results = [];
@@ -813,6 +815,12 @@ class Parser {
}
this.elem.elem = token;
this.state = State.ELEM_LABEL;
}
token_elem_label(token) {
if (token != LINE_END)
this.elem.label = token;
const action = { type: Action.ELEM, elem: this.elem };
this.elem = undefined
this.state = State.TOP;
@@ -1055,12 +1063,14 @@ export class Assembler {
action_elem(action) {
const table = this.tables[action.elem.table];
const index = Object.keys(this.funcs).indexOf(action.elem.elem);
if (index == -1) {
const fn = Object.keys(this.funcs).indexOf(action.elem.elem);
if (fn == -1) {
console.error(`ERROR: ${action.elem.elem}: no such function`);
return;
}
table.elems.push(index);
const index = table.elems.push(fn) - 1;
if (action.elem.label)
this.defs[action.elem.label] = index;
}
push(chunk) {