on master help sign in
javascript: decouple lookuptablenames
commitf33f1d826bd3ae260d71d6c63767c8e8c37d28c5 authorraichoo <raichoo@googlemail.com> dateTue 4 Feb 2014, 21:25 (13 years ago) parentd033452
1 file changed+21−25
src/IRTS/CodegenJavaScript.hs+21−25
src/IRTS/CodegenJavaScript.hs+21−25
@@ -786,10 +786,10 @@ optimizeRuntimeCalls fun tc js =
786786 JSSeq [ JSAlloc "ret" $ Just (
787787 JSTernary (
788788 (JSIdent "arg0" `jsInstanceOf` jsCon) `jsAnd`
789− (hasProp "__IDRLT__mEVAL0" "arg0")
789+ (hasProp "__IDRLT__EVAL" "arg0")
790790 ) (JSApp
791791 (JSIndex
792− (JSIdent "__IDRLT__mEVAL0")
792+ (JSIdent "__IDRLT__EVAL")
793793 (JSProj (JSIdent "arg0") "tag")
794794 )
795795 [JSIdent "arg0"]
@@ -812,10 +812,10 @@ optimizeRuntimeCalls fun tc js =
812812 , JSAlloc "ret" $ Just (
813813 JSTernary (
814814 (JSIdent "ev" `jsInstanceOf` jsCon) `jsAnd`
815− (hasProp "__IDRLT__mAPPLY0" "ev")
815+ (hasProp "__IDRLT__APPLY" "ev")
816816 ) (JSApp
817817 (JSIndex
818− (JSIdent "__IDRLT__mAPPLY0")
818+ (JSIdent "__IDRLT__APPLY")
819819 (JSProj (JSIdent "ev") "tag")
820820 )
821821 [JSIdent "fn0", JSIdent "arg0", JSIdent "ev"]
@@ -838,8 +838,8 @@ optimizeRuntimeCalls fun tc js =
838838
839839unfoldLookupTable :: [JS] -> [JS]
840840unfoldLookupTable input =
841− let (evals, evalunfold) = unfoldLT "__IDRLT__mEVAL0" input
842− (applys, applyunfold) = unfoldLT "__IDRLT__mAPPLY0" evalunfold
841+ let (evals, evalunfold) = unfoldLT "__IDRLT__EVAL" input
842+ (applys, applyunfold) = unfoldLT "__IDRLT__APPLY" evalunfold
843843 js = applyunfold in
844844 adaptRuntime $ expandCons evals applys js
845845 where
@@ -849,12 +849,12 @@ unfoldLookupTable input =
849849
850850
851851 adaptApply var = map (jsSubst (
852− JSIndex (JSIdent "__IDRLT__mAPPLY0") (JSProj (JSIdent var) "tag")
852+ JSIndex (JSIdent "__IDRLT__APPLY") (JSProj (JSIdent var) "tag")
853853 ) (JSProj (JSIdent var) "app"))
854854
855855
856856 adaptEval = map (jsSubst (
857− JSIndex (JSIdent "__IDRLT__mEVAL0") (JSProj (JSIdent "arg0") "tag")
857+ JSIndex (JSIdent "__IDRLT__EVAL") (JSProj (JSIdent "arg0") "tag")
858858 ) (JSProj (JSIdent "arg0") "eval"))
859859
860860
@@ -894,8 +894,8 @@ unfoldLookupTable input =
894894 where
895895 expandCons' :: JS -> JS
896896 expandCons' (JSNew "__IDRRT__Con" [JSNum (JSInt tag), JSArray args])
897− | evalid <- getId "__IDRLT__mEVAL0" tag evals
898− , applyid <- getId "__IDRLT__mAPPLY0" tag applys =
897+ | evalid <- getId "__IDRLT__EVAL" tag evals
898+ , applyid <- getId "__IDRLT__APPLY" tag applys =
899899 JSNew "__IDRRT__Con" [ JSNum (JSInt tag)
900900 , maybe JSNull JSIdent evalid
901901 , maybe JSNull JSIdent applyid
@@ -912,8 +912,8 @@ unfoldLookupTable input =
912912
913913
914914 ltIdentifier :: String -> Int -> String
915− ltIdentifier "__IDRLT__mEVAL0" id = idrLTNamespace ++ "EVAL" ++ show id
916− ltIdentifier "__IDRLT__mAPPLY0" id = idrLTNamespace ++ "APPLY" ++ show id
915+ ltIdentifier "__IDRLT__EVAL" id = idrLTNamespace ++ "EVAL" ++ show id
916+ ltIdentifier "__IDRLT__APPLY" id = idrLTNamespace ++ "APPLY" ++ show id
917917
918918
919919 extractLT :: String -> [JS] -> (JS, [JS])
@@ -1228,7 +1228,7 @@ translateDeclaration (path, SFun name params stackSize body)
12281228 lookup t = (JSApp
12291229 (JSIndex (JSIdent t) (JSProj (JSIdent lvar) "tag"))
12301230 [JSIdent "fn0", JSIdent "arg0", JSIdent lvar]) in
1231− [ lookupTable [(var, "chk")] var cases
1231+ [ lookupTable "APPLY" [(var, "chk")] var cases
12321232 , jsDecl $ JSFunction ["fn0", "arg0"] (
12331233 JSSeq [ JSAlloc "__var_0" (Just $ JSIdent "fn0")
12341234 , JSAlloc (translateVariableName var) (
@@ -1236,8 +1236,8 @@ translateDeclaration (path, SFun name params stackSize body)
12361236 )
12371237 , JSReturn $ (JSTernary (
12381238 (JSVar var `jsInstanceOf` jsCon) `jsAnd`
1239− (hasProp lookupTableName (translateVariableName var))
1240− ) (lookup lookupTableName) JSNull)
1239+ (hasProp (idrLTNamespace ++ "APPLY") (translateVariableName var))
1240+ ) (lookup (idrLTNamespace ++ "APPLY")) JSNull)
12411241 ]
12421242 )
12431243 ]
@@ -1245,13 +1245,13 @@ translateDeclaration (path, SFun name params stackSize body)
12451245 | (MN _ ev) <- name
12461246 , (SChkCase var cases) <- body
12471247 , ev == txt "EVAL" =
1248− [ lookupTable [] var cases
1248+ [ lookupTable "EVAL" [] var cases
12491249 , jsDecl $ JSFunction ["arg0"] (JSReturn $
12501250 JSTernary (
12511251 (JSIdent "arg0" `jsInstanceOf` jsCon) `jsAnd`
1252− (hasProp lookupTableName "arg0")
1252+ (hasProp (idrLTNamespace ++ "EVAL") "arg0")
12531253 ) (JSApp
1254− (JSIndex (JSIdent lookupTableName) (JSProj (JSIdent "arg0") "tag"))
1254+ (JSIndex (JSIdent (idrLTNamespace ++ "EVAL")) (JSProj (JSIdent "arg0") "tag"))
12551255 [JSIdent "arg0"]
12561256 ) (JSIdent "arg0")
12571257 )
@@ -1277,13 +1277,9 @@ translateDeclaration (path, SFun name params stackSize body)
12771277 getTag _ = Nothing
12781278
12791279
1280− lookupTableName :: String
1281− lookupTableName = idrLTNamespace ++ translateName name
1282−
1283−
1284− lookupTable :: [(LVar, String)] -> LVar -> [SAlt] -> JS
1285− lookupTable aux var cases =
1286− JSAlloc lookupTableName $ Just (
1280+ lookupTable :: String -> [(LVar, String)] -> LVar -> [SAlt] -> JS
1281+ lookupTable table aux var cases =
1282+ JSAlloc (idrLTNamespace ++ table) $ Just (
12871283 JSApp (JSFunction [] (
12881284 JSSeq $ [
12891285 JSAlloc "t" $ Just (JSArray [])