on master help sign in
Cosmetic: import the prefixed version of `Generate.Cases`
commitea383763585b5c62f9cd9df114656bd0fa57d830 authorEvan Czaplicki <info@elm-lang.org> dateTue 8 Oct 2013, 20:04 (13 years ago) parent0b11d4f
2 files changed+18−15
compiler/Generate/Cases.hs+3−3 compiler/Generate/JavaScript.hs+15−12
compiler/Generate/Cases.hs+3−3
@@ -1,4 +1,4 @@
1−module Generate.Cases (caseToMatch, Match (..), Clause (..), matchSubst) where
1+module Generate.Cases (toMatch, Match (..), Clause (..), matchSubst) where
22
33import Control.Applicative ((<$>),(<*>))
44import Control.Arrow (first,second)
@@ -13,8 +13,8 @@ import SourceSyntax.Expression
1313import Transform.Substitute
1414
1515
16−caseToMatch :: [(Pattern, LExpr t v)] -> State Int (String, Match t v)
17−caseToMatch patterns = do
16+toMatch :: [(Pattern, LExpr t v)] -> State Int (String, Match t v)
17+toMatch patterns = do
1818 v <- newVar
1919 (,) v <$> match [v] (map (first (:[])) patterns) Fail
2020
compiler/Generate/JavaScript.hs+15−12
@@ -8,7 +8,7 @@ import qualified Data.Map as Map
88import qualified Data.Set as Set
99import qualified Text.Pandoc as Pan
1010
11−import Generate.Cases
11+import qualified Generate.Cases as Case
1212import SourceSyntax.Everything
1313import SourceSyntax.Location
1414import qualified Transform.SortDefinitions as SD
@@ -166,10 +166,10 @@ expression (L span expr) =
166166 iff (if', then') else' = CondExpr () if' then' else'
167167
168168 Case e cases ->
169− do (tempVar,initialMatch) <- caseToMatch cases
169+ do (tempVar,initialMatch) <- Case.toMatch cases
170170 (revisedMatch, stmt) <-
171171 case e of
172− L _ (Var x) -> return (matchSubst [(tempVar,x)] initialMatch, [])
172+ L _ (Var x) -> return (Case.matchSubst [(tempVar,x)] initialMatch, [])
173173 _ -> do e' <- expression e
174174 return (initialMatch, [VarDeclStmt () [varDecl tempVar e']])
175175 match' <- match span revisedMatch
@@ -239,33 +239,36 @@ definition def =
239239 toDef y = definition $
240240 Def (PVar y) (L span $ Case (mkVar "$") [(pattern, mkVar y)])
241241
242+match :: (Show a) => a -> Case.Match () () -> State Int [Statement ()]
242243match span mtch =
243244 case mtch of
244− Match name clauses mtch' ->
245+ Case.Match name clauses mtch' ->
245246 do clauses' <- mapM (clause span name) clauses
246247 mtch'' <- match span mtch'
247248 return (SwitchStmt () (access name) clauses' : mtch'')
248249 where
249250 isLiteral p = case p of
250− Clause (Right _) _ _ -> True
251+ Case.Clause (Right _) _ _ -> True
251252 _ -> False
252253 access name = if any isLiteral clauses then ref name else dotSep [name,"ctor"]
253254
254− Fail -> return [ ExprStmt () (obj "_E.Case" `call` [ref "$moduleName", string (show span)]) ]
255− Break -> return []
256− Other e ->
255+ Case.Fail ->
256+ return [ ExprStmt () (obj "_E.Case" `call` [ref "$moduleName", string (show span)]) ]
257+
258+ Case.Break -> return []
259+ Case.Other e ->
257260 do e' <- expression e
258261 return [ ReturnStmt () (Just e') ]
259− Seq ms -> concat <$> mapM (match span) (dropEnd [] ms)
262+ Case.Seq ms -> concat <$> mapM (match span) (dropEnd [] ms)
260263 where
261264 dropEnd acc [] = acc
262265 dropEnd acc (m:ms) =
263266 case m of
264− Other _ -> acc ++ [m]
267+ Case.Other _ -> acc ++ [m]
265268 _ -> dropEnd (acc ++ [m]) ms
266269
267−clause span variable (Clause value vars mtch) =
268− CaseClause () pattern <$> match span (matchSubst (zip vars vars') mtch)
270+clause span variable (Case.Clause value vars mtch) =
271+ CaseClause () pattern <$> match span (Case.matchSubst (zip vars vars') mtch)
269272 where
270273 vars' = map (\n -> variable ++ "._" ++ show n) [0..]
271274 pattern = case value of