mirror of
https://github.com/catseye/SixtyPical.git
synced 2025-01-10 02:29:23 +00:00
Backed out changeset fddaf1476975. Going to do this differently.
This commit is contained in:
parent
f43612e616
commit
cb53d461df
@ -211,40 +211,3 @@ Reserving and assigning byte tables.
|
||||
= .space frequencies 16
|
||||
= .alias screen 1024
|
||||
|
||||
Temporary storage. Note that these temporaries are not unioned yet, but
|
||||
they could be.
|
||||
|
||||
| routine a
|
||||
| temporary byte foo
|
||||
| temporary word bar {
|
||||
| lda foo
|
||||
| sta >bar
|
||||
| }
|
||||
| routine b
|
||||
| temporary byte baz
|
||||
| temporary word quuz {
|
||||
| lda baz
|
||||
| sta <quuz
|
||||
| }
|
||||
| routine main {
|
||||
| jsr a
|
||||
| jsr b
|
||||
| }
|
||||
= main:
|
||||
= jsr a
|
||||
= jsr b
|
||||
= rts
|
||||
= a:
|
||||
= lda _temp_1
|
||||
= sta _temp_2+1
|
||||
= rts
|
||||
= b:
|
||||
= lda _temp_3
|
||||
= sta _temp_4
|
||||
= rts
|
||||
=
|
||||
= .data
|
||||
= .space _temp_1 1
|
||||
= .space _temp_2 2
|
||||
= .space _temp_3 1
|
||||
= .space _temp_4 2
|
||||
|
@ -13,7 +13,7 @@ analyzeProgram program@(Program decls routines) =
|
||||
checkRoutines routines Map.empty
|
||||
where
|
||||
checkRoutines [] progCtx = progCtx
|
||||
checkRoutines (rout@(Routine name outputs temps _) : routs) progCtx =
|
||||
checkRoutines (rout@(Routine name outputs _) : routs) progCtx =
|
||||
let
|
||||
routCtx = Map.empty
|
||||
routAnalysis = checkRoutine rout progCtx routCtx
|
||||
@ -21,7 +21,7 @@ analyzeProgram program@(Program decls routines) =
|
||||
in
|
||||
checkRoutines routs progCtx'
|
||||
|
||||
checkRoutine (Routine name outputs temps instrs) progCtx routCtx =
|
||||
checkRoutine (Routine name outputs instrs) progCtx routCtx =
|
||||
checkBlock name instrs progCtx routCtx
|
||||
|
||||
checkBlock nm [] progCtx routCtx = routCtx
|
||||
@ -103,7 +103,7 @@ analyzeProgram program@(Program decls routines) =
|
||||
-- JSR'ed to (immediately previously) -- and merge them to create a new
|
||||
-- context for the current routine.
|
||||
--
|
||||
mergeRoutCtxs nm routCtx calledRoutCtx calledRout@(Routine name outputs temps _) =
|
||||
mergeRoutCtxs nm routCtx calledRoutCtx calledRout@(Routine name outputs _) =
|
||||
let
|
||||
-- go through all the Usages in the calledRoutCtx
|
||||
-- insert any that were updated, into routCtx
|
||||
|
@ -72,11 +72,11 @@ numberRoutinesLoops (routine:routines) iid =
|
||||
((routine':routines'), iid'')
|
||||
|
||||
numberRoutineLoops :: Routine -> InternalID -> (Routine, InternalID)
|
||||
numberRoutineLoops (Routine name outputs temps instrs) iid =
|
||||
numberRoutineLoops (Routine name outputs instrs) iid =
|
||||
let
|
||||
(instrs', iid') = numberBlockLoops instrs iid
|
||||
in
|
||||
((Routine name outputs temps instrs'), iid')
|
||||
((Routine name outputs instrs'), iid')
|
||||
|
||||
numberBlockLoops :: [Instruction] -> InternalID -> ([Instruction], InternalID)
|
||||
numberBlockLoops [] iid = ([], iid)
|
||||
|
@ -65,7 +65,7 @@ ppAnalysis program progCtx =
|
||||
ppRoutines program [] = return ()
|
||||
ppRoutines program ((name, routCtx):rest) =
|
||||
let
|
||||
Just (Routine rname outputs temps _) = lookupRoutine program name
|
||||
Just (Routine rname outputs _) = lookupRoutine program name
|
||||
in do
|
||||
putStrLn (rname ++ " (" ++ (show outputs) ++ ")")
|
||||
ppRoutine routCtx
|
||||
|
@ -8,8 +8,8 @@ import SixtyPical.Model
|
||||
|
||||
emitProgram p@(Program decls routines) =
|
||||
let
|
||||
mains = filter (\(Routine name _ _ _) -> name == "main") routines
|
||||
allElse = filter (\(Routine name _ _ _) -> name /= "main") routines
|
||||
mains = filter (\(Routine name _ _) -> name == "main") routines
|
||||
allElse = filter (\(Routine name _ _) -> name /= "main") routines
|
||||
initializedDecls = filter (\d -> isInitializedDecl d) decls
|
||||
uninitializedDecls = filter (\d -> not $ isInitializedDecl d) decls
|
||||
in
|
||||
@ -47,7 +47,7 @@ emitRoutines _ [] = ""
|
||||
emitRoutines p (rout:routs) =
|
||||
emitRoutine p rout ++ "\n" ++ emitRoutines p routs
|
||||
|
||||
emitRoutine p r@(Routine name _ _ instrs) =
|
||||
emitRoutine p r@(Routine name _ instrs) =
|
||||
name ++ ":\n" ++ emitInstrs p r instrs ++ " rts\n"
|
||||
|
||||
emitInstrs _ _ [] = ""
|
||||
|
@ -81,11 +81,7 @@ data Instruction = COPY StorageLocation StorageLocation
|
||||
| NOP
|
||||
deriving (Show, Ord, Eq)
|
||||
|
||||
data Temporary = Temporary InternalID LocationName StorageType
|
||||
deriving (Show, Ord, Eq)
|
||||
|
||||
-- name outputs temporaries body
|
||||
data Routine = Routine RoutineName [StorageLocation] [Temporary] [Instruction]
|
||||
data Routine = Routine RoutineName [StorageLocation] [Instruction]
|
||||
deriving (Show, Ord, Eq)
|
||||
|
||||
data Program = Program [Decl] [Routine]
|
||||
@ -97,7 +93,7 @@ data Program = Program [Decl] [Routine]
|
||||
programSummary p@(Program decls routs) =
|
||||
show ((length $ show p) < 99999)
|
||||
|
||||
getRoutineName (Routine name _ _ _) = name
|
||||
getRoutineName (Routine name _ _) = name
|
||||
|
||||
getDeclLocationName (Assign name _ _) = name
|
||||
getDeclLocationName (Reserve name _ _) = name
|
||||
@ -137,8 +133,8 @@ mapBlock :: (Instruction -> Instruction) -> [Instruction] -> [Instruction]
|
||||
mapBlock = map
|
||||
|
||||
mapRoutine :: (Instruction -> Instruction) -> Routine -> Routine
|
||||
mapRoutine f (Routine name outputs temps instrs) =
|
||||
Routine name outputs temps (mapBlock f instrs)
|
||||
mapRoutine f (Routine name outputs instrs) =
|
||||
Routine name outputs (mapBlock f instrs)
|
||||
|
||||
mapRoutines :: (Instruction -> Instruction) -> [Routine] -> [Routine]
|
||||
mapRoutines f [] = []
|
||||
@ -155,7 +151,7 @@ foldBlock :: (Instruction -> a -> a) -> a -> [Instruction] -> a
|
||||
foldBlock = foldr
|
||||
|
||||
foldRoutine :: (Instruction -> a -> a) -> a -> Routine -> a
|
||||
foldRoutine f a (Routine name outputs temps instrs) =
|
||||
foldRoutine f a (Routine name outputs instrs) =
|
||||
foldBlock f a instrs
|
||||
|
||||
foldRoutines :: (Instruction -> a -> a) -> a -> [Routine] -> a
|
||||
@ -184,6 +180,6 @@ lookupRoutine (Program _ routines) name =
|
||||
lookupRoutine' routines name
|
||||
|
||||
lookupRoutine' [] _ = Nothing
|
||||
lookupRoutine' (rout@(Routine rname _ _ _):routs) name
|
||||
lookupRoutine' (rout@(Routine rname _ _):routs) name
|
||||
| rname == name = Just rout
|
||||
| otherwise = lookupRoutine' routs name
|
||||
|
@ -10,15 +10,14 @@ import SixtyPical.Model
|
||||
|
||||
{-
|
||||
|
||||
Toplevel ::= {Decl} {Routine}.
|
||||
Decl ::= "reserve" StorageType LocationName [":" Literal]
|
||||
| "assign" StorageType LocationName Literal
|
||||
| "external" RoutineName Address.
|
||||
StorageType ::= "byte" ["[" Literal "]"] | "word" | "vector".
|
||||
Routine ::= "routine" RoutineName ["outputs" "(" {LocationName} ")"] Block.
|
||||
Block ::= "{" {Temporary} {Command} "}".
|
||||
Temporary ::= "temporary" StorageType LocationName
|
||||
Command ::= "if" Branch Block "else" Block
|
||||
Toplevel := {Decl} {Routine}.
|
||||
Decl := "reserve" StorageType LocationName [":" Literal]
|
||||
| "assign" StorageType LocationName Literal
|
||||
| "external" RoutineName Address.
|
||||
StorageType := "byte" ["[" Literal "]"] | "word" | "vector".
|
||||
Routine := "routine" RoutineName ["outputs" "(" {LocationName} ")"] Block.
|
||||
Block := "{" {Command} "}".
|
||||
Command := "if" Branch Block "else" Block
|
||||
| "lda" (LocationName | Immediate)
|
||||
| "ldx" (LocationName | Immediate)
|
||||
| "ldy" (LocationName | Immediate)
|
||||
@ -79,10 +78,10 @@ assign :: Parser Decl
|
||||
assign = do
|
||||
string "assign"
|
||||
nspaces
|
||||
typ <- storage_type
|
||||
sz <- storage_type
|
||||
name <- location_name
|
||||
addr <- literal_address
|
||||
return $ Assign name typ addr
|
||||
return $ Assign name sz addr
|
||||
|
||||
external :: Parser Decl
|
||||
external = do
|
||||
@ -92,14 +91,6 @@ external = do
|
||||
addr <- literal_address
|
||||
return $ External name addr
|
||||
|
||||
temporary :: Parser Temporary
|
||||
temporary = do
|
||||
string "temporary"
|
||||
nspaces
|
||||
typ <- storage_type
|
||||
name <- location_name
|
||||
return $ Temporary 0 name typ
|
||||
|
||||
storage :: String -> StorageType -> Parser StorageType
|
||||
storage s t = do
|
||||
string s
|
||||
@ -127,9 +118,8 @@ routine = do
|
||||
nspaces
|
||||
name <- routineName
|
||||
outputs <- (try routine_outputs <|> return [])
|
||||
temps <- many temporary
|
||||
instrs <- block
|
||||
return (Routine name outputs temps instrs)
|
||||
return (Routine name outputs instrs)
|
||||
|
||||
routine_outputs :: Parser [StorageLocation]
|
||||
routine_outputs = do
|
||||
|
Loading…
x
Reference in New Issue
Block a user