diff --git a/doc/Emitting.markdown b/doc/Emitting.markdown index f156af7..1671539 100644 --- a/doc/Emitting.markdown +++ b/doc/Emitting.markdown @@ -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 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) diff --git a/src/SixtyPical/Context.hs b/src/SixtyPical/Context.hs index 4f3f98a..9453d0e 100644 --- a/src/SixtyPical/Context.hs +++ b/src/SixtyPical/Context.hs @@ -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 diff --git a/src/SixtyPical/Emitter.hs b/src/SixtyPical/Emitter.hs index df11d37..43369d2 100644 --- a/src/SixtyPical/Emitter.hs +++ b/src/SixtyPical/Emitter.hs @@ -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 _ _ [] = "" diff --git a/src/SixtyPical/Model.hs b/src/SixtyPical/Model.hs index 5ee1046..b790ff0 100644 --- a/src/SixtyPical/Model.hs +++ b/src/SixtyPical/Model.hs @@ -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 diff --git a/src/SixtyPical/Parser.hs b/src/SixtyPical/Parser.hs index 1df9ba7..683b278 100644 --- a/src/SixtyPical/Parser.hs +++ b/src/SixtyPical/Parser.hs @@ -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