File tree Expand file tree Collapse file tree 1 file changed +17
-6
lines changed Expand file tree Collapse file tree 1 file changed +17
-6
lines changed Original file line number Diff line number Diff line change 53
53
(def ^:dynamic *load-macros* true )
54
54
(def ^:dynamic *reload-macros* false )
55
55
(def ^:dynamic *macro-infer* true )
56
-
56
+ ( def ^:dynamic *passes* nil )
57
57
(def ^:dynamic *file-defs* nil )
58
58
59
59
(def constants-ns-sym
1289
1289
(defn valid-proto [x]
1290
1290
(when (symbol? x) x))
1291
1291
1292
+ (defn elide-env [env ast opts]
1293
+ (dissoc ast :env ))
1294
+
1295
+ (defn constant-value?
1296
+ [{:keys [op] :as ast}]
1297
+ (or (= :constant op)
1298
+ (and (#{:map :set :vector :list } op)
1299
+ (every? constant-value? (:children ast)))))
1300
+
1292
1301
(defmethod parse 'def
1293
1302
[op env form _ _]
1294
1303
(when (> (count form) 4 )
1383
1392
f))))}
1384
1393
(when doc {:doc doc})
1385
1394
(when const?
1386
- {:const-init (:init args)})
1395
+ (let [const-expr
1396
+ (binding [*passes* (conj *passes* elide-env)]
1397
+ (analyze env (:init args)))]
1398
+ (when (constant-value? const-expr)
1399
+ {:const-expr const-expr})))
1387
1400
(when (true ? dynamic) {:dynamic true })
1388
1401
(source-info var-name env)
1389
1402
; ; the protocol a protocol fn belongs to
2919
2932
(if-not (true ? (:def-var env))
2920
2933
(merge
2921
2934
(assoc ret :op :var :info info)
2922
- (when-let [const-init (:const-init info)]
2923
- {:const-expr ( analyze env const-init) }))
2935
+ (when-let [const-expr (:const-expr info)]
2936
+ {:const-expr const-expr }))
2924
2937
(let [info (resolve-var env sym)]
2925
2938
(assoc ret :op :var :info info))))))))
2926
2939
3202
3215
ast)))
3203
3216
ast)))
3204
3217
3205
- (def ^:dynamic *passes* nil )
3206
-
3207
3218
#?(:clj
3208
3219
(defn analyze-form [env form name opts]
3209
3220
(load-core )
You can’t perform that action at this time.
0 commit comments