|
250 | 250 | (emit-constant (hash kw)) |
251 | 251 | (emits ")"))) |
252 | 252 |
|
253 | | -(defmethod emit-constant #?(:clj clojure.lang.Keyword :cljs Keyword) [x] |
254 | | - (if (-> @env/*compiler* :options :emit-constants) |
255 | | - (let [value (-> @env/*compiler* ::ana/constant-table x)] |
256 | | - (emits "cljs.core." value)) |
257 | | - (emits-keyword x) |
258 | | - )) |
259 | | - |
260 | | -(defmethod emit-constant #?(:clj clojure.lang.Symbol :cljs Symbol) [x] |
261 | | - (let [ns (namespace x) |
262 | | - name (name x) |
| 253 | +(defn emits-symbol [sym] |
| 254 | + (let [ns (namespace sym) |
| 255 | + name (name sym) |
263 | 256 | symstr (if-not (nil? ns) |
264 | 257 | (str ns "/" name) |
265 | 258 | name)] |
|
270 | 263 | (emits ",") |
271 | 264 | (emit-constant symstr) |
272 | 265 | (emits ",") |
273 | | - (emit-constant (hash x)) |
| 266 | + (emit-constant (hash sym)) |
274 | 267 | (emits ",") |
275 | 268 | (emit-constant nil) |
276 | 269 | (emits ")"))) |
277 | 270 |
|
| 271 | +(defmethod emit-constant #?(:clj clojure.lang.Keyword :cljs Keyword) [x] |
| 272 | + (if (-> @env/*compiler* :options :emit-constants) |
| 273 | + (let [value (-> @env/*compiler* ::ana/constant-table x)] |
| 274 | + (emits "cljs.core." value)) |
| 275 | + (emits-keyword x))) |
| 276 | + |
| 277 | +(defmethod emit-constant #?(:clj clojure.lang.Symbol :cljs Symbol) [x] |
| 278 | + (if (-> @env/*compiler* :options :emit-constants) |
| 279 | + (let [value (-> @env/*compiler* ::ana/constant-table x)] |
| 280 | + (emits "cljs.core." value)) |
| 281 | + (emits-symbol x))) |
| 282 | + |
278 | 283 | ;; tagged literal support |
279 | 284 |
|
280 | 285 | (defmethod emit-constant #?(:clj java.util.Date :cljs js/Date) [^java.util.Date date] |
|
1293 | 1298 | ;; TODO: needs fixing, table will include other things than keywords - David |
1294 | 1299 |
|
1295 | 1300 | (defn emit-constants-table [table] |
1296 | | - (doseq [[keyword value] table] |
1297 | | - (let [ns (namespace keyword) |
1298 | | - name (name keyword)] |
| 1301 | + (doseq [[sym value] table] |
| 1302 | + (let [ns (namespace sym) |
| 1303 | + name (name sym)] |
1299 | 1304 | (emits "cljs.core." value " = ") |
1300 | | - (emits-keyword keyword) |
| 1305 | + (cond |
| 1306 | + (keyword? sym) (emits-keyword sym) |
| 1307 | + (symbol? sym) (emits-symbol sym) |
| 1308 | + :else (throw |
| 1309 | + (ex-info |
| 1310 | + (str "Cannot emit constant for type " (type sym)) |
| 1311 | + {:error :invalid-constant-type}))) |
1301 | 1312 | (emits ";\n")))) |
1302 | 1313 |
|
1303 | 1314 | #?(:clj |
|
0 commit comments