From 386ef6478c16b25783dc7c4b36c0ed136dc24f91 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Sun, 24 Jul 2016 19:48:55 -0400 Subject: - Added the [bit count] procedure. --- src/lux/analyser/host.clj | 11 ++++++++++- src/lux/compiler/host.clj | 12 ++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/lux/analyser/host.clj b/src/lux/analyser/host.clj index 76c499f10..87a174f7f 100644 --- a/src/lux/analyser/host.clj +++ b/src/lux/analyser/host.clj @@ -1020,6 +1020,14 @@ ^:private analyse-bit-xor "xor" ) +(defn ^:private analyse-bit-count [analyse exo-type ?values] + (|do [:let [(&/$Cons input (&/$Nil)) ?values] + =input (&&/analyse-1 analyse &type/Int input) + _ (&type/check exo-type &type/Int) + _cursor &/cursor] + (return (&/|list (&&/|meta exo-type _cursor + (&&/$proc (&/T ["bit" "count"]) (&/|list =input) (&/|list))))))) + (do-template [ ] (defn [analyse exo-type ?values] (|do [:let [(&/$Cons input (&/$Cons shift (&/$Nil))) ?values] @@ -1052,9 +1060,10 @@ "lux" (case proc "==" (analyse-lux-== analyse exo-type ?values)) - + "bit" (case proc + "count" (analyse-bit-count analyse exo-type ?values) "and" (analyse-bit-and analyse exo-type ?values) "or" (analyse-bit-or analyse exo-type ?values) "xor" (analyse-bit-xor analyse exo-type ?values) 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 [ ] (defn [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) -- cgit v1.2.3