b8c9f1f9f9
PARSE and PARSE-NAME were using the deferred pending mechanism which broke when called from compiled code (the calling word continued executing before PARSE ran). Replaced with inline host functions that read >IN/#TIB directly from WASM memory and parse immediately. This fixes utilities.fth $"/$2" failures that left stack residue cascading into all subsequent compliance test suites. Also: core_ext 17→14, string 27→17.
64 lines
1.9 KiB
JavaScript
64 lines
1.9 KiB
JavaScript
// WAFER JS Loader - generated by wafer build --js
|
|
// Loads and runs test_js.wasm in the browser.
|
|
|
|
const WAFER = (() => {
|
|
const CELL_SIZE = 4;
|
|
const DATA_STACK_TOP = 0x1540;
|
|
const SYSVAR_BASE = 0x0004;
|
|
let outputCallback = (s) => {
|
|
const el = document.getElementById('output');
|
|
if (el) el.textContent += s;
|
|
else console.log(s);
|
|
};
|
|
|
|
async function run(opts) {
|
|
if (opts && opts.output) outputCallback = opts.output;
|
|
|
|
const memory = new WebAssembly.Memory({ initial: 16 });
|
|
const dsp = new WebAssembly.Global({ value: 'i32', mutable: true }, 5440);
|
|
const rsp = new WebAssembly.Global({ value: 'i32', mutable: true }, 9536);
|
|
const fsp = new WebAssembly.Global({ value: 'i32', mutable: true }, 11584);
|
|
const table = new WebAssembly.Table({ element: 'anyfunc', initial: 256 });
|
|
|
|
function emit(code) {
|
|
outputCallback(String.fromCharCode(code));
|
|
}
|
|
|
|
const importObject = {
|
|
env: { emit, memory, dsp, rsp, fsp, table }
|
|
};
|
|
|
|
// Register host functions
|
|
const view = () => new DataView(memory.buffer);
|
|
const pop = () => {
|
|
const sp = dsp.value;
|
|
const v = view().getInt32(sp, true);
|
|
dsp.value = sp + CELL_SIZE;
|
|
return v;
|
|
};
|
|
const push = (v) => {
|
|
const sp = dsp.value - CELL_SIZE;
|
|
view().setInt32(sp, v, true);
|
|
dsp.value = sp;
|
|
};
|
|
|
|
table.set(84, new WebAssembly.Function({parameters:[], results:[]}, () => {
|
|
const n = pop();
|
|
const base = view().getUint32(SYSVAR_BASE, true);
|
|
outputCallback((base === 16 ? n.toString(16).toUpperCase() : n.toString()) + ' ');
|
|
}));
|
|
|
|
const response = await fetch('test_js.wasm');
|
|
const bytes = await response.arrayBuffer();
|
|
const { instance } = await WebAssembly.instantiate(bytes, importObject);
|
|
|
|
if (instance.exports._start) {
|
|
instance.exports._start();
|
|
}
|
|
|
|
return instance;
|
|
}
|
|
|
|
return { run };
|
|
})();
|