on master help sign in
Use `Location.none` less
a4c4cf0Evan Czaplicki
compiler/Generate/JavaScript.hs+6−6
@@ -12,7 +12,7 @@ import qualified Text.Pandoc as Pan
12import Unique
12import Unique
13import Generate.Cases
13import Generate.Cases
14import SourceSyntax.Everything hiding (parens)
14import SourceSyntax.Everything hiding (parens)
15−import SourceSyntax.Location as Loc
15+import SourceSyntax.Location
16import qualified Transform.SortDefinitions as SD
16import qualified Transform.SortDefinitions as SD
17
17
18deprime :: String -> String
18deprime :: String -> String
@@ -130,12 +130,12 @@ instance ToJS (Def t v) where
130 | isOp x = globalAssign ("_op['" ++ x ++ "']") `liftM` toJS' e
130 | isOp x = globalAssign ("_op['" ++ x ++ "']") `liftM` toJS' e
131 | otherwise = assign (deprime x) `liftM` toJS' e
131 | otherwise = assign (deprime x) `liftM` toJS' e
132
132
133− toJS (Def pattern e) =
133+ toJS (Def pattern e@(L s _)) =
134 do n <- guid
134 do n <- guid
135 let x = "_" ++ show n
135 let x = "_" ++ show n
136− var = Loc.none . Var
136+ var = L s . Var
137 toDef y' = let y = deprime y' in
137 toDef y' = let y = deprime y' in
138− Def (PVar y) (Loc.none $ Case (var x) [(pattern, var y)])
138+ Def (PVar y) (L s $ Case (var x) [(pattern, var y)])
139 stmt <- assign x `liftM` toJS' e
139 stmt <- assign x `liftM` toJS' e
140 vars <- toJS . map toDef . Set.toList $ SD.boundVars pattern
140 vars <- toJS . map toDef . Set.toList $ SD.boundVars pattern
141 return (stmt ++ vars)
141 return (stmt ++ vars)
@@ -196,7 +196,7 @@ instance ToJS (Expr t v) where
196 Record fs -> makeRecord fs
196 Record fs -> makeRecord fs
197 Binop op e1 e2 -> binop op `liftM` toJS' e1 `ap` toJS' e2
197 Binop op e1 e2 -> binop op `liftM` toJS' e1 `ap` toJS' e2
198
198
199− Lambda p e -> liftM (fastFunc . ret) (toJS' body)
199+ Lambda p e@(L s _) -> liftM (fastFunc . ret) (toJS' body)
200 where
200 where
201 fastFunc body
201 fastFunc body
202 | length args < 2 || length args > 9 = foldr jsFunc body args
202 | length args < 2 || length args > 9 = foldr jsFunc body args
@@ -207,7 +207,7 @@ instance ToJS (Expr t v) where
207 case pattern of
207 case pattern of
208 PVar x -> (deprime x : args, body)
208 PVar x -> (deprime x : args, body)
209 _ -> let arg = "arg" ++ show n
209 _ -> let arg = "arg" ++ show n
210− in (arg:args, Loc.none (Case (Loc.none (Var arg)) [(pattern, body)]))
210+ in (arg:args, L s (Case (L s (Var arg)) [(pattern, body)]))
211
211
212 (patterns, innerBody) = collect [p] e
212 (patterns, innerBody) = collect [p] e
213
213
compiler/Parse/Expression.hs+2−1
@@ -157,7 +157,8 @@ ifExpr = reserved "if" >> whitespace >> (normal <|> multiIf)
157 thenBranch <- expr
157 thenBranch <- expr
158 whitespace <?> "an 'else' branch" ; reserved "else" <?> "an 'else' branch" ; whitespace
158 whitespace <?> "an 'else' branch" ; reserved "else" <?> "an 'else' branch" ; whitespace
159 elseBranch <- expr
159 elseBranch <- expr
160− return $ MultiIf [(bool, thenBranch), (Location.none (Var "otherwise"), elseBranch)]
160+ return $ MultiIf [(bool, thenBranch),
161+ (Location.sameAs elseBranch (Var "otherwise"), elseBranch)]
161 multiIf = MultiIf <$> spaceSep1 iff
162 multiIf = MultiIf <$> spaceSep1 iff
162 where iff = do string "|" ; whitespace
163 where iff = do string "|" ; whitespace
163 b <- expr ; whitespace ; string "->" ; whitespace
164 b <- expr ; whitespace ; string "->" ; whitespace
compiler/SourceSyntax/Location.hs+2−1
@@ -26,7 +26,6 @@ instance Show SrcSpan where
26instance Show e => Show (Located e) where
26instance Show e => Show (Located e) where
27 show (L _ e) = show e
27 show (L _ e) = show e
28
28
29−
30none = L NoSpan
29none = L NoSpan
31
30
32at start end = L (Span (Pos (Parsec.sourceLine start) (Parsec.sourceColumn start))
31at start end = L (Span (Pos (Parsec.sourceLine start) (Parsec.sourceColumn start))
@@ -37,3 +36,5 @@ merge (L s1 _) (L s2 _) = L span
37 (Span start _, Span _ end) -> Span start end
36 (Span start _, Span _ end) -> Span start end
38 (_, NoSpan) -> s1
37 (_, NoSpan) -> s1
39 (NoSpan, _) -> s2
38 (NoSpan, _) -> s2
39+
40+sameAs (L s _) = L s
compiler/Transform/Optimize.hs+3−3
@@ -56,9 +56,9 @@ isValue e =
56 _ -> False
56 _ -> False
57
57
58
58
59−binop op ce1@(L t1 s1 e1) ce2@(L t2 s2 e2) =
59+binop op ce1@(L s1 e1) ce2@(L s2 e2) =
60− let c1 = L t1 s1
60+ let c1 = L s1
61− c2 = L t2 s2
61+ c2 = L s2
62 int = Literal . IntNum
62 int = Literal . IntNum
63 str = Literal . Str
63 str = Literal . Str
64 bool = Literal . Boolean
64 bool = Literal . Boolean
compiler/Type/Constrain/Declaration.hs+2−2
@@ -64,5 +64,5 @@ toDefs decl =
64arguments :: [String]
64arguments :: [String]
65arguments = map (:[]) ['a'..'z'] ++ map (\n -> "_" ++ show n) [1..]
65arguments = map (:[]) ['a'..'z'] ++ map (\n -> "_" ++ show n) [1..]
66
66
67−buildFunction body vars =
67+buildFunction body@(Src.L s _) vars =
68− foldr (\p e -> Src.none (Src.Lambda p e)) body (map Src.PVar vars)
68+ foldr (\p e -> Src.L s (Src.Lambda p e)) body (map Src.PVar vars)
compiler/Type/Constrain/Expression.hs+3−3
@@ -182,15 +182,15 @@ constrainDef env info (pattern, expr, maybeTipe) =
182
182
183expandPattern :: (Pattern, LExpr t v, Maybe SrcT.Type)
183expandPattern :: (Pattern, LExpr t v, Maybe SrcT.Type)
184 -> [(Pattern, LExpr t v, Maybe SrcT.Type)]
184 -> [(Pattern, LExpr t v, Maybe SrcT.Type)]
185−expandPattern triple@(pattern, lexpr, maybeType) =
185+expandPattern triple@(pattern, lexpr@(L s _), maybeType) =
186 case pattern of
186 case pattern of
187 PVar _ -> [triple]
187 PVar _ -> [triple]
188 _ -> (PVar x, lexpr, maybeType) : map toDef vars
188 _ -> (PVar x, lexpr, maybeType) : map toDef vars
189 where
189 where
190 vars = Set.toList $ SD.boundVars pattern
190 vars = Set.toList $ SD.boundVars pattern
191 x = concat vars
191 x = concat vars
192− var = Loc.none . Var
192+ var = L s . Var
193− toDef y = (PVar y, Loc.none $ Case (var x) [(pattern, var y)], Nothing)
193+ toDef y = (PVar y, L s $ Case (var x) [(pattern, var y)], Nothing)
194
194
195collapseDefs :: [Def t v] -> [(Pattern, LExpr t v, Maybe SrcT.Type)]
195collapseDefs :: [Def t v] -> [(Pattern, LExpr t v, Maybe SrcT.Type)]
196collapseDefs = concatMap expandPattern . go [] Map.empty Map.empty
196collapseDefs = concatMap expandPattern . go [] Map.empty Map.empty