1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-11-22 17:32:01 +00:00

Always emit main first.

This commit is contained in:
Cat's Eye Technologies 2014-04-04 16:54:25 +01:00
parent 5e4bf5caad
commit 37215cb72a
5 changed files with 34 additions and 12 deletions

View File

@ -119,3 +119,4 @@ TODO
* insist on EOL after each instruction. need spacesWOEOL production * insist on EOL after each instruction. need spacesWOEOL production
* asl .a * asl .a
* `outputs` on externals * `outputs` on externals
* Routine is a kind of StorageLocation? (Location)?

View File

@ -19,7 +19,6 @@ Emitting an `if`.
| } | }
| sta screen | sta screen
| } | }
= jmp main
= main: = main:
= lda screen = lda screen
= cmp screen = cmp screen
@ -47,7 +46,6 @@ Emitting a `repeat`.
| } | }
| sty screen | sty screen
| } | }
= jmp main
= main: = main:
= ldy zero = ldy zero
= =
@ -79,7 +77,6 @@ Nested ifs.
| lda #3 | lda #3
| } | }
| } | }
= jmp main
= main: = main:
= BEQ _label_3 = BEQ _label_3
= lda #3 = lda #3
@ -116,7 +113,6 @@ Installing an interrupt handler (at the Kernal level, i.e. with CINV)
| inc screen | inc screen
| jmp (save_cinv) | jmp (save_cinv)
| } | }
= jmp main
= main: = main:
= sei = sei
= lda cinv = lda cinv
@ -145,7 +141,6 @@ Copy command: immediate -> byte
| routine main { | routine main {
| copy #23 position | copy #23 position
| } | }
= jmp main
= main: = main:
= lda #23 = lda #23
= sta position = sta position
@ -159,7 +154,6 @@ Copy command: immediate -> word
| routine main { | routine main {
| copy #$0400 position | copy #$0400 position
| } | }
= jmp main
= main: = main:
= lda #0 = lda #0
= sta position = sta position
@ -168,3 +162,24 @@ Copy command: immediate -> word
= rts = rts
= =
= position: .word 0 = position: .word 0
`main` is always emitted first.
| reserve word position
| routine foo {
| inx
| }
| routine main {
| jsr foo
| jsr foo
| }
= main:
= jsr foo
= jsr foo
= rts
=
= foo:
= inx
= rts
=
= position: .word 0

View File

@ -203,7 +203,6 @@ Big test for parsing and emitting instructions.
| ora #8 | ora #8
| ora vbyte | ora vbyte
| } | }
= jmp main
= main: = main:
= lda #4 = lda #4
= ldx #0 = ldx #0
@ -277,7 +276,6 @@ Big test for parsing and emitting instructions.
| eor #5 | eor #5
| eor vbyte | eor vbyte
| } | }
= jmp main
= main: = main:
= asl = asl
= asl vbyte = asl vbyte
@ -307,7 +305,6 @@ Big test for parsing and emitting instructions.
| lda #2 | lda #2
| } | }
| } | }
= jmp main
= main: = main:
= pha = pha
= sei = sei

View File

@ -7,9 +7,13 @@ import Data.Bits
import SixtyPical.Model import SixtyPical.Model
emitProgram p@(Program decls routines) = emitProgram p@(Program decls routines) =
" jmp main\n" ++ let
emitRoutines p routines ++ mains = findRoutines (\(Routine name _ _) -> name == "main") routines
emitDecls p decls allElse = findRoutines (\(Routine name _ _) -> name /= "main") routines
in
emitRoutines p mains ++
emitRoutines p allElse ++
emitDecls p decls
emitDecls _ [] = "" emitDecls _ [] = ""
emitDecls p (decl:decls) = emitDecls p (decl:decls) =

View File

@ -176,3 +176,8 @@ lookupRoutine' [] _ = Nothing
lookupRoutine' (rout@(Routine rname _ _):routs) name lookupRoutine' (rout@(Routine rname _ _):routs) name
| rname == name = Just rout | rname == name = Just rout
| otherwise = lookupRoutine' routs name | otherwise = lookupRoutine' routs name
findRoutines f [] = []
findRoutines f (rout:routs)
| f rout = (rout:findRoutines f routs)
| otherwise = findRoutines f routs