on master help sign in
javascript: smarter compilation of conditionals
commitcd2032051f195bcdd31c1c1c2eac5ee7083fe85f authorraichoo <raichoo@googlemail.com> dateFri 17 Jan 2014, 17:42 (13 years ago) parentecb2818
1 file changed+9−1
src/IRTS/CodegenJavaScript.hs+9−1
src/IRTS/CodegenJavaScript.hs+9−1
@@ -170,8 +170,16 @@ compileJS (JSIndex lhs rhs) =
170170 compileJS lhs ++ "[" ++ compileJS rhs ++ "]"
171171
172172compileJS (JSCond branches) =
173− intercalate " else " $ map createIfBlock branches
173+ intercalate " else " $ map createIfBlock (eliminateDeadBranches branches)
174174 where
175+ eliminateDeadBranches (e@(JSTrue, _):_) = [e]
176+ eliminateDeadBranches (x:xs) = x : eliminateDeadBranches xs
177+ eliminateDeadBranches [] = []
178+
179+ createIfBlock (JSTrue, e) =
180+ "{\n"
181+ ++ "return " ++ compileJS e
182+ ++ ";\n}"
175183 createIfBlock (cond, e) =
176184 "if (" ++ compileJS cond ++") {\n"
177185 ++ "return " ++ compileJS e