@@ -310,15 +310,15 @@ crushIfsHelp visitedBranches unvisitedBranches finally =
311generateCase
311generateCase
312 :: String
312 :: String
313− -> DT.DecisionTree Opt.Jump
313+ -> DT.DecisionTree Opt.Decision
314− -> [(Int, Opt.Branch)]
314+ -> [(Int, Opt.Expr)]
315 -> State Int [Statement ()]
315 -> State Int [Statement ()]
316generateCase root decisionTree jumpBranches =
316generateCase root decisionTree jumpBranches =
317 do decider <- generateDecisionTree root decisionTree
317 do decider <- generateDecisionTree root decisionTree
318 foldM (goto root) decider jumpBranches
318 foldM (goto root) decider jumpBranches
321−goto :: String -> [Statement ()] -> (Int, Opt.Branch) -> State Int [Statement ()]
321+goto :: String -> [Statement ()] -> (Int, Opt.Expr) -> State Int [Statement ()]
322goto root decider (target, branch) =
322goto root decider (target, branch) =
324 deciderStmt =
324 deciderStmt =
@@ -326,8 +326,8 @@ goto root decider (target, branch) =
326 (targetLabel root target)
326 (targetLabel root target)
327 (DoWhileStmt () (BlockStmt () decider) (BoolLit () False))
327 (DoWhileStmt () (BlockStmt () decider) (BoolLit () False))
329− do stmts <- generateBranch root branch
329+ do code <- generateCode branch
330− return (deciderStmt : stmts)
330+ return (deciderStmt : toStatementList code)
333targetLabel :: String -> Int -> Id ()
333targetLabel :: String -> Int -> Id ()
@@ -335,11 +335,11 @@ targetLabel root target =
335 Id () (root ++ "_" ++ show target)
335 Id () (root ++ "_" ++ show target)
338−generateDecisionTree :: String -> DT.DecisionTree Opt.Jump -> State Int [Statement ()]
338+generateDecisionTree :: String -> DT.DecisionTree Opt.Decision -> State Int [Statement ()]
339generateDecisionTree root decisionTree =
339generateDecisionTree root decisionTree =
340 case decisionTree of
340 case decisionTree of
341 DT.Match (Opt.Inline branch) ->
341 DT.Match (Opt.Inline branch) ->
342− generateBranch root branch
342+ toStatementList <$> generateCode branch
344 DT.Match (Opt.Jump target) ->
344 DT.Match (Opt.Jump target) ->
345 return [ BreakStmt () (Just (targetLabel root target)) ]
345 return [ BreakStmt () (Just (targetLabel root target)) ]
@@ -368,9 +368,9 @@ generateDecisionTree root decisionTree =
369collapseTests
369collapseTests
370 :: [(DT.Path, DT.Test)]
370 :: [(DT.Path, DT.Test)]
371− -> DT.DecisionTree Opt.Jump
371+ -> DT.DecisionTree Opt.Decision
372− -> DT.DecisionTree Opt.Jump
372+ -> DT.DecisionTree Opt.Decision
373− -> ([(DT.Path, DT.Test)], DT.DecisionTree Opt.Jump)
373+ -> ([(DT.Path, DT.Test)], DT.DecisionTree Opt.Decision)
374collapseTests tests outerFallback decisionTree =
374collapseTests tests outerFallback decisionTree =
375 case decisionTree of
375 case decisionTree of
376 DT.Decision testPath [(test, subTree)] (Just fallback)
376 DT.Decision testPath [(test, subTree)] (Just fallback)
@@ -381,7 +381,7 @@ collapseTests tests outerFallback decisionTree =
381 (tests, decisionTree)
381 (tests, decisionTree)
384−edgeToCaseClause :: String -> (DT.Test, DT.DecisionTree Opt.Jump) -> State Int (CaseClause ())
384+edgeToCaseClause :: String -> (DT.Test, DT.DecisionTree Opt.Decision) -> State Int (CaseClause ())
385edgeToCaseClause root (test, subTree) =
385edgeToCaseClause root (test, subTree) =
386 CaseClause () (testToExpr test) <$> generateDecisionTree root subTree
386 CaseClause () (testToExpr test) <$> generateDecisionTree root subTree
@@ -410,7 +410,7 @@ testToExpr test =
410 Literal.literal lit
410 Literal.literal lit
413−fallbackToDefault :: String -> Maybe (DT.DecisionTree Opt.Jump) -> State Int [CaseClause ()]
413+fallbackToDefault :: String -> Maybe (DT.DecisionTree Opt.Decision) -> State Int [CaseClause ()]
414fallbackToDefault root fallback =
414fallbackToDefault root fallback =
415 case fallback of
415 case fallback of
416 Nothing ->
416 Nothing ->
@@ -421,21 +421,6 @@ fallbackToDefault root fallback =
421 return [ CaseDefault () stmts ]
421 return [ CaseDefault () stmts ]
424−generateBranch :: String -> Opt.Branch -> State Int [Statement ()]
425−generateBranch root (Opt.Branch substitutions expr) =
426− do substs <- mapM (loadPath root) substitutions
428− if null substs then [] else [ VarDeclStmt () substs ]
429− code <- generateCode expr
430− return (substStmts ++ toStatementList code)
433−loadPath :: String -> (String, DT.Path) -> State Int (VarDecl ())
434−loadPath root (name, path) =
435− do jsAccessExpr <- generateJsExpr (pathToExpr root path)
436− return $ varDecl (Var.safe name) jsAccessExpr
439pathToExpr :: String -> DT.Path -> Opt.Expr
424pathToExpr :: String -> DT.Path -> Opt.Expr
440pathToExpr root fullPath =
425pathToExpr root fullPath =
441 go (Opt.Var (Var.local root)) fullPath
426 go (Opt.Var (Var.local root)) fullPath