on master help sign in
Merge pull request #875 from raichoo/javascript
ce4fef0Edwin Brady
src/IRTS/CodegenJavaScript.hs+19−1
@@ -1031,7 +1031,7 @@ extractLocalConstructors js =
1031
1031
1032 extractLocalConstructors' :: JS -> [JS]
1032 extractLocalConstructors' :: JS -> [JS]
1033 extractLocalConstructors' js@(JSAlloc fun (Just (JSFunction args body))) =
1033 extractLocalConstructors' js@(JSAlloc fun (Just (JSFunction args body))) =
1034− map allocCon cons ++ [foldr (uncurry jsSubst) js (reverse cons)]
1034+ addCons cons [foldr (uncurry jsSubst) js (reverse cons)]
1035 where
1035 where
1036 cons :: [(JS, JS)]
1036 cons :: [(JS, JS)]
1037 cons = zipWith genName (foldJS match (++) [] body) [1..]
1037 cons = zipWith genName (foldJS match (++) [] body) [1..]
@@ -1047,6 +1047,24 @@ extractLocalConstructors js =
1047 | otherwise = []
1047 | otherwise = []
1048
1048
1049
1049
1050+ addCons :: [(JS, JS)] -> [JS] -> [JS]
1051+ addCons [] js = js
1052+ addCons (con@(_, name):cons) js
1053+ | sum (map (countOccur name) js) > 0 =
1054+ addCons cons ((allocCon con) : js)
1055+ | otherwise =
1056+ addCons cons js
1057+
1058+
1059+ countOccur :: JS -> JS -> Int
1060+ countOccur ident js = foldJS match (+) 0 js
1061+ where
1062+ match :: JS -> Int
1063+ match js
1064+ | js == ident = 1
1065+ | otherwise = 0
1066+
1067+
1050 allocCon :: (JS, JS) -> JS
1068 allocCon :: (JS, JS) -> JS
1051 allocCon (js, JSIdent name) =
1069 allocCon (js, JSIdent name) =
1052 JSAlloc name (Just js)
1070 JSAlloc name (Just js)