Skip to content

Commit dbaa3c2

Browse files
committed
yooo
1 parent 468dbd0 commit dbaa3c2

5 files changed

Lines changed: 80 additions & 26 deletions

File tree

src/sci/impl/copy_vars.cljc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[sci.impl.cljs]
55
[sci.impl.macros :as macros]
66
[sci.impl.utils :as utils :refer [clojure-core-ns]]
7-
[sci.lang])
7+
[sci.lang :as lang])
88
#?(:cljs (:require-macros [sci.impl.copy-vars :refer [copy-var copy-core-var macrofy]])))
99

1010
#?(:clj (set! *warn-on-reflection* true))
@@ -106,14 +106,14 @@
106106
;; NOTE: emit as little code as possible, so our JS bundle is as small as possible
107107
(if macro
108108
(macros/? :clj
109-
#?(:clj `(sci.lang.Var. ~(deref the-var) ~nm ~varm false ~ctx nil)
110-
:cljs `(sci.lang.Var. ~init ~nm ~varm false ~ctx nil))
111-
:cljs `(sci.lang.Var. ~init ~nm ~varm false ~ctx nil))
109+
#?(:clj `(utils/->Var ~(deref the-var) ~nm ~varm false ~ctx nil)
110+
:cljs `(utils/->Var ~init ~nm ~varm false ~ctx nil))
111+
:cljs `(utils/->Var ~init ~nm ~varm false ~ctx nil))
112112
(if elide-vars
113113
(if (or dyn ctx)
114-
`(sci.lang.Var. ~init ~nm ~varm false ~ctx nil)
114+
`(utils/->Var ~init ~nm ~varm false ~ctx nil)
115115
sym)
116-
`(sci.lang.Var. ~init ~nm ~varm false ~ctx nil)))))
116+
`(utils/->Var ~init ~nm ~varm false ~ctx nil)))))
117117
(defmacro copy-core-var
118118
[sym]
119119
`(copy-var ~sym clojure-core-ns {:copy-meta-from ~(core-sym sym)}))

src/sci/impl/namespaces.cljc

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,19 +1931,19 @@
19311931
(def clojure-edn-namespace (sci.lang/->Namespace 'clojure.edn nil))
19321932

19331933
(def macroexpand-all
1934-
(sci.lang.Var. (fn [ctx form]
1935-
(clojure.walk/prewalk
1936-
(fn [x]
1937-
(if (seq? x)
1938-
(@sci.impl.utils/macroexpand* ctx x) x))
1939-
form))
1940-
'macroexpand-all
1941-
{:ns clojure-walk-namespace
1942-
:name 'macroexpand-all
1943-
:doc "Recursively performs all possible macroexpansions in form."}
1944-
false
1945-
true
1946-
nil))
1934+
(utils/->Var (fn [ctx form]
1935+
(clojure.walk/prewalk
1936+
(fn [x]
1937+
(if (seq? x)
1938+
(@sci.impl.utils/macroexpand* ctx x) x))
1939+
form))
1940+
'macroexpand-all
1941+
{:ns clojure-walk-namespace
1942+
:name 'macroexpand-all
1943+
:doc "Recursively performs all possible macroexpansions in form."}
1944+
false
1945+
true
1946+
nil))
19471947

19481948
(def clojure-walk-ns
19491949
{:obj clojure-walk-namespace
@@ -1963,7 +1963,7 @@
19631963
)
19641964

19651965
(macros/usetime
1966-
1966+
19671967
;; #_#?(:clj (alter-var-root #'clojure-core assoc
19681968
;; 'locking (macrofy 'locking locking*)
19691969
;; '-locking-impl (copy-var -locking-impl clojure-core-ns))

src/sci/impl/utils.cljc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(ns sci.impl.utils
22
{:no-doc true}
3-
(:refer-clojure :exclude [eval demunge var?])
3+
(:refer-clojure :exclude [eval demunge var? ->Var])
44
(:require [clojure.string :as str]
55
[sci.impl.macros :as macros]
66
[sci.impl.types :as t]
@@ -276,13 +276,17 @@
276276
(let [curr-ns @current-ns]
277277
(if (symbol? curr-ns) curr-ns (t/getName curr-ns))))
278278

279+
(defn ->Var [root sym meta thread-bound needs-ctx watches]
280+
(let [root (if needs-ctx (vars/->CtxFn root) root)]
281+
(sci.lang.Var. root sym meta thread-bound needs-ctx watches)))
282+
279283
(defn new-var
280284
"Returns a new sci var."
281285
([name] (doto (new-var name nil nil false)
282286
(vars/unbind)))
283287
([name init-val] (new-var name init-val (meta name) false))
284288
([name init-val meta] (new-var name init-val meta false))
285-
([name init-val meta ctx?] (sci.lang.Var. init-val name (assoc meta :name (unqualify-symbol name)) false ctx? nil)))
289+
([name init-val meta ctx?] (->Var init-val name (assoc meta :name (unqualify-symbol name)) false ctx? nil)))
286290

287291
(defn var? [x]
288292
(instance? sci.lang.Var x))

src/sci/impl/vars.cljc

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@
7474
(dynamic? [this]))
7575

7676
(defprotocol CtxVar
77-
(needs-ctx? [this])
78-
(needs-ctx! [this]))
77+
(needs-ctx? [this]))
7978

8079
(extend-type #?(:clj Object :cljs default)
8180
DynVar
@@ -206,6 +205,57 @@
206205
(defn built-in-var? [var-meta]
207206
(:sci/built-in var-meta))
208207

208+
(deftype CtxFn [f]
209+
;; #?(:cljs Fn) ;; In the real CLJS this is there... why?
210+
#?(:clj clojure.lang.IFn :cljs IFn)
211+
(#?(:clj invoke :cljs -invoke) [_this]
212+
(f))
213+
(#?(:clj invoke :cljs -invoke) [_this a]
214+
(f a))
215+
(#?(:clj invoke :cljs -invoke) [_this a b]
216+
(f a b))
217+
(#?(:clj invoke :cljs -invoke) [_this a b c]
218+
(f a b c))
219+
(#?(:clj invoke :cljs -invoke) [_this a b c d]
220+
(f a b c d))
221+
(#?(:clj invoke :cljs -invoke) [_this a b c d e]
222+
(f a b c d e))
223+
(#?(:clj invoke :cljs -invoke) [_this a b c d e f]
224+
(f a b c d e f))
225+
(#?(:clj invoke :cljs -invoke) [_this a b c d e f g]
226+
(f a b c d e f g))
227+
(#?(:clj invoke :cljs -invoke) [_this a b c d e f g h]
228+
(f a b c d e f g h))
229+
(#?(:clj invoke :cljs -invoke) [_this a b c d e f g h i]
230+
(f a b c d e f g h i))
231+
(#?(:clj invoke :cljs -invoke) [_this a b c d e f g h i j]
232+
(f a b c d e f g h i j))
233+
(#?(:clj invoke :cljs -invoke) [_this a b c d e f g h i j k]
234+
(f a b c d e f g h i j k))
235+
(#?(:clj invoke :cljs -invoke) [_this a b c d e f g h i j k l]
236+
(f a b c d e f g h i j k l))
237+
(#?(:clj invoke :cljs -invoke) [_this a b c d e f g h i j k l m]
238+
(f a b c d e f g h i j k l m))
239+
(#?(:clj invoke :cljs -invoke) [_this a b c d e f g h i j k l m n]
240+
(f a b c d e f g h i j k l m n))
241+
(#?(:clj invoke :cljs -invoke) [_this a b c d e f g h i j k l m n o]
242+
(f a b c d e f g h i j k l m n o))
243+
(#?(:clj invoke :cljs -invoke) [_this a b c d e f g h i j k l m n o p]
244+
(f a b c d e f g h i j k l m n o p))
245+
(#?(:clj invoke :cljs -invoke) [_this a b c d e f g h i j k l m n o p q]
246+
(f a b c d e f g h i j k l m n o p q))
247+
(#?(:clj invoke :cljs -invoke) [_this a b c d e f g h i j k l m n o p q r]
248+
(f a b c d e f g h i j k l m n o p q r))
249+
(#?(:clj invoke :cljs -invoke) [_this a b c d e f g h i j k l m n o p q r s]
250+
(f a b c d e f g h i j k l m n o p q r s))
251+
(#?(:clj invoke :cljs -invoke) [_this a b c d e f g h i j k l m n o p q r s t]
252+
(f a b c d e f g h i j k l m n o p q r s t))
253+
(#?(:clj invoke :cljs -invoke) [_this a b c d e f g h i j k l m n o p q r s t rest]
254+
(apply f a b c d e f g h i j k l m n o p q r s t rest))
255+
#?(:clj
256+
(applyTo [_this args]
257+
(apply f args))))
258+
209259
(macros/deftime
210260
(defmacro with-writeable-var
211261
[the-var var-meta & body]

src/sci/lang.cljc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,8 +251,8 @@
251251
(applyTo [this args]
252252
(apply @this args)))
253253
vars/CtxVar
254-
(needs-ctx? [_] needs-ctx)
255-
(needs-ctx! [_] (set! needs-ctx true)))
254+
(needs-ctx? [_] (when needs-ctx
255+
(instance? sci.impl.vars.CtxFn root))))
256256

257257
#?(:clj
258258
;; Use public interface for print-method so it can be overriden in bb itself

0 commit comments

Comments
 (0)