Skip to content

Commit d9993ca

Browse files
committed
Add examples
1 parent 73019c5 commit d9993ca

File tree

4 files changed

+113
-1
lines changed

4 files changed

+113
-1
lines changed

examples/binaryAdd.txt

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
init test
2+
blank *
3+
4+
test 0 0 R skipO1
5+
test 1 1 R skipO1
6+
test * * R halt
7+
8+
skipO1 z z R skipO1
9+
skipO1 o o R skipO1
10+
skipO1 0 0 R skipO1
11+
skipO1 1 1 R skipO1
12+
skipO1 * * R getO2
13+
14+
getO2 * * L rewrite
15+
getO2 0 0 R getO2_0
16+
getO2 1 1 R getO2_1
17+
18+
getO2_0 0 0 R getO2_0
19+
getO2_0 1 1 R getO2_1
20+
getO2_0 * * L biteO2_0
21+
22+
getO2_1 0 0 R getO2_0
23+
getO2_1 1 1 R getO2_1
24+
getO2_1 * * L biteO2_1
25+
26+
biteO2_0 0 * L rskipO2_0
27+
28+
biteO2_1 1 * L rskipO2_1
29+
30+
rskipO2_0 0 0 L rskipO2_0
31+
rskipO2_0 1 1 L rskipO2_0
32+
rskipO2_0 * * L add_0
33+
34+
add_0 z z L add_0
35+
add_0 o o L add_0
36+
add_0 0 z R skipO1
37+
add_0 1 o R skipO1
38+
add_0 * z R skipO1
39+
40+
rskipO2_1 0 0 L rskipO2_1
41+
rskipO2_1 1 1 L rskipO2_1
42+
rskipO2_1 * * L add_1
43+
44+
add_1 z z L add_1
45+
add_1 o o L add_1
46+
add_1 0 o R skipO1
47+
add_1 1 z L incr
48+
add_1 * o R skipO1
49+
50+
incr 1 0 L incr
51+
incr 0 1 R skipO1
52+
incr * 1 R skipO1
53+
54+
rewrite * * L rewrite'
55+
56+
rewrite' z 0 L rewrite'
57+
rewrite' o 1 L rewrite'
58+
rewrite' 0 0 L rewrite'
59+
rewrite' 1 1 L rewrite'
60+
rewrite' * * R halt

examples/binaryIncr.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
init q0
2+
blank *
3+
4+
q0 * * L q1
5+
q0 0 0 R q0
6+
q0 1 1 R q0
7+
8+
q1 * 1 L q2
9+
q1 0 1 L q2
10+
q1 1 0 L q1
11+
12+
q2 * * R halt
13+
q2 0 0 L q2
14+
q2 1 1 L q2

examples/unaryDup.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
init test
2+
blank *
3+
4+
test 1 * R skipOrigR
5+
test * * R halt
6+
7+
skipOrigR 1 1 R skipOrigR
8+
skipOrigR * * R skipCopyR
9+
10+
skipCopyR 1 1 R skipCopyR
11+
skipCopyR * 1 R write1
12+
13+
write1 * 1 L skipCopyL
14+
15+
skipCopyL 1 1 L skipCopyL
16+
skipCopyL * * L skipOrigL
17+
18+
skipOrigL 1 1 L skipOrigL
19+
skipOrigL * * R test

src/index.mjs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1233,7 +1233,7 @@ class App {
12331233
this.updateGraphStyle(this.state, prevTransition);
12341234
};
12351235

1236-
const init = () => {
1236+
const init = async () => {
12371237
const prev = this.editorTextArea.value;
12381238

12391239
this.editorTextArea.value = "init halt\nblank *\n";
@@ -1249,6 +1249,25 @@ class App {
12491249

12501250
this.tapeResizeObserver = new ResizeObserver(() => this.updateTape(true));
12511251
this.tapeResizeObserver.observe(this.tape);
1252+
1253+
const params = new URLSearchParams(window.location.search);
1254+
if (!params.has('fetch'))
1255+
return;
1256+
1257+
try {
1258+
const response = await fetch(params.get('fetch'));
1259+
if (!response.ok) {
1260+
UIkit.notification('Could not load example', 'warning');
1261+
return;
1262+
}
1263+
1264+
this.state = null;
1265+
this.editorTextArea.value = await response.text();
1266+
this.editorHighlights.innerText = this.editorTextArea.value + " ";
1267+
this.update();
1268+
} catch (err) {
1269+
UIkit.notification('Could not load example', 'warning');
1270+
}
12521271
}
12531272

12541273
if (document.readyState === 'complete') {

0 commit comments

Comments
 (0)