-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
205 lines (204 loc) · 6.57 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
<menu type="context" id="menu">
<menuitem label="Run SJW Code" onclick="newrun();"></menuitem>
</menu>
<textarea id="in" rows="20" cols="50" contextmenu="menu"></textarea>
<br/>
<button type="button" onclick="newrun()">
Run
</button>
<br/>
<br/>
<input type="text" id="subbies" name="fname" value=""><button type="button" onclick="submitrun()" visible="false">
Trigger
</button>
<p id="out">
OUT:
</p>
<script>
function sleep(ms) {
return new Promise(
resolve => setTimeout(resolve, ms)
);
}
var linez = "TEMPORARY LINE; WILL BE REPLACED BY CODE";
var curline = 0;
var out = document.getElementById("out");
var input = document.getElementById("subbies");
var worknumber = 0;
var datatape = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
var curREOP = 0;
var submit = false;
var cellZ = 0;
var REPLAYon = false;
var newREOP = 0;
var running = false;
var threadkill = false;
async function newrun() {
if (!running) {
curline = 0;
worknumber = 0;
datatape = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
curREOP = 0;
REPLAYon = false;
newREOP = 0;
out.innerHTML = "OUT:";
run();
} else {
alert("Code currently running!!! Killing active thread...");
threadkill = true;
}
}
function submitrun() {
if (submit) {
datatape[cellZ] = input.value;
curline++;
run();
}
}
async function run() {
running = true;
var c1 = document.getElementById("in");
var c2 = c1.value;
var code = c2.split("\n");
var command = code[curline].split(" ");
switch (command[0]) {
case 'DEMAND':
if (command[1] == "DATATAPE" || command[1] == "DT") {
if (command[3] == "BE") {
datatape[parseInt(command[2])] = parseInt(command[4]);
} else if (command[3] == "READS") {
datatape[parseInt(command[2])] = command[4];
} else if (command[3] == "STEAL") {
datatape[parseInt(command[2])] = worknumber;
worknumber = 0;
} else if (command[3] == "HAS" && command[4] == "OPINION")
datatape[parseInt(command[2])] = Math.round(Math.random());
else {
console.log("Invalid operation.");
}
} else if (command[1] == "WORKNUMBER") {
if (command[2] == "ADD") {
worknumber += parseInt(datatape[parseInt(command[3])]);
//console.log(datatape[parseInt(command[3])]);
}
if (command[2] == "REMOVE") {
worknumber -= parseInt(datatape[parseInt(command[3])]);
}
if (command[2] == "BE") {
worknumber = parseInt(datatape[parseInt(command[3])]);
}
} else {
console.log("Invalid Data Type.");
}
break;
case 'CHECK':
if (command[2] == "IS") {
if (datatape[parseInt(command[1])] == datatape[parseInt(command[3])]) {
curREOP = 0;
} else {
if (curREOP != 0) {
curline += curREOP;
curREOP = 0;
REPLAYon = false;
} else {
curline += 1;
}
curREOP = 0;
}
} else if (command[2] == "ISNT") {
if (datatape[parseInt(command[1])] == datatape[parseInt(command[3])]) {
if (curREOP != 0) {
curline += curREOP;
REPLAYon = false;
} else {
curline += 1;
}
curREOP = 0;
}
} else if (command[2] == "GREATER") {
if (datatape[parseInt(command[1])] > datatape[parseInt(command[3])]) {} else {
if (curREOP != 0) {
curline += curREOP;
REPLAYon = false;
} else {
curline += 1;
}
}
curREOP = 0;
} else if (command[2] == "LESSER") {
if (datatape[parseInt(command[1])] < datatape[parseInt(command[3])]) {} else {
if (curREOP != 0) {
curline += curREOP;
REPLAYon = false;
} else {
curline += 1;
}
curREOP = 0;
}
}
//curREOP = 0;
break;
case 'END':
//console.log(datatape);
//console.log(worknumber);
console.log(curREOP);
console.log("END hit; Process finished.");
running = false;
threadkill = false;
return;
case 'STUTTER':
if (command[1] == "DATATAPE" || command[1] == "DT") {
curREOP = datatape[parseInt(command[2])];
} else {
curREOP = parseInt(command[1]);
}
break;
case 'STORM':
curREOP = 0;
curline = parseInt(command[1]) - 2;
break;
case 'YELL':
out.innerHTML = out.innerHTML + datatape[parseInt(command[1])];
break;
case 'SCREAM':
out.innerHTML = out.innerHTML + "<br/>" + datatape[parseInt(command[1])];
break;
case '#':
break;
case 'TRIGGER':
cellZ = command[1];
alert("The program is calling for input. Please input a value on the below input form and press \"Trigger\".")
curREOP = 0;
submit = true;
return;
default:
console.log("Error: Unrecognized command.");
running = false;
threadkill = false;
return;
}
/* console.log(datatape);
console.log(worknumber);
console.log(code[curline]);
console.log("REOP: " + curREOP);*/
if (threadkill) {
running = false;
threadkill = false;
return;
}
await sleep(100);
if (!REPLAYon) {
curline++;
} else {
curREOP--;
}
if (curREOP > 0) {
REPLAYon = true;
} else {
REPLAYon = false;
}
if (curline < code.length) {
run();
}
}
</script>