on master help sign in
Merge pull request #1339 from raichoo/javascript

javascript: do not include jsbn if not needed

commitb641b9a6209c85c567ab8f3db5b9bd2889901693 authorraichoo <raichoo@googlemail.com> dateSat 28 Jun 2014, 00:01 (12 years ago) parent146dda281e8dfc
1 file changed+30−4
src/IRTS/CodegenJavaScript.hs+30−4
src/IRTS/CodegenJavaScript.hs+30−4
@@ -30,15 +30,39 @@ idrRTNamespace = "__IDRRT__"
3030idrLTNamespace = "__IDRLT__"
3131idrCTRNamespace = "__IDRCTR__"
3232
33−data CompileInfo = CompileInfo { compileInfoApplyCases :: [Int]
34− , compileInfoEvalCases :: [Int]
33+data CompileInfo = CompileInfo { compileInfoApplyCases :: [Int]
34+ , compileInfoEvalCases :: [Int]
35+ , compileInfoNeedsBigInt :: Bool
3536 }
3637
3738
3839initCompileInfo :: [(Name, [BC])] -> CompileInfo
3940initCompileInfo bc =
40− CompileInfo (collectCases "APPLY" bc) (collectCases "EVAL" bc)
41+ CompileInfo (collectCases "APPLY" bc) (collectCases "EVAL" bc) (lookupBigInt bc)
4142 where
43+ lookupBigInt :: [(Name, [BC])] -> Bool
44+ lookupBigInt = any (needsBigInt . snd)
45+ where
46+ needsBigInt :: [BC] -> Bool
47+ needsBigInt bc = any id $ map testBCForBigInt bc
48+ where
49+ testBCForBigInt :: BC -> Bool
50+ testBCForBigInt (ASSIGNCONST _ c) =
51+ testConstForBigInt c
52+
53+ testBCForBigInt (CONSTCASE _ c d) =
54+ (maybe False needsBigInt d)
55+ || (any id $ map (needsBigInt . snd) c)
56+ || (any id $ map (testConstForBigInt . fst) c)
57+
58+ testBCForBigInt _ = False
59+
60+ testConstForBigInt :: Const -> Bool
61+ testConstForBigInt (BI _) = True
62+ testConstForBigInt (B64 _) = True
63+ testConstForBigInt _ = False
64+
65+
4266 collectCases :: String -> [(Name, [BC])] -> [Int]
4367 collectCases fun bc = getCases $ findFunction fun bc
4468
@@ -368,7 +392,9 @@ codegenJS_all target definitions includes libs filename outputType = do
368392 path <- (++) <$> getDataDir <*> (pure "/jsrts/")
369393 idrRuntime <- readFile $ path ++ "Runtime-common.js"
370394 tgtRuntime <- readFile $ concat [path, "Runtime", rt, ".js"]
371− jsbn <- readFile $ path ++ "jsbn/jsbn.js"
395+ jsbn <- if compileInfoNeedsBigInt info
396+ then readFile $ path ++ "jsbn/jsbn.js"
397+ else return ""
372398 let runtime = ( header
373399 ++ includeLibs libs
374400 ++ included