|
326 | 326 | (defmethod emit-constant clojure.lang.Cons [x] |
327 | 327 | (FIXME-IMPLEMENT)) |
328 | 328 |
|
| 329 | +(defn- emit-seq-construction [items empty prefix emitter postfix] |
| 330 | + (letfn [(emit-rec [xs] |
| 331 | + (if xs |
| 332 | + (do |
| 333 | + (emits prefix) |
| 334 | + (emit-rec (next xs)) |
| 335 | + (emitter (first xs)) |
| 336 | + (emits postfix)) |
| 337 | + (emits empty)))] |
| 338 | + (emit-rec (seq (reverse items))))) |
| 339 | + |
329 | 340 | (defn- persistent-vector-emit-seq [items] |
330 | | - (letfn [(emit-conj [xs] |
331 | | - (if (empty? xs) |
332 | | - (emits "VAR_NAME (cljc_DOT_core_DOT_PersistentVector_SLASH_EMPTY)") |
333 | | - (do |
334 | | - (emits "FUNCALL2 ((closure_t*)VAR_NAME (cljc_DOT_core_SLASH__conj), ") |
335 | | - (emit-conj (rest xs)) |
336 | | - (emits ", " (first xs) ")"))))] |
337 | | - (emit-conj (reverse items)))) |
| 341 | + (emit-seq-construction items |
| 342 | + "VAR_NAME (cljc_DOT_core_DOT_PersistentVector_SLASH_EMPTY)" |
| 343 | + "FUNCALL2 ((closure_t*)VAR_NAME (cljc_DOT_core_SLASH__conj), " |
| 344 | + #(emits ", " %) |
| 345 | + ")")) |
338 | 346 |
|
339 | 347 | (defmethod emit-constant clojure.lang.IPersistentVector [x] |
340 | 348 | (let [names (doall (map emit-constant x))] |
|
343 | 351 | (persistent-vector-emit-seq names))))) |
344 | 352 |
|
345 | 353 | (defn- persistent-hash-map-emit-kv-pairs [keys vals] |
346 | | - (letfn [(emit-assoc [keys vals] |
347 | | - (if (empty? keys) |
348 | | - (emits "VAR_NAME (cljc_DOT_core_DOT_PersistentHashMap_SLASH_EMPTY)") |
349 | | - (do |
350 | | - (emits "FUNCALL3 ((closure_t*)VAR_NAME (cljc_DOT_core_SLASH__assoc), ") |
351 | | - (emit-assoc (next keys)(next vals)) |
352 | | - (emits ", " (first keys)) |
353 | | - (emits ", " (first vals) ")"))))] |
354 | | - (emit-assoc (reverse keys) (reverse vals)))) |
| 354 | + (emit-seq-construction (map vector keys vals) |
| 355 | + "VAR_NAME (cljc_DOT_core_DOT_PersistentHashMap_SLASH_EMPTY)" |
| 356 | + "FUNCALL3 ((closure_t*)VAR_NAME (cljc_DOT_core_SLASH__assoc), " |
| 357 | + (fn [[k v]] |
| 358 | + (emits ", " k ", " v)) |
| 359 | + ")")) |
355 | 360 |
|
356 | 361 | (defmethod emit-constant clojure.lang.IPersistentMap [x] |
357 | 362 | (FIXME-IMPLEMENT)) |
|
0 commit comments