@@ -33,10 +33,10 @@ internalImports name =
33 , include "_P" "Ports"
33 , include "_P" "Ports"
34 , varDecl Help.localModuleName (string (Module.nameToString name))
34 , varDecl Help.localModuleName (string (Module.nameToString name))
37− include :: String -> String -> VarDecl ()
37+ include :: String -> String -> VarDecl ()
38− include alias modul =
38+ include alias modul =
39− varDecl alias (Help.make ["_N", modul])
39+ varDecl alias (Help.make ["_N", modul])
42_Utils :: String -> Expression ()
42_Utils :: String -> Expression ()
@@ -256,13 +256,14 @@ match :: Region -> Case.Match -> State Int [Statement ()]
256match region mtch =
256match region mtch =
257 case mtch of
257 case mtch of
258 Case.Match name clauses mtch' ->
258 Case.Match name clauses mtch' ->
259− do (isChars, clauses') <- unzip <$> mapM (clause region name) clauses
259+ do (isChars, clauses') <- unzip <$> mapM (clause region name) clauses
260− mtch'' <- match region mtch'
260+ mtch'' <- match region mtch'
261− return (SwitchStmt () (format isChars (access name)) clauses' : mtch'')
261+ return (SwitchStmt () (format isChars (access name)) clauses' : mtch'')
263− isLiteral p = case p of
263+ isLiteral p =
264− Case.Clause (Right _) _ _ -> True
265+ Case.Clause (Right _) _ _ -> True
265− _ -> False
266+ _ -> False
267 access name
268 access name
268 | any isLiteral clauses = obj [name]
269 | any isLiteral clauses = obj [name]
@@ -275,26 +276,30 @@ match region mtch =
275 Case.Fail ->
276 Case.Fail ->
276 return [ ExprStmt () (Help.throw "badCase" region) ]
277 return [ ExprStmt () (Help.throw "badCase" region) ]
278− Case.Break -> return [BreakStmt () Nothing]
280+ return [BreakStmt () Nothing]
280 Case.Other e ->
282 Case.Other e ->
281− do e' <- expression e
283+ do e' <- expression e
282− return [ ret e' ]
284+ return [ ret e' ]
284− Case.Seq ms -> concat <$> mapM (match region) (dropEnd [] ms)
287+ concat <$> mapM (match region) (dropEnd [] ms)
286− dropEnd acc [] = acc
289+ dropEnd acc [] = acc
287− dropEnd acc (m:ms) =
290+ dropEnd acc (m:ms) =
288− case m of
291+ case m of
289− Case.Other _ -> acc ++ [m]
292+ Case.Other _ -> acc ++ [m]
290− _ -> dropEnd (acc ++ [m]) ms
293+ _ -> dropEnd (acc ++ [m]) ms
293clause :: Region -> String -> Case.Clause -> State Int (Bool, CaseClause ())
296clause :: Region -> String -> Case.Clause -> State Int (Bool, CaseClause ())
294clause region variable (Case.Clause value vars mtch) =
297clause region variable (Case.Clause value vars mtch) =
295 (,) isChar . CaseClause () pattern <$> match region (Case.matchSubst (zip vars vars') mtch)
298 (,) isChar . CaseClause () pattern <$> match region (Case.matchSubst (zip vars vars') mtch)
297− vars' = map (\n -> variable ++ "._" ++ show n) [0..]
301+ map (\n -> variable ++ "._" ++ show n) [0..]
298 (isChar, pattern) =
303 (isChar, pattern) =
299 case value of
304 case value of
300 Right (Chr c) -> (True, string [c])
305 Right (Chr c) -> (True, string [c])