Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix for ASYNC-3, cljs set! inside gos doesn't work
  • Loading branch information
halgari committed Aug 9, 2013
1 parent 89e036a commit 018d26a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/main/clojure/cljs/core/async/impl/ioc_macros.clj
Expand Up @@ -306,6 +306,16 @@
~STATE-IDX :finished)
nil))))

(defrecord Set! [field object val]
IInstruction
(reads-from [this] [object val])
(writes-to [this] [(:id this)])
(block-references [this] [])
IEmittableInstruction
(emit-instruction [this state-sym]
`[~(:id this)
(set! (~field ~object) ~val)]))

(defrecord CondBr [test then-block else-block]
IInstruction
(reads-from [this] [test])
Expand Down Expand Up @@ -396,6 +406,14 @@
ret-id (add-instruction (->Const ::value))]
ret-id)))

(defmethod sexpr-to-ssa 'set!
[[_ [field obj] val]]
(gen-plan
[obj-id (item-to-ssa obj)
val-id (item-to-ssa val)
ret-id (add-instruction (->Set! field obj-id val-id))]
ret-id))

(defmethod sexpr-to-ssa 'do
[[_ & body]]
(gen-plan
Expand Down
4 changes: 4 additions & 0 deletions src/test/cljs/cljs/core/async/runner_tests.cljs
Expand Up @@ -88,6 +88,10 @@
(pause x))
42)))

(testing "set!"
(let [x (js-obj)]
(runner (set! (.-foo x) "bar"))))

(testing "keywords as functions"
(is (= :bar
(runner (:foo (pause {:foo :bar}))))))
Expand Down

0 comments on commit 018d26a

Please sign in to comment.