forked from supposedly/nutshell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbct.ruel
121 lines (97 loc) · 3.26 KB
/
bct.ruel
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
@NUTSHELL bct
An implementation of bitwise cyclic tag.
0: Vacuum.
1: Data-tape 0.
2: Data-tape 1.
3: Program-tape 0.
4: Program-tape 1.
5: Shifter. Moves both itself and the data tape one unit down to render program execution cyclic.
6: Transitory program-tape 0.
7: Transitory program-tape 1.
8: Pre-copying program-tape 0. (Used when a prgm-tape bit is the x in a 1x instruction)
9: Pre-copying program-tape 1. (Ditto)
10: Transitory program-tape 0.
11: Transitory program-tape 1.
12: Rightward-moving data-tape 0.
13: Rightward-moving data-tape 1.
14: Transitory reflector.
15: Ditto but about to turn into normal reflector.
16: To-be-moved-down data-tape 0.
17: To-be-moved-down data-tape 1.
@COLORS
C8C8C8: 3 # light gray
5A5A5A: 4 # dark gray
EBEBEB: 1 12 16 # lighter gray
1E1E1E: 2 13 17 # darker gray
00FFFF: 5 14 15 # cyan
@TABLE
data = (1, 2)
rdata = (12, 13)
ddata = (16, 17)
vacdata = (0..2)
vacrdata = (0, 12, 13)
vacddata = (0, 16, 17)
## If a shifter is encountered, reflect + shift data tape down 2 cells
# go right
vacddata, (1, 2), NE..W any, 5; [N: (16, 17)]
ddata, 0, NE..W any, 5; 0
# pull down
vacrdata, (16, 17), NE..NW any; [N: (12, 13)]
# go left
vacdata, (12, 13), 5, E..NW any; [N: (1, 2)]
# Move rightward-moving data to the right
vacrdata, W rdata, NW..SW any; [W]
rdata, W 0, NW..SW any; 0
## shift the shifter down two as well
# right
0, 5, NE..SW any, 0, rdata; 14
# left
0, 5, data, 0, SE..NW any; 14
# finally
(14, 15), N..NW any; 0 -> S[0: (15, 5)]
# delete shifter at end of its input stream
5, SE ddata, S..E 0; 0
5, SW data, W..S 0; 0
# Shift prgm tape down 1 if rightward data above it
(3, 4), rdata, NE..NW any; [0: (10, 11)]
# If a data bit has a shifter to its right, don't attempt to copy it
data, E 5, SE..NE any; 0
# If a prgm-tape 1 is encountered, shift it downward
# and append the command to its left (by copying+shifting down) onto the right end of the data tape,
# if the leftmost bit is 1 -- otherwise just shift it down
# ----
# check the x in 1x
# leftmost bit 1?
(3, 4), NE 2, E 4, SE..N any; [0: (8, 9)] # copy+shift down
# ----
# leftmost bit 0?
(3, 4), NE 1, E 4, SE..N any; [0: (6, 7)] # just shift down
# ----
# shift the 1 in 1x down
4, data, NE..NW any; 7
7, N..NW any; 0 -> S[(11, _, ...)]
# ----
# state 8 becomes state 1 and below it state 3
8, N..NW any; 1 -> S[(10, _, ...)]
# state 9 becomes state 2 and below it state 4
9, N..NW any; 2 -> S[(11, _, ...)]
# ----
# states 10 and 11 become 3 and 4 moving down
(10, 11), N..NW any; 0 -> S[0: (3, 4)]
# If a bit of data has reached the right end of the tape, append it
# and delete the waiting data
data, E 0, SE any, S data, SW..NE any; [S]
# next line accounts for single-item data tape being appended to
data, E 0, SE data, S..NE any; [SE]
data, data, 0, E..NW any; 0
# If a prgm-tape 0 is encountered, shift it down and delete the leftmost data-tape bit
3, data, NE..NW any; 6
6, N..NW any; 0 -> S:10 # 3
# Delete the leftmost bit if a program-tape 0 is encountered
0, E data, SE 3, S..NE any; 0
# Keep a data-tape bit in place if it's waiting below the data tape (to prepare for moving to the end)
data, data, NE..NW any; [0]
0, data, any, data, SE..NW any; 0
# Move data tape to the left otherwise
0, any, data, data, SE..NW any; 0
vacdata, E vacdata, SE..NE any; [E]