|
29 | 29 | (:require-macros |
30 | 30 | [sci.impl.analyzer :refer [gen-return-recur |
31 | 31 | gen-return-binding-call |
32 | | - gen-return-needs-ctx-call |
33 | 32 | gen-return-call |
34 | 33 | with-top-level-loc]]))) |
35 | 34 |
|
|
80 | 79 | (let [var? (utils/var? f) |
81 | 80 | macro-var? (and var? |
82 | 81 | (vars/isMacro f)) |
83 | | - needs-ctx? (and var? |
84 | | - (vars/needs-ctx? f)) |
85 | 82 | f (if macro-var? @f f)] |
86 | 83 | (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)) |
90 | 85 | (if (str/starts-with? (str op) ".") |
91 | 86 | (list* '. (second expr) (symbol (subs (str op) 1)) (nnext expr)) |
92 | 87 | expr)))))) |
|
1355 | 1350 | (declare return-binding-call) ;; for clj-kondo |
1356 | 1351 | (gen-return-binding-call) |
1357 | 1352 |
|
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 | | - |
1390 | 1353 | ;; NOTE: there is a small perf win (about 3%) when checking if all |
1391 | 1354 | ;; analyzed-children are EvalFn and then using those fns directly. See |
1392 | 1355 | ;; inline-evals branch. |
|
1678 | 1641 | :file @utils/current-file |
1679 | 1642 | :sci.impl/f-meta f-meta) |
1680 | 1643 | 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)))))))) |
1708 | 1665 | (catch #?(:clj Exception :cljs js/Error) e |
1709 | 1666 | ;; we pass a ctx-fn because the rethrow function calls |
1710 | 1667 | ;; stack on it, the only interesting bit it the map |
|
1868 | 1825 | mv (meta v)] |
1869 | 1826 | (cond (constant? v) (->constant v) |
1870 | 1827 | (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))) |
1885 | 1836 | #?@(:clj |
1886 | 1837 | [(:sci.impl.analyzer/interop mv) |
1887 | 1838 | (analyze-interop ctx expr v)]) |
|
0 commit comments