|
309 | 309 | (str/join ", " (emit-args (expr-env env) expr))) |
310 | 310 | env)) |
311 | 311 |
|
| 312 | +(defn- make-get-expander [env] |
| 313 | + (when (:anf env) |
| 314 | + (fn [op env] |
| 315 | + (when (symbol? op) |
| 316 | + (let [ns-state (some-> (:ns-state env) deref) |
| 317 | + current (:current ns-state) |
| 318 | + current-ns-state (get ns-state current) |
| 319 | + excluded? (contains? current-ns-state op) |
| 320 | + head (strip-core-symbol op)] |
| 321 | + (when-not (or (:squint.compiler/skip-macro (meta op)) |
| 322 | + excluded?) |
| 323 | + (case head |
| 324 | + let (fn [form env & args] |
| 325 | + (let [result (core-let env (first args) (rest args))] |
| 326 | + ;; core-let returns (cljs.core/let* ...), normalize |
| 327 | + (if (and (seq? result) (= 'cljs.core/let* (first result))) |
| 328 | + (cons 'let* (rest result)) |
| 329 | + result))) |
| 330 | + fn (fn [form _env & sigs] |
| 331 | + (apply core-fn form {} sigs)) |
| 332 | + (or (built-in-macros head) |
| 333 | + (let [ns (namespace head) |
| 334 | + nm (name head) |
| 335 | + nms (symbol nm)] |
| 336 | + (if ns |
| 337 | + (let [nss (symbol ns)] |
| 338 | + (or |
| 339 | + (some-> env :macros (get nss) (get nms)) |
| 340 | + (let [resolved-ns (get-in current-ns-state [:aliases nss] nss)] |
| 341 | + (get-in ns-state [:macros resolved-ns nms])))) |
| 342 | + (let [refers (:refers current-ns-state)] |
| 343 | + (when-let [macro-ns (get refers nms)] |
| 344 | + (get-in ns-state [:macros macro-ns nms]))))))))))))) |
| 345 | + |
312 | 346 | (defn transpile-form |
313 | 347 | ([f] (transpile-form f nil)) |
314 | 348 | ([f env] |
|
331 | 365 | ::cc/keyword emit-keyword |
332 | 366 | ::cc/set emit-set |
333 | 367 | ::cc/special emit-special} |
334 | | - ::anf/get-expander |
335 | | - (fn [op env] |
336 | | - (when (symbol? op) |
337 | | - (let [ns-state (some-> (:ns-state env) deref) |
338 | | - current (:current ns-state) |
339 | | - current-ns-state (get ns-state current) |
340 | | - excluded? (contains? current-ns-state op) |
341 | | - head (strip-core-symbol op)] |
342 | | - (when-not (or (:squint.compiler/skip-macro (meta op)) |
343 | | - excluded?) |
344 | | - (case head |
345 | | - let (fn [form env & args] |
346 | | - (let [result (core-let env (first args) (rest args))] |
347 | | - ;; core-let returns (cljs.core/let* ...), normalize |
348 | | - (if (and (seq? result) (= 'cljs.core/let* (first result))) |
349 | | - (cons 'let* (rest result)) |
350 | | - result))) |
351 | | - fn (fn [form _env & sigs] |
352 | | - (apply core-fn form {} sigs)) |
353 | | - (or (built-in-macros head) |
354 | | - (let [ns (namespace head) |
355 | | - nm (name head) |
356 | | - nms (symbol nm)] |
357 | | - (if ns |
358 | | - (let [nss (symbol ns)] |
359 | | - (or |
360 | | - (some-> env :macros (get nss) (get nms)) |
361 | | - (let [resolved-ns (get-in current-ns-state [:aliases nss] nss)] |
362 | | - (get-in ns-state [:macros resolved-ns nms])))) |
363 | | - (let [refers (:refers current-ns-state)] |
364 | | - (when-let [macro-ns (get refers nms)] |
365 | | - (get-in ns-state [:macros macro-ns nms]))))))))))) |
366 | | - } env)))))) |
367 | | - |
| 368 | + ::anf/get-expander (make-get-expander env)} env)))))) |
368 | 369 | (def ^:dynamic *jsx* false) |
369 | 370 |
|
370 | 371 | (defn jsx [form] |
|
0 commit comments