on master help sign in
javascript: collapse continuations
commitd700f08c1779309251bb4bae5eea4879b2acedb8 authorraichoo <raichoo@googlemail.com> dateSat 8 Feb 2014, 15:19 (13 years ago) parent1a3acbe
1 file changed+29−3
src/IRTS/CodegenJavaScript.hs+29−3
src/IRTS/CodegenJavaScript.hs+29−3
@@ -1062,7 +1062,7 @@ extractLocalConstructors js =
10621062
10631063evalCons :: [JS] -> [JS]
10641064evalCons js =
1065− map (collapseTC . expandProj . evalCons') js
1065+ map (collapseCont . collapseTC . expandProj . evalCons') js
10661066 where
10671067 cons :: [(String, JS)]
10681068 cons = concatMap getGlobalCons js
@@ -1072,12 +1072,25 @@ evalCons js =
10721072 where
10731073 match :: JS -> JS
10741074 match (JSApp (JSIdent "__IDRRT__EVALTC") [arg])
1075− | JSIdent name <- arg
1076− , Just (JSNew _ [_, JSNull, _, _]) <- lookup name cons = arg
1075+ | JSIdent name <- 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
10771083
10781084 match js = transformJS match js
10791085
10801086
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+
10811094 expandProj :: JS -> JS
10821095 expandProj js = transformJS match js
10831096 where
@@ -1107,6 +1120,17 @@ evalCons js =
11071120 match js = transformJS match js
11081121
11091122
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+
11101134getGlobalCons :: JS -> [(String, JS)]
11111135getGlobalCons js = foldJS match (++) [] js
11121136 where
@@ -1114,6 +1138,8 @@ getGlobalCons js = foldJS match (++) [] js
11141138 match js
11151139 | (JSAlloc name (Just con@(JSNew "__IDRRT__Con" _))) <- js =
11161140 [(name, con)]
1141+ | (JSAlloc name (Just con@(JSIdent _))) <- js =
1142+ [(name, con)]
11171143 | otherwise =
11181144 []
11191145