on master help sign in
javascript: adapt apply on table unfold
commit83ae8c9f80a6b7a9604624c4a50c66546edbd5dd authorraichoo <raichoo@googlemail.com> dateFri 14 Feb 2014, 15:45 (13 years ago) parentc4323fb
1 file changed+23−9
src/IRTS/CodegenJavaScript.hs+23−9
src/IRTS/CodegenJavaScript.hs+23−9
@@ -857,24 +857,38 @@ unfoldLookupTable input =
857857 adaptRuntime $ expandCons evals applys js
858858 where
859859 adaptRuntime :: [JS] -> [JS]
860− adaptRuntime =
861− adaptCon . adaptApply "__var_2" . adaptApply "ev" . adaptEval
860+ adaptRuntime js = (adaptApply . adaptCon) js
862861
863862
864− adaptApply var = map (jsSubst (
865− JSIndex (JSIdent "__IDRLT__APPLY") (JSProj (JSIdent var) "tag")
866− ) (JSProj (JSIdent var) "app"))
863+ adaptApply :: [JS] -> [JS]
864+ adaptApply js = adaptApply' [] js
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
867872
873+ adaptApply' front [] = front
868874
869− adaptEval = map (jsSubst (
870− JSIndex (JSIdent "__IDRLT__EVAL") (JSProj (JSIdent "arg0") "tag")
871− ) (JSProj (JSIdent "arg0") "eval"))
875+ new =
876+ JSAlloc "__IDR__mAPPLY0" (Just $ JSFunction ["mfn0", "marg0"] (JSReturn $
877+ JSTernary (
878+ (JSIdent "mfn0" `jsInstanceOf` jsCon) `jsAnd`
879+ (JSProj (JSIdent "mfn0") "app")
880+ ) (JSApp
881+ (JSProj (JSIdent "mfn0") "app")
882+ [JSIdent "mfn0", JSIdent "marg0"]
883+ ) JSNull
884+ )
885+ )
872886
873887
874888 adaptCon js =
875889 adaptCon' [] js
876890 where
877− adaptCon' front ((JSAlloc "__IDRRT__Con" (Just body)):back) =
891+ adaptCon' front ((JSAlloc "__IDRRT__Con" (Just _)):back) =
878892 front ++ (new:back)
879893
880894 adaptCon' front (next:back) =