|
7 | 7 | ; You must not remove this notice, or any other, from this software. |
8 | 8 |
|
9 | 9 | (ns cljs.analyzer |
10 | | - #?(:clj (:refer-clojure :exclude [macroexpand-1 ensure]) |
11 | | - :cljs (:refer-clojure :exclude [macroexpand-1 ns-interns ensure js-reserved])) |
12 | | - #?(:cljs (:require-macros |
13 | | - [cljs.analyzer.macros |
14 | | - :refer [no-warn wrapping-errors with-warning-handlers |
15 | | - disallowing-recur allowing-redef disallowing-ns*]] |
| 10 | + #?(:clj (:refer-clojure :exclude [ensure macroexpand-1]) |
| 11 | + :cljs (:refer-clojure :exclude [ensure js-reserved macroexpand-1 ns-interns])) |
| 12 | + #?(:cljs (:require-macros [cljs.analyzer.macros |
| 13 | + :refer [allowing-redef disallowing-ns* disallowing-recur |
| 14 | + no-warn with-warning-handlers wrapping-errors]] |
16 | 15 | [cljs.env.macros :refer [ensure]])) |
17 | | - #?(:clj (:require [cljs.util :as util :refer [ns->relpath topo-sort]] |
18 | | - [clojure.java.io :as io] |
19 | | - [clojure.string :as string] |
20 | | - [clojure.set :as set] |
| 16 | + #?(:clj (:require [cljs.analyzer.impl :as impl] |
21 | 17 | [cljs.env :as env :refer [ensure]] |
| 18 | + [cljs.externs :as externs] |
22 | 19 | [cljs.js-deps :as deps] |
23 | 20 | [cljs.tagged-literals :as tags] |
24 | | - [clojure.tools.reader :as reader] |
25 | | - [clojure.tools.reader.reader-types :as readers] |
| 21 | + [cljs.util :as util :refer [ns->relpath topo-sort]] |
26 | 22 | [clojure.edn :as edn] |
27 | | - [cljs.externs :as externs]) |
28 | | - :cljs (:require [goog.string :as gstring] |
29 | | - [clojure.string :as string] |
| 23 | + [clojure.java.io :as io] |
30 | 24 | [clojure.set :as set] |
| 25 | + [clojure.string :as string] |
| 26 | + [clojure.tools.reader :as reader] |
| 27 | + [clojure.tools.reader.reader-types :as readers]) |
| 28 | + :cljs (:require [cljs.analyzer.impl :as impl] |
31 | 29 | [cljs.env :as env] |
| 30 | + [cljs.reader :as edn] |
32 | 31 | [cljs.tagged-literals :as tags] |
33 | 32 | [cljs.tools.reader :as reader] |
34 | 33 | [cljs.tools.reader.reader-types :as readers] |
35 | | - [cljs.reader :as edn])) |
36 | | - #?(:clj (:import [java.io File Reader PushbackReader] |
37 | | - [java.util.regex Pattern] |
38 | | - [java.net URL] |
39 | | - [java.lang Throwable] |
| 34 | + [clojure.set :as set] |
| 35 | + [clojure.string :as string] |
| 36 | + [goog.string :as gstring])) |
| 37 | + #?(:clj (:import [cljs.tagged_literals JSValue] |
40 | 38 | [clojure.lang Namespace Var LazySeq ArityException] |
41 | | - [cljs.tagged_literals JSValue]))) |
| 39 | + [java.io File Reader PushbackReader] |
| 40 | + [java.lang Throwable] |
| 41 | + [java.net URL] |
| 42 | + [java.util.regex Pattern]))) |
42 | 43 |
|
43 | 44 | #?(:clj (set! *warn-on-reflection* true)) |
44 | 45 |
|
|
220 | 221 | (when-not (identical? m SENTINEL) |
221 | 222 | (get m k3))))))))) |
222 | 223 |
|
223 | | -#?(:cljs |
224 | | - (def CLJ_NIL_SYM 'clj-nil)) |
225 | | - |
226 | | -#?(:cljs |
227 | | - (def NUMBER_SYM 'number)) |
228 | | - |
229 | | -#?(:cljs |
230 | | - (def STRING_SYM 'string)) |
231 | | - |
232 | | -(def BOOLEAN_SYM 'boolean) |
233 | | - |
234 | | -#?(:cljs |
235 | | - (def JS_STAR_SYM 'js*)) |
236 | | - |
237 | | -#?(:cljs |
238 | | - (def DOT_SYM '.)) |
239 | | - |
240 | | -#?(:cljs |
241 | | - (def NEW_SYM 'new)) |
242 | | - |
243 | | -#?(:cljs |
244 | | - (def CLJS_CORE_SYM 'cljs.core)) |
245 | | - |
246 | | -#?(:cljs |
247 | | - (def CLJS_CORE_MACROS_SYM 'cljs.core$macros)) |
248 | | - |
249 | | -(def IGNORE_SYM 'ignore) |
250 | | - |
251 | | -(def ANY_SYM 'any) |
252 | | - |
253 | | -#?(:cljs |
254 | | - (defn ^boolean cljs-seq? [x] |
255 | | - (implements? ISeq x))) |
256 | | - |
257 | | -#?(:cljs |
258 | | - (defn ^boolean cljs-map? [x] |
259 | | - (implements? IMap x))) |
260 | | - |
261 | | -#?(:cljs |
262 | | - (defn ^boolean cljs-vector? [x] |
263 | | - (implements? IVector x))) |
264 | | - |
265 | | -#?(:cljs |
266 | | - (defn ^boolean cljs-set? [x] |
267 | | - (implements? ISet x))) |
268 | | - |
269 | 224 | #?(:cljs |
270 | 225 | (defn munge-path [ss] |
271 | 226 | (munge (str ss)))) |
|
950 | 905 | "Ensures that a type tag is a set." |
951 | 906 | [t] |
952 | 907 | (if #?(:clj (set? t) |
953 | | - :cljs (cljs-set? t)) |
| 908 | + :cljs (impl/cljs-set? t)) |
954 | 909 | t |
955 | 910 | #{t})) |
956 | 911 |
|
|
1348 | 1303 | (let [ns (cond |
1349 | 1304 | (some? (get-in namespaces [ns :macros sym])) ns |
1350 | 1305 | (core-name? env sym) #?(:clj 'cljs.core |
1351 | | - :cljs CLJS_CORE_MACROS_SYM))] |
| 1306 | + :cljs impl/CLJS_CORE_MACROS_SYM))] |
1352 | 1307 | (when (some? ns) |
1353 | 1308 | #?(:clj (get-in namespaces [ns :macros sym]) |
1354 | 1309 | :cljs (get-in namespaces [ns :defs sym]))))))) |
|
1417 | 1372 |
|
1418 | 1373 | (declare infer-tag) |
1419 | 1374 |
|
1420 | | -(def NOT_NATIVE '#{clj not-native}) |
1421 | | - |
1422 | | -(def BOOLEAN_OR_SEQ '#{boolean seq}) |
1423 | | - |
1424 | 1375 | (defn unwrap-quote [{:keys [op] :as expr}] |
1425 | 1376 | (if #?(:clj (= op :quote) |
1426 | 1377 | :cljs (keyword-identical? op :quote)) |
|
1439 | 1390 | (cond |
1440 | 1391 | (or #?(:clj (= then-tag else-tag) |
1441 | 1392 | :cljs (symbol-identical? then-tag else-tag)) |
1442 | | - #?(:clj (= else-tag IGNORE_SYM) |
1443 | | - :cljs (symbol-identical? else-tag IGNORE_SYM))) then-tag |
1444 | | - #?(:clj (= then-tag IGNORE_SYM) |
1445 | | - :cljs (symbol-identical? then-tag IGNORE_SYM)) else-tag |
| 1393 | + #?(:clj (= else-tag impl/IGNORE_SYM) |
| 1394 | + :cljs (symbol-identical? else-tag impl/IGNORE_SYM))) then-tag |
| 1395 | + #?(:clj (= then-tag impl/IGNORE_SYM) |
| 1396 | + :cljs (symbol-identical? then-tag impl/IGNORE_SYM)) else-tag |
1446 | 1397 | ;; TODO: temporary until we move not-native -> clj - David |
1447 | | - (and (or (some? (get NOT_NATIVE then-tag)) (type? env then-tag)) |
1448 | | - (or (some? (get NOT_NATIVE else-tag)) (type? env else-tag))) |
| 1398 | + (and (or (some? (get impl/NOT_NATIVE then-tag)) (type? env then-tag)) |
| 1399 | + (or (some? (get impl/NOT_NATIVE else-tag)) (type? env else-tag))) |
1449 | 1400 | 'clj |
1450 | 1401 | :else |
1451 | | - (if (and (some? (get BOOLEAN_OR_SEQ then-tag)) |
1452 | | - (some? (get BOOLEAN_OR_SEQ else-tag))) |
| 1402 | + (if (and (some? (get impl/BOOLEAN_OR_SEQ then-tag)) |
| 1403 | + (some? (get impl/BOOLEAN_OR_SEQ else-tag))) |
1453 | 1404 | 'seq |
1454 | 1405 | (let [then-tag (if #?(:clj (set? then-tag) |
1455 | | - :cljs (cljs-set? then-tag)) |
| 1406 | + :cljs (impl/cljs-set? then-tag)) |
1456 | 1407 | then-tag #{then-tag}) |
1457 | 1408 | else-tag (if #?(:clj (set? else-tag) |
1458 | | - :cljs (cljs-set? else-tag)) |
| 1409 | + :cljs (impl/cljs-set? else-tag)) |
1459 | 1410 | else-tag #{else-tag})] |
1460 | 1411 | (into then-tag else-tag)))))))) |
1461 | 1412 |
|
|
1469 | 1420 | (:ret-tag info) |
1470 | 1421 | (when (= 'js (:ns info)) 'js))] |
1471 | 1422 | ret-tag |
1472 | | - ANY_SYM))))) |
| 1423 | + impl/ANY_SYM))))) |
1473 | 1424 |
|
1474 | 1425 | (defn infer-tag |
1475 | 1426 | "Given env, an analysis environment, and e, an AST node, return the inferred |
|
1478 | 1429 | (if-some [tag (get-tag e)] |
1479 | 1430 | tag |
1480 | 1431 | (case (:op e) |
1481 | | - :recur IGNORE_SYM |
1482 | | - :throw IGNORE_SYM |
| 1432 | + :recur impl/IGNORE_SYM |
| 1433 | + :throw impl/IGNORE_SYM |
1483 | 1434 | :let (infer-tag env (:body e)) |
1484 | 1435 | :loop (infer-tag env (:body e)) |
1485 | 1436 | :do (infer-tag env (:ret e)) |
|
1488 | 1439 | :invoke (infer-invoke env e) |
1489 | 1440 | :if (infer-if env e) |
1490 | 1441 | :const (case (:form e) |
1491 | | - true BOOLEAN_SYM |
1492 | | - false BOOLEAN_SYM |
1493 | | - ANY_SYM) |
| 1442 | + true impl/BOOLEAN_SYM |
| 1443 | + false impl/BOOLEAN_SYM |
| 1444 | + impl/ANY_SYM) |
1494 | 1445 | :quote (infer-tag env (:expr e)) |
1495 | 1446 | (:var :local :js-var :binding) |
1496 | 1447 | (if-some [init (:init e)] |
1497 | 1448 | (infer-tag env init) |
1498 | 1449 | (infer-tag env (:info e))) |
1499 | | - (:host-field :host-call) ANY_SYM |
1500 | | - :js ANY_SYM |
| 1450 | + (:host-field :host-call) |
| 1451 | + impl/ANY_SYM |
| 1452 | + :js impl/ANY_SYM |
1501 | 1453 | nil))) |
1502 | 1454 |
|
1503 | 1455 | (defmulti parse (fn [op & rest] op)) |
|
1940 | 1892 | tag (cond |
1941 | 1893 | fn-var? (or (:ret-tag init-expr) tag (:inferred-ret-tag init-expr)) |
1942 | 1894 | tag tag |
1943 | | - dynamic ANY_SYM |
| 1895 | + dynamic impl/ANY_SYM |
1944 | 1896 | :else (:tag init-expr)) |
1945 | 1897 | export-as (when-let [export-val (-> sym meta :export)] |
1946 | 1898 | (if (= true export-val) var-name export-val)) |
|
3527 | 3479 | (if (and (symbol? t) (some? (get NUMERIC_SET t))) |
3528 | 3480 | true |
3529 | 3481 | (when #?(:clj (set? t) |
3530 | | - :cljs (cljs-set? t)) |
| 3482 | + :cljs (impl/cljs-set? t)) |
3531 | 3483 | (or (contains? t 'number) |
3532 | 3484 | (contains? t 'long) |
3533 | 3485 | (contains? t 'double) |
|
3550 | 3502 | :else |
3551 | 3503 | (boolean |
3552 | 3504 | (when #?(:clj (set? t) |
3553 | | - :cljs (cljs-set? t)) |
| 3505 | + :cljs (impl/cljs-set? t)) |
3554 | 3506 | (or (contains? t 'any) |
3555 | 3507 | (contains? t 'js) |
3556 | 3508 | (some array-types t)))))) |
|
3837 | 3789 | nstr (if (some? res) (str res) nstr)] |
3838 | 3790 | (cond |
3839 | 3791 | #?@(:clj [(= "clojure.core" nstr) (find-ns 'cljs.core)] |
3840 | | - :cljs [(identical? "clojure.core" nstr) (find-macros-ns CLJS_CORE_MACROS_SYM)]) |
| 3792 | + :cljs [(identical? "clojure.core" nstr) (find-macros-ns impl/CLJS_CORE_MACROS_SYM)]) |
3841 | 3793 | #?@(:clj [(= "clojure.repl" nstr) (find-ns 'cljs.repl)] |
3842 | 3794 | :cljs [(identical? "clojure.repl" nstr) (find-macros-ns 'cljs.repl)]) |
3843 | 3795 | #?@(:clj [(.contains nstr ".") (find-ns (symbol nstr))] |
|
3868 | 3820 | (.findInternedVar ^clojure.lang.Namespace |
3869 | 3821 | #?(:clj (find-ns nsym) :cljs (find-macros-ns nsym)) sym) |
3870 | 3822 | (.findInternedVar ^clojure.lang.Namespace |
3871 | | - #?(:clj (find-ns 'cljs.core) :cljs (find-macros-ns CLJS_CORE_MACROS_SYM)) sym))))))) |
| 3823 | + #?(:clj (find-ns 'cljs.core) :cljs (find-macros-ns impl/CLJS_CORE_MACROS_SYM)) sym))))))) |
3872 | 3824 |
|
3873 | 3825 | (defn get-expander |
3874 | 3826 | "Given a sym, a symbol identifying a macro, and env, an analysis environment |
|
3933 | 3885 | (throw (ArityException. (- (.actual e) 2) (.name e))))) |
3934 | 3886 | (catch #?(:clj Throwable :cljs :default) e |
3935 | 3887 | (throw (ex-info nil (error-data env :macroexpansion (var->sym mac-var)) e))))] |
3936 | | - (if #?(:clj (seq? form') :cljs (cljs-seq? form')) |
| 3888 | + (if #?(:clj (seq? form') :cljs (impl/cljs-seq? form')) |
3937 | 3889 | (let [sym' (first form') |
3938 | 3890 | sym (first form)] |
3939 | 3891 | (if #?(:clj (= sym' 'js*) |
3940 | | - :cljs (symbol-identical? sym' JS_STAR_SYM)) |
| 3892 | + :cljs (symbol-identical? sym' impl/JS_STAR_SYM)) |
3941 | 3893 | (let [sym (if (some? (namespace sym)) |
3942 | 3894 | sym |
3943 | 3895 | (symbol "cljs.core" (str sym))) |
|
3960 | 3912 | #?(:clj (first opname) |
3961 | 3913 | :cljs (.charAt opname 0))) |
3962 | 3914 | (let [[target & args] (next form)] |
3963 | | - (with-meta (list* #?(:clj '. :cljs DOT_SYM) target (symbol (subs opname 1)) args) |
| 3915 | + (with-meta (list* #?(:clj '. :cljs impl/DOT_SYM) target (symbol (subs opname 1)) args) |
3964 | 3916 | (meta form))) |
3965 | 3917 |
|
3966 | 3918 | (identical? \. |
3967 | 3919 | #?(:clj (last opname) |
3968 | 3920 | :cljs (.charAt opname (dec (. opname -length))))) |
3969 | 3921 | (with-meta |
3970 | | - (list* #?(:clj 'new :cljs NEW_SYM) (symbol (subs opname 0 (dec (count opname)))) (next form)) |
| 3922 | + (list* #?(:clj 'new :cljs impl/NEW_SYM) (symbol (subs opname 0 (dec (count opname)))) (next form)) |
3971 | 3923 | (meta form)) |
3972 | 3924 |
|
3973 | 3925 | :else form)) |
|
4222 | 4174 | (defn analyze-form [env form name opts] |
4223 | 4175 | (cond |
4224 | 4176 | (symbol? form) (analyze-symbol env form) |
4225 | | - (and (cljs-seq? form) (some? (seq form))) (analyze-seq env form name opts) |
| 4177 | + (and (impl/cljs-seq? form) (some? (seq form))) (analyze-seq env form name opts) |
4226 | 4178 | (record? form) (analyze-record env form) |
4227 | | - (cljs-map? form) (analyze-map env form) |
4228 | | - (cljs-vector? form) (analyze-vector env form) |
4229 | | - (cljs-set? form) (analyze-set env form) |
| 4179 | + (impl/cljs-map? form) (analyze-map env form) |
| 4180 | + (impl/cljs-vector? form) (analyze-vector env form) |
| 4181 | + (impl/cljs-set? form) (analyze-set env form) |
4230 | 4182 | (keyword? form) (analyze-keyword env form) |
4231 | 4183 | (instance? cljs.tagged-literals/JSValue form) (analyze-js-value env form) |
4232 | 4184 | :else |
4233 | 4185 | (let [tag (cond |
4234 | | - (nil? form) CLJ_NIL_SYM |
4235 | | - (number? form) NUMBER_SYM |
4236 | | - (string? form) STRING_SYM |
4237 | | - (true? form) BOOLEAN_SYM |
4238 | | - (false? form) BOOLEAN_SYM |
| 4186 | + (nil? form) impl/CLJ_NIL_SYM |
| 4187 | + (number? form) impl/NUMBER_SYM |
| 4188 | + (string? form) impl/STRING_SYM |
| 4189 | + (true? form) impl/BOOLEAN_SYM |
| 4190 | + (false? form) impl/BOOLEAN_SYM |
4239 | 4191 | (= () form) 'cljs.core/IList)] |
4240 | 4192 | (cond-> {:op :const :val form :env env :form form} |
4241 | 4193 | tag (assoc :tag tag)))))) |
|
0 commit comments