-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathday18_tests.tal
178 lines (151 loc) · 4.63 KB
/
day18_tests.tal
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
~library/macros.tal
~library/devices.tal
( variables )
|0000
|0100 @program
T< "parse-snailfish-number: >T
S< "[1,1] 0a >S ;test-parse-snailnum JSR2 ( EXPECT [1,1] )
S< "[[1,2],3] 0a >S ;test-parse-snailnum JSR2 ( EXPECT [[1,2],3] )
S< "[[1,2],[3,4]] 0a >S ;test-parse-snailnum JSR2 ( EXPECT [[1,2],[3,4]] )
S< aaaa >S STH2
S< >S ;make-get-byte JSR2 STH2rk ;snailcalc/parse JSR2
STH2r LDA2 DBGSHORT POP2
( EXPECT 0xffff )
T< "shift-left4: >T
S< aaaa bbbb cccc ffff >S
DUP2 ;snailcalc/shift-left4 JSR2
LDA2k DBGSHORTn SP POP2
2++ LDA2k DBGSHORTn LF POP2
POP2
( EXPECT 0xcccc 0xffff )
T< "explode: >T
S< "[1,2] >S ;test-explode JSR2 ( EXPECT 0x00 [1,2] )
S< "[[[[[9,8],1],2],3],4] >S ;test-explode JSR2 ( EXPECT 0x01 [[[[0,9],2],3],4] )
S< "[7,[6,[5,[4,[3,2]]]]] >S ;test-explode JSR2 ( EXPECT 0x01 [7,[6,[5,[7,0]]]] )
S< "[[6,[5,[4,[3,2]]]],1] >S ;test-explode JSR2 ( EXPECT 0x01 [[6,[5,[7,0]]],3] )
S< "[[3,[2,[1,[7,3]]]],[6,[5,[4,[3,2]]]]] >S ;test-explode JSR2 ( EXPECT 0x01 [[3,[2,[8,0]]],[9,[5,[4,[3,2]]]]] )
S< "[[3,[2,[8,0]]],[9,[5,[4,[3,2]]]]] >S ;test-explode JSR2 ( EXPECT 0x01 [[3,[2,[8,0]]],[9,[5,[7,0]]]] )
T< "shift-right4: >T
S< aaaa bbbb cccc dddd ffff >S
DUP2 ;snailcalc/shift-right4 JSR2
LDA2k DBGSHORTn SP POP2
2++ LDA2k DBGSHORTn SP POP2
2++ LDA2k DBGSHORTn SP POP2
2++ LDA2k DBGSHORTn SP POP2
2++ LDA2k DBGSHORTn SP POP2
2++ LDA2k DBGSHORTn SP POP2
2++ LDA2k DBGSHORTn LF POP2
POP2
( EXPECT 0x0000 0x0000 0xaaaa 0xbbbb 0xcccc 0xdddd 0xffff )
T< "split: >T
S< "[1,2] >S ;test-split JSR2 ( EXPECT 0x00 [1,2] )
S< "[[[[0,7],4],[15,[0,13]]],[1,1]] >S ;test-split JSR2 ( EXPECT 0x01 [[[[0,7],4],[[7,8],[0,13]]],[1,1]] )
S< "[[[[0,7],4],[[7,8],[0,13]]],[1,1]] >S ;test-split JSR2 ( EXPECT 0x01 [[[[0,7],4],[[7,8],[0,[6,7]]]],[1,1]] )
T< "reduce: >T
S< "[[[[[4,3],4],4],[7,[[8,4],9]]],[1,1]] >S ;test-reduce JSR2
( EXPECT [[[[0,7],4],[[7,8],[6,0]]],[8,1]] )
T< "copy: >T
S< aaaa aaaa aaaa >S S< bbbb cccc ffff >S
OVR2 SWP2 ;snailcalc/copy JSR2
LDA2k DBGSHORTn SP POP2
2++ LDA2k DBGSHORTn SP POP2
2++ LDA2k DBGSHORTn LF POP2
POP2
( EXPECT 0xbbbb 0xcccc 0xffff )
T< "add: >T
S< "[[[[4,3],4],4],[7,[[8,4],9]]] >S S< "[1,1] >S ;test-add JSR2
( EXPECT [[[[[4,3],4],4],[7,[[8,4],9]]],[1,1]] )
( EXPECT [[[[0,7],4],[[7,8],[6,0]]],[8,1]] )
T< "list-add: >T
S< "[1,1] 0a
"[2,2] 0a
"[3,3] 0a
"[4,4] 0a >S ;test-list-add JSR2
( EXPECT [[[[1,1],[2,2]],[3,3]],[4,4]] )
S< "[[[0,[5,8]],[[1,7],[9,6]]],[[4,[1,2]],[[1,4],2]]] 0a
"[[[5,[2,8]],4],[5,[[9,9],0]]] 0a
"[6,[[[6,2],[5,6]],[[7,6],[4,7]]]] 0a
"[[[6,[0,7]],[0,9]],[4,[9,[9,0]]]] 0a
"[[[7,[6,4]],[3,[1,3]]],[[[5,5],1],9]] 0a
"[[6,[[7,3],[3,2]]],[[[3,8],[5,7]],4]] 0a
"[[[[5,4],[7,7]],8],[[8,3],8]] 0a
"[[9,3],[[9,9],[6,[4,9]]]] 0a
"[[2,[[7,7],7]],[[5,8],[[9,3],[0,2]]]] 0a
"[[[[5,2],5],[8,[3,7]]],[[5,[7,5]],[4,4]]] 0a >S ;test-list-add JSR2
( EXPECT [[[[6,6],[7,6]],[[7,7],[7,0]]],[[[7,7],[7,7]],[[7,8],[9,9]]]] )
T< "magnitude: >T
S< "[[[[6,6],[7,6]],[[7,7],[7,0]]],[[[7,7],[7,7]],[[7,8],[9,9]]]] >S
;test-magnitude JSR2
( EXPECT 4140 )
T< "🎄 >T
BRK !
( s* -- )
@test-parse-snailnum
;make-get-byte JSR2 ;&tmp ;snailcalc/parse JSR2
;&tmp ;snailcalc/print JSR2
LF
RTN
[ &tmp $100 ]
( s* -- )
@test-explode
;make-get-byte JSR2 ;&tmp ;snailcalc/parse JSR2
;&tmp ;snailcalc/explode JSR2
DBGBYTEn SP POP
;&tmp ;snailcalc/print JSR2
LF
RTN
[ &tmp $100 ]
( s* -- )
@test-split
;make-get-byte JSR2 ;&tmp ;snailcalc/parse JSR2
;&tmp ;snailcalc/split JSR2
DBGBYTEn SP POP
;&tmp ;snailcalc/print JSR2
LF
RTN
[ &tmp $100 ]
( s* -- )
@test-reduce
;make-get-byte JSR2 ;&tmp ;snailcalc/parse JSR2
;&tmp ;snailcalc/reduce JSR2
;&tmp ;snailcalc/print JSR2
LF
RTN
[ &tmp $100 ]
( s1* s2* -- )
@test-add
;make-get-byte JSR2 ;&sn2 ;snailcalc/parse JSR2
;make-get-byte JSR2 ;&sn1 ;snailcalc/parse JSR2
;&sn1 ;&sn2 ;snailcalc/add JSR2
;&sn1 ;snailcalc/print JSR2 LF
;&sn1 ;snailcalc/reduce JSR2
;&sn1 ;snailcalc/print JSR2 LF
RTN
[ &sn1 $100 &sn2 $100 ]
( s* -- )
@test-list-add
;make-get-byte JSR2 ;&result ;snailcalc/list-add JSR2
;&result ;snailcalc/print JSR2 LF
RTN
[ &result $200 ]
( s* -- )
@test-magnitude
;make-get-byte JSR2 ;&result ;snailcalc/parse JSR2
;&result ;snailcalc/magnitude JSR2
DBGSHORTDEC POP2
RTN
[ &result $200 ]
( s* -- get-byte )
@make-get-byte
;input STA2
;get-byte-from-input
RTN
( -- b )
@get-byte-from-input
[ ;input LDA2 ] LDA STH
[ ;input LDA2 ] INC2 [ ;input STA2 ]
STHr
RTN
@input $2
~library/test.tal
~day18_lib.tal