git @ Cat's Eye Technologies SixtyPical / 9a0896c
Explicit `with` syntax. Cat's Eye Technologies 7 years ago
11 changed file(s) with 39 addition(s) and 33 deletion(s). Raw diff Collapse all Expand all
130130 * `outputs` on externals
131131 * Routine is a kind of StorageLocation? (Location)?
132132 * remove DELTA -> ADD/SUB (requires carry be notated on ADD and SUB though)
133 * explicit `with` syntax
104104 | reserve vector save_cinv
105105 |
106106 | routine main {
107 | sei {
107 | with sei {
108108 | copy cinv save_cinv
109109 | copy routine our_cinv to cinv
110110 | }
296296 = .alias table 1024
297297
298298 | routine main {
299 | pha {
300 | sei {
301 | php {
299 | with pha {
300 | with sei {
301 | with php {
302302 | lda #0
303303 | }
304304 | lda #1
22 reserve vector save_cinv
33
44 routine main {
5 sei {
5 with sei {
66 copy cinv save_cinv
77 copy routine our_cinv to cinv
88 }
100100 sta vic_bg
101101 jsr reset_position
102102 jsr clear_screen
103 sei {
103 with sei {
104104 copy cinv save_cinv
105105 copy routine our_cinv to cinv
106106 }
155155 sta vic_bg
156156 jsr reset_position
157157 jsr clear_screen
158 sei {
158 with sei {
159159 copy cinv save_cinv
160160 copy routine our_cinv to cinv
161161 }
7272 routCtx
7373
7474 -- 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 =
7876 checkBlock nm blk progCtx routCtx
7977
8078 checkInstr nm (BIT dst) progCtx routCtx =
133133 REPEAT iid branch (mapBlock xform blk)
134134 xform (DELTA dest val) =
135135 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)
140140 xform (COPYROUTINE name dest) =
141141 COPYROUTINE name (resolve dest)
142142 xform other =
168168 emitInstrs p r blk ++
169169 " " ++ (show branch) ++ " _repeat_" ++ (show iid)
170170
171 emitInstr p r (SEI blk) =
171 emitInstr p r (WITH SEI blk) =
172172 "sei\n" ++
173173 emitInstrs p r blk ++
174174 " cli"
175175
176 emitInstr p r (PUSH A blk) =
176 emitInstr p r (WITH (PUSH A) blk) =
177177 "pha\n" ++
178178 emitInstrs p r blk ++
179179 " pla"
180180
181 emitInstr p r (PUSH AllFlags blk) =
181 emitInstr p r (WITH (PUSH AllFlags) blk) =
182182 "php\n" ++
183183 emitInstrs p r blk ++
184184 " plp"
5555 data Branch = BCC | BCS | BEQ | BMI | BNE | BPL | BVC | BVS
5656 deriving (Show, Ord, Eq)
5757
58 data WithInstruction = SEI
59 | PUSH StorageLocation
60 deriving (Show, Ord, Eq)
61
5862 data Instruction = COPY StorageLocation StorageLocation
5963 | CMP StorageLocation StorageLocation
6064 | ADD StorageLocation StorageLocation
7175 | IF InternalID Branch [Instruction] [Instruction]
7276 | REPEAT InternalID Branch [Instruction]
7377 | DELTA StorageLocation DataValue
74 | SEI [Instruction]
75 | PUSH StorageLocation [Instruction]
78 | WITH WithInstruction [Instruction]
7679 | COPYROUTINE RoutineName StorageLocation
7780 | NOP
7881 deriving (Show, Ord, Eq)
2626 | "cpy" (LocationName | Immediate)
2727 | "inx" | "iny" | "dex" | "dey" | "inc" Location | "dec" Location
2828 | "clc" | "cld" | "clv" | "sec" | "sed"
29 | "sei" Block | "pha" Block | "php" Block
29 | "with ("sei" | "pha" | "php") Block
3030 | "jmp" LocationName
3131 | "jsr" RoutineName
3232 | "nop".
225225 (try sbc) <|> (try ora) <|>
226226 (try asl) <|> (try bit) <|> (try eor) <|> (try lsr) <|>
227227 (try rol) <|> (try ror) <|>
228 (try sei) <|> (try pha) <|> (try php) <|>
229228 (try jmp) <|> (try jsr) <|>
229 (try with_block) <|>
230230 (try copy_routine_statement) <|>
231231 (try copy_general_statement) <|>
232232 if_statement <|> repeat_statement <|> nop
476476 nspaces
477477 return (COPY A Y)
478478
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
480489 sei = do
481490 string "sei"
482491 nspaces
483 blk <- block
484 return (SEI blk)
485
486 pha :: Parser Instruction
492 return SEI
493
494 pha :: Parser WithInstruction
487495 pha = do
488496 string "pha"
489497 nspaces
490 blk <- block
491 return (PUSH A blk)
492
493 php :: Parser Instruction
498 return (PUSH A)
499
500 php :: Parser WithInstruction
494501 php = do
495502 string "php"
496503 nspaces
497 blk <- block
498 return (PUSH AllFlags blk)
504 return (PUSH AllFlags)
499505
500506 jmp :: Parser Instruction
501507 jmp = do