From c49cef5287547b4e82e3ba14d82ab9fbb84ee821 Mon Sep 17 00:00:00 2001 From: Brandon Bloom Date: Tue, 11 Dec 2012 19:41:11 -0800 Subject: [PATCH] CLJS-1126: Distinct :let op --- src/clj/cljs/analyzer.clj | 2 +- src/clj/cljs/compiler.clj | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/clj/cljs/analyzer.clj b/src/clj/cljs/analyzer.clj index ec9cb4a..69805f6 100644 --- a/src/clj/cljs/analyzer.clj +++ b/src/clj/cljs/analyzer.clj @@ -497,7 +497,7 @@ is-loop (or *loop-lets* ()) *loop-lets* (cons {:params bes} *loop-lets*))] (analyze-block (assoc env :context (if (= :expr context) :return context)) exprs))] - {:env encl-env :op :let :loop is-loop + {:env encl-env :op (if is-loop :loop :let) :bindings bes :statements statements :ret ret :form form :children (into (vec (map :init bes)) (conj (vec statements) ret))})) diff --git a/src/clj/cljs/compiler.clj b/src/clj/cljs/compiler.clj index 978f3fe..a57f477 100644 --- a/src/clj/cljs/compiler.clj +++ b/src/clj/cljs/compiler.clj @@ -548,8 +548,8 @@ (emit-block subcontext statements ret) (when (and statements (= :expr context)) (emits "})()")))))) -(defmethod emit :let - [{:keys [bindings statements ret env loop]}] +(defn emit-let + [{:keys [bindings statements ret env]} is-loop] (let [context (:context env)] (when (= :expr context) (emits "(function (){")) (binding [*lexical-renames* (into *lexical-renames* @@ -559,14 +559,19 @@ bindings)))] (doseq [{:keys [init] :as binding} bindings] (emitln "var " (munge binding) " = " init ";")) - (when loop (emitln "while(true){")) + (when is-loop (emitln "while(true){")) (emit-block (if (= :expr context) :return context) statements ret) - (when loop + (when is-loop (emitln "break;") (emitln "}"))) - ;(emits "}") (when (= :expr context) (emits "})()")))) +(defmethod emit :let [ast] + (emit-let ast false)) + +(defmethod emit :loop [ast] + (emit-let ast true)) + (defmethod emit :recur [{:keys [frame exprs env]}] (let [temps (vec (take (count exprs) (repeatedly gensym))) -- 1.8.0