-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
260 lines (254 loc) · 10.3 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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
<!DOCTYPE html>
<meta charset="UTF-8">
<head>
<link rel="stylesheet" href="style.css">
</head>
<html>
<head>
<title>SOGL interpreter</title>
<script src="processing.js"></script>
<script src="bigDecimal.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body style="background: #f5fff5;">
<canvas data-processing-sources="compiled.pde" height=1 width=1 hidden></canvas>
<center><H1 style="height:10px; margin-top:0;"><a href="https://github.com/dzaima/SOGLOnline" style="color:#400050">SOGL interpreter</a></H1></center>
<div id="all">
<div id="left">
<div id="p" style="width:40%;"><span id="bytecount" style="font-size:12px">0 bytes</span></div><div id="p" style="width:20%;"><center><b>CODE</b></center></div>
<textarea id="program" placeholder="Enter code..." spellcheck="false" onclick="setTimeout(updater, 0);" oninput="setTimeout(updater, 0);"></textarea>
</div>
<div id="right" align="right">
<center><b>INPUTS</b></center>
<textarea id="inputs" placeholder="Enter inputs in each line" spellcheck="false" style="width:100%"></textarea>
</div>
<textarea id="output" style="width: 100%; height:300px" placeholder="Output will appear here once some code has been executed" readonly></textarea>
<br/>
<div id="p" style="width:220px">
<button id="runBtn" onclick="runClicked()" style="width:47%" disabled>run</button>
<button id="plink" onclick="permalink()" style="width:47%; float:right;">permalink</button>
</div>
<button id="stop" onclick="stopRunning()" style="width:83px;">stop</button>
<button id="compmode" onclick="compmode()" style="width:134px;">compatibility mode</button>
<button id="topost" onclick="postify()" style="width:80px;">postify</button>
<button id="toCMC" onclick="CMCify()" style="width:60px;">CMCify</button>
<br>
<div id="p" style="width:220px">
<input type="button" id="loadSOGL" value="load SOGL codepage encoded file" onclick="loadSOGL()"; style="width:100%"></input>
<br/>
<input type="button" id="saveSOGL" value="save SOGL codepage encoded file" onclick="saveSOGL();" style="width:100%"></input>
</div>
<div id="p">
<input type="file" id="fileinput" accept=".soglbin"/>
<br>
<input id="debugCheck" type="checkbox" onclick="updateDebugMode()">debug mode</input>
<button id="stepBtn" onclick="step()" style="width:83px;" hidden>step</button>
<button id="contBtn" onclick="dCont()" style="width:83px;" hidden>continue</button>
<span id="vArrH" hidden><input id="visualizeArrays" type="checkbox" onclick="updateStackViz()" checked>vizualize arrays</input></span>
<a id="savedLink"></a>
</div>
</div>
<div id="stackPlace"> </div>
<div id="wtest" class="wtest"/>
<script>
var lastPremalink;
var args = location.search.substring(1).split(",");
var pobj = document.getElementById("program");
var consoleDebug = false;
for (var i = 0; i < args.length; i++) {
var carg = args[i];
if (carg.startsWith("code="))
pobj.value = unescape(atob(carg.substring(5).replace(/_/g, "=")));
if (carg.startsWith("inputs="))
document.getElementById("inputs").value = unescape(atob(carg.substring(7).replace(/_/g, "=")));
}
function compmode() {
permalink();
window.location = lastPremalink.replace(/(index\.html)?\?/, "comp/index.html?")
}
function permalink() {
var res = location.href.substring(0,location.href.length-location.search.length)+"?";
res+= "code="+ (btoa(escape(pobj.value)).replace(/=/g, "_"));
var inputs = document.getElementById("inputs").value;
if (inputs != "")
res+= ",inputs="+ btoa(escape(inputs)).replace(/=/g, "_");
res+= ",v=0.12"
lastPremalink = res;
document.getElementById("output").value = res;
}
function postify() {
permalink();
let link = `\n\n[Try it Here!](${output.value})`;
output.value = `# [SOGL V0.12](https://github.com/dzaima/SOGLOnline), ${program.value.length} [byte${program.value.length===1? "" : "s"}](https://github.com/dzaima/SOGL/blob/master/chartable.md)`;
for (var cs of program.value.split("\n")) output.value+= "\n "+cs;
output.value+= link;
}
function CMCify() {
permalink();
output.value = `SOGL, ${program.value.length} byte${program.value.length===1? "" : "s"}: [\`${program.value.replace(/\n/g, "\\n")}\`](${output.value})`;
}
function PLoaded() {
runBtn.disabled = false;
if (!cp) cp = Processing.instances[0];
}
</script>
<script>
var soglOS = "";
var soglOSP = "";
var sleepBI = false;
var stopProgram = false;
var running = false;
var cp;
var debugMode = 0;
var justStepped = false;
var bpS, bpE;
var ALLCHARS = "⁰¹²³⁴⁵⁶⁷⁸\t\n⁹±∑«»æÆø‽§°¦‚‛⁄¡¤№℮½← !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~↑↓≠≤≥∞√═║─│≡∙∫○׀′¬⁽⁾⅟‰÷╤╥ƨƧαΒβΓγΔδΕεΖζΗηΘθΙιΚκΛλΜμΝνΞξΟοΠπΡρΣσΤτΥυΦφΧχΨψΩωāčēģīķļņōŗšūž¼¾⅓⅔⅛⅜⅝⅞↔↕∆≈┌┐└┘╬┼╔╗╚╝░▒▓█▲►▼◄■□…‼⌠⌡¶→“”‘’";
var lastScroll;
document.onkeydown = updater;
async function runClicked() {
if (!cp) cp = Processing.instances[0];
if (running) {
stopProgram = true;
while (stopProgram) {
await sleep(50);
}
}
stopProgram = false;
soglOS = "";
var prog = pobj.value;
var inps = document.getElementById("inputs").value;
running = true;
await cp.launchSOGL(prog, inps.split("\n"));
document.getElementById("output").value = soglOSP;
}
function stopRunning() {
stopProgram = true;
}
function updater() {
setTimeout (update, 0);
setTimeout (update, 10);
}
function update() {
var bytecount = pobj.value.length;
var startPos = pobj.selectionStart;
var endPos = pobj.selectionEnd;
var co = bytecount +" byte"+ (bytecount==1? "" : "s");
if (endPos != startPos)
co+= " ("+ (endPos-startPos) +" byte"+ (endPos-startPos==1? "" : "s") +" selected)"
document.getElementById("bytecount").innerHTML = co;
//console.log(startPos+" "+endPos);
}
function updateDebugMode () {
debugMode = document.getElementById("debugCheck").checked? 1 : 0;
document.getElementById("stepBtn").hidden = !debugMode;
document.getElementById("contBtn").hidden = !debugMode;
document.getElementById("vArrH").hidden = !debugMode;
outputMode(debugMode? 2 : 0)
}
function saveSOGL() {
if (!cp) cp = Processing.instances[0];
var link = document.getElementById("savedLink");
var prog = pobj.value;
link.download = "encoded.soglbin";
var progBin = "";
for (var i = 0; i < prog.length; i++) {
progBin+= String.fromCodePoint(ALLCHARS.indexOf(prog.charAt(i)));
}
link.href = 'data:text/plain;base64,' + btoa(progBin);
link.click();
}
var fr;
function loadSOGL() {
var f = document.getElementById('fileinput').files[0];
fr = new FileReader();
fr.onload = recieved;
fr.readAsBinaryString(f);
}
function recieved() {
if (!cp) cp = Processing.instances[0];
var progbin = fr.result;
var prog = "";
for (var i = 0; i < progbin.length; i++) {
prog+= ALLCHARS.charAt(progbin.charCodeAt(i));
}
pobj.value = prog;
update();
}
//https://stackoverflow.com/a/39914235/7528415
function sleep (ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function currOutput() {
await sleep(0);
cp.readyOutput();
document.getElementById("output").value = soglOSP;
}
function jsmodify (js) {
return js.replace(/function execute/g, "async function execute")
.replace(/function launchSOGLP2\b/g, "async function launchSOGLP2")
.replace(/function launchSOGL\b/g, "async function launchSOGL");
}
function step () {
if (!cp) runClicked();
lastScroll = window.pageYOffset;
justStepped = true;
}
function dCont () {
if (!cp) runClicked();
lastScroll = window.pageYOffset;
debugMode = 2;
justStepped = true;
}
var lstack, llastptr, lptr;
var charW = 8;
var charH = 17;
function execFinished (stack, lastptr, ptr) {
lstack = stack;
llastptr = lastptr;
lptr = ptr;
var program = document.getElementById("program")
program.focus();
program.setSelectionRange(lastptr+1, ptr+1);
var stackHoriz = false;
var stackPlace = document.getElementById("stackPlace");
var wtest = document.getElementById("wtest");
stackPlace.innerHTML = "";
stack.forEach(item=> {
if (stackHoriz) {
} else {
var ce = document.createElement("textarea")
ce.value = item.stringRepr(document.getElementById("visualizeArrays").checked)
let sval = ce.value.split("\n");
let mlen = 0;
for (let i = 0; i < sval.length; i++) {
if (sval[i].length > mlen) mlen = sval[i].length;
}
ce.style = "width:"+ (mlen*charW+33) +"px; height:"+ Math.max((sval.length+1)*charH, 70) +"px;vertical-align:top;"//"width:"+ cwidth +"px; height:"+ cheight +"px;vertical-align:top;"//
stackPlace.appendChild(ce);
}
})
if (lastScroll) {
window.scrollTo(window.pageXOffset, lastScroll);
lastScroll = undefined;
}
}
function updateStackViz () {
execFinished(lstack, llastptr, lptr);
}
function outputMode (mode) {
document.getElementById("output").style = mode==1? "width: 49%; height:300px" : (mode==2? "width: 100%; height:50px" : "width: 100%; height:300px");
}
document.addEventListener ("keydown", e=> {
if (e.ctrlKey && e.code === "KeyB") {
bpS = document.getElementById("program").selectionStart;
bpE = document.getElementById("program").selectionEnd;
}
//console.log(e.code);
if (e.ctrlKey && e.code === "Enter") {
runClicked();
}
});
update();
</script>
</body>
</html>