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

37
asm.js
View File

@@ -1278,24 +1278,20 @@ export class Assembler {
const local_types = Object.values(locals); const local_types = Object.values(locals);
const local_count = local_types.length; const local_count = local_types.length;
if (local_count == 0) { if (local_count == 0) {
return [ const full_body = [ 0, body, opcodes.end ].flat()
body.length + 2, return [ full_body.length, full_body ].flat();
0,
...body,
opcodes["end"]
]
} else { } else {
return [ const groups = this.group(local_types);
body.length + local_count + 3, const full_body = [
local_count, groups.length,
local_count, ...groups.flat(),
...local_types, body,
...body, opcodes.end,
opcodes["end"] ].flat();
]; return [ full_body.length, full_body ].flat();
} }
}); });
return [ contents.length ].concat(...contents); return [ contents.length, contents ].flat(Infinity);
} }
wasm_section_data() { wasm_section_data() {
@@ -1369,4 +1365,15 @@ export class Assembler {
for (const func of Object.values(this.funcs)) for (const func of Object.values(this.funcs))
func.type = this.ensure_type(this.func_type(func)); func.type = this.ensure_type(this.func_type(func));
} }
group(array) {
return array.reduce((acc, val) => {
const last = acc.at(-1);
if (last != undefined && last[1] == val)
++last[0]
else
acc.push([1, val]);
return acc;
}, []);
}
} }