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:
parent
5e4bf5caad
commit
37215cb72a
@ -119,3 +119,4 @@ TODO
|
||||
* insist on EOL after each instruction. need spacesWOEOL production
|
||||
* asl .a
|
||||
* `outputs` on externals
|
||||
* Routine is a kind of StorageLocation? (Location)?
|
||||
|
@ -19,7 +19,6 @@ Emitting an `if`.
|
||||
| }
|
||||
| sta screen
|
||||
| }
|
||||
= jmp main
|
||||
= main:
|
||||
= lda screen
|
||||
= cmp screen
|
||||
@ -47,7 +46,6 @@ Emitting a `repeat`.
|
||||
| }
|
||||
| sty screen
|
||||
| }
|
||||
= jmp main
|
||||
= main:
|
||||
= ldy zero
|
||||
=
|
||||
@ -79,7 +77,6 @@ Nested ifs.
|
||||
| lda #3
|
||||
| }
|
||||
| }
|
||||
= jmp main
|
||||
= main:
|
||||
= BEQ _label_3
|
||||
= lda #3
|
||||
@ -116,7 +113,6 @@ Installing an interrupt handler (at the Kernal level, i.e. with CINV)
|
||||
| inc screen
|
||||
| jmp (save_cinv)
|
||||
| }
|
||||
= jmp main
|
||||
= main:
|
||||
= sei
|
||||
= lda cinv
|
||||
@ -145,7 +141,6 @@ Copy command: immediate -> byte
|
||||
| routine main {
|
||||
| copy #23 position
|
||||
| }
|
||||
= jmp main
|
||||
= main:
|
||||
= lda #23
|
||||
= sta position
|
||||
@ -159,7 +154,6 @@ Copy command: immediate -> word
|
||||
| routine main {
|
||||
| copy #$0400 position
|
||||
| }
|
||||
= jmp main
|
||||
= main:
|
||||
= lda #0
|
||||
= sta position
|
||||
@ -168,3 +162,24 @@ Copy command: immediate -> word
|
||||
= rts
|
||||
=
|
||||
= 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
|
||||
|
@ -203,7 +203,6 @@ Big test for parsing and emitting instructions.
|
||||
| ora #8
|
||||
| ora vbyte
|
||||
| }
|
||||
= jmp main
|
||||
= main:
|
||||
= lda #4
|
||||
= ldx #0
|
||||
@ -277,7 +276,6 @@ Big test for parsing and emitting instructions.
|
||||
| eor #5
|
||||
| eor vbyte
|
||||
| }
|
||||
= jmp main
|
||||
= main:
|
||||
= asl
|
||||
= asl vbyte
|
||||
@ -307,7 +305,6 @@ Big test for parsing and emitting instructions.
|
||||
| lda #2
|
||||
| }
|
||||
| }
|
||||
= jmp main
|
||||
= main:
|
||||
= pha
|
||||
= sei
|
||||
|
@ -7,9 +7,13 @@ import Data.Bits
|
||||
import SixtyPical.Model
|
||||
|
||||
emitProgram p@(Program decls routines) =
|
||||
" jmp main\n" ++
|
||||
emitRoutines p routines ++
|
||||
emitDecls p decls
|
||||
let
|
||||
mains = findRoutines (\(Routine name _ _) -> name == "main") routines
|
||||
allElse = findRoutines (\(Routine name _ _) -> name /= "main") routines
|
||||
in
|
||||
emitRoutines p mains ++
|
||||
emitRoutines p allElse ++
|
||||
emitDecls p decls
|
||||
|
||||
emitDecls _ [] = ""
|
||||
emitDecls p (decl:decls) =
|
||||
|
@ -176,3 +176,8 @@ lookupRoutine' [] _ = Nothing
|
||||
lookupRoutine' (rout@(Routine rname _ _):routs) name
|
||||
| rname == name = Just rout
|
||||
| otherwise = lookupRoutine' routs name
|
||||
|
||||
findRoutines f [] = []
|
||||
findRoutines f (rout:routs)
|
||||
| f rout = (rout:findRoutines f routs)
|
||||
| otherwise = findRoutines f routs
|
||||
|
Loading…
Reference in New Issue
Block a user