-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
230 lines (203 loc) · 7.45 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Hook's Playground</title>
<link href="node_modules/bootstrap/dist/css/bootstrap.min.css" rel="stylesheet">
<style type="text/css">
.output-content {
background-color: #FAFAFA;
color: #0C1E3F;
font-family: monospace;
font-size: medium;
padding: 10px;
width: 500px;
height: 300px;
overflow: scroll;
}
</style>
</head>
<body>
<nav class="navbar navbar-expand-lg bg-light">
<div class="container-fluid">
<a class="navbar-brand" href="#">
<img src="resource/logo.png" alt="Logo" width="30" height="24">
</a>
<div class="fw-lighter">
<div class="me-auto mb-2 mb-lg-0"></div>
<div>Version 0.1.0</div>
</div>
</div>
</nav>
<div class="container-fluid">
<div class="row align-items-start">
<div class="col">
<div class="container-fluid">
<div class="row" style="margin-top: 1rem; margin-bottom: 1rem">
<div class="col">
<div class="dropdown text-begin">
<button class="btn text-bg-light btn-sm dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
Source
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#" onclick="loadSample(0)">Blank</a></li>
<li><a class="dropdown-item" href="#" onclick="loadSample(1)">Binary search</a></li>
<li><a class="dropdown-item" href="#" onclick="loadSample(2)">Factorial</a></li>
<li><a class="dropdown-item" href="#" onclick="loadSample(3)">Fibonnaci</a></li>
<li><a class="dropdown-item" href="#" onclick="loadSample(4)">Fizz buzz</a></li>
<li><a class="dropdown-item" href="#" onclick="loadSample(5)">Hello, world!</a></li>
<li><a class="dropdown-item" href="#" onclick="loadSample(6)">Knuth shuffle</a></li>
<li><a class="dropdown-item" href="#" onclick="loadSample(7)">Mandelbrot set</a></li>
<li><a class="dropdown-item" href="#" onclick="loadSample(8)">Quicksort</a></li>
<li><a class="dropdown-item" href="#" onclick="loadSample(9)">Rule 110</a></li>
<li><a class="dropdown-item" href="#" onclick="loadSample(10)">Tower of Hanoi</a></li>
</ul>
</div>
</div>
</div>
<div class="row">
<div class="col">
<div id="source" style="height: 100vh"></div>
</div>
</div>
</div>
</div>
<div class="col">
<div class="container-fluid">
<div class="row" style="margin-top: 1rem; margin-bottom: 1rem">
<div class="col">
<div class="dropdown text-begin">
<button id="output-type" class="btn text-bg-light btn-sm dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
Output
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="#" onclick="selectOutputType(0)">Output</a></li>
<li><a class="dropdown-item" href="#" onclick="selectOutputType(1)">Bytecode</a></li>
</ul>
</div>
</div>
</div>
<div class="row">
<div class="col">
<div>
<pre id="output" class="output-content" style="height: 100vh; width: 45vw"></pre>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script src="node_modules/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
<script src="node_modules/monaco-editor/min/vs/loader.js"></script>
<script src="tokens-provider.js"></script>
<script src="samples.js"></script>
<script>
var samples = getSamples();
var loadSample;
var asmText = "";
var resultText = "";
var outputType = 0;
function selectOutputType(type) {
outputType = type;
const outputTypeElem = document.getElementById("output-type");
outputTypeElem.innerHTML = outputType == 0 ? "Output" : "Bytecode";
const outputElem = document.getElementById("output");
outputElem.innerHTML = outputType == 0 ? resultText : asmText;
}
function prepareRequestBody(source) {
return {
source: source,
options: {
userArguments: "",
compilerOptions: {
skipAsm: false
},
filters: {
binaryObject: false,
binary: false,
execute: true,
intel: true,
demangle: true,
labels: false,
directives: false,
commentOnly: false,
trim: false
},
tools: [
],
libraries: [
]
},
lang: "hook",
files: [
],
bypassCache: false,
allowStoreCodeDebug: true
};
}
function handleResponseBody(data) {
const asm = data.asm;
asmText = "";
for (let i = 0; i < asm.length; i++) {
const elem = asm[i];
asmText += `${elem.text}\n`;
}
const execResult = data.execResult;
const out = data.code == 0 ? execResult.stdout : data.stderr;
resultText = "";
for (let i = 0; i < out.length; i++) {
const elem = out[i];
resultText += `${elem.text}\n`;
}
}
function doRequest(body, callback) {
const url = "https://godbolt.org/api/compiler/hook010/compile";
fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
},
body: JSON.stringify(body)
})
.then(response => response.json())
.then(data => callback(data))
.catch(error => console.error(error));
}
function evalutate(source) {
const body = prepareRequestBody(source);
doRequest(body, function(data) {
handleResponseBody(data);
const outputElem = document.getElementById("output");
outputElem.innerHTML = outputType == 0 ? resultText : asmText;
});
}
require.config({
paths: {
vs: "node_modules/monaco-editor/min/vs"
}
});
require(["vs/editor/editor.main"], function () {
monaco.languages.register({ id: "hook" });
monaco.languages.setMonarchTokensProvider("hook", getTokensProvider());
let sourceElem = document.getElementById("source");
var editor = monaco.editor.create(sourceElem, {
language: "hook"
});
editor.onDidChangeModelContent(function() {
evalutate(editor.getValue());
});
loadSample = function (index) {
const sample = samples[index];
editor.setValue(sample);
}
function getDefaultSample() {
return samples[5];
}
editor.setValue(getDefaultSample());
});
</script>
</body>
</html>