on master help sign in
javascript: remove empty eval
commit64f55f64f45c605019a557ed3f790445e5fb34b3 authorraichoo <raichoo@googlemail.com> dateSun 16 Feb 2014, 17:23 (13 years ago) parentf2e94fa
1 file changed+38−1
src/IRTS/CodegenJavaScript.hs+38−1
src/IRTS/CodegenJavaScript.hs+38−1
@@ -503,6 +503,42 @@ inlineJS = inlineAssign . inlineError . inlineApply . inlineCaseMatch . inlineJS
503503 inlineAssign js = transformJS inlineAssign js
504504
505505
506+removeEval :: [JS] -> [JS]
507+removeEval js =
508+ let (ret, isReduced) = checkEval js in
509+ if isReduced
510+ then removeEvalApp ret
511+ else ret
512+ where
513+ removeEvalApp js = catMaybes (map removeEvalApp' js)
514+ where
515+ removeEvalApp' :: JS -> Maybe JS
516+ removeEvalApp' (JSAlloc "__IDR__mEVAL0" _) = Nothing
517+ removeEvalApp' js = Just $ transformJS match js
518+ where
519+ match (JSApp (JSIdent "__IDR__mEVAL0") [val]) = val
520+ match js = transformJS match js
521+
522+ removeEvalApp js = js
523+
524+ checkEval :: [JS] -> ([JS], Bool)
525+ checkEval js = foldr f ([], False) $ map checkEval' js
526+ where
527+ f :: (Maybe JS, Bool) -> ([JS], Bool) -> ([JS], Bool)
528+ f (Just js, isReduced) (ret, b) = (js : ret, isReduced || b)
529+ f (Nothing, isReduced) (ret, b) = (ret, isReduced || b)
530+
531+
532+ checkEval' :: JS -> (Maybe JS, Bool)
533+ checkEval' (JSAlloc "__IDRLT__EVAL" (Just (JSApp (JSFunction [] (
534+ JSSeq [ _
535+ , JSReturn (JSIdent "t")
536+ ]
537+ )) []))) = (Nothing, True)
538+
539+ checkEval' js = (Just js, False)
540+
541+
506542reduceJS :: [JS] -> [JS]
507543reduceJS js = moveJSDeclToTop "__IDRRT__Con" $ reduceLoop [] ([], js)
508544
@@ -1319,7 +1355,8 @@ codegenJavaScript target definitions filename outputType = do
13191355 map compileJS
13201356
13211357 opt =
1322− [ map inlineJS
1358+ [ removeEval
1359+ , map inlineJS
13231360 , removeIDs
13241361 , reduceJS
13251362 , map reduceConstants