diff options
author | Eduardo Julian | 2017-02-26 20:17:23 -0400 |
---|---|---|
committer | Eduardo Julian | 2017-02-26 20:17:23 -0400 |
commit | 2f77d20394274e89da509716b4cf78fba9724e46 (patch) | |
tree | 323f1da5f3c7702c2498a35319c2cd99796b6669 /luxc | |
parent | 79c10caf4c7e370dc53c4c60c57cc16ccec48773 (diff) |
- Added try-catch procedure to JS backend.
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 |