/
index.html
65 lines (55 loc) · 1.96 KB
/
index.html
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Rust Brainfuck Webassembly</title>
</head>
<body>
<h1>Rust Brainfuck WASM</h1>
<p>Blog post / tutorial is at: <a href="https://shr.ite.sh/brainfuck-rust-wasm.html">https://shr.ite.sh/brainfuck-rust-wasm.html</a>.</p>
<label for="source">Brainfuck Source</label>
<br>
<textarea name="source" id="source" cols="30" rows="10">++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.</textarea>
<br>
<label for="inp">Input</label>
<br>
<input name="inp" id="inp" placeholder="Program Input" />
<button id="btn">Run</button>
<br>
<p>Output</p>
<pre id="output"></pre>
<script src="bundle.js"></script>
<script>
window.Module = {}
var Brainfuck = {
run: function (source, input) {
let src_buf = newString(Module, source);
let input_buf = newString(Module, input);
let outptr = Module.brainfuck(src_buf, input_buf);
let result = copyCStr(Module, outptr);
Module.dealloc(src_buf);
Module.dealloc(input_buf);
Module.dealloc(outptr);
return result;
}
}
fetchAndInstantiate("./brainfuck.wasm", {})
.then(mod => {
Module.alloc = mod.exports.alloc;
Module.dealloc = mod.exports.dealloc;
Module.dealloc_str = mod.exports.dealloc_str;
Module.brainfuck = mod.exports.brainfuck;
Module.memory = mod.exports.memory;
function run() {
var src = document.getElementById('source').value;
var inp = document.getElementById('inp').value;
document.getElementById('output').innerText = Brainfuck.run(src, inp);
}
document.getElementById('btn').addEventListener('click', function () {
run();
})
run()
}); </script>
</body>
</html>