mirror of
https://github.com/catseye/SixtyPical.git
synced 2024-06-15 14:29:32 +00:00
No duplicate routine names check.
This commit is contained in:
parent
f9f8cfc0ca
commit
180efe281d
|
@ -9,26 +9,6 @@ allTrue = foldl (&&) True
|
|||
trueOrDie message test =
|
||||
if test then True else error message
|
||||
|
||||
routineDeclared routName (Program _ routines) =
|
||||
elem routName (map (getRoutineName) routines)
|
||||
where
|
||||
getRoutineName (Routine name _) = name
|
||||
|
||||
getDeclLocationName (Assign name _ _) = name
|
||||
getDeclLocationName (Reserve name _) = name
|
||||
|
||||
locationDeclared locName (Program decls _) =
|
||||
elem locName (map (getDeclLocationName) decls)
|
||||
|
||||
lookupDecl (Program [] _) _ = Nothing
|
||||
lookupDecl (Program (decl:decls) routs) name =
|
||||
if
|
||||
(getDeclLocationName decl) == name
|
||||
then
|
||||
Just decl
|
||||
else
|
||||
lookupDecl (Program decls routs) name
|
||||
|
||||
-- in the following, we mean Named locations
|
||||
|
||||
routineUsedLocations (Routine _ instrs) = blockUsedLocations instrs
|
||||
|
@ -59,13 +39,11 @@ allUsedLocationsDeclared p@(Program _ routines) =
|
|||
isUnique [] = True
|
||||
isUnique (x:xs) = (not (x `elem` xs)) && isUnique xs
|
||||
|
||||
noDuplicateDecls p@(Program decls routines) =
|
||||
isUnique (map (getDeclLocationName) decls)
|
||||
noDuplicateDecls program =
|
||||
isUnique $ declaredLocationNames program
|
||||
|
||||
noDuplicateRoutines p@(Program decls routines) =
|
||||
isUnique (map (getRoutineName) routines)
|
||||
where
|
||||
getRoutineName (Routine name _) = name
|
||||
noDuplicateRoutines program =
|
||||
isUnique $ declaredRoutineNames program
|
||||
|
||||
-- wow. efficiency is clearly our watchword
|
||||
-- (and sarcasm is our backup watchword)
|
||||
|
|
|
@ -85,6 +85,35 @@ data Routine = Routine RoutineName [Instruction]
|
|||
data Program = Program [Decl] [Routine]
|
||||
deriving (Show, Ord, Eq)
|
||||
|
||||
-- -- -- accessors and helpers -- -- --
|
||||
|
||||
getRoutineName (Routine name _) = name
|
||||
|
||||
getDeclLocationName (Assign name _ _) = name
|
||||
getDeclLocationName (Reserve name _) = name
|
||||
|
||||
isLocationDecl (Assign _ _ _) = True
|
||||
isLocationDecl (Reserve _ _) = True
|
||||
isLocationDecl _ = False
|
||||
|
||||
declaredLocationNames (Program decls _) =
|
||||
map (getDeclLocationName) (filter (isLocationDecl) decls)
|
||||
|
||||
locationDeclared locName p =
|
||||
elem locName $ declaredLocationNames p
|
||||
|
||||
getDeclRoutineName (External name _) = name
|
||||
|
||||
isRoutineDecl (External _ _) = True
|
||||
isRoutineDecl _ = False
|
||||
|
||||
declaredRoutineNames (Program decls routines) =
|
||||
map (getRoutineName) routines ++
|
||||
map (getDeclRoutineName) (filter (isRoutineDecl) decls)
|
||||
|
||||
routineDeclared routName p =
|
||||
elem routName (declaredRoutineNames p)
|
||||
|
||||
mapBlock :: (Instruction -> Instruction) -> [Instruction] -> [Instruction]
|
||||
mapBlock = map
|
||||
|
||||
|
@ -98,3 +127,15 @@ mapRoutines f (rout:routs) =
|
|||
|
||||
mapProgramRoutines :: (Instruction -> Instruction) -> Program -> Program
|
||||
mapProgramRoutines f (Program decls routs) = Program decls $ mapRoutines f routs
|
||||
|
||||
|
||||
|
||||
|
||||
lookupDecl (Program [] _) _ = Nothing
|
||||
lookupDecl (Program (decl:decls) routs) name =
|
||||
if
|
||||
(getDeclLocationName decl) == name
|
||||
then
|
||||
Just decl
|
||||
else
|
||||
lookupDecl (Program decls routs) name
|
||||
|
|
Loading…
Reference in New Issue
Block a user