on master help sign in
cosmetic: use more module prefixes
commit25a64770a737dd342f0d06969d0f776a27171003 authorEvan Czaplicki <info@elm-lang.org> dateThu 29 May 2014, 14:35 (12 years ago) parentd8b5511
1 file changed+24−15
compiler/Transform/Canonicalize.hs+24−15
compiler/Transform/Canonicalize.hs+24−15
@@ -13,12 +13,12 @@ import AST.Expression.General (Expr'(..), dummyLet)
1313import qualified AST.Expression.Valid as Valid
1414import qualified AST.Expression.Canonical as Canonical
1515
16−import AST.Module (Interfaces, Interface(..), Module(..), CanonicalBody(..), ImportMethod)
16+import AST.Module (Interface(iAdts, iTypes, iAliases), CanonicalBody(..))
1717import qualified AST.Module as Module
1818import qualified AST.Type as Type
1919import qualified AST.Variable as Var
2020import qualified AST.Annotation as A
21−import AST.Declaration as D
21+import qualified AST.Declaration as D
2222import AST.PrettyPrint (pretty, commaSep)
2323import qualified AST.Pattern as P
2424import Text.PrettyPrint as P
@@ -29,14 +29,15 @@ import Transform.Canonicalize.Variable (variable, pvar)
2929import qualified Transform.SortDefinitions as Transform
3030import qualified Transform.Declaration as Transform
3131
32−environment :: Interfaces -> Module.ValidModule -> Either [Doc] Environment
32+environment :: Module.Interfaces -> Module.ValidModule -> Either [Doc] Environment
3333environment interfaces m@(Module.Module _ _ _ ims decls) =
3434 do () <- allImportsAvailable interfaces ims
3535 nonLocalEnv <- foldM (toEnv interfaces) Env.builtIns ims
3636 let moduleName = Module.getName m
3737 foldM (addDecl moduleName) nonLocalEnv decls
3838
39−toEnv :: Interfaces -> Environment -> (String, ImportMethod) -> Either [Doc] Environment
39+toEnv :: Module.Interfaces -> Environment -> (String, Module.ImportMethod)
40+ -> Either [Doc] Environment
4041toEnv interfaces environ (name,method)
4142 | List.isPrefixOf "Native." name = return environ
4243 | otherwise =
@@ -151,27 +152,33 @@ addDecl moduleName env decl =
151152
152153 D.Fixity _ _ _ -> return env
153154
154−module' :: Interfaces -> Module.ValidModule -> Either [Doc] Module.CanonicalModule
155+module' :: Module.Interfaces -> Module.ValidModule -> Either [Doc] Module.CanonicalModule
155156module' interfaces modul@(Module.Module _ _ exs _ decls) =
156157 do env <- environment interfaces modul
157158 canonicalDecls <- mapM (declaration env) decls
158159 exports' <- delist locals exs
159− return $ modul { exports = exports'
160− , body = body canonicalDecls
160+ return $ modul { Module.exports = exports'
161+ , Module.body = body canonicalDecls
161162 }
162163 where
163164 locals :: [Var.Value]
164165 locals = concatMap declToValue decls
165166
166− body :: [D.CanonicalDecl] -> CanonicalBody
167+ body :: [D.CanonicalDecl] -> Module.CanonicalBody
167168 body decls =
168− CanonicalBody
169− { program = Transform.sortDefs . dummyLet $ Transform.toExpr (Module.getName modul) decls
169+ Module.CanonicalBody
170+ { program =
171+ let expr = Transform.toExpr (Module.getName modul) decls
172+ in Transform.sortDefs (dummyLet expr)
170173 , types = Map.empty
171− , datatypes = Map.fromList [ (name,(vars,ctors)) | Datatype name vars ctors <- decls ]
172− , fixities = [ (assoc,level,op) | Fixity assoc level op <- decls ]
173− , aliases = Map.fromList [ (name,(tvs,alias)) | TypeAlias name tvs alias <- decls ]
174− , ports = [ portName port | Port port <- decls ]
174+ , datatypes =
175+ Map.fromList [ (name,(vars,ctors)) | D.Datatype name vars ctors <- decls ]
176+ , fixities =
177+ [ (assoc,level,op) | D.Fixity assoc level op <- decls ]
178+ , aliases =
179+ Map.fromList [ (name,(tvs,alias)) | D.TypeAlias name tvs alias <- decls ]
180+ , ports =
181+ [ D.portName port | D.Port port <- decls ]
175182 }
176183
177184delist :: [Var.Value] -> Var.Listing Var.Value -> Either [Doc] [Var.Value]
@@ -275,7 +282,9 @@ declaration env decl =
275282 D.Fixity assoc prec op -> return $ D.Fixity assoc prec op
276283
277284
278−allImportsAvailable :: Interfaces -> [(String,ImportMethod)] -> Either [Doc] ()
285+allImportsAvailable :: Module.Interfaces
286+ -> [(String, Module.ImportMethod)]
287+ -> Either [Doc] ()
279288allImportsAvailable interfaces imports =
280289 case filter (not . found) modules of
281290 [] -> Right ()