From 2f77d20394274e89da509716b4cf78fba9724e46 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sun, 26 Feb 2017 20:17:23 -0400 Subject: - Added try-catch procedure to JS backend. --- luxc/src/lux/compiler/js/proc/common.clj | 8 +++++++- luxc/src/lux/compiler/js/rt.clj | 14 +++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'luxc') 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 -- cgit v1.2.3