Remove race condition between assemble and prelude load prints

This commit was merged in pull request #1.
This commit is contained in:
2026-03-18 15:17:08 +00:00
parent 4000522b3a
commit 67fc1d8d7b
3 changed files with 16 additions and 8 deletions

19
boot.js
View File

@@ -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;
}
};

3
emu.js
View File

@@ -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')

View File

@@ -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 .