@@ -1060,6 +1060,52 @@ extractLocalConstructors js =
10601060 []
10611061
10621062
1063+evalCons :: [JS] -> [JS]
1064+evalCons js =
1065+ map (expandProj . evalCons') js
1066+ where
1067+ cons :: [(String, JS)]
1068+ cons = concatMap getGlobalCons js
1069+
1070+ evalCons' :: JS -> JS
1071+ evalCons' js = transformJS match js
1072+ where
1073+ match :: JS -> JS
1074+ match (JSApp (JSIdent "__IDRRT__EVALTC") [arg])
1075+ | JSIdent name <- arg
1076+ , Just (JSNew _ [_, JSNull, _, _]) <- lookup name cons = arg
1077+
1078+ match js = transformJS match js
1079+
1080+
1081+ expandProj :: JS -> JS
1082+ expandProj js = transformJS match js
1083+ where
1084+ match :: JS -> JS
1085+ match (
1086+ JSIndex (
1087+ JSProj (JSIdent name) "vars"
1088+ ) (
1089+ JSNum (JSInt idx)
1090+ )
1091+ )
1092+ | Just (JSNew _ [_, _, _, JSArray args]) <- lookup name cons =
1093+ args !! idx
1094+
1095+ match js = transformJS match js
1096+
1097+
1098+getGlobalCons :: JS -> [(String, JS)]
1099+getGlobalCons js = foldJS match (++) [] js
1100+ where
1101+ match :: JS -> [(String, JS)]
1102+ match js
1103+ | (JSAlloc name (Just con@(JSNew "__IDRRT__Con" _))) <- js =
1104+ [(name, con)]
1105+ | otherwise =
1106+ []
1107+
1108+
10631109codegenJavaScript
10641110 :: JSTarget
10651111 -> [(Name, SDecl)]
@@ -1118,6 +1164,7 @@ codegenJavaScript target definitions filename outputType = do
11181164 , map reduceContinuations
11191165 , extractLocalConstructors
11201166 , unfoldLookupTable
1167+ , evalCons
11211168 ]
11221169
11231170 prelude :: [JS]