git @ Cat's Eye Technologies Oxcart / c804467
Remove X instruction. Chris Pressey 5 years ago
2 changed file(s) with 8 addition(s) and 18 deletion(s). Raw diff Collapse all Expand all
178178 | 0^^^0vv
179179 = > 0:[-2,3]
180180
181 The instruction `X` pops a value from the current stack, doubles
182 it, and pushes the result back onto the current stack.
183
184 | 0^XXXX
185 = > 0:[16]
186
187181 The instruction `:` pops a value from the current stack and pushes
188182 two copies of the value back on the stack.
189183
190 | 0^XXX:^
184 | 0^^^^^^^^:^
191185 = > 0:[9,8]
192186
193187 The instruction `$` pops a value from the current stack and discards
194188 it.
195189
196 | 0^XXX$
190 | 0^^^^^$
197191 =
198192
199193 The instruction `\\` pops the top two values, swaps them, and pushes
200194 them back on the stack.
201195
202 | 0^XXX0^\0^^
196 | 0^^^^^^^^0^\0^^
203197 = > 0:[2,8,1]
204198
205199 ### Navigating the stacks
207201 The instruction `<` (resp `>`) moves one space left (resp. right)
208202 on the tape, changing which stack is the current stack.
209203
210 | 0^XX<0^XXX<0^XXXX>
211 = -2:[16]
204 | 0^^^^<0^^^^^^^^<0^^^^^^^^^^>
205 = -2:[10]
212206 = >-1:[8]
213207 = 0:[4]
214208
216210 moves one space left (resp. right) on the tape, and pushes the value
217211 onto the new current stack.
218212
219 | 0^XX<0^XXX(0^XXXX)
213 | 0^^^^<0^^^^^^^^(0^^^^^^^^^^)
220214 = -2:[8]
221 = >-1:[16]
215 = >-1:[10]
222216 = 0:[4]
223217
224218 The instruction `'` (apostrophe) makes stack zero (the stack that
438432
439433 One could say that "Core Oxcart" omits the following operations:
440434
441 X<>\\'
442
443 `X` can probably be implemented with a loop.
435 <>\\'
444436
445437 `<` and `>` can be thought of as just shorthands for `0v0^Y` and
446438 `0^0^Y`.
4040 push0 st k = k $ push (Num 0) st
4141 incr st k = let (Just (Num n), st') = pop st in k (push (Num (n+1)) st')
4242 decr st k = let (Just (Num n), st') = pop st in k (push (Num (n-1)) st')
43 dbl st k = let (Just (Num n), st') = pop st in k (push (Num (n*2)) st')
4443 dup st k = let (Just v, st') = pop st in k (push v (push v st'))
4544 pop' st k = let (Just v, st') = pop st in k st'
4645 swap st k =
9998 m' '0' = push0
10099 m' '^' = incr
101100 m' 'v' = decr
102 m' 'X' = dbl
103101 m' ':' = dup
104102 m' '$' = pop'
105103 m' '\\' = swap