on master help sign in
javascript: collapse continuations
d700f08raichoo
src/IRTS/CodegenJavaScript.hs+29−3
@@ -1062,7 +1062,7 @@ extractLocalConstructors js =
1062
1062
1063evalCons :: [JS] -> [JS]
1063evalCons :: [JS] -> [JS]
1064evalCons js =
1064evalCons js =
1065− map (collapseTC . expandProj . evalCons') js
1065+ map (collapseCont . collapseTC . expandProj . evalCons') js
1066 where
1066 where
1067 cons :: [(String, JS)]
1067 cons :: [(String, JS)]
1068 cons = concatMap getGlobalCons js
1068 cons = concatMap getGlobalCons js
@@ -1072,12 +1072,25 @@ evalCons js =
1072 where
1072 where
1073 match :: JS -> JS
1073 match :: JS -> JS
1074 match (JSApp (JSIdent "__IDRRT__EVALTC") [arg])
1074 match (JSApp (JSIdent "__IDRRT__EVALTC") [arg])
1075− | JSIdent name <- arg
1075+ | JSIdent name <- arg
1076− , Just (JSNew _ [_, JSNull, _, _]) <- lookup name cons = arg
1076+ , Just (JSNew _ [_, JSNull, _, _]) <- lookupConstructor name cons =
1077+ arg
1078+
1079+ match (JSApp (JSIdent "__IDR__mEVAL0") [arg])
1080+ | JSIdent name <- arg
1081+ , Just (JSNew _ [_, JSNull, _, _]) <- lookupConstructor name cons =
1082+ arg
1077
1083
1078 match js = transformJS match js
1084 match js = transformJS match js
1079
1085
1080
1086
1087+ lookupConstructor :: String -> [(String, JS)] -> Maybe JS
1088+ lookupConstructor ctr cons
1089+ | Just (JSIdent name) <- lookup ctr cons = lookupConstructor name cons
1090+ | Just con@(JSNew _ _) <- lookup ctr cons = Just con
1091+ | otherwise = Nothing
1092+
1093+
1081 expandProj :: JS -> JS
1094 expandProj :: JS -> JS
1082 expandProj js = transformJS match js
1095 expandProj js = transformJS match js
1083 where
1096 where
@@ -1107,6 +1120,17 @@ evalCons js =
1107 match js = transformJS match js
1120 match js = transformJS match js
1108
1121
1109
1122
1123+ collapseCont :: JS -> JS
1124+ collapseCont js = transformJS match js
1125+ where
1126+ match :: JS -> JS
1127+ match (JSNew "__IDRRT__Cont" [JSFunction [] (
1128+ JSReturn (JSIdent name)
1129+ )]) = JSIdent name
1130+
1131+ match js = transformJS match js
1132+
1133+
1110getGlobalCons :: JS -> [(String, JS)]
1134getGlobalCons :: JS -> [(String, JS)]
1111getGlobalCons js = foldJS match (++) [] js
1135getGlobalCons js = foldJS match (++) [] js
1112 where
1136 where
@@ -1114,6 +1138,8 @@ getGlobalCons js = foldJS match (++) [] js
1114 match js
1138 match js
1115 | (JSAlloc name (Just con@(JSNew "__IDRRT__Con" _))) <- js =
1139 | (JSAlloc name (Just con@(JSNew "__IDRRT__Con" _))) <- js =
1116 [(name, con)]
1140 [(name, con)]
1141+ | (JSAlloc name (Just con@(JSIdent _))) <- js =
1142+ [(name, con)]
1117 | otherwise =
1143 | otherwise =
1118 []
1144 []
1119
1145