on master help sign in
javascript: optimize branches
commit54b959e5f76b419b9fc455b9e72d3b2b05d77f0e authorraichoo <raichoo@googlemail.com> dateThu 30 Jan 2014, 23:52 (13 years ago) parentc5ad26a
1 file changed+11−6
src/IRTS/CodegenJavaScript.hs+11−6
src/IRTS/CodegenJavaScript.hs+11−6
@@ -173,12 +173,8 @@ compileJS (JSIndex lhs rhs) =
173173 compileJS lhs ++ "[" ++ compileJS rhs ++ "]"
174174
175175compileJS (JSCond branches) =
176− intercalate " else " $ map createIfBlock (eliminateDeadBranches branches)
176+ intercalate " else " $ map createIfBlock branches
177177 where
178− eliminateDeadBranches (e@(JSTrue, _):_) = [e]
179− eliminateDeadBranches (x:xs) = x : eliminateDeadBranches xs
180− eliminateDeadBranches [] = []
181−
182178 createIfBlock (JSTrue, e) =
183179 "{\n"
184180 ++ compileJS e
@@ -938,13 +934,22 @@ optimizeEvalTailcalls (fun, tc) js =
938934
939935removeInstanceChecks :: JS -> JS
940936removeInstanceChecks (JSCond conds) =
941− JSCond $ map (removeHelper *** removeInstanceChecks) conds
937+ JSCond $ eliminateDeadBranches $ map (
938+ removeHelper *** removeInstanceChecks
939+ ) conds
942940 where
943941 removeHelper (
944942 JSOp "&&" (JSOp "instanceof" _ (JSIdent "__IDRRT__Con")) check
945943 ) = removeHelper check
946944 removeHelper js = js
947945
946+
947+ eliminateDeadBranches (e@(JSTrue, _):_) = [e]
948+ eliminateDeadBranches [(_, js)] = [(JSTrue, js)]
949+ eliminateDeadBranches (x:xs) = x : eliminateDeadBranches xs
950+ eliminateDeadBranches [] = []
951+
952+
948953removeInstanceChecks (JSFunction args body) =
949954 JSFunction args $ removeInstanceChecks body
950955