@@ -30,15 +30,39 @@ idrRTNamespace = "__IDRRT__"
30idrLTNamespace = "__IDRLT__"
30idrLTNamespace = "__IDRLT__"
31idrCTRNamespace = "__IDRCTR__"
31idrCTRNamespace = "__IDRCTR__"
33−data CompileInfo = CompileInfo { compileInfoApplyCases :: [Int]
33+data CompileInfo = CompileInfo { compileInfoApplyCases :: [Int]
34− , compileInfoEvalCases :: [Int]
34+ , compileInfoEvalCases :: [Int]
35+ , compileInfoNeedsBigInt :: Bool
38initCompileInfo :: [(Name, [BC])] -> CompileInfo
39initCompileInfo :: [(Name, [BC])] -> CompileInfo
39initCompileInfo bc =
40initCompileInfo bc =
40− CompileInfo (collectCases "APPLY" bc) (collectCases "EVAL" bc)
41+ CompileInfo (collectCases "APPLY" bc) (collectCases "EVAL" bc) (lookupBigInt bc)
43+ lookupBigInt :: [(Name, [BC])] -> Bool
44+ lookupBigInt = any (needsBigInt . snd)
46+ needsBigInt :: [BC] -> Bool
47+ needsBigInt bc = any id $ map testBCForBigInt bc
49+ testBCForBigInt :: BC -> Bool
50+ testBCForBigInt (ASSIGNCONST _ c) =
53+ testBCForBigInt (CONSTCASE _ c d) =
54+ (maybe False needsBigInt d)
55+ || (any id $ map (needsBigInt . snd) c)
56+ || (any id $ map (testConstForBigInt . fst) c)
58+ testBCForBigInt _ = False
60+ testConstForBigInt :: Const -> Bool
61+ testConstForBigInt (BI _) = True
62+ testConstForBigInt (B64 _) = True
63+ testConstForBigInt _ = False
42 collectCases :: String -> [(Name, [BC])] -> [Int]
66 collectCases :: String -> [(Name, [BC])] -> [Int]
43 collectCases fun bc = getCases $ findFunction fun bc
67 collectCases fun bc = getCases $ findFunction fun bc
@@ -368,7 +392,9 @@ codegenJS_all target definitions includes libs filename outputType = do
368 path <- (++) <$> getDataDir <*> (pure "/jsrts/")
392 path <- (++) <$> getDataDir <*> (pure "/jsrts/")
369 idrRuntime <- readFile $ path ++ "Runtime-common.js"
393 idrRuntime <- readFile $ path ++ "Runtime-common.js"
370 tgtRuntime <- readFile $ concat [path, "Runtime", rt, ".js"]
394 tgtRuntime <- readFile $ concat [path, "Runtime", rt, ".js"]
395+ jsbn <- if compileInfoNeedsBigInt info
371− jsbn <- readFile $ path ++ "jsbn/jsbn.js"
396+ then readFile $ path ++ "jsbn/jsbn.js"
372 let runtime = ( header
398 let runtime = ( header
373 ++ includeLibs libs
399 ++ includeLibs libs
374 ++ included
400 ++ included