-
Notifications
You must be signed in to change notification settings - Fork 0
/
repl.html
44 lines (37 loc) · 1005 Bytes
/
repl.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
<!DOCTYPE html>
<style>
*{box-sizing: border-box}
html, body {height: 100%; margin: 0}
</style>
<body style="display: flex; flex-direction: column;">
<textarea id="wat" style="display: block; flex-grow: 1;">
(module
(global $g0 (mut i32) (i32.const 1))
)
</textarea>
<div id="log" style="height: 50%;"></div>
<script type="module">
import Wabt from './lib/wabt.js'
let wabt = await Wabt()
let textarea = document.getElementById('wat'),
errarea = document.getElementById('log')
textarea.onchange = () => {
compile(textarea.value)
}
compile(textarea.value)
function compile(code) {
errarea.textContent = ''
try {
var wasmModule = wabt.parseWat('', code)
let wasmBinary = wasmModule.toBinary({log: true})
const mod = new WebAssembly.Module(wasmBinary.buffer)
// const instance = new WebAssembly.Instance(mod)
// console.log(instance)
}
catch (e) {
console.error(e)
errarea.textContent = e
}
}
</script>
</body>