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

javascript: use %include directive to include external javascript files

commita8ce1616cf4755001ad341bf1ef388022fccbfe2 authorEdwin Brady <edwin.brady@gmail.com> dateThu 20 Feb 2014, 22:44 (13 years ago) parent2afab0db357c64
3 files changed+15−7
CHANGELOG+3 src/IRTS/CodegenJavaScript.hs+10−5 src/IRTS/Compiler.hs+2−2
CHANGELOG+3
@@ -4,6 +4,9 @@ New in 0.9.12:
44* Proof search now works for metavariables in types, giving some interactive
55 type inference.
66* New 'Lazy' type, replacing laziness annotations.
7+* JavaScript and Node codegen now understand the %include directive
8+* Concept up 'null' is now understood in the JavaScript and Node codegen
9+* Lots of performance patches for generated JavaScript
710
811New in 0.9.11:
912--------------
src/IRTS/CodegenJavaScript.hs+10−5
@@ -1327,27 +1327,32 @@ getGlobalCons js = foldJS match (++) [] js
13271327 []
13281328
13291329
1330+getIncludes :: [FilePath] -> IO [String]
1331+getIncludes = mapM readFile
1332+
13301333codegenJavaScript
13311334 :: JSTarget
13321335 -> [(Name, SDecl)]
1336+ -> [FilePath]
13331337 -> FilePath
13341338 -> OutputType
13351339 -> IO ()
1336−codegenJavaScript target definitions filename outputType = do
1340+codegenJavaScript target definitions includes filename outputType = do
13371341 let (header, runtime) = case target of
13381342 Node ->
13391343 ("#!/usr/bin/env node\n", "-node")
13401344 JavaScript ->
13411345 ("", "-browser")
1346+ included <- getIncludes includes
13421347 path <- (++) <$> getDataDir <*> (pure "/jsrts/")
13431348 idrRuntime <- readFile $ path ++ "Runtime-common.js"
13441349 tgtRuntime <- readFile $ concat [path, "Runtime", runtime, ".js"]
13451350 jsbn <- readFile $ path ++ "jsbn/jsbn.js"
13461351 writeFile filename $ header ++ (
1347− intercalate "\n" $ [ jsbn
1348− , idrRuntime
1349− , tgtRuntime
1350− ] ++ functions
1352+ intercalate "\n" $ included ++ [ jsbn
1353+ , idrRuntime
1354+ , tgtRuntime
1355+ ] ++ functions
13511356 )
13521357
13531358 setPermissions filename (emptyPermissions { readable = True
src/IRTS/Compiler.hs+2−2
@@ -86,9 +86,9 @@ compile codegen f tm
8686 ViaJava ->
8787 codegenJava [] c f hdrs libs outty
8888 ViaJavaScript ->
89− codegenJavaScript JavaScript c f outty
89+ codegenJavaScript JavaScript c hdrs f outty
9090 ViaNode ->
91− codegenJavaScript Node c f outty
91+ codegenJavaScript Node c hdrs f outty
9292 ViaLLVM -> codegenLLVM c triple cpu optimize f outty
9393 Bytecode -> dumpBC c f
9494 Error e -> ierror e