on master help sign in
Add TopLevel type, initialize in env
cc26a64jmite
src/AST/Variable.hs+6
@@ -20,6 +20,7 @@ newtype Raw = Raw String
20data Home
20data Home
21 = BuiltIn
21 = BuiltIn
22 | Module [String]
22 | Module [String]
23+ | TopLevel [String]
23 | Local
24 | Local
24 deriving (Eq, Ord, Show)
25 deriving (Eq, Ord, Show)
25
26
@@ -35,6 +36,10 @@ local :: String -> Canonical
35local x = Canonical Local x
36local x = Canonical Local x
36
37
37
38
39+topLevel :: [String] -> String -> Canonical
40+topLevel names x = Canonical (TopLevel names) x
41+
42+
38builtin :: String -> Canonical
43builtin :: String -> Canonical
39builtin x = Canonical BuiltIn x
44builtin x = Canonical BuiltIn x
40
45
@@ -125,6 +130,7 @@ instance ToString Canonical where
125 BuiltIn -> name
130 BuiltIn -> name
126 Module path -> List.intercalate "." (path ++ [name])
131 Module path -> List.intercalate "." (path ++ [name])
127 Local -> name
132 Local -> name
133+ TopLevel _ -> name
128
134
129
135
130-- LISTINGS
136-- LISTINGS
src/Canonicalize/Setup.hs+12−7
@@ -282,7 +282,9 @@ declarationsToPatches moduleName decls =
282 (Maybe.catMaybes maybeNodes, concat patchLists)
282 (Maybe.catMaybes maybeNodes, concat patchLists)
283
283
284
284
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
286-- should be fully namespaced. With _adts, they may appear in types that can
288-- should be fully namespaced. With _adts, they may appear in types that can
287-- escape the module.
289-- escape the module.
288declToPatches
290declToPatches
@@ -290,8 +292,11 @@ declToPatches
290 -> D.ValidDecl
292 -> D.ValidDecl
291 -> (Maybe Node, [Env.Patch])
293 -> (Maybe Node, [Env.Patch])
292declToPatches moduleName (A.A (region,_) decl) =
294declToPatches moduleName (A.A (region,_) decl) =
295+ let --local mkPatch x =
296+ -- mkPatch x (Var.local x)
297+
293− let local mkPatch x =
298+ topLevel mkPatch x =
294− mkPatch x (Var.local x)
299+ mkPatch x (Var.topLevel moduleName x )
295
300
296 namespaced mkPatch x =
301 namespaced mkPatch x =
297 mkPatch x (Var.fromModule moduleName x)
302 mkPatch x (Var.fromModule moduleName x)
@@ -302,7 +307,7 @@ declToPatches moduleName (A.A (region,_) decl) =
302 case decl of
307 case decl of
303 D.Definition (Valid.Definition pattern _ _) ->
308 D.Definition (Valid.Definition pattern _ _) ->
304 ( Nothing
309 ( Nothing
305− , map (local Env.Value) (P.boundVarList pattern)
310+ , map (topLevel Env.Value) (P.boundVarList pattern)
306 )
311 )
307
312
308 D.Datatype name _ ctors ->
313 D.Datatype name _ ctors ->
@@ -310,7 +315,7 @@ declToPatches moduleName (A.A (region,_) decl) =
310 in
315 in
311 ( Nothing
316 ( Nothing
312 , namespaced Env.Union name
317 , namespaced Env.Union name
313− : map (local Env.Value) ctorNames
318+ : map (topLevel Env.Value) ctorNames
314 ++ map patternPatch ctors
319 ++ map patternPatch ctors
315 )
320 )
316
321
@@ -318,14 +323,14 @@ declToPatches moduleName (A.A (region,_) decl) =
318 ( Just (node region name tvars alias)
323 ( Just (node region name tvars alias)
319 , case alias of
324 , case alias of
320 A.A _ (Type.RRecord _ _) ->
325 A.A _ (Type.RRecord _ _) ->
321− [local Env.Value name]
326+ [topLevel Env.Value name]
322 _ ->
327 _ ->
323 []
328 []
324 )
329 )
325
330
326 D.Port port ->
331 D.Port port ->
327 ( Nothing
332 ( Nothing
328− , [local Env.Value (D.validPortName port)]
333+ , [topLevel Env.Value (D.validPortName port)]
329 )
334 )
330
335
331 D.Fixity _ _ _ ->
336 D.Fixity _ _ _ ->