on master help sign in
moved js code from AST.hs to Runtime-common.js
c76582fRui Barreiro
idris.cabal+1
@@ -48,6 +48,7 @@ Tested-With: GHC == 7.6.3, GHC == 7.8.4, GHC == 7.10.3, GHC == 8.0.1
48
48
49Data-files: idrisdoc/styles.css
49Data-files: idrisdoc/styles.css
50 jsrts/jsbn/jsbn.js
50 jsrts/jsbn/jsbn.js
51+ jsrts/Runtime-common.js
51 jsrts/jsbn/LICENSE
52 jsrts/jsbn/LICENSE
52 rts/arduino/idris_main.c
53 rts/arduino/idris_main.c
53 rts/idris_bitstring.c
54 rts/idris_bitstring.c
jsrts/Runtime-common.jsnew file+15
@@ -0,0 +1,15 @@
1+
2+var js_idris_throw2 = function (x){
3+ throw x;
4+}
5+
6+var js_idris_force = function (x){
7+ if(x === undefined || x.js_idris_lazy_calc === undefined){
8+ return x
9+ }else{
10+ if(x.js_idris_lazy_val === undefined){
11+ x.js_idris_lazy_val = x.js_idris_lazy_calc()
12+ }
13+ return x.js_idris_lazy_val
14+ }
15+}
src/IRTS/JavaScript/AST.hs−20
@@ -9,7 +9,6 @@ Maintainer : The Idris Community.
9
9
10module IRTS.JavaScript.AST( JsAST(..)
10module IRTS.JavaScript.AST( JsAST(..)
11 , jsAst2Text
11 , jsAst2Text
12− , jsAuxDefs
13 ) where
12 ) where
14
13
15import Data.Char
14import Data.Char
@@ -181,25 +180,6 @@ case2Text (x,y) =
181 , indent $ T.concat [ jsAst2Text y, ";\nbreak;\n"]
180 , indent $ T.concat [ jsAst2Text y, ";\nbreak;\n"]
182 ]
181 ]
183
182
184−throw2 = T.concat [ "var js_idris_throw2 = function (x){\n"
185− , " throw x;\n"
186− , "}\n\n"
187− ]
188−
189−force = T.concat [ "var js_idris_force = function (x){\n"
190− , " if(x === undefined || x.js_idris_lazy_calc === undefined){\n"
191− , " return x\n"
192− , " }else{\n"
193− , " if(x.js_idris_lazy_val === undefined){\n"
194− , " x.js_idris_lazy_val = x.js_idris_lazy_calc()\n"
195− , " }"
196− , " return x.js_idris_lazy_val"
197− , "}"
198− , "}\n\n"
199− ]
200−
201−jsAuxDefs = T.concat [throw2, force]
202−
203default2Text :: Maybe JsAST -> Text
183default2Text :: Maybe JsAST -> Text
204default2Text Nothing = ""
184default2Text Nothing = ""
205default2Text (Just z) =
185default2Text (Just z) =
src/IRTS/JavaScript/Codegen.hs+2−1
@@ -98,6 +98,7 @@ codegenJs conf ci =
98 then TIO.readFile $ path </> "jsbn/jsbn.js"
98 then TIO.readFile $ path </> "jsbn/jsbn.js"
99 else return ""
99 else return ""
100
100
101+ runtimeCommon <- TIO.readFile $ path </> "Runtime-common.js"
101
102
102 includes <- getIncludes $ includes ci
103 includes <- getIncludes $ includes ci
103 TIO.writeFile (outputFile ci) $ T.concat [ header conf
104 TIO.writeFile (outputFile ci) $ T.concat [ header conf
@@ -107,7 +108,7 @@ codegenJs conf ci =
107 , initialization conf stats
108 , initialization conf stats
108 , doPartials (partialApplications stats)
109 , doPartials (partialApplications stats)
109 , includes, "\n"
110 , includes, "\n"
110− , jsAuxDefs, "\n"
111+ , runtimeCommon, "\n"
111 , out, "\n"
112 , out, "\n"
112 , "\n"
113 , "\n"
113 , jsName (sMN 0 "runMain"), "();\n\n"
114 , jsName (sMN 0 "runMain"), "();\n\n"