-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest.js
More file actions
36 lines (31 loc) · 906 Bytes
/
Copy pathtest.js
File metadata and controls
36 lines (31 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { writeAllSync } from "jsr:@std/io/write-all";
const wasmCode = Deno.readFileSync(Deno.args[0] ?? "./test.wasm");
const wasmModule = new WebAssembly.Module(wasmCode);
let memory = undefined;
let wasmInstance;
try {
wasmInstance = new WebAssembly.Instance(wasmModule, {
env: {
print_u32: function (u32) {
var enc = new TextEncoder();
writeAllSync(Deno.stdout, enc.encode(u32.toString()));
},
print_i64: function (i64) {
var enc = new TextEncoder();
writeAllSync(Deno.stdout, enc.encode(i64.toString()));
},
print_string: function (ptr, len) {
let str = new Uint8Array(memory.buffer, ptr, len);
writeAllSync(Deno.stdout, str);
},
},
});
} catch (error) {
console.error(error);
}
memory = wasmInstance.exports.memory;
try {
wasmInstance.exports.main();
} catch (error) {
console.error(error);
}