on master help sign in
javascript: adapt eval on table unfold
72c1c4eraichoo
src/IRTS/CodegenJavaScript.hs+26−1
@@ -857,7 +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 js = (adaptApply . adaptCon) js
861+ (adaptEval . adaptApply . adaptCon) js
861
862
862
863
863 adaptApply :: [JS] -> [JS]
864 adaptApply :: [JS] -> [JS]
@@ -885,6 +886,30 @@ unfoldLookupTable input =
885 )
886 )
886
887
887
888
889+ adaptEval :: [JS] -> [JS]
890+ adaptEval js = adaptEval' [] js
891+ where
892+ adaptEval' :: [JS] -> [JS] -> [JS]
893+ adaptEval' front ((JSAlloc "__IDR__mEVAL0" (Just _)):back) =
894+ front ++ (new:back)
895+
896+ adaptEval' front (next:back) =
897+ adaptEval' (front ++ [next]) back
898+
899+ adaptEval' front [] = front
900+
901+ new =
902+ JSAlloc "__IDR__mEVAL0" (Just $ JSFunction ["marg0"] (JSReturn $
903+ JSTernary (
904+ (JSIdent "marg0" `jsInstanceOf` jsCon) `jsAnd`
905+ (JSProj (JSIdent "marg0") "eval")
906+ ) (JSApp
907+ (JSProj (JSIdent "marg0") "eval")
908+ [JSIdent "marg0"]
909+ ) (JSIdent "marg0")
910+ )
911+ )
912+
888 adaptCon js =
913 adaptCon js =
889 adaptCon' [] js
914 adaptCon' [] js
890 where
915 where