on master help sign in
cosmetic
commit01593aa8c08c5a8be2e9d7c6d192873c631bd7d5 authorEvan Czaplicki <info@elm-lang.org> dateMon 31 Mar 2014, 10:54 (13 years ago) parente9dfea7
2 files changed+16−11
compiler/Generate/Cases.hs+14−11 compiler/Generate/JavaScript.hs+2
compiler/Generate/Cases.hs+14−11
@@ -13,7 +13,6 @@ import qualified SourceSyntax.Pattern as P
1313import qualified SourceSyntax.Variable as V
1414import Transform.Substitute
1515
16−
1716toMatch :: [(P.Pattern, Expr)] -> State Int (String, Match)
1817toMatch patterns = do
1918 v <- newVar
@@ -37,16 +36,19 @@ data Clause =
3736 deriving Show
3837
3938matchSubst :: [(String,String)] -> Match -> Match
40−matchSubst _ Break = Break
41−matchSubst _ Fail = Fail
42−matchSubst pairs (Seq ms) = Seq (map (matchSubst pairs) ms)
43−matchSubst pairs (Other (A a e)) =
44− Other . A a $ foldr ($) e $ map (\(x,y) -> subst x (rawVar y)) pairs
45−matchSubst pairs (Match n cs m) =
46− Match (varSubst n) (map clauseSubst cs) (matchSubst pairs m)
47− where varSubst v = fromMaybe v (lookup v pairs)
48− clauseSubst (Clause c vs m) =
49− Clause c (map varSubst vs) (matchSubst pairs m)
39+matchSubst pairs match =
40+ case match of
41+ Break -> Break
42+ Fail -> Fail
43+ Seq ms -> Seq (map (matchSubst pairs) ms)
44+ Other (A a e) ->
45+ Other . A a $ foldr ($) e $ map (\(x,y) -> subst x (rawVar y)) pairs
46+ Match n cs m ->
47+ Match (varSubst n) (map clauseSubst cs) (matchSubst pairs m)
48+ where
49+ varSubst v = fromMaybe v (lookup v pairs)
50+ clauseSubst (Clause c vs m) =
51+ Clause c (map varSubst vs) (matchSubst pairs m)
5052
5153isCon (p:_, _) =
5254 case p of
@@ -68,6 +70,7 @@ match vs@(v:_) cs def
6870 where
6971 cs' = map (dealias v) cs
7072
73+dealias :: String -> ([P.Pattern],Expr) -> ([P.Pattern],Expr)
7174dealias v c@(p:ps, A a e) =
7275 case p of
7376 P.Alias x pattern -> (pattern:ps, A a $ subst x (rawVar v) e)
compiler/Generate/JavaScript.hs+2
@@ -255,9 +255,11 @@ match region mtch =
255255 return [ ExprStmt () (obj "_E.Case" `call` [ref "$moduleName", string (renderPretty region)]) ]
256256
257257 Case.Break -> return [BreakStmt () Nothing]
258+
258259 Case.Other e ->
259260 do e' <- expression e
260261 return [ ret e' ]
262+
261263 Case.Seq ms -> concat <$> mapM (match region) (dropEnd [] ms)
262264 where
263265 dropEnd acc [] = acc