From c91f46be887d1adb41b5c78058e88e4e1ec8dfc6 Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Wed, 18 Mar 2026 14:23:37 +0000 Subject: [PATCH] Assemble kernel on client --- boot.js | 16 ++++++++++++++-- emu.js | 9 ++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/boot.js b/boot.js index 263b8f9..6bca6ae 100644 --- a/boot.js +++ b/boot.js @@ -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) => { const exports = { emu: { mem: e.data } }; - const mod = await WebAssembly.instantiateStreaming( - fetch('wipforth.wasm'), exports) + const wasm = await assemble; + const mod = await WebAssembly.instantiate(wasm, exports); + await self.postMessage('booting'); mod.instance.exports.reset(); console.log('System halt'); }; diff --git a/emu.js b/emu.js index 03e6477..337b2a6 100644 --- a/emu.js +++ b/emu.js @@ -11,6 +11,7 @@ const RXBUF_SIZE = 32; const PERIPHS_SIZE = 81; const POLL_INTERVAL_MS = 20; +const DOT_INTERVAL_MS = 120; const COLS = 80; const TAB_WIDTH = 8; @@ -50,8 +51,14 @@ class Emulator { document.addEventListener('keydown', (e) => this.handle_keydown(e)); 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.onmessage = (e) => { + clearInterval(dots); + this.print(" done\n"); + }; fetch('prelude.f') .then(res => res.text())