on master help sign in
javascript: inline assignments
commitf2e94fa5573587757ef73bbb3198e11a2688338f authorraichoo <raichoo@googlemail.com> dateSun 16 Feb 2014, 16:07 (13 years ago) parentcaf50dd
1 file changed+16−1
src/IRTS/CodegenJavaScript.hs+16−1
src/IRTS/CodegenJavaScript.hs+16−1
@@ -444,7 +444,7 @@ isJSConstantConstructor constants js
444444
445445
446446inlineJS :: JS -> JS
447−inlineJS = inlineError . inlineApply . inlineCaseMatch . inlineJSLet
447+inlineJS = inlineAssign . inlineError . inlineApply . inlineCaseMatch . inlineJSLet
448448 where
449449 inlineJSLet :: JS -> JS
450450 inlineJSLet (JSApp (JSFunction [arg] (JSReturn ret)) [val])
@@ -488,6 +488,21 @@ inlineJS = inlineError . inlineApply . inlineCaseMatch . inlineJSLet
488488 inlineError js = transformJS inlineError js
489489
490490
491+ inlineAssign (JSAssign lhs rhs)
492+ | JSVar _ <- lhs
493+ , JSVar _ <- rhs
494+ , lhs == rhs =
495+ lhs
496+
497+ inlineAssign (JSAssign lhs rhs)
498+ | JSIdent _ <- lhs
499+ , JSIdent _ <- rhs
500+ , lhs == rhs =
501+ lhs
502+
503+ inlineAssign js = transformJS inlineAssign js
504+
505+
491506reduceJS :: [JS] -> [JS]
492507reduceJS js = moveJSDeclToTop "__IDRRT__Con" $ reduceLoop [] ([], js)
493508