Remove accidentally committed test files
This commit is contained in:
@@ -1,18 +0,0 @@
|
|||||||
<!DOCTYPE html>
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8">
|
|
||||||
<title>WAFER - test_js.wasm</title>
|
|
||||||
<style>
|
|
||||||
body { font-family: monospace; background: #1a1a2e; color: #e0e0e0; padding: 2em; }
|
|
||||||
#output { white-space: pre-wrap; font-size: 1.2em; padding: 1em; background: #16213e;
|
|
||||||
border: 1px solid #0f3460; border-radius: 4px; min-height: 4em; }
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<h2>WAFER Output</h2>
|
|
||||||
<div id="output"></div>
|
|
||||||
<script src="test_js.js"></script>
|
|
||||||
<script>WAFER.run();</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
-63
@@ -1,63 +0,0 @@
|
|||||||
// 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 };
|
|
||||||
})();
|
|
||||||
Reference in New Issue
Block a user