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

28
asm.js
View File

@@ -483,9 +483,7 @@ class Parser {
const action = { type: Action.DATA, size: 1 };
const value = this.integer(token);
if (value == null) {
console.error(
`ERROR: Unexpected token ${token}, expected value`);
return;
action.symbol = token;
} else {
if (value > 0xff)
console.error(`WARNING: Value ${token} is truncated`);
@@ -502,9 +500,7 @@ class Parser {
const action = { type: Action.DATA, size: 2 };
const value = this.integer(token);
if (value == null) {
console.error(
`ERROR: Unexpected token ${token}, expected value`);
return;
action.symbol = token;
} else {
if (value > 0xffff)
console.error(`WARNING: Value ${token} is truncated`);
@@ -723,7 +719,10 @@ export class Assembler {
action_data(action) {
const data = this.data.at(-1).data;
data.push(...action.value);
const value = action.value != null
? action.value
: this.le_bytes(this.lookup_def(action.symbol), action.size);
data.push(...value);
this.pos.addr += action.size;
}
@@ -762,6 +761,21 @@ export class Assembler {
return index == -1 ? null : index;
}
lookup_def(symbol) {
return this.defs[symbol];
}
le_bytes(value, count) {
let bytes = []
while (value != 0 && bytes.length < count) {
bytes.push(value & 0xff);
value >>= 8;
}
while (bytes.length < count)
bytes.push(0);
return bytes;
}
wasm_section_type() {
const funcs = Object.values(this.funcs);
const contents = funcs.map(({ params, results }) => {