on master help sign in
cosmetic: use more module prefixes
25a6477Evan Czaplicki
compiler/Transform/Canonicalize.hs+24−15
@@ -13,12 +13,12 @@ import AST.Expression.General (Expr'(..), dummyLet)
13import qualified AST.Expression.Valid as Valid
13import qualified AST.Expression.Valid as Valid
14import qualified AST.Expression.Canonical as Canonical
14import qualified AST.Expression.Canonical as Canonical
15
15
16−import AST.Module (Interfaces, Interface(..), Module(..), CanonicalBody(..), ImportMethod)
16+import AST.Module (Interface(iAdts, iTypes, iAliases), CanonicalBody(..))
17import qualified AST.Module as Module
17import qualified AST.Module as Module
18import qualified AST.Type as Type
18import qualified AST.Type as Type
19import qualified AST.Variable as Var
19import qualified AST.Variable as Var
20import qualified AST.Annotation as A
20import qualified AST.Annotation as A
21−import AST.Declaration as D
21+import qualified AST.Declaration as D
22import AST.PrettyPrint (pretty, commaSep)
22import AST.PrettyPrint (pretty, commaSep)
23import qualified AST.Pattern as P
23import qualified AST.Pattern as P
24import Text.PrettyPrint as P
24import Text.PrettyPrint as P
@@ -29,14 +29,15 @@ import Transform.Canonicalize.Variable (variable, pvar)
29import qualified Transform.SortDefinitions as Transform
29import qualified Transform.SortDefinitions as Transform
30import qualified Transform.Declaration as Transform
30import qualified Transform.Declaration as Transform
31
31
32−environment :: Interfaces -> Module.ValidModule -> Either [Doc] Environment
32+environment :: Module.Interfaces -> Module.ValidModule -> Either [Doc] Environment
33environment interfaces m@(Module.Module _ _ _ ims decls) =
33environment interfaces m@(Module.Module _ _ _ ims decls) =
34 do () <- allImportsAvailable interfaces ims
34 do () <- allImportsAvailable interfaces ims
35 nonLocalEnv <- foldM (toEnv interfaces) Env.builtIns ims
35 nonLocalEnv <- foldM (toEnv interfaces) Env.builtIns ims
36 let moduleName = Module.getName m
36 let moduleName = Module.getName m
37 foldM (addDecl moduleName) nonLocalEnv decls
37 foldM (addDecl moduleName) nonLocalEnv decls
38
38
39−toEnv :: Interfaces -> Environment -> (String, ImportMethod) -> Either [Doc] Environment
39+toEnv :: Module.Interfaces -> Environment -> (String, Module.ImportMethod)
40+ -> Either [Doc] Environment
40toEnv interfaces environ (name,method)
41toEnv interfaces environ (name,method)
41 | List.isPrefixOf "Native." name = return environ
42 | List.isPrefixOf "Native." name = return environ
42 | otherwise =
43 | otherwise =
@@ -151,27 +152,33 @@ addDecl moduleName env decl =
151
152
152 D.Fixity _ _ _ -> return env
153 D.Fixity _ _ _ -> return env
153
154
154−module' :: Interfaces -> Module.ValidModule -> Either [Doc] Module.CanonicalModule
155+module' :: Module.Interfaces -> Module.ValidModule -> Either [Doc] Module.CanonicalModule
155module' interfaces modul@(Module.Module _ _ exs _ decls) =
156module' interfaces modul@(Module.Module _ _ exs _ decls) =
156 do env <- environment interfaces modul
157 do env <- environment interfaces modul
157 canonicalDecls <- mapM (declaration env) decls
158 canonicalDecls <- mapM (declaration env) decls
158 exports' <- delist locals exs
159 exports' <- delist locals exs
159− return $ modul { exports = exports'
160+ return $ modul { Module.exports = exports'
160− , body = body canonicalDecls
161+ , Module.body = body canonicalDecls
161 }
162 }
162 where
163 where
163 locals :: [Var.Value]
164 locals :: [Var.Value]
164 locals = concatMap declToValue decls
165 locals = concatMap declToValue decls
165
166
166− body :: [D.CanonicalDecl] -> CanonicalBody
167+ body :: [D.CanonicalDecl] -> Module.CanonicalBody
167 body decls =
168 body decls =
168− CanonicalBody
169+ Module.CanonicalBody
170+ { program =
169− { program = Transform.sortDefs . dummyLet $ Transform.toExpr (Module.getName modul) decls
171+ let expr = Transform.toExpr (Module.getName modul) decls
172+ in Transform.sortDefs (dummyLet expr)
170 , types = Map.empty
173 , types = Map.empty
174+ , datatypes =
171− , datatypes = Map.fromList [ (name,(vars,ctors)) | Datatype name vars ctors <- decls ]
175+ Map.fromList [ (name,(vars,ctors)) | D.Datatype name vars ctors <- decls ]
176+ , fixities =
172− , fixities = [ (assoc,level,op) | Fixity assoc level op <- decls ]
177+ [ (assoc,level,op) | D.Fixity assoc level op <- decls ]
178+ , aliases =
173− , aliases = Map.fromList [ (name,(tvs,alias)) | TypeAlias name tvs alias <- decls ]
179+ Map.fromList [ (name,(tvs,alias)) | D.TypeAlias name tvs alias <- decls ]
180+ , ports =
174− , ports = [ portName port | Port port <- decls ]
181+ [ D.portName port | D.Port port <- decls ]
175 }
182 }
176
183
177delist :: [Var.Value] -> Var.Listing Var.Value -> Either [Doc] [Var.Value]
184delist :: [Var.Value] -> Var.Listing Var.Value -> Either [Doc] [Var.Value]
@@ -275,7 +282,9 @@ declaration env decl =
275 D.Fixity assoc prec op -> return $ D.Fixity assoc prec op
282 D.Fixity assoc prec op -> return $ D.Fixity assoc prec op
276
283
277
284
278−allImportsAvailable :: Interfaces -> [(String,ImportMethod)] -> Either [Doc] ()
285+allImportsAvailable :: Module.Interfaces
286+ -> [(String, Module.ImportMethod)]
287+ -> Either [Doc] ()
279allImportsAvailable interfaces imports =
288allImportsAvailable interfaces imports =
280 case filter (not . found) modules of
289 case filter (not . found) modules of
281 [] -> Right ()
290 [] -> Right ()