|
1224 | 1224 | c (count params)]
|
1225 | 1225 | (some
|
1226 | 1226 | (fn [m]
|
1227 |
| - (and (or (== (:max-fixed-arity m) c) |
1228 |
| - (:variadic m)) |
| 1227 | + (and (or (== (:fixed-arity m) c) |
| 1228 | + (:variadic? m)) |
1229 | 1229 | m))
|
1230 | 1230 | methods)))
|
1231 | 1231 |
|
|
1289 | 1289 | (when (= 'js (:ns info)) 'js))]
|
1290 | 1290 | ret-tag
|
1291 | 1291 | (let [args (:args e)
|
1292 |
| - me (assoc (find-matching-method f args) :op :method)] |
| 1292 | + me (assoc (find-matching-method f args) :op :fn-method)] |
1293 | 1293 | (if-some [ret-tag (infer-tag env me)]
|
1294 | 1294 | ret-tag
|
1295 | 1295 | ANY_SYM)))))
|
|
1306 | 1306 | :let (infer-tag env (:body e))
|
1307 | 1307 | :loop (infer-tag env (:body e))
|
1308 | 1308 | :do (infer-tag env (:ret e))
|
1309 |
| - :method (infer-tag env (:expr e)) |
| 1309 | + :fn-method (infer-tag env (:body e)) |
1310 | 1310 | :def (infer-tag env (:init e))
|
1311 | 1311 | :invoke (infer-invoke env e)
|
1312 | 1312 | :if (infer-if env e)
|
|
1317 | 1317 | :var (if-some [init (:init e)]
|
1318 | 1318 | (infer-tag env init)
|
1319 | 1319 | (infer-tag env (:info e)))
|
1320 |
| - :dot ANY_SYM |
| 1320 | + (:host-field :host-call) ANY_SYM |
1321 | 1321 | :js ANY_SYM
|
1322 | 1322 | nil)))
|
1323 | 1323 |
|
|
1390 | 1390 | v (disallowing-recur (analyze expr-env sym))
|
1391 | 1391 | tests (mapv #(mapv (fn [t] (analyze expr-env t)) %) tests)
|
1392 | 1392 | thens (mapv #(analyze env %) thens)
|
| 1393 | + nodes (mapv (fn [tests then] |
| 1394 | + {:op :case-node |
| 1395 | + ;synthetic node, no :form |
| 1396 | + :env env |
| 1397 | + :tests (mapv (fn [test] |
| 1398 | + {:op :case-test |
| 1399 | + :form (:form test) |
| 1400 | + :env expr-env |
| 1401 | + :test test |
| 1402 | + :children [test]}) |
| 1403 | + tests) |
| 1404 | + :then {:op :case-then |
| 1405 | + :form (:form then) |
| 1406 | + :env env |
| 1407 | + :then then |
| 1408 | + :children [then]} |
| 1409 | + :children (conj tests then)}) |
| 1410 | + tests |
| 1411 | + thens) |
1393 | 1412 | default (analyze env default)]
|
1394 | 1413 | (assert (every? (fn [t]
|
1395 | 1414 | (or
|
|
1398 | 1417 | ((some-fn number? string? char?) (:form t)))))
|
1399 | 1418 | (apply concat tests))
|
1400 | 1419 | "case* tests must be numbers, strings, or constants")
|
1401 |
| - {:env env :op :case* :form form |
1402 |
| - :v v :tests tests :thens thens :default default |
1403 |
| - :children (vec (concat [v] tests thens (if default [default])))})) |
| 1420 | + {:env env :op :case :form form |
| 1421 | + :test v :nodes nodes :default default |
| 1422 | + :children (vec (concat [v] nodes [default]))})) |
1404 | 1423 |
|
1405 | 1424 | (defmethod parse 'throw
|
1406 | 1425 | [op env [_ throw-form :as form] name _]
|
|
1627 | 1646 | :protocol-inline (:protocol-inline init-expr)}
|
1628 | 1647 | (if-some [top-fn-meta (:top-fn sym-meta)]
|
1629 | 1648 | top-fn-meta
|
1630 |
| - {:variadic (:variadic init-expr) |
| 1649 | + {:variadic? (:variadic? init-expr) |
1631 | 1650 | :max-fixed-arity (:max-fixed-arity init-expr)
|
1632 | 1651 | :method-params params
|
1633 | 1652 | :arglists (:arglists sym-meta)
|
|
1720 | 1739 | (analyze-fn-method-body body-env body-form recur-frames))
|
1721 | 1740 | recurs @(:flag recur-frame)]
|
1722 | 1741 | {:env env
|
1723 |
| - :variadic variadic |
| 1742 | + :op :fn-method |
| 1743 | + :variadic? variadic |
1724 | 1744 | :params params
|
1725 |
| - :max-fixed-arity fixed-arity |
| 1745 | + :fixed-arity fixed-arity |
1726 | 1746 | :type type
|
1727 | 1747 | :form form
|
1728 |
| - :expr expr |
| 1748 | + :body expr |
1729 | 1749 | :recurs recurs}))
|
1730 | 1750 |
|
1731 | 1751 | (declare analyze-wrap-meta)
|
|
1783 | 1803 | {:protocol-impl proto-impl
|
1784 | 1804 | :protocol-inline proto-inline})
|
1785 | 1805 | methods (map #(disallowing-ns* (analyze-fn-method menv locals % type (nil? name))) meths)
|
1786 |
| - mfa (apply max (map :max-fixed-arity methods)) |
1787 |
| - variadic (boolean (some :variadic methods)) |
| 1806 | + mfa (apply max (map :fixed-arity methods)) |
| 1807 | + variadic (boolean (some :variadic? methods)) |
1788 | 1808 | locals (if named-fn?
|
1789 | 1809 | (update-in locals [name] assoc
|
1790 | 1810 | ;; TODO: can we simplify? - David
|
1791 | 1811 | :fn-var true
|
1792 |
| - :variadic variadic |
| 1812 | + :variadic? variadic |
1793 | 1813 | :max-fixed-arity mfa
|
1794 | 1814 | :method-params (map :params methods))
|
1795 | 1815 | locals)
|
|
1801 | 1821 | form (vary-meta form dissoc ::protocol-impl ::protocol-inline ::type)
|
1802 | 1822 | js-doc (when (true? variadic)
|
1803 | 1823 | "@param {...*} var_args")
|
1804 |
| - children (mapv :expr methods) |
| 1824 | + children (mapv :body methods) |
1805 | 1825 | ast {:op :fn
|
1806 | 1826 | :env env
|
1807 | 1827 | :form form
|
1808 | 1828 | :name name-var
|
1809 | 1829 | :methods methods
|
1810 |
| - :variadic variadic |
| 1830 | + :variadic? variadic |
1811 | 1831 | :tag 'function
|
1812 | 1832 | :recur-frames *recur-frames*
|
1813 | 1833 | :loop-lets *loop-lets*
|
|
1816 | 1836 | :protocol-impl proto-impl
|
1817 | 1837 | :protocol-inline proto-inline
|
1818 | 1838 | :children children}]
|
1819 |
| - (let [variadic-methods (filter :variadic methods) |
| 1839 | + (let [variadic-methods (filter :variadic? methods) |
1820 | 1840 | variadic-params (count (:params (first variadic-methods)))
|
1821 | 1841 | param-counts (map (comp count :params) methods)]
|
1822 | 1842 | (when (< 1 (count variadic-methods))
|
|
1846 | 1866 | :column (get-col n env)
|
1847 | 1867 | :local true
|
1848 | 1868 | :shadow (locals n)
|
1849 |
| - :variadic (:variadic fexpr) |
| 1869 | + :variadic? (:variadic? fexpr) |
1850 | 1870 | :max-fixed-arity (:max-fixed-arity fexpr)
|
1851 | 1871 | :method-params (map :params (:methods fexpr))}
|
1852 | 1872 | ret-tag (assoc :ret-tag ret-tag))]
|
|
1861 | 1881 | fexpr (analyze env (n->fexpr name))
|
1862 | 1882 | be' (assoc be
|
1863 | 1883 | :init fexpr
|
1864 |
| - :variadic (:variadic fexpr) |
| 1884 | + :variadic? (:variadic? fexpr) |
1865 | 1885 | :max-fixed-arity (:max-fixed-arity fexpr)
|
1866 | 1886 | :method-params (map :params (:methods fexpr)))]
|
1867 | 1887 | [(assoc-in env [:locals name] be')
|
|
1943 | 1963 | ;; TODO: can we simplify - David
|
1944 | 1964 | (merge be
|
1945 | 1965 | {:fn-var true
|
1946 |
| - :variadic (:variadic init-expr) |
| 1966 | + :variadic? (:variadic? init-expr) |
1947 | 1967 | :max-fixed-arity (:max-fixed-arity init-expr)
|
1948 | 1968 | :method-params (map :params (:methods init-expr))})
|
1949 | 1969 | be)]
|
|
2958 | 2978 | (into [::namespaces (-> env :ns :name) :externs] pre) merge {}))))
|
2959 | 2979 | (case dot-action
|
2960 | 2980 | ::access (let [children [targetexpr]]
|
2961 |
| - {:op :dot |
| 2981 | + {:op :host-field |
2962 | 2982 | :env env
|
2963 | 2983 | :form form
|
2964 | 2984 | :target targetexpr
|
|
2969 | 2989 | tag)})
|
2970 | 2990 | ::call (let [argexprs (map #(analyze enve %) args)
|
2971 | 2991 | children (into [targetexpr] argexprs)]
|
2972 |
| - {:op :dot |
| 2992 | + {:op :host-call |
2973 | 2993 | :env env
|
2974 | 2994 | :form form
|
2975 | 2995 | :target targetexpr
|
|
3155 | 3175 | bind-args? (and HO-invoke?
|
3156 | 3176 | (not (all-values? args)))]
|
3157 | 3177 | (when ^boolean fn-var?
|
3158 |
| - (let [{:keys [^boolean variadic max-fixed-arity method-params name ns macro]} (:info fexpr)] |
| 3178 | + (let [{^boolean variadic :variadic? :keys [max-fixed-arity method-params name ns macro]} (:info fexpr)] |
3159 | 3179 | ;; don't warn about invalid arity when when compiling a macros namespace
|
3160 | 3180 | ;; that requires itself, as that code is not meant to be executed in the
|
3161 | 3181 | ;; `$macros` ns - António Monteiro
|
|
3442 | 3462 | (defn analyze-js-value
|
3443 | 3463 | [env ^JSValue form]
|
3444 | 3464 | (let [val (.-val form)
|
3445 |
| - expr-env (assoc env :context :expr) |
3446 |
| - items (if (map? val) |
3447 |
| - (zipmap (keys val) |
3448 |
| - (disallowing-recur (doall (map #(analyze expr-env %) (vals val))))) |
3449 |
| - (disallowing-recur (doall (map #(analyze expr-env %) val))))] |
3450 |
| - {:op :js-value |
3451 |
| - :js-type (if (map? val) :object :array) |
3452 |
| - :env env |
3453 |
| - :form form |
3454 |
| - :items items |
3455 |
| - :children items |
3456 |
| - :tag (if (map? val) 'object 'array)})) |
| 3465 | + expr-env (assoc env :context :expr)] |
| 3466 | + (if (map? val) |
| 3467 | + (let [keys (vec (keys val)) |
| 3468 | + vals (disallowing-recur |
| 3469 | + (mapv #(analyze expr-env %) (vals val)))] |
| 3470 | + {:op :js-object |
| 3471 | + :env env |
| 3472 | + :form form |
| 3473 | + :keys keys |
| 3474 | + :vals vals |
| 3475 | + :children vals |
| 3476 | + :tag 'object}) |
| 3477 | + (let [items (disallowing-recur |
| 3478 | + (mapv #(analyze expr-env %) val))] |
| 3479 | + {:op :js-array |
| 3480 | + :env env |
| 3481 | + :form form |
| 3482 | + :items items |
| 3483 | + :children items |
| 3484 | + :tag 'array})))) |
3457 | 3485 |
|
3458 | 3486 | (defn analyze-record
|
3459 | 3487 | [env x]
|
|
0 commit comments