Permalink
Browse files

CLJS-440: Distinct :loop op

  • Loading branch information...
1 parent 88b36c1 commit 26b2541cd66d3139eca354434a56137218b17d09 @brandonbloom brandonbloom committed with David Nolen Dec 12, 2012
Showing with 11 additions and 6 deletions.
  1. +1 −1 src/clj/cljs/analyzer.clj
  2. +10 −5 src/clj/cljs/compiler.clj
@@ -507,7 +507,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))}))
View
@@ -549,8 +549,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*
@@ -560,14 +560,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)))

0 comments on commit 26b2541

Please sign in to comment.