@@ -858,7 +858,7 @@ unfoldLookupTable input =
858858 where
859859 adaptRuntime :: [JS] -> [JS]
860860 adaptRuntime js =
861− (adaptEval . adaptApply . adaptCon) js
861+ (adaptApplyTC . adaptEval . adaptApply . adaptCon) js
862862
863863
864864 adaptApply :: [JS] -> [JS]
@@ -886,6 +886,39 @@ unfoldLookupTable input =
886886 )
887887
888888
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+
889922 adaptEval :: [JS] -> [JS]
890923 adaptEval js = adaptEval' [] js
891924 where