on master help sign in
cosmetic: minor whitespace stuff
73b288aEvan Czaplicki
src/AST/Variable.hs+23−13
@@ -33,15 +33,18 @@ data Canonical = Canonical
33
33
34
34
35local :: String -> Canonical
35local :: String -> Canonical
36+local x =
36−local x = Canonical Local x
37+ Canonical Local x
37
38
38
39
39topLevel :: [String] -> String -> Canonical
40topLevel :: [String] -> String -> Canonical
41+topLevel names x =
40−topLevel names x = Canonical (TopLevel names) x
42+ Canonical (TopLevel names) x
41
43
42
44
43builtin :: String -> Canonical
45builtin :: String -> Canonical
46+builtin x =
44−builtin x = Canonical BuiltIn x
47+ Canonical BuiltIn x
45
48
46
49
47fromModule :: [String] -> String -> Canonical
50fromModule :: [String] -> String -> Canonical
@@ -127,10 +130,17 @@ instance ToString Raw where
127instance ToString Canonical where
130instance ToString Canonical where
128 toString (Canonical home name) =
131 toString (Canonical home name) =
129 case home of
132 case home of
130− BuiltIn -> name
133+ BuiltIn ->
134+ name
135+
136+ Module path ->
131− Module path -> List.intercalate "." (path ++ [name])
137+ List.intercalate "." (path ++ [name])
132− Local -> name
138+
133− TopLevel _ -> name
139+ TopLevel _ ->
140+ name
141+
142+ Local ->
143+ name
134
144
135
145
136-- LISTINGS
146-- LISTINGS
@@ -255,19 +265,19 @@ instance Binary Canonical where
255 Module path ->
265 Module path ->
256 putWord8 1 >> put path >> put name
266 putWord8 1 >> put path >> put name
257
267
258− Local ->
259− putWord8 2 >> put name
260−
261 TopLevel path ->
268 TopLevel path ->
262− putWord8 3 >> put path >> put name
269+ putWord8 2 >> put path >> put name
270+
271+ Local ->
272+ putWord8 3 >> put name
263
273
264 get =
274 get =
265 do tag <- getWord8
275 do tag <- getWord8
266 case tag of
276 case tag of
267 0 -> Canonical BuiltIn <$> get
277 0 -> Canonical BuiltIn <$> get
268 1 -> Canonical . Module <$> get <*> get
278 1 -> Canonical . Module <$> get <*> get
269− 2 -> Canonical Local <$> get
270− 3 -> Canonical . TopLevel <$> get <*> get
279+ 2 -> Canonical . TopLevel <$> get <*> get
280+ 3 -> Canonical Local <$> get
271 _ -> error "Unexpected tag when deserializing canonical variable"
281 _ -> error "Unexpected tag when deserializing canonical variable"
272
282
273
283
src/Canonicalize/Setup.hs+5−5
@@ -282,11 +282,11 @@ 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, except for top-level definitions
285+-- When canonicalizing, it is important that:
286−-- However _adts and _patterns
286+-- _adts are fully namespaced (Var.Module ...)
287−-- should be fully namespaced, thought constructors are top_level.
287+-- _patterns are fully namespaced (Var.Module ...)
288−-- With _adts, they may appear in types that can
288+-- _values that are defined as top-level declarations are (Var.TopLevel ...)
289−-- escape the module.
289+-- all other _values are local (Var.Local)
290declToPatches
290declToPatches
291 :: Module.Name
291 :: Module.Name
292 -> D.ValidDecl
292 -> D.ValidDecl
src/Canonicalize/Variable.hs+34−22
@@ -30,10 +30,10 @@ variable region env var =
30 Just [v] ->
30 Just [v] ->
31 Result.var v
31 Result.var v
32
32
33− Just vs ->
33+ Just vs ->
34 preferLocals region env "variable" vs var
34 preferLocals region env "variable" vs var
35
35
36− Nothing ->
36+ Nothing ->
37 notFound region "variable" (Map.keys (Env._values env)) var
37 notFound region "variable" (Map.keys (Env._values env)) var
38
38
39
39
@@ -110,7 +110,7 @@ preferLocals'
110 -> String
110 -> String
111 -> Result.ResultErr a
111 -> Result.ResultErr a
112preferLocals' region env extract kind possibilities var =
112preferLocals' region env extract kind possibilities var =
113− case filter (isLocal . extract) possibilities of
113+ case filter (isLocal (Env._home env) . extract) possibilities of
114 [] ->
114 [] ->
115 ambiguous possibilities
115 ambiguous possibilities
116
116
@@ -118,36 +118,48 @@ preferLocals' region env extract kind possibilities var =
118 Result.var' extract v
118 Result.var' extract v
119
119
120 --Local vars shadow top-level vars
120 --Local vars shadow top-level vars
121+ [v1, v2]
121− [v1, v2] | isTopLevel (extract v1) ->
122+ | isTopLevel (extract v1) ->
122− Result.var' extract v2
123+ Result.var' extract v2
123
124
124− [v1, v2] | isTopLevel (extract v2) ->
125+ | isTopLevel (extract v2) ->
125− Result.var' extract v1
126+ Result.var' extract v1
126
127
127 locals ->
128 locals ->
128 ambiguous locals
129 ambiguous locals
129 where
130 where
130− isLocal :: Var.Canonical -> Bool
131− isLocal (Var.Canonical home _) =
132− case home of
133− Var.Local -> True
134− Var.TopLevel _ -> True
135− Var.BuiltIn -> False
136− Var.Module name ->
137− name == Env._home env
138−
139− isTopLevel :: Var.Canonical -> Bool
140− isTopLevel (Var.Canonical home _) =
141− case home of
142− Var.TopLevel _ -> True
143− _ -> False
144−
145 ambiguous possibleVars =
131 ambiguous possibleVars =
146 Result.err (A.A region (Error.variable kind var Error.Ambiguous vars))
132 Result.err (A.A region (Error.variable kind var Error.Ambiguous vars))
147 where
133 where
148 vars = map (Var.toString . extract) possibleVars
134 vars = map (Var.toString . extract) possibleVars
149
135
150
136
137+isLocal :: [String] -> Var.Canonical -> Bool
138+isLocal contextName (Var.Canonical home _) =
139+ case home of
140+ Var.Local ->
141+ True
142+
143+ Var.TopLevel _ ->
144+ True
145+
146+ Var.BuiltIn ->
147+ False
148+
149+ Var.Module name ->
150+ name == contextName
151+
152+
153+isTopLevel :: Var.Canonical -> Bool
154+isTopLevel (Var.Canonical home _) =
155+ case home of
156+ Var.TopLevel _ ->
157+ True
158+
159+ _ ->
160+ False
161+
162+
151-- NOT FOUND HELPERS
163-- NOT FOUND HELPERS
152
164
153type VarName =
165type VarName =