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 cfa4fa7d4f - Show all commits

22
asm.js
View File

@@ -90,6 +90,7 @@ const State = Object.freeze({
AT_MEM: 18, AT_MEM: 18,
AT_ADDR: 19, AT_ADDR: 19,
BYTE: 20, BYTE: 20,
WORD: 21,
}); });
const Action = Object.freeze({ const Action = Object.freeze({
@@ -149,6 +150,7 @@ class Parser {
".global": State.GLOBAL_NAME, ".global": State.GLOBAL_NAME,
".at": State.AT_MEM, ".at": State.AT_MEM,
".byte": State.BYTE, ".byte": State.BYTE,
".word": State.WORD,
}; };
this.handlers = { this.handlers = {
[State.TOP]: (token) => this.token_top(token), [State.TOP]: (token) => this.token_top(token),
@@ -172,6 +174,7 @@ class Parser {
[State.AT_MEM]: (token) => this.token_at_mem(token), [State.AT_MEM]: (token) => this.token_at_mem(token),
[State.AT_ADDR]: (token) => this.token_at_addr(token), [State.AT_ADDR]: (token) => this.token_at_addr(token),
[State.BYTE]: (token) => this.token_byte(token), [State.BYTE]: (token) => this.token_byte(token),
[State.WORD]: (token) => this.token_word(token),
}; };
this.results = []; this.results = [];
@@ -477,6 +480,25 @@ class Parser {
return action; return action;
} }
token_word(token) {
if (token == LINE_END) {
this.state = State.TOP;
return;
}
const action = { type: Action.DATA, size: 2 };
const value = this.integer(token);
if (value == null) {
console.error(
`ERROR: Unexpected token ${token}, expected value`);
return;
} else {
if (value > 0xffff)
console.error(`WARNING: Value ${token} is truncated`);
action.value = [ value & 0xff, (value >> 8) & 0xff ];
}
return action;
}
mem_action() { mem_action() {
const action = { const action = {
type: Action.MEM, type: Action.MEM,