Skip to content

Commit c40b392

Browse files
committed
Added PersistentHashMap
1 parent 545d2c1 commit c40b392

File tree

3 files changed

+801
-1
lines changed

3 files changed

+801
-1
lines changed

src/clj/cljc/compiler.clj

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,17 @@
342342
(emit-meta-constant x
343343
(persistent-vector-emit-seq names)))))
344344

345+
(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))))
355+
345356
(defmethod emit-constant clojure.lang.IPersistentMap [x]
346357
(FIXME-IMPLEMENT))
347358

@@ -402,7 +413,10 @@
402413

403414
(defmethod emit :map
404415
[{:keys [env simple-keys? keys vals]}]
405-
(FIXME-IMPLEMENT))
416+
(let [keys (doall (map emit keys))
417+
vals (doall (map emit vals))]
418+
(emit-value-wrap :map env
419+
(emits (persistent-hash-map-emit-kv-pairs keys vals)))))
406420

407421
(defmethod emit :vector
408422
[{:keys [items env]}]

src/clj/cljc/core.clj

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,22 @@
305305
;; FIXME: see bit-clear
306306
(list 'c* "make_integer (integer_get (~{}) | (1ul << integer_get (~{})))" x n))
307307

308+
;; internal
309+
(defmacro mask [hash shift]
310+
(list 'c* "make_integer (((integer_get (~{}) >> integer_get (~{})) & 0x01f)) " hash shift))
311+
312+
;; internal
313+
(defmacro bitpos [hash shift]
314+
(list 'c* "make_integer ((1 << integer_get (~{})))" `(mask ~hash ~shift)))
315+
316+
;;internal
317+
(defmacro bit-count [num]
318+
(list 'c* "make_integer (__builtin_popcountll(integer_get (~{})))" num))
319+
320+
;;internal
321+
(defmacro bit-index [bitmap bitpos]
322+
(list 'c* "make_integer (__builtin_popcountll(integer_get (~{}) & (integer_get (~{}) - 1)))" bitmap bitpos))
323+
308324
;; internal
309325
(defmacro caching-hash [coll hash-fn hash-key]
310326
`(let [h# ~hash-key]

0 commit comments

Comments
 (0)