Remove X instruction.
Chris Pressey
5 years ago
178 | 178 |
| 0^^^0vv
|
179 | 179 |
= > 0:[-2,3]
|
180 | 180 |
|
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 | |
|
187 | 181 |
The instruction `:` pops a value from the current stack and pushes
|
188 | 182 |
two copies of the value back on the stack.
|
189 | 183 |
|
190 | |
| 0^XXX:^
|
|
184 |
| 0^^^^^^^^:^
|
191 | 185 |
= > 0:[9,8]
|
192 | 186 |
|
193 | 187 |
The instruction `$` pops a value from the current stack and discards
|
194 | 188 |
it.
|
195 | 189 |
|
196 | |
| 0^XXX$
|
|
190 |
| 0^^^^^$
|
197 | 191 |
=
|
198 | 192 |
|
199 | 193 |
The instruction `\\` pops the top two values, swaps them, and pushes
|
200 | 194 |
them back on the stack.
|
201 | 195 |
|
202 | |
| 0^XXX0^\0^^
|
|
196 |
| 0^^^^^^^^0^\0^^
|
203 | 197 |
= > 0:[2,8,1]
|
204 | 198 |
|
205 | 199 |
### Navigating the stacks
|
|
207 | 201 |
The instruction `<` (resp `>`) moves one space left (resp. right)
|
208 | 202 |
on the tape, changing which stack is the current stack.
|
209 | 203 |
|
210 | |
| 0^XX<0^XXX<0^XXXX>
|
211 | |
= -2:[16]
|
|
204 |
| 0^^^^<0^^^^^^^^<0^^^^^^^^^^>
|
|
205 |
= -2:[10]
|
212 | 206 |
= >-1:[8]
|
213 | 207 |
= 0:[4]
|
214 | 208 |
|
|
216 | 210 |
moves one space left (resp. right) on the tape, and pushes the value
|
217 | 211 |
onto the new current stack.
|
218 | 212 |
|
219 | |
| 0^XX<0^XXX(0^XXXX)
|
|
213 |
| 0^^^^<0^^^^^^^^(0^^^^^^^^^^)
|
220 | 214 |
= -2:[8]
|
221 | |
= >-1:[16]
|
|
215 |
= >-1:[10]
|
222 | 216 |
= 0:[4]
|
223 | 217 |
|
224 | 218 |
The instruction `'` (apostrophe) makes stack zero (the stack that
|
|
438 | 432 |
|
439 | 433 |
One could say that "Core Oxcart" omits the following operations:
|
440 | 434 |
|
441 | |
X<>\\'
|
442 | |
|
443 | |
`X` can probably be implemented with a loop.
|
|
435 |
<>\\'
|
444 | 436 |
|
445 | 437 |
`<` and `>` can be thought of as just shorthands for `0v0^Y` and
|
446 | 438 |
`0^0^Y`.
|
40 | 40 |
push0 st k = k $ push (Num 0) st
|
41 | 41 |
incr st k = let (Just (Num n), st') = pop st in k (push (Num (n+1)) st')
|
42 | 42 |
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')
|
44 | 43 |
dup st k = let (Just v, st') = pop st in k (push v (push v st'))
|
45 | 44 |
pop' st k = let (Just v, st') = pop st in k st'
|
46 | 45 |
swap st k =
|
|
99 | 98 |
m' '0' = push0
|
100 | 99 |
m' '^' = incr
|
101 | 100 |
m' 'v' = decr
|
102 | |
m' 'X' = dbl
|
103 | 101 |
m' ':' = dup
|
104 | 102 |
m' '$' = pop'
|
105 | 103 |
m' '\\' = swap
|