aboutsummaryrefslogtreecommitdiff
path: root/src/lux/compiler/host.clj
diff options
context:
space:
mode:
Diffstat (limited to 'src/lux/compiler/host.clj')
-rw-r--r--src/lux/compiler/host.clj12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/lux/compiler/host.clj b/src/lux/compiler/host.clj
index 1f055e10f..ae4b98f9f 100644
--- a/src/lux/compiler/host.clj
+++ b/src/lux/compiler/host.clj
@@ -1358,6 +1358,17 @@
^:private compile-bit-xor Opcodes/LXOR
)
+(defn ^:private compile-bit-count [compile ?values special-args]
+ (|do [:let [(&/$Cons ?input (&/$Nil)) ?values]
+ ^MethodVisitor *writer* &/get-writer
+ _ (compile ?input)
+ :let [_ (&&/unwrap-long *writer*)]
+ :let [_ (doto *writer*
+ (.visitMethodInsn Opcodes/INVOKESTATIC "java/lang/Long" "bitCount" "(J)I")
+ (.visitInsn Opcodes/I2L)
+ &&/wrap-long)]]
+ (return nil)))
+
(do-template [<name> <op>]
(defn <name> [compile ?values special-args]
(|do [:let [(&/$Cons ?input (&/$Cons ?shift (&/$Nil))) ?values]
@@ -1403,6 +1414,7 @@
"bit"
(case proc-name
+ "count" (compile-bit-count compile ?values special-args)
"and" (compile-bit-and compile ?values special-args)
"or" (compile-bit-or compile ?values special-args)
"xor" (compile-bit-xor compile ?values special-args)