Skip to content

Commit

Permalink
Provide default implementation for deo/dei
Browse files Browse the repository at this point in the history
  • Loading branch information
remko committed Oct 28, 2023
1 parent 52e6cd5 commit 75b18dc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
15 changes: 4 additions & 11 deletions src/benchmarks/suite.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,7 @@ export default [
{
name: "mandelbrot",
init: async (uxn) => {
await uxn.init({
deo: () => {},
dei: (port) => {
return uxn.dev[port];
},
});
await uxn.init();
},
run: (uxn) => {
uxn.load(mandelbrot);
Expand All @@ -34,9 +29,6 @@ export default [
break;
}
},
dei: (port) => {
return uxn.dev[port];
},
});
},
run: (uxn) => {
Expand All @@ -51,8 +43,9 @@ export default [
const output = new TextDecoder().decode(
Uint8Array.from(uxn._prime32.output)
);
if (output !== "fffffffb 01\n") {
throw Error(`unexpected output: ${output}`);
const expected = "fffffffb 01\n".repeat(14);
if (output !== expected) {
throw Error(`unexpected output: '${output}' != '${expected}`);
}
},
},
Expand Down
16 changes: 14 additions & 2 deletions src/uxn.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,20 @@ function Uxn() {
};

this.init = async (system) => {
core = (await WebAssembly.instantiate(wasmModule, { system })).instance
.exports;
system = system != null ? system : {};
core = (
await WebAssembly.instantiate(wasmModule, {
system: {
deo: system.deo != null ? system.deo : () => {},
dei:
system.dei != null
? system.dei
: (port) => {
this.dev[port];
},
},
})
).instance.exports;
this.ram = new Uint8Array(core.memory.buffer, 0, 0x10300);
this.dev = new Uint8Array(core.memory.buffer, 0x10200, 0x100);
wst = new Uint8Array(core.memory.buffer, 0x10000, 0xff);
Expand Down

0 comments on commit 75b18dc

Please sign in to comment.