diff --git a/src/main/clojure/cljs/core/async/impl/ioc_macros.clj b/src/main/clojure/cljs/core/async/impl/ioc_macros.clj index 7bd63c27..e3ae7c35 100644 --- a/src/main/clojure/cljs/core/async/impl/ioc_macros.clj +++ b/src/main/clojure/cljs/core/async/impl/ioc_macros.clj @@ -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]) @@ -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 diff --git a/src/test/cljs/cljs/core/async/runner_tests.cljs b/src/test/cljs/cljs/core/async/runner_tests.cljs index 3dfd4738..7151b4a2 100644 --- a/src/test/cljs/cljs/core/async/runner_tests.cljs +++ b/src/test/cljs/cljs/core/async/runner_tests.cljs @@ -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}))))))