-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
62 lines (57 loc) · 2.07 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>monkey-playground</title>
<script src="wasm_exec.js"></script>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
</head>
<body>
<div class="container">
<div class="row">
<div class="col">
<h4 class="mt-5">Input</h4>
<div class="form-group">
<textarea class="form-control" id="code" rows="10">
</textarea>
</div>
<br>
<button type="button" class="btn btn-outline-primary" onclick="runcode()">RUN</button>
</div>
<div class="col">
<h4 class="mt-5">Output</h4>
<div class="mt-1" style="outline: 1px solid silver; padding: 2em;">
<pre id="received"><span class="text-muted">Nothing received yet...</span></pre>
</div>
</div>
</div>
</div>
</body>
<script>
function loadWasm(path) {
const go = new Go()
return new Promise((resolve, reject) => { WebAssembly.instantiateStreaming(
fetch(path),
go.importObject
)
.then(result => {
go.run(result.instance)
resolve(result.instance)
})
.catch(error => {
reject(error)
})
}) }
const runcode = () => {
let codes = document.getElementById('code').value
loadWasm("main.wasm").then(wasm => {
let res = Run(codes)
console.log(res)
let recevied = document.getElementById("received");
recevied.innerHTML =res;
})
}
</script>
</html>