on master help sign in
javascript: adapt applytc on table unfold
4dba224raichoo
src/IRTS/CodegenJavaScript.hs+34−1
@@ -858,7 +858,7 @@ unfoldLookupTable input =
858 where
858 where
859 adaptRuntime :: [JS] -> [JS]
859 adaptRuntime :: [JS] -> [JS]
860 adaptRuntime js =
860 adaptRuntime js =
861− (adaptEval . adaptApply . adaptCon) js
861+ (adaptApplyTC . adaptEval . adaptApply . adaptCon) js
862
862
863
863
864 adaptApply :: [JS] -> [JS]
864 adaptApply :: [JS] -> [JS]
@@ -886,6 +886,39 @@ unfoldLookupTable input =
886 )
886 )
887
887
888
888
889+ adaptApplyTC :: [JS] -> [JS]
890+ adaptApplyTC js = adaptApplyTC' [] js
891+ where
892+ adaptApplyTC' :: [JS] -> [JS] -> [JS]
893+ adaptApplyTC' front ((JSAlloc "__IDRRT__APPLYTC" (Just _)):back) =
894+ front ++ (new:back)
895+
896+ adaptApplyTC' front (next:back) =
897+ adaptApplyTC' (front ++ [next]) back
898+
899+ adaptApplyTC' front [] = front
900+
901+ new =
902+ JSAlloc "__IDRRT__APPLYTC" (Just $ JSFunction ["mfn0", "marg0"] (
903+ JSSeq [ JSAlloc "ret" $ Just (
904+ JSTernary (
905+ (JSIdent "mfn0" `jsInstanceOf` jsCon) `jsAnd`
906+ (JSProj (JSIdent "mfn0") "app")
907+ ) (JSApp
908+ (JSProj (JSIdent "mfn0") "app")
909+ [JSIdent "mfn0", JSIdent "marg0"]
910+ ) JSNull
911+ )
912+ , JSWhile (JSIdent "ret" `jsInstanceOf` (JSIdent "__IDRRT__Cont")) (
913+ JSAssign (JSIdent "ret") (
914+ JSApp (JSProj (JSIdent "ret") "k") []
915+ )
916+ )
917+ , JSReturn $ JSIdent "ret"
918+ ]
919+ ))
920+
921+
889 adaptEval :: [JS] -> [JS]
922 adaptEval :: [JS] -> [JS]
890 adaptEval js = adaptEval' [] js
923 adaptEval js = adaptEval' [] js
891 where
924 where