Skip to content

Commit a10814b

Browse files
committed
remove cruft
1 parent 47c733e commit a10814b

File tree

4 files changed

+39
-94
lines changed

4 files changed

+39
-94
lines changed

src/sci/impl/analyzer.cljc

Lines changed: 30 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
(:require-macros
3030
[sci.impl.analyzer :refer [gen-return-recur
3131
gen-return-binding-call
32-
gen-return-needs-ctx-call
3332
gen-return-call
3433
with-top-level-loc]])))
3534

@@ -80,13 +79,9 @@
8079
(let [var? (utils/var? f)
8180
macro-var? (and var?
8281
(vars/isMacro f))
83-
needs-ctx? (and var?
84-
(vars/needs-ctx? f))
8582
f (if macro-var? @f f)]
8683
(if (or macro-var? (macro? f))
87-
(if needs-ctx?
88-
(apply f original-expr (:bindings ctx) ctx (rest expr))
89-
(apply f original-expr (:bindings ctx) (rest expr)))
84+
(apply f original-expr (:bindings ctx) (rest expr))
9085
(if (str/starts-with? (str op) ".")
9186
(list* '. (second expr) (symbol (subs (str op) 1)) (nnext expr))
9287
expr))))))
@@ -1355,38 +1350,6 @@
13551350
(declare return-binding-call) ;; for clj-kondo
13561351
(gen-return-binding-call)
13571352

1358-
(macros/deftime
1359-
(defmacro gen-return-needs-ctx-call
1360-
[]
1361-
(let [let-bindings (map (fn [i]
1362-
[i (vec (mapcat (fn [j]
1363-
[(symbol (str "arg" j))
1364-
`(nth ~'analyzed-children ~j)])
1365-
(range i)))])
1366-
(range 20))]
1367-
`(defn ~'return-needs-ctx-call
1368-
~'[_ctx expr f analyzed-children]
1369-
(let [~'stack (assoc (meta ~'expr)
1370-
:file @utils/current-file
1371-
:ns @utils/current-ns)]
1372-
(case (count ~'analyzed-children)
1373-
~@(concat
1374-
(mapcat (fn [[i binds]]
1375-
[i `(let ~binds
1376-
(sci.impl.types/->Node
1377-
(~'f ~'ctx
1378-
~@(map (fn [j]
1379-
`(t/eval ~(symbol (str "arg" j)) ~'ctx ~'bindings))
1380-
(range i)))
1381-
~'stack))])
1382-
let-bindings)
1383-
`[(sci.impl.types/->Node
1384-
(eval/fn-call ~'ctx ~'bindings ~'f (cons ~'ctx ~'analyzed-children))
1385-
~'stack)])))))))
1386-
1387-
(declare return-needs-ctx-call) ;; for clj-kondo
1388-
(gen-return-needs-ctx-call)
1389-
13901353
;; NOTE: there is a small perf win (about 3%) when checking if all
13911354
;; analyzed-children are EvalFn and then using those fns directly. See
13921355
;; inline-evals branch.
@@ -1678,33 +1641,27 @@
16781641
:file @utils/current-file
16791642
:sci.impl/f-meta f-meta)
16801643
nil)))
1681-
(let [needs-ctx? (and (utils/var? f)
1682-
(vars/needs-ctx? f))]
1683-
(if needs-ctx?
1684-
(return-needs-ctx-call ctx
1685-
expr
1686-
f (analyze-children ctx (rest expr)))
1687-
(let [self-ref? (:self-ref? ctx)]
1688-
(if (and self-ref? (self-ref? f))
1689-
(let [children (analyze-children ctx (rest expr))]
1690-
(return-call ctx
1691-
expr
1692-
f children (assoc m
1693-
:ns @utils/current-ns
1694-
:file @utils/current-file
1695-
:sci.impl/f-meta f-meta)
1696-
(fn [_ bindings _]
1697-
(deref
1698-
(eval/resolve-symbol bindings fsym)))))
1699-
(let [children (analyze-children ctx (rest expr))]
1700-
(return-call ctx
1701-
expr
1702-
f children (assoc m
1703-
:ns @utils/current-ns
1704-
:file @utils/current-file
1705-
:sci.impl/f-meta f-meta)
1706-
#?(:cljs (when (utils/var? f) (fn [_ _ v]
1707-
(deref v))) :clj nil))))))))))
1644+
(let [self-ref? (:self-ref? ctx)]
1645+
(if (and self-ref? (self-ref? f))
1646+
(let [children (analyze-children ctx (rest expr))]
1647+
(return-call ctx
1648+
expr
1649+
f children (assoc m
1650+
:ns @utils/current-ns
1651+
:file @utils/current-file
1652+
:sci.impl/f-meta f-meta)
1653+
(fn [_ bindings _]
1654+
(deref
1655+
(eval/resolve-symbol bindings fsym)))))
1656+
(let [children (analyze-children ctx (rest expr))]
1657+
(return-call ctx
1658+
expr
1659+
f children (assoc m
1660+
:ns @utils/current-ns
1661+
:file @utils/current-file
1662+
:sci.impl/f-meta f-meta)
1663+
#?(:cljs (when (utils/var? f) (fn [_ _ v]
1664+
(deref v))) :clj nil))))))))
17081665
(catch #?(:clj Exception :cljs js/Error) e
17091666
;; we pass a ctx-fn because the rethrow function calls
17101667
;; stack on it, the only interesting bit it the map
@@ -1868,20 +1825,14 @@
18681825
mv (meta v)]
18691826
(cond (constant? v) (->constant v)
18701827
(utils/var? v)
1871-
(if (and (vars/needs-ctx? v)
1872-
(:sci/built-in mv))
1873-
;; this is for built-in vars like require that
1874-
;; are used within a higher order function, not
1875-
;; in call position
1876-
(partial v ctx)
1877-
(if (:const mv)
1878-
@v
1879-
(if (vars/isMacro v)
1880-
(throw (new #?(:clj IllegalStateException :cljs js/Error)
1881-
(str "Can't take value of a macro: " v "")))
1882-
(sci.impl.types/->Node
1883-
(faster/deref-1 v)
1884-
nil))))
1828+
(if (:const mv)
1829+
@v
1830+
(if (vars/isMacro v)
1831+
(throw (new #?(:clj IllegalStateException :cljs js/Error)
1832+
(str "Can't take value of a macro: " v "")))
1833+
(sci.impl.types/->Node
1834+
(faster/deref-1 v)
1835+
nil)))
18851836
#?@(:clj
18861837
[(:sci.impl.analyzer/interop mv)
18871838
(analyze-interop ctx expr v)])

src/sci/impl/namespaces.cljc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,18 +1979,19 @@
19791979
(def clojure-edn-namespace (sci.lang/->Namespace 'clojure.edn nil))
19801980

19811981
(def macroexpand-all
1982-
(sci.lang.Var. (fn [ctx form]
1983-
(clojure.walk/prewalk
1984-
(fn [x]
1985-
(if (seq? x)
1986-
(@sci.impl.utils/macroexpand* ctx x) x))
1987-
form))
1982+
(sci.lang.Var. (fn [form]
1983+
(let [ctx (store/get-ctx)]
1984+
(clojure.walk/prewalk
1985+
(fn [x]
1986+
(if (seq? x)
1987+
(@sci.impl.utils/macroexpand* ctx x) x))
1988+
form)))
19881989
'macroexpand-all
19891990
{:ns clojure-walk-namespace
19901991
:name 'macroexpand-all
19911992
:doc "Recursively performs all possible macroexpansions in form."}
19921993
false
1993-
true
1994+
nil
19941995
nil))
19951996

19961997
(def clojure-walk-ns

src/sci/impl/vars.cljc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,6 @@
7373
(defprotocol DynVar
7474
(dynamic? [this]))
7575

76-
(defprotocol CtxVar
77-
(needs-ctx? [this])
78-
(needs-ctx! [this]))
79-
8076
(extend-type #?(:clj Object :cljs default)
8177
DynVar
8278
(dynamic? [_] false))

src/sci/lang.cljc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,10 +249,7 @@
249249
(apply @this a b c d e f g h i j k l m n o p q r s t rest))
250250
#?(:clj
251251
(applyTo [this args]
252-
(apply @this args)))
253-
vars/CtxVar
254-
(needs-ctx? [_] needs-ctx)
255-
(needs-ctx! [_] (set! needs-ctx true)))
252+
(apply @this args))))
256253

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

0 commit comments

Comments
 (0)