on master help sign in
javascript: elim some duplicate evals
commit9349d9c5b97a4d8dca9ac86443d95e1c6da33132 authorraichoo <raichoo@googlemail.com> dateWed 29 Jan 2014, 20:55 (13 years ago) parentd37c3d4
1 file changed+16−1
src/IRTS/CodegenJavaScript.hs+16−1
src/IRTS/CodegenJavaScript.hs+16−1
@@ -834,6 +834,20 @@ reduceConstants js
834834 , ret /= js = reduceConstants ret
835835 | otherwise = js
836836
837+
838+elimDuplicateEvals :: JS -> JS
839+elimDuplicateEvals (JSAlloc fun (Just (JSFunction args (JSSeq seq)))) =
840+ JSAlloc fun $ Just (JSFunction args $ JSSeq (elimHelper seq))
841+ where
842+ elimHelper :: [JS] -> [JS]
843+ elimHelper (j@(JSAlloc var (Just val)):js) =
844+ j : map (jsSubst val (JSIdent var)) (elimHelper js)
845+ elimHelper (j:js) =
846+ j : elimHelper js
847+ elimHelper [] = []
848+
849+elimDuplicateEvals js = js
850+
837851reduceLoop :: [String] -> ([JS], [JS]) -> [JS]
838852reduceLoop reduced (cons, program) =
839853 case partition findConstructors program of
@@ -961,7 +975,8 @@ codegenJavaScript target definitions filename outputType = do
961975 constrInit = initConstructors constRemoved
962976 removeAlloc = map removeAllocations constrInit
963977 deadElim = elimDeadLoop removeAlloc
964− js = inlineFunctions deadElim in
978+ inlined = inlineFunctions deadElim
979+ js = map elimDuplicateEvals inlined in
965980 map compileJS js
966981
967982 mainLoop :: JS