git @ Cat's Eye Technologies SixtyPical / 37215cb
Always emit `main` first. Cat's Eye Technologies 7 years ago
5 changed file(s) with 34 addition(s) and 12 deletion(s). Raw diff Collapse all Expand all
118118 * insist on EOL after each instruction. need spacesWOEOL production
119119 * asl .a
120120 * `outputs` on externals
121 * Routine is a kind of StorageLocation? (Location)?
1818 | }
1919 | sta screen
2020 | }
21 = jmp main
2221 = main:
2322 = lda screen
2423 = cmp screen
4645 | }
4746 | sty screen
4847 | }
49 = jmp main
5048 = main:
5149 = ldy zero
5250 =
7876 | lda #3
7977 | }
8078 | }
81 = jmp main
8279 = main:
8380 = BEQ _label_3
8481 = lda #3
115112 | inc screen
116113 | jmp (save_cinv)
117114 | }
118 = jmp main
119115 = main:
120116 = sei
121117 = lda cinv
144140 | routine main {
145141 | copy #23 position
146142 | }
147 = jmp main
148143 = main:
149144 = lda #23
150145 = sta position
158153 | routine main {
159154 | copy #$0400 position
160155 | }
161 = jmp main
162156 = main:
163157 = lda #0
164158 = sta position
167161 = rts
168162 =
169163 = position: .word 0
164
165 `main` is always emitted first.
166
167 | reserve word position
168 | routine foo {
169 | inx
170 | }
171 | routine main {
172 | jsr foo
173 | jsr foo
174 | }
175 = main:
176 = jsr foo
177 = jsr foo
178 = rts
179 =
180 = foo:
181 = inx
182 = rts
183 =
184 = position: .word 0
202202 | ora #8
203203 | ora vbyte
204204 | }
205 = jmp main
206205 = main:
207206 = lda #4
208207 = ldx #0
276275 | eor #5
277276 | eor vbyte
278277 | }
279 = jmp main
280278 = main:
281279 = asl
282280 = asl vbyte
306304 | lda #2
307305 | }
308306 | }
309 = jmp main
310307 = main:
311308 = pha
312309 = sei
66 import SixtyPical.Model
77
88 emitProgram p@(Program decls routines) =
9 " jmp main\n" ++
10 emitRoutines p routines ++
11 emitDecls p decls
9 let
10 mains = findRoutines (\(Routine name _ _) -> name == "main") routines
11 allElse = findRoutines (\(Routine name _ _) -> name /= "main") routines
12 in
13 emitRoutines p mains ++
14 emitRoutines p allElse ++
15 emitDecls p decls
1216
1317 emitDecls _ [] = ""
1418 emitDecls p (decl:decls) =
175175 lookupRoutine' (rout@(Routine rname _ _):routs) name
176176 | rname == name = Just rout
177177 | otherwise = lookupRoutine' routs name
178
179 findRoutines f [] = []
180 findRoutines f (rout:routs)
181 | f rout = (rout:findRoutines f routs)
182 | otherwise = findRoutines f routs