Skip to content

Commit a476f5a

Browse files
committed
ctx
1 parent 1a3e71b commit a476f5a

File tree

1 file changed

+28
-28
lines changed

1 file changed

+28
-28
lines changed

src/sci/impl/analyzer.cljc

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -63,35 +63,35 @@
6363

6464
(defn macroexpand-1 [ctx expr]
6565
(let [ctx (assoc ctx :sci.impl/macroexpanding true)
66-
_ (set! store/*ctx* ctx)
6766
original-expr expr]
68-
(if (seq? expr)
69-
(let [op (first expr)]
70-
(if (symbol? op)
71-
(cond (get special-syms op) expr
72-
(contains? #{'for} op) (analyze ctx expr)
73-
(= 'clojure.core/defrecord op) expr
74-
:else
75-
(let [f (try (resolve/resolve-symbol ctx op true)
76-
(catch #?(:clj Exception :cljs :default)
77-
_ ::unresolved))]
78-
(if (kw-identical? ::unresolved f)
79-
expr
80-
(let [var? (utils/var? f)
81-
macro-var? (and var?
82-
(vars/isMacro f))
83-
needs-ctx? (and var?
84-
(vars/needs-ctx? f))
85-
f (if macro-var? @f f)]
86-
(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)))
90-
(if (str/starts-with? (str op) ".")
91-
(list* '. (second expr) (symbol (subs (str op) 1)) (nnext expr))
92-
expr))))))
93-
expr))
94-
expr)))
67+
(store/with-ctx ctx
68+
(if (seq? expr)
69+
(let [op (first expr)]
70+
(if (symbol? op)
71+
(cond (get special-syms op) expr
72+
(contains? #{'for} op) (analyze ctx expr)
73+
(= 'clojure.core/defrecord op) expr
74+
:else
75+
(let [f (try (resolve/resolve-symbol ctx op true)
76+
(catch #?(:clj Exception :cljs :default)
77+
_ ::unresolved))]
78+
(if (kw-identical? ::unresolved f)
79+
expr
80+
(let [var? (utils/var? f)
81+
macro-var? (and var?
82+
(vars/isMacro f))
83+
needs-ctx? (and var?
84+
(vars/needs-ctx? f))
85+
f (if macro-var? @f f)]
86+
(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)))
90+
(if (str/starts-with? (str op) ".")
91+
(list* '. (second expr) (symbol (subs (str op) 1)) (nnext expr))
92+
expr))))))
93+
expr))
94+
expr))))
9595

9696
(defn macroexpand
9797
[ctx form]

0 commit comments

Comments
 (0)