diff --git a/boot.js b/boot.js index 6bca6ae..96bc257 100644 --- a/boot.js +++ b/boot.js @@ -10,10 +10,17 @@ const assemble = (async () => { })(); self.onmessage = async (e) => { - const exports = { emu: { mem: e.data } }; - const wasm = await assemble; - const mod = await WebAssembly.instantiate(wasm, exports); - await self.postMessage('booting'); - mod.instance.exports.reset(); - console.log('System halt'); + switch (e.data.type) { + case "load": + const exports = { emu: { mem: e.data.mem } }; + const wasm = await assemble; + self.mod = await WebAssembly.instantiate(wasm, exports); + await self.postMessage('ready'); + break; + + case "boot": + self.mod.instance.exports.reset(); + console.log('System halt'); + break; + } }; diff --git a/emu.js b/emu.js index 337b2a6..ad4488a 100644 --- a/emu.js +++ b/emu.js @@ -54,10 +54,11 @@ class Emulator { 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({ type: "load", mem: this.mem }); this.worker.onmessage = (e) => { clearInterval(dots); this.print(" done\n"); + this.worker.postMessage({ type: "boot" }); }; fetch('prelude.f') diff --git a/prelude.f b/prelude.f index b8191b9..379b181 100644 --- a/prelude.f +++ b/prelude.f @@ -250,7 +250,7 @@ CHAR . EMIT 0 CONSTANT VERSION-MAJOR 2 CONSTANT VERSION-MINOR -0 CONSTANT VERSION-PATCH +1 CONSTANT VERSION-PATCH : PRINT-VERSION CHAR v EMIT VERSION-MAJOR .