Explicit `with` syntax.
Cat's Eye Technologies
8 years ago
130 | 130 |
* `outputs` on externals
|
131 | 131 |
* Routine is a kind of StorageLocation? (Location)?
|
132 | 132 |
* remove DELTA -> ADD/SUB (requires carry be notated on ADD and SUB though)
|
133 | |
* explicit `with` syntax
|
2 | 2 |
reserve vector save_cinv
|
3 | 3 |
|
4 | 4 |
routine main {
|
5 | |
sei {
|
|
5 |
with sei {
|
6 | 6 |
copy cinv save_cinv
|
7 | 7 |
copy routine our_cinv to cinv
|
8 | 8 |
}
|
72 | 72 |
routCtx
|
73 | 73 |
|
74 | 74 |
-- TODO -- THESE ARE WEAK --
|
75 | |
checkInstr nm (SEI blk) progCtx routCtx =
|
76 | |
checkBlock nm blk progCtx routCtx
|
77 | |
checkInstr nm (PUSH _ blk) progCtx routCtx =
|
|
75 |
checkInstr nm (WITH _ blk) progCtx routCtx =
|
78 | 76 |
checkBlock nm blk progCtx routCtx
|
79 | 77 |
|
80 | 78 |
checkInstr nm (BIT dst) progCtx routCtx =
|
133 | 133 |
REPEAT iid branch (mapBlock xform blk)
|
134 | 134 |
xform (DELTA dest val) =
|
135 | 135 |
DELTA (resolve dest) val
|
136 | |
xform (SEI blk) =
|
137 | |
SEI (mapBlock xform blk)
|
138 | |
xform (PUSH val blk) =
|
139 | |
PUSH (resolve val) (mapBlock xform blk)
|
|
136 |
xform (WITH SEI blk) =
|
|
137 |
WITH SEI (mapBlock xform blk)
|
|
138 |
xform (WITH (PUSH val) blk) =
|
|
139 |
WITH (PUSH (resolve val)) (mapBlock xform blk)
|
140 | 140 |
xform (COPYROUTINE name dest) =
|
141 | 141 |
COPYROUTINE name (resolve dest)
|
142 | 142 |
xform other =
|
168 | 168 |
emitInstrs p r blk ++
|
169 | 169 |
" " ++ (show branch) ++ " _repeat_" ++ (show iid)
|
170 | 170 |
|
171 | |
emitInstr p r (SEI blk) =
|
|
171 |
emitInstr p r (WITH SEI blk) =
|
172 | 172 |
"sei\n" ++
|
173 | 173 |
emitInstrs p r blk ++
|
174 | 174 |
" cli"
|
175 | 175 |
|
176 | |
emitInstr p r (PUSH A blk) =
|
|
176 |
emitInstr p r (WITH (PUSH A) blk) =
|
177 | 177 |
"pha\n" ++
|
178 | 178 |
emitInstrs p r blk ++
|
179 | 179 |
" pla"
|
180 | 180 |
|
181 | |
emitInstr p r (PUSH AllFlags blk) =
|
|
181 |
emitInstr p r (WITH (PUSH AllFlags) blk) =
|
182 | 182 |
"php\n" ++
|
183 | 183 |
emitInstrs p r blk ++
|
184 | 184 |
" plp"
|
55 | 55 |
data Branch = BCC | BCS | BEQ | BMI | BNE | BPL | BVC | BVS
|
56 | 56 |
deriving (Show, Ord, Eq)
|
57 | 57 |
|
|
58 |
data WithInstruction = SEI
|
|
59 |
| PUSH StorageLocation
|
|
60 |
deriving (Show, Ord, Eq)
|
|
61 |
|
58 | 62 |
data Instruction = COPY StorageLocation StorageLocation
|
59 | 63 |
| CMP StorageLocation StorageLocation
|
60 | 64 |
| ADD StorageLocation StorageLocation
|
|
71 | 75 |
| IF InternalID Branch [Instruction] [Instruction]
|
72 | 76 |
| REPEAT InternalID Branch [Instruction]
|
73 | 77 |
| DELTA StorageLocation DataValue
|
74 | |
| SEI [Instruction]
|
75 | |
| PUSH StorageLocation [Instruction]
|
|
78 |
| WITH WithInstruction [Instruction]
|
76 | 79 |
| COPYROUTINE RoutineName StorageLocation
|
77 | 80 |
| NOP
|
78 | 81 |
deriving (Show, Ord, Eq)
|
26 | 26 |
| "cpy" (LocationName | Immediate)
|
27 | 27 |
| "inx" | "iny" | "dex" | "dey" | "inc" Location | "dec" Location
|
28 | 28 |
| "clc" | "cld" | "clv" | "sec" | "sed"
|
29 | |
| "sei" Block | "pha" Block | "php" Block
|
|
29 |
| "with ("sei" | "pha" | "php") Block
|
30 | 30 |
| "jmp" LocationName
|
31 | 31 |
| "jsr" RoutineName
|
32 | 32 |
| "nop".
|
|
225 | 225 |
(try sbc) <|> (try ora) <|>
|
226 | 226 |
(try asl) <|> (try bit) <|> (try eor) <|> (try lsr) <|>
|
227 | 227 |
(try rol) <|> (try ror) <|>
|
228 | |
(try sei) <|> (try pha) <|> (try php) <|>
|
229 | 228 |
(try jmp) <|> (try jsr) <|>
|
|
229 |
(try with_block) <|>
|
230 | 230 |
(try copy_routine_statement) <|>
|
231 | 231 |
(try copy_general_statement) <|>
|
232 | 232 |
if_statement <|> repeat_statement <|> nop
|
|
476 | 476 |
nspaces
|
477 | 477 |
return (COPY A Y)
|
478 | 478 |
|
479 | |
sei :: Parser Instruction
|
|
479 |
with_block :: Parser Instruction
|
|
480 |
with_block = do
|
|
481 |
string "with"
|
|
482 |
nspaces
|
|
483 |
instr <- (try sei) <|> (try pha) <|> php
|
|
484 |
blk <- block
|
|
485 |
return (WITH instr blk)
|
|
486 |
|
|
487 |
|
|
488 |
sei :: Parser WithInstruction
|
480 | 489 |
sei = do
|
481 | 490 |
string "sei"
|
482 | 491 |
nspaces
|
483 | |
blk <- block
|
484 | |
return (SEI blk)
|
485 | |
|
486 | |
pha :: Parser Instruction
|
|
492 |
return SEI
|
|
493 |
|
|
494 |
pha :: Parser WithInstruction
|
487 | 495 |
pha = do
|
488 | 496 |
string "pha"
|
489 | 497 |
nspaces
|
490 | |
blk <- block
|
491 | |
return (PUSH A blk)
|
492 | |
|
493 | |
php :: Parser Instruction
|
|
498 |
return (PUSH A)
|
|
499 |
|
|
500 |
php :: Parser WithInstruction
|
494 | 501 |
php = do
|
495 | 502 |
string "php"
|
496 | 503 |
nspaces
|
497 | |
blk <- block
|
498 | |
return (PUSH AllFlags blk)
|
|
504 |
return (PUSH AllFlags)
|
499 | 505 |
|
500 | 506 |
jmp :: Parser Instruction
|
501 | 507 |
jmp = do
|