diff options
Diffstat (limited to '')
-rw-r--r-- | luxc/src/lux/compiler/js/proc/common.clj | 8 | ||||
-rw-r--r-- | luxc/src/lux/compiler/js/rt.clj | 14 |
2 files changed, 20 insertions, 2 deletions
diff --git a/luxc/src/lux/compiler/js/proc/common.clj b/luxc/src/lux/compiler/js/proc/common.clj index a1b26a45b..08bf94b04 100644 --- a/luxc/src/lux/compiler/js/proc/common.clj +++ b/luxc/src/lux/compiler/js/proc/common.clj @@ -49,6 +49,11 @@ =right (compile ?right)] (return (str "(" =left " === " =right ")")))) +(defn ^:private compile-lux-try [compile ?values special-args] + (|do [:let [(&/$Cons ?op (&/$Nil)) ?values] + =op (compile ?op)] + (return (str "LuxRT.runTry(" =op ")")))) + (defn ^:private compile-array-new [compile ?values special-args] (|do [:let [(&/$Cons ?length (&/$Nil)) ?values] =length (compile ?length)] @@ -496,7 +501,8 @@ (case category "lux" (case proc - "is" (compile-lux-is compile ?values special-args)) + "is" (compile-lux-is compile ?values special-args) + "try" (compile-lux-try compile ?values special-args)) "io" (case proc diff --git a/luxc/src/lux/compiler/js/rt.clj b/luxc/src/lux/compiler/js/rt.clj index 2416445e5..e6a50b373 100644 --- a/luxc/src/lux/compiler/js/rt.clj +++ b/luxc/src/lux/compiler/js/rt.clj @@ -1375,11 +1375,23 @@ "})") })) +(def ^:private lux-methods + {"runTry" (str "(function runTry(op) {" + (str "try {" + (str "return [1,'',op(null)];") + "}" + "catch(ex) {" + (str "return [0,null,ex.toString()];") + "}") + "})") + }) + (def LuxRT "LuxRT") (def compile-LuxRT (|do [_ (&&/run-js! "var console = { log: print };") - :let [rt-object (str "{" (->> (merge adt-methods + :let [rt-object (str "{" (->> (merge lux-methods + adt-methods i64-methods n64-methods text-methods |