diff options
author | Eduardo Julian | 2016-07-24 19:48:55 -0400 |
---|---|---|
committer | Eduardo Julian | 2016-07-24 19:48:55 -0400 |
commit | 386ef6478c16b25783dc7c4b36c0ed136dc24f91 (patch) | |
tree | 85a514e1e27bece71702119ad42c8dfb67e1fa5a | |
parent | 9b452b13a50f75b4ab5fb28aa6febddbdb2e6680 (diff) |
- Added the [bit count] procedure.
Diffstat (limited to '')
-rw-r--r-- | src/lux/analyser/host.clj | 11 | ||||
-rw-r--r-- | src/lux/compiler/host.clj | 12 |
2 files changed, 22 insertions, 1 deletions
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 [<name> <op>] (defn <name> [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 [<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) |