@@ -1398,7 +1398,7 @@ codegenJavaScript
1398 -> OutputType
1398 -> OutputType
1399 -> IO ()
1399 -> IO ()
1400codegenJavaScript target definitions includes filename outputType = do
1400codegenJavaScript target definitions includes filename outputType = do
1401− let (header, runtime) = case target of
1401+ let (header, rt) = case target of
1403 ("#!/usr/bin/env node\n", "-node")
1403 ("#!/usr/bin/env node\n", "-node")
1404 JavaScript ->
1404 JavaScript ->
@@ -1406,13 +1406,10 @@ codegenJavaScript target definitions includes filename outputType = do
1406 included <- getIncludes includes
1406 included <- getIncludes includes
1407 path <- (++) <$> getDataDir <*> (pure "/jsrts/")
1407 path <- (++) <$> getDataDir <*> (pure "/jsrts/")
1408 idrRuntime <- readFile $ path ++ "Runtime-common.js"
1408 idrRuntime <- readFile $ path ++ "Runtime-common.js"
1409− tgtRuntime <- readFile $ concat [path, "Runtime", runtime, ".js"]
1409+ tgtRuntime <- readFile $ concat [path, "Runtime", rt, ".js"]
1410 jsbn <- readFile $ path ++ "jsbn/jsbn.js"
1410 jsbn <- readFile $ path ++ "jsbn/jsbn.js"
1411 writeFile filename $ header ++ (
1411 writeFile filename $ header ++ (
1412− intercalate "\n" $ included ++ [ jsbn
1412+ intercalate "\n" $ included ++ runtime jsbn idrRuntime tgtRuntime ++ functions
1418 setPermissions filename (emptyPermissions { readable = True
1415 setPermissions filename (emptyPermissions { readable = True
@@ -1424,15 +1421,32 @@ codegenJavaScript target definitions includes filename outputType = do
1424 def = map (first translateNamespace) definitions
1421 def = map (first translateNamespace) definitions
1427− functions :: [String]
1424+ checkForBigInt :: [JS] -> Bool
1425+ checkForBigInt js = occur
1428+ occur = or $ map (foldJS match (||) False) js
1430+ match :: JS -> Bool
1431+ match (JSIdent "__IDRRT__bigInt") = True
1432+ match (JSNum (JSInteger _)) = True
1436+ runtime :: String -> String -> String -> [String]
1437+ runtime jsbn idrRuntime tgtRuntime =
1438+ if checkForBigInt optimized
1439+ then [jsbn, idrRuntime, tgtRuntime]
1440+ else [idrRuntime, tgtRuntime]
1428− functions = translate >>> optimize >>> compile $ def
1444+ optimized = translate >>> optimize $ def
1430 translate p =
1446 translate p =
1431 prelude ++ concatMap translateDeclaration p ++ [mainLoop, invokeLoop]
1447 prelude ++ concatMap translateDeclaration p ++ [mainLoop, invokeLoop]
1432 optimize p =
1448 optimize p =
1433 foldl' (flip ($)) p opt
1449 foldl' (flip ($)) p opt
1438 [ removeEval
1452 [ removeEval
@@ -1454,6 +1468,9 @@ codegenJavaScript target definitions includes filename outputType = do
1454 , evalCons
1468 , evalCons
1471+ functions :: [String]
1472+ functions = map compileJS optimized
1457 prelude :: [JS]
1474 prelude :: [JS]
1458 prelude =
1475 prelude =
1459 [ JSAnnotation JSConstructor $
1476 [ JSAnnotation JSConstructor $