Assemble kernel on client

This commit is contained in:
2026-03-18 14:23:37 +00:00
parent 6ee4adfea5
commit c91f46be88
2 changed files with 22 additions and 3 deletions

16
boot.js
View File

@@ -1,7 +1,19 @@
import { Assembler } from './asm.js';
const assemble = (async () => {
const asm = new Assembler();
const resp = await fetch('wipforth.ws');
for await (const chunk of resp.body) {
asm.push(chunk);
}
return asm.wasm();
})();
self.onmessage = async (e) => { self.onmessage = async (e) => {
const exports = { emu: { mem: e.data } }; const exports = { emu: { mem: e.data } };
const mod = await WebAssembly.instantiateStreaming( const wasm = await assemble;
fetch('wipforth.wasm'), exports) const mod = await WebAssembly.instantiate(wasm, exports);
await self.postMessage('booting');
mod.instance.exports.reset(); mod.instance.exports.reset();
console.log('System halt'); console.log('System halt');
}; };

9
emu.js
View File

@@ -11,6 +11,7 @@ const RXBUF_SIZE = 32;
const PERIPHS_SIZE = 81; const PERIPHS_SIZE = 81;
const POLL_INTERVAL_MS = 20; const POLL_INTERVAL_MS = 20;
const DOT_INTERVAL_MS = 120;
const COLS = 80; const COLS = 80;
const TAB_WIDTH = 8; const TAB_WIDTH = 8;
@@ -50,8 +51,14 @@ class Emulator {
document.addEventListener('keydown', (e) => this.handle_keydown(e)); document.addEventListener('keydown', (e) => this.handle_keydown(e));
window.addEventListener('resize', () => this.handle_resize()); window.addEventListener('resize', () => this.handle_resize());
this.worker = new Worker('boot.js'); this.print("Assembling kernel ");
const dots = setInterval(() => this.print("."), DOT_INTERVAL_MS);
this.worker = new Worker('boot.js', { type: 'module' });
this.worker.postMessage(this.mem); this.worker.postMessage(this.mem);
this.worker.onmessage = (e) => {
clearInterval(dots);
this.print(" done\n");
};
fetch('prelude.f') fetch('prelude.f')
.then(res => res.text()) .then(res => res.text())