|
2 | 2 | {:no-doc true |
3 | 3 | :clj-kondo/config '{:linters {:unresolved-symbol {:exclude [ctx this bindings]}}}} |
4 | 4 | (:require |
| 5 | + #?(:clj [sci.impl.reflector :as reflector]) |
5 | 6 | #?(:clj [sci.impl.types :as t :refer [#?(:cljs ->Node) ->constant]]) |
6 | 7 | #?(:cljs [cljs.tagged-literals :refer [JSValue]]) |
7 | 8 | #?(:cljs [goog.object :as gobj]) |
|
20 | 21 | [ana-macros constant? macro? rethrow-with-location-of-node |
21 | 22 | set-namespace! recur special-syms]] |
22 | 23 | [sci.impl.vars :as vars] |
23 | | - [sci.lang] |
24 | | - #?(:clj [sci.impl.reflector :as reflector])) |
| 24 | + [sci.lang]) |
25 | 25 | #?(:cljs |
26 | 26 | (:require-macros |
27 | 27 | [sci.impl.analyzer :refer [gen-return-recur |
|
902 | 902 | :ex ex}) |
903 | 903 | (throw-error-with-location (str "Unable to resolve classname: " ex) ex)))) |
904 | 904 | catches) |
905 | | - sci-error (let [fst (when (= 1 (count catches)) |
906 | | - (nth catches 0)) |
907 | | - ex (:ex fst)] |
908 | | - (and (= #?(:clj 'Exception |
909 | | - :cljs 'js/Error) ex) |
910 | | - (some-> ex meta :sci/error))) |
| 905 | + sci-error (some (fn [{:keys [ex]}] |
| 906 | + (and (= #?(:clj 'Exception |
| 907 | + :cljs 'js/Error) ex) |
| 908 | + (some-> ex meta :sci/error))) |
| 909 | + catches) |
911 | 910 | finally (when finally |
912 | 911 | (analyze ctx (cons 'do (rest finally))))] |
913 | 912 | (sci.impl.types/->Node |
|
1444 | 1443 | :file @utils/current-file)] |
1445 | 1444 | (cond (str/starts-with? meth ".") |
1446 | 1445 | (let [meth (subs meth 1) |
1447 | | - arg-types (when-let [param-tags (some-> (meta expr) :param-tags)] |
1448 | | - (let [param-count (count param-tags) |
1449 | | - ^"[Ljava.lang.Class;" arg-types (when (pos? param-count) |
1450 | | - (make-array Class param-count))] |
1451 | | - (areduce arg-types idx _ret nil |
1452 | | - (when-let [t (nth param-tags idx)] |
1453 | | - (when-not (= '_ t) |
1454 | | - (when-let [t (interop/resolve-type-hint ctx t)] |
1455 | | - (aset arg-types idx t))))) |
1456 | | - arg-types)) |
1457 | | - f (fn [obj & args] |
1458 | | - (let [args (object-array args) |
1459 | | - arg-count (alength args) |
1460 | | - ^java.util.List methods (interop/meth-cache ctx clazz meth arg-count #(reflector/get-methods clazz arg-count meth false) :instance-methods)] |
1461 | | - (reflector/invoke-matching-method meth methods clazz obj args arg-types)))] |
1462 | | - (sci.impl.types/->Node |
1463 | | - f |
1464 | | - stack)) |
| 1446 | + arg-types (when-let [param-tags (some-> (meta expr) :param-tags)] |
| 1447 | + (let [param-count (count param-tags) |
| 1448 | + ^"[Ljava.lang.Class;" arg-types (when (pos? param-count) |
| 1449 | + (make-array Class param-count))] |
| 1450 | + (areduce arg-types idx _ret nil |
| 1451 | + (when-let [t (nth param-tags idx)] |
| 1452 | + (when-not (= '_ t) |
| 1453 | + (when-let [t (interop/resolve-type-hint ctx t)] |
| 1454 | + (aset arg-types idx t))))) |
| 1455 | + arg-types)) |
| 1456 | + f (fn [obj & args] |
| 1457 | + (let [args (object-array args) |
| 1458 | + arg-count (alength args) |
| 1459 | + ^java.util.List methods (interop/meth-cache ctx clazz meth arg-count #(reflector/get-methods clazz arg-count meth false) :instance-methods)] |
| 1460 | + (reflector/invoke-matching-method meth methods clazz obj args arg-types)))] |
| 1461 | + (sci.impl.types/->Node |
| 1462 | + f |
| 1463 | + stack)) |
1465 | 1464 | (try (reflector/get-static-field ^Class clazz ^String meth) |
1466 | 1465 | (catch IllegalArgumentException _ |
1467 | 1466 | nil)) |
1468 | 1467 | (sci.impl.types/->Node |
1469 | | - (interop/get-static-field clazz meth) |
1470 | | - stack) |
| 1468 | + (interop/get-static-field clazz meth) |
| 1469 | + stack) |
1471 | 1470 | :else (sci.impl.types/->Node |
1472 | | - (fn [& args] |
1473 | | - (reflector/invoke-static-method |
1474 | | - clazz meth |
1475 | | - ^objects (into-array Object args))) |
1476 | | - stack))))) |
| 1471 | + (fn [& args] |
| 1472 | + (reflector/invoke-static-method |
| 1473 | + clazz meth |
| 1474 | + ^objects (into-array Object args))) |
| 1475 | + stack))))) |
1477 | 1476 |
|
1478 | 1477 | (defn analyze-call [ctx expr m top-level?] |
1479 | 1478 | (with-top-level-loc top-level? m |
|
1569 | 1568 | :sci.impl/f-meta f-meta) |
1570 | 1569 | ^"[Ljava.lang.Class;" arg-types (when (pos? arg-count) |
1571 | 1570 | (make-array Class arg-count)) |
1572 | | - has-types? (volatile! nil) |
1573 | | - ] |
| 1571 | + has-types? (volatile! nil)] |
1574 | 1572 | (when arg-types |
1575 | 1573 | (or (when-let [param-tags (-> f* (some-> meta :param-tags))] |
1576 | 1574 | (vreset! has-types? true) |
1577 | | - (areduce arg-types idx _ret nil |
| 1575 | + (areduce arg-types idx _ret nil |
1578 | 1576 | (when-let [t (nth param-tags idx)] |
1579 | 1577 | (when-not (= '_ t) |
1580 | 1578 | (when-let [t (interop/resolve-type-hint ctx t)] |
|
1690 | 1688 | arg1 (nth children 1)] |
1691 | 1689 | (sci.impl.types/->Node |
1692 | 1690 | (f* (t/eval arg0 ctx bindings) |
1693 | | - (t/eval arg1 ctx bindings)) |
| 1691 | + (t/eval arg1 ctx bindings)) |
1694 | 1692 | nil)) |
1695 | 1693 | (throw-error-with-location (str "Wrong number of args (" ccount ") passed to: " f*) expr))) |
1696 | 1694 | :else |
|
0 commit comments