on master help sign in
moved js code from AST.hs to Runtime-common.js
commitc76582f2cd6230f974080e55f8da57793d9f7dcb authorRui Barreiro <rui.barreiro@gmail.com> dateThu 18 May 2017, 20:17 (9 years ago) parent1c908c3
4 files changed+18−21
idris.cabal+1 jsrts/Runtime-common.js+15 src/IRTS/JavaScript/AST.hs−20 src/IRTS/JavaScript/Codegen.hs+2−1
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
4848
4949Data-files: idrisdoc/styles.css
5050 jsrts/jsbn/jsbn.js
51+ jsrts/Runtime-common.js
5152 jsrts/jsbn/LICENSE
5253 rts/arduino/idris_main.c
5354 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.
99
1010module IRTS.JavaScript.AST( JsAST(..)
1111 , jsAst2Text
12− , jsAuxDefs
1312 ) where
1413
1514import Data.Char
@@ -181,25 +180,6 @@ case2Text (x,y) =
181180 , indent $ T.concat [ jsAst2Text y, ";\nbreak;\n"]
182181 ]
183182
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−
203183default2Text :: Maybe JsAST -> Text
204184default2Text Nothing = ""
205185default2Text (Just z) =
src/IRTS/JavaScript/Codegen.hs+2−1
@@ -98,6 +98,7 @@ codegenJs conf ci =
9898 then TIO.readFile $ path </> "jsbn/jsbn.js"
9999 else return ""
100100
101+ runtimeCommon <- TIO.readFile $ path </> "Runtime-common.js"
101102
102103 includes <- getIncludes $ includes ci
103104 TIO.writeFile (outputFile ci) $ T.concat [ header conf
@@ -107,7 +108,7 @@ codegenJs conf ci =
107108 , initialization conf stats
108109 , doPartials (partialApplications stats)
109110 , includes, "\n"
110− , jsAuxDefs, "\n"
111+ , runtimeCommon, "\n"
111112 , out, "\n"
112113 , "\n"
113114 , jsName (sMN 0 "runMain"), "();\n\n"