@@ -338,21 +338,24 @@ compileJS' indent (JSWord word)
338 | JSWord64 b <- word = idrRTNamespace ++ "bigInt(\"" ++ show b ++ "\")"
338 | JSWord64 b <- word = idrRTNamespace ++ "bigInt(\"" ++ show b ++ "\")"
340codegenJavaScript :: CodeGenerator
340codegenJavaScript :: CodeGenerator
341+codegenJavaScript ci =
341−codegenJavaScript ci = codegenJS_all JavaScript (simpleDecls ci)
342+ codegenJS_all JavaScript (simpleDecls ci)
342− (includes ci) (outputFile ci) (outputType ci)
343+ (includes ci) [] (outputFile ci) (outputType ci)
344codegenNode :: CodeGenerator
345codegenNode :: CodeGenerator
345−codegenNode ci = codegenJS_all Node (simpleDecls ci)
347+ codegenJS_all Node (simpleDecls ci)
346− (includes ci) (outputFile ci) (outputType ci)
348+ (includes ci) (compileLibs ci) (outputFile ci) (outputType ci)
348codegenJS_all
350codegenJS_all
349 :: JSTarget
351 :: JSTarget
350 -> [(Name, SDecl)]
352 -> [(Name, SDecl)]
351 -> [FilePath]
353 -> [FilePath]
352 -> FilePath
355 -> FilePath
353 -> OutputType
356 -> OutputType
355−codegenJS_all target definitions includes filename outputType = do
358+codegenJS_all target definitions includes libs filename outputType = do
356 let bytecode = map toBC definitions
359 let bytecode = map toBC definitions
357 let info = initCompileInfo bytecode
360 let info = initCompileInfo bytecode
358 let js = concatMap (translateDecl info) bytecode
361 let js = concatMap (translateDecl info) bytecode
@@ -366,13 +369,23 @@ codegenJS_all target definitions includes filename outputType = do
366 idrRuntime <- readFile $ path ++ "Runtime-common.js"
369 idrRuntime <- readFile $ path ++ "Runtime-common.js"
367 tgtRuntime <- readFile $ concat [path, "Runtime", rt, ".js"]
370 tgtRuntime <- readFile $ concat [path, "Runtime", rt, ".js"]
368 jsbn <- readFile $ path ++ "jsbn/jsbn.js"
371 jsbn <- readFile $ path ++ "jsbn/jsbn.js"
369− let runtime = header ++ included ++ jsbn ++ idrRuntime ++ tgtRuntime
372+ let runtime = ( header
370 writeFile filename $ runtime ++ concat code ++ main ++ invokeMain
379 writeFile filename $ runtime ++ concat code ++ main ++ invokeMain
371 setPermissions filename (emptyPermissions { readable = True
380 setPermissions filename (emptyPermissions { readable = True
372 , executable = target == Node
381 , executable = target == Node
373 , writable = True
382 , writable = True
385+ includeLibs :: [String] -> String
387+ concatMap (\lib -> "var " ++ lib ++ " = require(\"" ++ lib ++"\");\n")
376 getIncludes :: [FilePath] -> IO [String]
389 getIncludes :: [FilePath] -> IO [String]
377 getIncludes = mapM readFile
390 getIncludes = mapM readFile