|
63 | 63 |
|
64 | 64 | (defn macroexpand-1 [ctx expr] |
65 | 65 | (let [ctx (assoc ctx :sci.impl/macroexpanding true) |
66 | | - _ (set! store/*ctx* ctx) |
67 | 66 | 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)))) |
95 | 95 |
|
96 | 96 | (defn macroexpand |
97 | 97 | [ctx form] |
|
0 commit comments