test node019 runs

This commit is contained in:
Rui Barreiro 2020-06-22 20:57:25 +01:00
parent ca0c8f9d42
commit 7c7f7efe04
3 changed files with 12 additions and 9 deletions

View File

@ -85,8 +85,8 @@ jsName (Resolved i) = "fn__" ++ show i
jsCrashExp : {auto c : Ref ESs ESSt} -> String -> Core String
jsCrashExp message =
do
n <- addConstToPreamble "crashExp" "x=>{throw new Error(x)}"
pure $ n ++ "("++ jsString message ++ ")"
n <- addConstToPreamble "crashExp" "x=>{throw new IdrisError(x)}"
pure $ n ++ "("++ message ++ ")"
jsIntegerOfString : {auto c : Ref ESs ESSt} -> String -> Core String
jsIntegerOfString x =
@ -322,17 +322,20 @@ mutual
static_preamble : List String
static_preamble =
[ "function __prim_js2idris_array(x){if(x.length ===0){return {h:0}}else{return {h:1,a1:x[0],a2: __prim_js2idris_array(x.slice(1))}}}"
[ "class IdrisError extends Error { }"
, "function __prim_idris2js_FArgList(x){if(x.h === 0){return []}else{return x.a2.concat(__prim_idris2js_FArgList(x.a3))}}"
, "function __prim_js2idris_array(x){if(x.length ===0){return {h:0}}else{return {h:1,a1:x[0],a2: __prim_js2idris_array(x.slice(1))}}}"
]
export
compileToES : Ref Ctxt Defs -> ClosedTerm -> Core String
compileToES c tm =
do
statements <- compileToImperative c tm
(impDefs, impMain) <- compileToImperative c tm
s <- newRef ESs (MkESSt empty)
es_statements <- imperative2es 0 statements
defs <- imperative2es 0 impDefs
main_ <- imperative2es 0 impMain
let main = "try{" ++ main_ ++ "}catch(e){if(e instanceof IdrisError){console.log('ERROR: ' + e.message)}else{throw e} }"
st <- get ESs
let pre = showSep "\n" $ static_preamble ++ (SortedMap.values $ preamble st)
pure $ pre ++ "\n\n" ++ es_statements -- ++ "\n\n\n/*" ++ show statements ++ "*/"
pure $ pre ++ "\n\n" ++ defs ++ main

View File

@ -300,7 +300,7 @@ getImp (n, fc, MkNmCon _ _ _) =
pure DoNothing
export
compileToImperative : Ref Ctxt Defs -> ClosedTerm -> Core ImperativeStatement
compileToImperative : Ref Ctxt Defs -> ClosedTerm -> Core (ImperativeStatement, ImperativeStatement)
compileToImperative c tm =
do
cdata <- getCompileData Cases tm
@ -309,4 +309,4 @@ compileToImperative c tm =
s <- newRef Imps (MkImpSt 0)
compdefs <- traverse getImp (defsUsedByNamedCExp ctm ndefs)
(s, main) <- impExp ctm
pure $ concat compdefs <+> s <+> EvalExpStatement main -- <+> CommentStatement (show ndefs)
pure $ (concat compdefs, s <+> EvalExpStatement main)

View File

@ -1,3 +1,3 @@
$1 --cg node --no-banner partial.idr < input
rm -rf build testout.txt
rm -rf build