on master help sign in
Merge pull request #1339 from raichoo/javascript
b641b9araichoo
src/IRTS/CodegenJavaScript.hs+30−4
@@ -30,15 +30,39 @@ idrRTNamespace = "__IDRRT__"
30idrLTNamespace = "__IDRLT__"
30idrLTNamespace = "__IDRLT__"
31idrCTRNamespace = "__IDRCTR__"
31idrCTRNamespace = "__IDRCTR__"
32
32
33−data CompileInfo = CompileInfo { compileInfoApplyCases :: [Int]
33+data CompileInfo = CompileInfo { compileInfoApplyCases :: [Int]
34− , compileInfoEvalCases :: [Int]
34+ , compileInfoEvalCases :: [Int]
35+ , compileInfoNeedsBigInt :: Bool
35 }
36 }
36
37
37
38
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)
41 where
42 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+
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
44
68
@@ -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"
397+ else return ""
372 let runtime = ( header
398 let runtime = ( header
373 ++ includeLibs libs
399 ++ includeLibs libs
374 ++ included
400 ++ included