on master help sign in
Add TopLevel type, initialize in env
commitcc26a649285740b75a200ed955018b6c71a0b5cd authorjmite <jmitdase@gmail.com> dateMon 24 Aug 2015, 17:27 (11 years ago) parent4d7e3f6
2 files changed+18−7
src/AST/Variable.hs+6 src/Canonicalize/Setup.hs+12−7
src/AST/Variable.hs+6
@@ -20,6 +20,7 @@ newtype Raw = Raw String
2020data Home
2121 = BuiltIn
2222 | Module [String]
23+ | TopLevel [String]
2324 | Local
2425 deriving (Eq, Ord, Show)
2526
@@ -35,6 +36,10 @@ local :: String -> Canonical
3536local x = Canonical Local x
3637
3738
39+topLevel :: [String] -> String -> Canonical
40+topLevel names x = Canonical (TopLevel names) x
41+
42+
3843builtin :: String -> Canonical
3944builtin x = Canonical BuiltIn x
4045
@@ -125,6 +130,7 @@ instance ToString Canonical where
125130 BuiltIn -> name
126131 Module path -> List.intercalate "." (path ++ [name])
127132 Local -> name
133+ TopLevel _ -> name
128134
129135
130136-- LISTINGS
src/Canonicalize/Setup.hs+12−7
@@ -282,7 +282,9 @@ declarationsToPatches moduleName decls =
282282 (Maybe.catMaybes maybeNodes, concat patchLists)
283283
284284
285−-- When canonicalizing, all _values should be Local, but all _adts and _patterns
285+-- When canonicalizing, all _values should be Local, except for top-level definitions but all
286+-- For _adts and _patterns,
287+-- we assume constructors are top-evel
286288-- should be fully namespaced. With _adts, they may appear in types that can
287289-- escape the module.
288290declToPatches
@@ -290,8 +292,11 @@ declToPatches
290292 -> D.ValidDecl
291293 -> (Maybe Node, [Env.Patch])
292294declToPatches moduleName (A.A (region,_) decl) =
293− let local mkPatch x =
294− mkPatch x (Var.local x)
295+ let --local mkPatch x =
296+ -- mkPatch x (Var.local x)
297+
298+ topLevel mkPatch x =
299+ mkPatch x (Var.topLevel moduleName x )
295300
296301 namespaced mkPatch x =
297302 mkPatch x (Var.fromModule moduleName x)
@@ -302,7 +307,7 @@ declToPatches moduleName (A.A (region,_) decl) =
302307 case decl of
303308 D.Definition (Valid.Definition pattern _ _) ->
304309 ( Nothing
305− , map (local Env.Value) (P.boundVarList pattern)
310+ , map (topLevel Env.Value) (P.boundVarList pattern)
306311 )
307312
308313 D.Datatype name _ ctors ->
@@ -310,7 +315,7 @@ declToPatches moduleName (A.A (region,_) decl) =
310315 in
311316 ( Nothing
312317 , namespaced Env.Union name
313− : map (local Env.Value) ctorNames
318+ : map (topLevel Env.Value) ctorNames
314319 ++ map patternPatch ctors
315320 )
316321
@@ -318,14 +323,14 @@ declToPatches moduleName (A.A (region,_) decl) =
318323 ( Just (node region name tvars alias)
319324 , case alias of
320325 A.A _ (Type.RRecord _ _) ->
321− [local Env.Value name]
326+ [topLevel Env.Value name]
322327 _ ->
323328 []
324329 )
325330
326331 D.Port port ->
327332 ( Nothing
328− , [local Env.Value (D.validPortName port)]
333+ , [topLevel Env.Value (D.validPortName port)]
329334 )
330335
331336 D.Fixity _ _ _ ->