1
0
mirror of https://github.com/catseye/SixtyPical.git synced 2024-06-19 10:29:28 +00:00

Beginning of work on externals.

This commit is contained in:
Cat's Eye Technologies 2014-04-02 09:19:53 +01:00
parent 60287c3850
commit f9f8cfc0ca
3 changed files with 73 additions and 32 deletions

View File

@ -312,6 +312,14 @@ A program may `reserve` and `assign`.
| }
= True
A program may declare an `external`.
| external blastoff 49152
| routine main {
| jsr blastoff
| }
= True
All declarations (`reserve`s and `assign`s) must come before any `routines`.
| routine main {
@ -344,6 +352,13 @@ Even in inner blocks.
| }
? undeclared location
All routines jsr'ed to must be defined, or external.
| routine main {
| jsr blastoff
| }
? undeclared routine
No duplicate location names in declarations.
| reserve word score
@ -353,7 +368,7 @@ No duplicate location names in declarations.
| }
? duplicate location name
No duplicate routine names..
No duplicate routine names.
| routine main {
| nop
@ -363,6 +378,14 @@ No duplicate routine names..
| }
? duplicate routine name
No duplicate routine names, including externals.
| external main 7000
| routine main {
| nop
| }
? duplicate routine name
We can jump to a vector.
| reserve vector blah

View File

@ -46,6 +46,7 @@ data StorageType = Byte
data Decl = Assign LocationName StorageType Address -- .alias
| Reserve LocationName StorageType -- .word, .byte
| External RoutineName Address
deriving (Show, Ord, Eq)
type RoutineName = String

View File

@ -9,7 +9,8 @@ import Text.ParserCombinators.Parsec
Toplevel := {Decl} {Routine}.
Decl := "reserve" StorageType LocationName
| "assign" StorageType LocationName Address.
| "assign" StorageType LocationName Address
| "external" RoutineName Address.
StorageType := "byte" | "word" | "vector".
Routine := "routine" RoutineName Block.
Block := "{" {Command} "}".
@ -25,6 +26,7 @@ Command := "if" Branch Block "else" Block
| "clc" | "cld" | "clv" | "sec" | "sed"
| "sei" Block
| "jmp" LocationName
| "jsr" RoutineName
| "nop".
Branch := "bcc" | "bcs" | "beq" | "bmi" | "bne" | "bpl" | "bvc" | "bvs".
@ -32,7 +34,7 @@ Branch := "bcc" | "bcs" | "beq" | "bmi" | "bne" | "bpl" | "bvc" | "bvs".
toplevel :: Parser Program
toplevel = do
decls <- many (assign <|> try reserve)
decls <- many (try assign <|> try reserve <|> try external)
routines <- many routine
return $ Program decls routines
@ -53,6 +55,14 @@ assign = do
addr <- address
return $ Assign name sz addr
external :: Parser Decl
external = do
string "external"
spaces
name <- routineName
addr <- address
return $ External name addr
get_storage "byte" = Byte
get_storage "word" = Word
get_storage "vector" = Vector
@ -82,7 +92,34 @@ block = do
spaces
return cs
--command = (try lda_imm) <|> (try lda) <|>
-- -- -- -- -- -- commands -- -- -- -- --
immediate :: (DataValue -> Instruction) -> Parser Instruction
immediate f = do
string "#"
v <- data_value
return $ f v
absolute :: (LocationName -> Instruction) -> Parser Instruction
absolute f = do
l <- locationName
return $ f l
index :: Parser StorageLocation
index = do
string ","
spaces
c <- (string "x" <|> string "y")
spaces
return $ case c of
"x" -> X
"y" -> Y
absolute_indexed :: (LocationName -> [StorageLocation] -> Instruction) -> Parser Instruction
absolute_indexed f = do
l <- locationName
indexes <- many index
return $ f l indexes
command :: Parser Instruction
command = (try lda) <|>
@ -96,7 +133,7 @@ command = (try lda) <|>
(try adc) <|> (try SixtyPical.Parser.and) <|>
(try sbc) <|> (try ora) <|>
(try sei) <|>
(try jmp) <|>
(try jmp) <|> (try jsr) <|>
(try copy_vector_statement) <|>
(try copy_routine_statement) <|>
if_statement <|> repeat_statement <|> nop
@ -224,33 +261,6 @@ ora = do
(try $ immediate (\v -> ORIMM A v) <|>
absolute (\l -> OR A (NamedLocation l)))
immediate :: (DataValue -> Instruction) -> Parser Instruction
immediate f = do
string "#"
v <- data_value
return $ f v
absolute :: (LocationName -> Instruction) -> Parser Instruction
absolute f = do
l <- locationName
return $ f l
index :: Parser StorageLocation
index = do
string ","
spaces
c <- (string "x" <|> string "y")
spaces
return $ case c of
"x" -> X
"y" -> Y
absolute_indexed :: (LocationName -> [StorageLocation] -> Instruction) -> Parser Instruction
absolute_indexed f = do
l <- locationName
indexes <- many index
return $ f l indexes
lda :: Parser Instruction
lda = do
string "lda"
@ -335,6 +345,13 @@ jmp = do
l <- locationName
return $ JMPVECTOR (NamedLocation l)
jsr :: Parser Instruction
jsr = do
string "jsr"
spaces
l <- routineName
return $ JSR l
if_statement :: Parser Instruction
if_statement = do
string "if"