on master help sign in
javascript: inline more functions
commit2ac38b881b2d8f643bb99d423044d5a5a149a473 authorraichoo <raichoo@googlemail.com> dateWed 5 Feb 2014, 00:01 (13 years ago) parentf33f1d8
1 file changed+14−26
src/IRTS/CodegenJavaScript.hs+14−26
src/IRTS/CodegenJavaScript.hs+14−26
@@ -633,33 +633,11 @@ inlineFunctions js =
633633
634634
635635 inlineAble :: Int -> String -> [String] -> JS -> Maybe JS
636− inlineAble 1 fun args body
636+ inlineAble 1 fun args (JSReturn body)
637637 | nonRecur fun body =
638− inlineAble' body
639− where
640− inlineAble' :: JS -> Maybe JS
641− inlineAble' (
642− JSReturn js@(JSNew "__IDRRT__Con" [JSNum _, JSArray vals])
643− )
644− | and $ map (\x -> isJSIdent x || isJSConstant x) vals = Just js
645−
646− inlineAble' (
647− JSReturn js@(JSNew "__IDRRT__Cont" [JSFunction [] (
648− JSReturn (JSApp (JSIdent _) args)
649− )])
650− )
651− | and $ map (\x -> isJSIdent x || isJSConstant x) args = Just js
652−
653− inlineAble' (
654− JSReturn js@(JSIndex (JSProj (JSApp (JSIdent _) args) "vars") _)
655− )
656− | and $ map (\x -> isJSIdent x || isJSConstant x) args = Just js
657−
658− inlineAble' _ = Nothing
659−
660− isJSIdent js
661− | JSIdent _ <- js = True
662− | otherwise = False
638+ if all (<= 1) (map ($ body) (map countIDOccurences args))
639+ then Just body
640+ else Nothing
663641
664642 inlineAble _ _ _ _ = Nothing
665643
@@ -695,6 +673,16 @@ inlineFunctions js =
695673 countAll name js = sum $ map (countInvokations name) js
696674
697675
676+ countIDOccurences :: String -> JS -> Int
677+ countIDOccurences name = foldJS match (+) 0
678+ where
679+ match :: JS -> Int
680+ match js
681+ | JSIdent ident <- js
682+ , name == ident = 1
683+ | otherwise = 0
684+
685+
698686 countInvokations :: String -> JS -> Int
699687 countInvokations name = foldJS match (+) 0
700688 where