Skip to content

Commit

Permalink
compiler: fix free index lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
xificurC committed Jan 26, 2024
1 parent 35b7559 commit 10f7768
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/hyperfiddle/electric/impl/lang_de2.clj
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@
::let-ref
(if-some [node-e (first (ts/find ts ::ctor-node ctor-e, ::ctor-ref (::ref nd)))]
(list `r/node 'frame (::node-idx (get (:eav ts) node-e)))
(if-some [free-e (first (ts/find ts ::ctor-free ctor-e))]
(if-some [free-e (first (ts/find ts ::ctor-free ctor-e, ::closed-ref (::ref nd)))]
(list `r/free 'frame (::free-idx (ts/->node ts free-e)))
(recur ts ctor-e (get-ret-e ts (->let-val-e ts (::ref nd))))))
#_else (throw (ex-info (str "cannot gen on " (pr-str (::type nd))) (or nd {}))))))
Expand Down
26 changes: 22 additions & 4 deletions test/hyperfiddle/electric/impl/compiler_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -389,19 +389,37 @@
(r/pure 3)))
(r/cdef 0 [] [] nil
(fn [~'frame]
(r/pure 2)))]))
(r/pure 2)))])
(match (l/test-compile ::Main (let [fizz "fizz", buzz "buzz"]
(e/ctor (str fizz buzz))))
`[(r/cdef 0 [nil nil] [] nil
(fn [~'frame]
(r/define-node ~'frame 0 (r/pure "fizz"))
(r/define-node ~'frame 1 (r/pure "buzz"))
(r/pure (clojure.core/doto (r/make-ctor ~'frame ::Main 1)
(r/define-free 0 (r/node ~'frame 0))
(r/define-free 1 (r/node ~'frame 1))))))
(r/cdef 2 [] [] nil
(fn [~'frame]
(r/ap (r/lookup ~'frame :clojure.core/str (r/pure clojure.core/str))
(r/free ~'frame 0)
(r/free ~'frame 1))))])
)

(tests "test-lookup"
(match (l/test-compile ::Main (::lang/lookup 0))
`[(r/cdef 0 [] [] nil
(fn [~'frame]
(r/lookup ~'frame 0)))]))

(defn should-work-in-cljs [])
;; (defn should-work-in-cljs [])

(tests "test-unsited-cljs-fn"
(match (l/test-compile ::Main (should-work-in-cljs))))
;; (tests "test-unsited-cljs-fn"
;; (match (l/test-compile ::Main (should-work-in-cljs))))

(comment
(l/test-compile ::Main (let [fizz "fizz", buzz "buzz"]
(e/ctor (str fizz buzz)))))
;; TODO test site is cleared on ctor boundary

;; TODO rewrite or remove
Expand Down
16 changes: 9 additions & 7 deletions test/hyperfiddle/electric/impl/runtime_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,19 @@
% := {:degree 3, :permutation {}, :grow 0, :shrink 0, :change {1 :BAR}, :freeze #{}})

(tests
(def !n (atom 10))
(def !n (atom 20))
(def !fizz (atom "Fizz"))
(def !buzz (atom "Buzz"))
(on-diff! rcf/tap (root-frame (e/server (let [fizz (e/watch !fizz) ; i/fixed + m/watch + e/join
buzz (e/watch !buzz)
is (e/diff-by identity (range 1 (inc (e/watch !n)))) ; variable in time and space
results (e/cursor [i is]
(cond
(zero? (mod i (* 3 5))) (str fizz buzz)
(zero? (mod i 3)) fizz
(zero? (mod i 5)) buzz
:else i))]
(println results)))))
[i (cond
(zero? (mod i (* 3 5))) (str fizz buzz)
(zero? (mod i 3)) fizz
(zero? (mod i 5)) buzz
:else i)])]
(prn results)))))
% := {}
(swap! !n inc)
% := {})

0 comments on commit 10f7768

Please sign in to comment.