-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.html
92 lines (80 loc) · 2.56 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.37.0/codemirror.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.37.0/mode/scheme/scheme.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.37.0/addon/edit/matchbrackets.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.37.0/codemirror.css" />
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/codemirror/5.37.0/theme/neat.css" />
<script src="wasm_exec.js"></script>
<script>
const go = new Go();
function loadEditor() {
var timer = null;
var editor = null;
function editHook(cm, arg) {
if (timer) {
clearTimeout(timer);
}
timer = setTimeout(loadTextarea, 400);
}
function initHook(cm) {
cm.on("changes", editHook);
cm.on("update", editHook);
}
window.CodeMirror.defineInitHook(initHook);
editor = window.CodeMirror.fromTextArea(document.getElementById("lisp-source"), {
"lineNumbers": true,
"mode": "scheme",
"matchBrackets": true,
"indentUnit": 2,
"tabSize": 2,
"theme": "neat"});
function setLispOutput(result, err) {
var output = document.getElementById("lisp-output");
output.innerHTML = result;
var error = document.getElementById("lisp-error");
error.innerHTML = err;
}
function loadTextarea() {
var value = editor ? editor.getValue() : "";
var result = new Promise(function(resolve, reject) {
var context = {
resolve: resolve,
reject: reject
};
LoadString(value, context);
});
result.then(function(value) {
setLispOutput(value, "")
}).catch(function(err) {
setLispOutput("", err)
});
}
}
// Safari does not have support the function
// WebAssembly.instantiateStreaming so this hack performs
// inefficient, non-streaming compilation and instatiation.
var appWasm = fetch("app.wasm")
.then((source) => { return source.arrayBuffer(); })
.then((buffer) => { return WebAssembly.instantiate(buffer, go.importObject); })
.then((result) => { go.run(result.instance); loadEditor(); });
</script>
</head>
<body>
<div class="input">
<div class="source">
<textarea id="lisp-source" style="min-width: 500px; min-height: 100px;">(+ 2 1)</textarea>
</div>
</div>
<div class="output">
<pre id="lisp-output">
</pre>
</div>
<div class="error">
<pre id="lisp-error" style="color: red;">
</pre>
</div>
</body>
</html>