on master help sign in
Fix #209, bad JS generation for primes in patterns
bc0c6a4Evan Czaplicki
compiler/Generate/Cases.hs+6−3
@@ -1,4 +1,4 @@
1−module Generate.Cases (caseToMatch, Match (..), Clause (..), matchSubst) where
1+module Generate.Cases (caseToMatch, Match (..), Clause (..), matchSubst, deprime) where
2
2
3import Control.Arrow (first)
3import Control.Arrow (first)
4import Control.Monad (liftM,foldM)
4import Control.Monad (liftM,foldM)
@@ -12,6 +12,9 @@ import SourceSyntax.Pattern
12import SourceSyntax.Expression
12import SourceSyntax.Expression
13import Transform.Substitute
13import Transform.Substitute
14
14
15+deprime :: String -> String
16+deprime = map (\c -> if c == '\'' then '$' else c)
17+
15caseToMatch patterns = do
18caseToMatch patterns = do
16 v <- newVar
19 v <- newVar
17 (,) v `liftM` match [v] (map (first (:[])) patterns) Fail
20 (,) v `liftM` match [v] (map (first (:[])) patterns) Fail
@@ -65,7 +68,7 @@ match vs@(v:_) cs def
65
68
66dealias v c@(p:ps, L s e) =
69dealias v c@(p:ps, L s e) =
67 case p of
70 case p of
68− PAlias x pattern -> (pattern:ps, L s $ subst x (Var v) e)
71+ PAlias x pattern -> (pattern:ps, L s $ subst (deprime x) (Var v) e)
69 _ -> c
72 _ -> c
70
73
71matchVar :: [String] -> [([Pattern],LExpr t v)] -> Match t v
74matchVar :: [String] -> [([Pattern],LExpr t v)] -> Match t v
@@ -76,7 +79,7 @@ matchVar (v:vs) cs def = match vs (map subVar cs) def
76 where
79 where
77 subOnePattern pattern e =
80 subOnePattern pattern e =
78 case pattern of
81 case pattern of
79− PVar x -> subst x (Var v) e
82+ PVar x -> subst (deprime x) (Var v) e
80 PAnything -> e
83 PAnything -> e
81 PRecord fs ->
84 PRecord fs ->
82 foldr (\x -> subst x (Access (L s (Var v)) x)) e fs
85 foldr (\x -> subst x (Access (L s (Var v)) x)) e fs
compiler/Generate/JavaScript.hs+1−4
@@ -10,14 +10,11 @@ import Data.Either (partitionEithers)
10import qualified Text.Pandoc as Pan
10import qualified Text.Pandoc as Pan
11
11
12import Unique
12import Unique
13−import Generate.Cases
13+import Generate.Cases (caseToMatch, deprime, matchSubst, Match(..), Clause(..))
14import SourceSyntax.Everything
14import SourceSyntax.Everything
15import SourceSyntax.Location
15import SourceSyntax.Location
16import qualified Transform.SortDefinitions as SD
16import qualified Transform.SortDefinitions as SD
17
17
18−deprime :: String -> String
19−deprime = map (\c -> if c == '\'' then '$' else c)
20−
21indent = concatMap f
18indent = concatMap f
22 where f '\n' = "\n "
19 where f '\n' = "\n "
23 f c = [c]
20 f c = [c]