@@ -310,15 +310,15 @@ crushIfsHelp visitedBranches unvisitedBranches finally =
310310
311311generateCase
312312 :: String
313− -> DT.DecisionTree Opt.Jump
314− -> [(Int, Opt.Branch)]
313+ -> DT.DecisionTree Opt.Decision
314+ -> [(Int, Opt.Expr)]
315315 -> State Int [Statement ()]
316316generateCase root decisionTree jumpBranches =
317317 do decider <- generateDecisionTree root decisionTree
318318 foldM (goto root) decider jumpBranches
319319
320320
321−goto :: String -> [Statement ()] -> (Int, Opt.Branch) -> State Int [Statement ()]
321+goto :: String -> [Statement ()] -> (Int, Opt.Expr) -> State Int [Statement ()]
322322goto root decider (target, branch) =
323323 let
324324 deciderStmt =
@@ -326,8 +326,8 @@ goto root decider (target, branch) =
326326 (targetLabel root target)
327327 (DoWhileStmt () (BlockStmt () decider) (BoolLit () False))
328328 in
329− do stmts <- generateBranch root branch
330− return (deciderStmt : stmts)
329+ do code <- generateCode branch
330+ return (deciderStmt : toStatementList code)
331331
332332
333333targetLabel :: String -> Int -> Id ()
@@ -335,11 +335,11 @@ targetLabel root target =
335335 Id () (root ++ "_" ++ show target)
336336
337337
338−generateDecisionTree :: String -> DT.DecisionTree Opt.Jump -> State Int [Statement ()]
338+generateDecisionTree :: String -> DT.DecisionTree Opt.Decision -> State Int [Statement ()]
339339generateDecisionTree root decisionTree =
340340 case decisionTree of
341341 DT.Match (Opt.Inline branch) ->
342− generateBranch root branch
342+ toStatementList <$> generateCode branch
343343
344344 DT.Match (Opt.Jump target) ->
345345 return [ BreakStmt () (Just (targetLabel root target)) ]
@@ -368,9 +368,9 @@ generateDecisionTree root decisionTree =
368368
369369collapseTests
370370 :: [(DT.Path, DT.Test)]
371− -> DT.DecisionTree Opt.Jump
372− -> DT.DecisionTree Opt.Jump
373− -> ([(DT.Path, DT.Test)], DT.DecisionTree Opt.Jump)
371+ -> DT.DecisionTree Opt.Decision
372+ -> DT.DecisionTree Opt.Decision
373+ -> ([(DT.Path, DT.Test)], DT.DecisionTree Opt.Decision)
374374collapseTests tests outerFallback decisionTree =
375375 case decisionTree of
376376 DT.Decision testPath [(test, subTree)] (Just fallback)
@@ -381,7 +381,7 @@ collapseTests tests outerFallback decisionTree =
381381 (tests, decisionTree)
382382
383383
384−edgeToCaseClause :: String -> (DT.Test, DT.DecisionTree Opt.Jump) -> State Int (CaseClause ())
384+edgeToCaseClause :: String -> (DT.Test, DT.DecisionTree Opt.Decision) -> State Int (CaseClause ())
385385edgeToCaseClause root (test, subTree) =
386386 CaseClause () (testToExpr test) <$> generateDecisionTree root subTree
387387
@@ -410,7 +410,7 @@ testToExpr test =
410410 Literal.literal lit
411411
412412
413−fallbackToDefault :: String -> Maybe (DT.DecisionTree Opt.Jump) -> State Int [CaseClause ()]
413+fallbackToDefault :: String -> Maybe (DT.DecisionTree Opt.Decision) -> State Int [CaseClause ()]
414414fallbackToDefault root fallback =
415415 case fallback of
416416 Nothing ->
@@ -421,21 +421,6 @@ fallbackToDefault root fallback =
421421 return [ CaseDefault () stmts ]
422422
423423
424−generateBranch :: String -> Opt.Branch -> State Int [Statement ()]
425−generateBranch root (Opt.Branch substitutions expr) =
426− do substs <- mapM (loadPath root) substitutions
427− let substStmts =
428− if null substs then [] else [ VarDeclStmt () substs ]
429− code <- generateCode expr
430− return (substStmts ++ toStatementList code)
431−
432−
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
437−
438−
439424pathToExpr :: String -> DT.Path -> Opt.Expr
440425pathToExpr root fullPath =
441426 go (Opt.Var (Var.local root)) fullPath