-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplay.js
More file actions
executable file
·34 lines (30 loc) · 824 Bytes
/
play.js
File metadata and controls
executable file
·34 lines (30 loc) · 824 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
function getchar() {
const stdin = document.getElementById("stdin");
var inputBuffer = stdin.textContent;
if (inputBuffer.length == 0) {
inputBuffer = prompt("More input for stdin plz:");
}
const output = inputBuffer.charCodeAt(0);
stdin.textContent = inputBuffer.substr(1);
return output;
}
function putchar(charCode) {
console.log(charCode)
const stdout = document.getElementById("stdout");
stdout.textContent = stdout.textContent + String.fromCharCode(charCode);
}
function main(wasm) {
wasm.exports.bf();
}
fetch("main.wasm").then(reponse =>
reponse.arrayBuffer()
).then(bytes =>
WebAssembly.instantiate(bytes, {
"bf": {
putchar: putchar,
getchar: getchar
}
})
).then(result =>
result.instance
).then(main);