@@ -30,10 +30,11 @@ import qualified Transform.SortDefinitions as Transform
30import qualified Transform.Declaration as Transform
30import qualified Transform.Declaration as Transform
32environment :: Interfaces -> Module.ValidModule -> Either [Doc] Environment
32environment :: Interfaces -> Module.ValidModule -> Either [Doc] Environment
33−environment interfaces (Module.Module _ _ _ ims decls) =
33+environment 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− foldM addDecl nonLocalEnv decls
37+ foldM (addDecl moduleName) nonLocalEnv decls
38toEnv :: Interfaces -> Environment -> (String, ImportMethod) -> Either [Doc] Environment
39toEnv :: Interfaces -> Environment -> (String, ImportMethod) -> Either [Doc] Environment
39toEnv interfaces environ (name,method)
40toEnv interfaces environ (name,method)
@@ -72,9 +73,9 @@ addValue :: String -> Module.Interface -> Environment -> Var.Value
72 -> Either [Doc] Environment
73 -> Either [Doc] Environment
73addValue name interface env value =
74addValue name interface env value =
74 let insert' x = insert x (Var.Canonical (Var.Module name) x)
75 let insert' x = insert x (Var.Canonical (Var.Module name) x)
75− notFound x = Left [ P.text $
76− "Import Error: Could not import value '" ++ name ++ "." ++ x ++ "'.\n" ++
76+ msg x = "Import Error: Could not import value '" ++ name ++ "." ++ x ++
77− " It is not exported by module " ++ name ++ "." ]
77+ "'.\n It is not exported by module " ++ name ++ "."
78+ notFound x = Left [ P.text (msg x) ]
79 case value of
80 case value of
80 Var.Value x
81 Var.Value x
@@ -106,8 +107,9 @@ addValue name interface env value =
106 [] -> return names
107 [] -> return names
107 c:_ -> notFound c
108 c:_ -> notFound c
109−addDecl :: Environment -> D.ValidDecl -> Either [Doc] Environment
110+addDecl :: String -> Environment -> D.ValidDecl -> Either [Doc] Environment
110−addDecl env decl =
111+addDecl moduleName env decl =
112+ let typeVar = Var.Canonical (Var.Module moduleName) in
111 case decl of
113 case decl of
112 D.Definition (Valid.Definition pattern _ _) ->
114 D.Definition (Valid.Definition pattern _ _) ->
113 return $ env
115 return $ env
@@ -118,19 +120,19 @@ addDecl env decl =
118 D.Datatype name _ ctors ->
120 D.Datatype name _ ctors ->
119 return $ env
121 return $ env
120 { _values = addCtors (_values env)
122 { _values = addCtors (_values env)
121− , _adts = insert name (Var.local name) (_adts env)
123+ , _adts = insert name (typeVar name) (_adts env)
122 , _patterns = addCtors (_patterns env)
124 , _patterns = addCtors (_patterns env)
125 addCtors e = foldr add e (map fst ctors)
127 addCtors e = foldr add e (map fst ctors)
126− add name e = insert name (Var.local name) e
128+ add name e = insert name (typeVar name) e
128 D.TypeAlias name tvars alias ->
130 D.TypeAlias name tvars alias ->
129 do alias' <- Either.either throw return (tipe env alias)
131 do alias' <- Either.either throw return (tipe env alias)
130 return $ env
132 return $ env
131− { _aliases = insert name (Var.local name, tvars, alias') (_aliases env)
133+ { _aliases = insert name (typeVar name, tvars, alias') (_aliases env)
132 , _values = case alias of
134 , _values = case alias of
133− Type.Record _ _ -> insert name (Var.local name) (_values env)
135+ Type.Record _ _ -> insert name (typeVar name) (_values env)
134 _ -> _values env
136 _ -> _values env
@@ -158,7 +160,7 @@ module' interfaces modul@(Module.Module _ _ exs _ decls) =
158 body :: [D.CanonicalDecl] -> CanonicalBody
160 body :: [D.CanonicalDecl] -> CanonicalBody
159 body decls =
161 body decls =
160 CanonicalBody
162 CanonicalBody
161− { program = Transform.sortDefs . dummyLet $ Transform.toExpr decls
163+ { program = Transform.sortDefs . dummyLet $ Transform.toExpr (Module.getName modul) decls
162 , types = Map.empty
164 , types = Map.empty
163 , datatypes = Map.fromList [ (name,(vars,ctors)) | Datatype name vars ctors <- decls ]
165 , datatypes = Map.fromList [ (name,(vars,ctors)) | Datatype name vars ctors <- decls ]
164 , fixities = [ (assoc,level,op) | Fixity assoc level op <- decls ]
166 , fixities = [ (assoc,level,op) | Fixity assoc level op <- decls ]
@@ -198,6 +200,23 @@ delist fullList (Var.Listing partial open)
199 _ -> go list xs partial
201 _ -> go list xs partial
203+filterExports :: Module.Types -> [Var.Value] -> Module.Types
204+filterExports types values =
205+ Map.fromList (concatMap getValue values)
207+ getValue :: Var.Value -> [(String, Type.CanonicalType)]
210+ Var.Value x -> get x
211+ Var.Alias x -> get x
212+ Var.ADT _ (Var.Listing ctors _) -> concatMap get ctors
214+ get :: String -> [(String, Type.CanonicalType)]
216+ case Map.lookup x types of
201declToValue :: D.ValidDecl -> [Var.Value]
220declToValue :: D.ValidDecl -> [Var.Value]
202declToValue decl =
221declToValue decl =
203 case decl of
222 case decl of