Skip to content

Commit

Permalink
compiler: def, failing test for (set! a-root 1) in cljs
Browse files Browse the repository at this point in the history
  • Loading branch information
xificurC committed Feb 27, 2024
1 parent adb4f58 commit 32c7c6f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
8 changes: 6 additions & 2 deletions src/hyperfiddle/electric/impl/lang_de2.clj
Original file line number Diff line number Diff line change
Expand Up @@ -557,8 +557,12 @@
(def) (let [[_ sym v] form]
(case (->env-type env)
:clj (recur `((fn* ([x#] (def ~sym x#))) ~v) pe env ts)
:cljs (do (def-sym-in-cljs-compiler! sym (get-ns env))
(recur `(set! ~sym ~v) pe env ts))))
:cljs (let [e (->id), ce (->id)]
(def-sym-in-cljs-compiler! sym (get-ns env))
(recur v e env
(-> ts (ts/add {:db/id e, ::parent pe, ::type ::ap})
(ts/add {:db/id ce, ::parent e, ::type ::pure})
(ts/add {:db/id (->id), ::parent ce, ::type ::literal, ::v `(fn [v#] (set! ~sym v#))}))))))
(set!) (let [[_ target v] form] (recur `((fn* ([v#] (set! ~target v#))) ~v) pe env ts))
(::ctor) (let [e (->id), ce (->id)]
(recur (list ::site nil (second form))
Expand Down
17 changes: 12 additions & 5 deletions test/hyperfiddle/electric_de_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@
(with ((l/single {} (tap (loop [x 1] (if (odd? x) (recur (dec x)) x)))) tap tap)
% := 0))

;; TODO cljs def expands to set! which expands to cc/fn which passes DEFD as argument and breaks
#_(tests "def"
(with ((l/single {::lang/print-source true} (def DEFD 1)) tap tap))
(tests "def"
(with ((l/single {} (def DEFD 1)) tap tap))
DEFD := 1)

;;; MAIN ELECTRIC TEST SUITE
Expand Down Expand Up @@ -1400,6 +1399,15 @@
(set! (.-x o) ($ (e/fn [] 0)))))) tap tap)
% := 0)))

;; TODO `set!` expands to cc/fn which tries to convey `a-root`
;; note: transitively the same applies to `(cc/fn [] (set! a-root 2))`
#?(:cljs
(skip "set! to alter root binding"
(def a-root 1)
(with ((l/single {} (set! a-root 2)) tap tap))
(instance? Cancelled %) := true
a-root := 2))

;; TODO e/fn arity check, try/catch
(skip "e/fn arity check"
(with ((l/single {} (try (new (e/fn [x y z] (throw (ex-info "nope" {}))) 100 200 300 400)
Expand Down Expand Up @@ -1455,8 +1463,7 @@
(reset! !n 20)
% := 2432902008176640000)))

;; TODO cljs def expands to set! which expands to cc/fn which passes --foo as argument and breaks
#_(tests "clojure def inside electric code"
(tests "clojure def inside electric code"
(def !x (atom 0))
(with ((l/single {} (def --foo (tap (e/watch !x)))) tap tap)
% := 0, --foo := 0
Expand Down

0 comments on commit 32c7c6f

Please sign in to comment.