on master help sign in
javascript: adapt apply on table unfold
83ae8c9raichoo
src/IRTS/CodegenJavaScript.hs+23−9
@@ -857,24 +857,38 @@ 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 =
860+ adaptRuntime js = (adaptApply . adaptCon) js
861− adaptCon . adaptApply "__var_2" . adaptApply "ev" . adaptEval
862
861
863
862
864− adaptApply var = map (jsSubst (
863+ adaptApply :: [JS] -> [JS]
865− JSIndex (JSIdent "__IDRLT__APPLY") (JSProj (JSIdent var) "tag")
864+ adaptApply js = adaptApply' [] js
866− ) (JSProj (JSIdent var) "app"))
865+ where
866+ adaptApply' :: [JS] -> [JS] -> [JS]
867+ adaptApply' front ((JSAlloc "__IDR__mAPPLY0" (Just _)):back) =
868+ front ++ (new:back)
869+
870+ adaptApply' front (next:back) =
871+ adaptApply' (front ++ [next]) back
867
872
873+ adaptApply' front [] = front
868
874
869− adaptEval = map (jsSubst (
875+ new =
870− JSIndex (JSIdent "__IDRLT__EVAL") (JSProj (JSIdent "arg0") "tag")
876+ JSAlloc "__IDR__mAPPLY0" (Just $ JSFunction ["mfn0", "marg0"] (JSReturn $
877+ JSTernary (
878+ (JSIdent "mfn0" `jsInstanceOf` jsCon) `jsAnd`
879+ (JSProj (JSIdent "mfn0") "app")
880+ ) (JSApp
871− ) (JSProj (JSIdent "arg0") "eval"))
881+ (JSProj (JSIdent "mfn0") "app")
882+ [JSIdent "mfn0", JSIdent "marg0"]
883+ ) JSNull
884+ )
885+ )
872
886
873
887
874 adaptCon js =
888 adaptCon js =
875 adaptCon' [] js
889 adaptCon' [] js
876 where
890 where
877− adaptCon' front ((JSAlloc "__IDRRT__Con" (Just body)):back) =
891+ adaptCon' front ((JSAlloc "__IDRRT__Con" (Just _)):back) =
878 front ++ (new:back)
892 front ++ (new:back)
879
893
880 adaptCon' front (next:back) =
894 adaptCon' front (next:back) =