on master help sign in
javascript: adapt evaltc on table unfold
cb0f6f4raichoo
src/IRTS/CodegenJavaScript.hs+36−2
@@ -857,8 +857,8 @@ unfoldLookupTable input =
857 adaptRuntime $ expandCons evals applys js
857 adaptRuntime $ expandCons evals applys js
858 where
858 where
859 adaptRuntime :: [JS] -> [JS]
859 adaptRuntime :: [JS] -> [JS]
860− adaptRuntime js =
860+ adaptRuntime =
861− (adaptApplyTC . adaptEval . adaptApply . adaptCon) js
861+ adaptEvalTC . adaptApplyTC . adaptEval . adaptApply . adaptCon
862
862
863
863
864 adaptApply :: [JS] -> [JS]
864 adaptApply :: [JS] -> [JS]
@@ -943,6 +943,40 @@ unfoldLookupTable input =
943 )
943 )
944 )
944 )
945
945
946+
947+ adaptEvalTC :: [JS] -> [JS]
948+ adaptEvalTC js = adaptEvalTC' [] js
949+ where
950+ adaptEvalTC' :: [JS] -> [JS] -> [JS]
951+ adaptEvalTC' front ((JSAlloc "__IDRRT__EVALTC" (Just _)):back) =
952+ front ++ (new:back)
953+
954+ adaptEvalTC' front (next:back) =
955+ adaptEvalTC' (front ++ [next]) back
956+
957+ adaptEvalTC' front [] = front
958+
959+ new =
960+ JSAlloc "__IDRRT__EVALTC" (Just $ JSFunction ["marg0"] (
961+ JSSeq [ JSAlloc "ret" $ Just (
962+ JSTernary (
963+ (JSIdent "marg0" `jsInstanceOf` jsCon) `jsAnd`
964+ (JSProj (JSIdent "marg0") "eval")
965+ ) (JSApp
966+ (JSProj (JSIdent "marg0") "eval")
967+ [JSIdent "marg0"]
968+ ) (JSIdent "marg0")
969+ )
970+ , JSWhile (JSIdent "ret" `jsInstanceOf` (JSIdent "__IDRRT__Cont")) (
971+ JSAssign (JSIdent "ret") (
972+ JSApp (JSProj (JSIdent "ret") "k") []
973+ )
974+ )
975+ , JSReturn $ JSIdent "ret"
976+ ]
977+ ))
978+
979+
946 adaptCon js =
980 adaptCon js =
947 adaptCon' [] js
981 adaptCon' [] js
948 where
982 where