|
204 | 204 | (Exception. (str "constant type " (type value) " not supported"))))]
|
205 | 205 | (symbol (str prefix (swap! constant-counter inc)))))
|
206 | 206 |
|
207 |
| -(defn- register-constant! [val] |
208 |
| - (swap! env/*compiler* update-in [::constant-table] |
209 |
| - (fn [table] |
210 |
| - (if (get table val) |
211 |
| - table |
212 |
| - (assoc table val (gen-constant-id val)))))) |
| 207 | +(defn- register-constant! |
| 208 | + ([val] (register-constant! nil val)) |
| 209 | + ([env val] |
| 210 | + (swap! env/*compiler* |
| 211 | + (fn [cenv] |
| 212 | + (cond-> |
| 213 | + (-> cenv |
| 214 | + (update-in [::constant-table] |
| 215 | + (fn [table] |
| 216 | + (if (get table val) |
| 217 | + table |
| 218 | + (assoc table val (gen-constant-id val)))))) |
| 219 | + env (update-in [::namespaces (-> env :ns :name) ::constants] |
| 220 | + (fnil conj #{}) val)))))) |
213 | 221 |
|
214 | 222 | (def default-namespaces '{cljs.core {:name cljs.core}
|
215 | 223 | cljs.user {:name cljs.user}})
|
|
469 | 477 | ;; TODO: move this logic out - David
|
470 | 478 | (defn analyze-keyword
|
471 | 479 | [env sym]
|
472 |
| - (register-constant! sym) |
| 480 | + (register-constant! env sym) |
473 | 481 | {:op :constant :env env :form sym :tag 'cljs.core/Keyword})
|
474 | 482 |
|
475 | 483 | (defn get-tag [e]
|
@@ -1994,7 +2002,11 @@ argument, which the reader will use in any emitted errors."
|
1994 | 2002 | :load-macros true}))]
|
1995 | 2003 | (when (or *verbose* (:verbose opts))
|
1996 | 2004 | (util/debug-prn "Reading analysis cache for " res))
|
1997 |
| - (swap! env/*compiler* assoc-in [::analyzed-cljs path] true) |
1998 |
| - (swap! env/*compiler* assoc-in [::namespaces ns] |
1999 |
| - (edn/read-string (slurp cache)))))))))))) |
2000 |
| - |
| 2005 | + (swap! env/*compiler* |
| 2006 | + (fn [cenv] |
| 2007 | + (let [cached-ns (edn/read-string (slurp cache))] |
| 2008 | + (doseq [x (::constants cached-ns)] |
| 2009 | + (register-constant! x)) |
| 2010 | + (-> cenv |
| 2011 | + (assoc-in [::analyzed-cljs path] true) |
| 2012 | + (assoc-in [::namespaces ns] cached-ns)))))))))))))) |
0 commit comments