on master help sign in
javascript: remove empty eval
64f55f6raichoo
src/IRTS/CodegenJavaScript.hs+38−1
@@ -503,6 +503,42 @@ inlineJS = inlineAssign . inlineError . inlineApply . inlineCaseMatch . inlineJS
503 inlineAssign js = transformJS inlineAssign js
503 inlineAssign js = transformJS inlineAssign js
504
504
505
505
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+
506reduceJS :: [JS] -> [JS]
542reduceJS :: [JS] -> [JS]
507reduceJS js = moveJSDeclToTop "__IDRRT__Con" $ reduceLoop [] ([], js)
543reduceJS js = moveJSDeclToTop "__IDRRT__Con" $ reduceLoop [] ([], js)
508
544
@@ -1319,7 +1355,8 @@ codegenJavaScript target definitions filename outputType = do
1319 map compileJS
1355 map compileJS
1320
1356
1321 opt =
1357 opt =
1358+ [ removeEval
1322− [ map inlineJS
1359+ , map inlineJS
1323 , removeIDs
1360 , removeIDs
1324 , reduceJS
1361 , reduceJS
1325 , map reduceConstants
1362 , map reduceConstants