aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--stdlib/source/lux/data/coll/bits.lux44
1 files changed, 24 insertions, 20 deletions
diff --git a/stdlib/source/lux/data/coll/bits.lux b/stdlib/source/lux/data/coll/bits.lux
index 84e536676..950aadd0f 100644
--- a/stdlib/source/lux/data/coll/bits.lux
+++ b/stdlib/source/lux/data/coll/bits.lux
@@ -7,14 +7,14 @@
(coll [array "array/" Fold<Array>])
text/format)))
-(type: #export Chunk Nat)
+(type: #export Chunk I64)
(def: #export chunk-size bit.width)
(type: #export Bits
(Array Chunk))
-(def: empty-chunk Chunk +0)
+(def: empty-chunk Chunk (.i64 +0))
(def: #export empty
Bits
@@ -23,7 +23,7 @@
(def: #export (size bits)
(-> Bits Nat)
(array/fold (function (_ chunk total)
- (n/+ total (bit.count chunk)))
+ (|> chunk bit.count (n/+ total)))
+0
bits))
@@ -31,9 +31,9 @@
(-> Bits Nat)
(|> bits array.size (n/* chunk-size)))
-(def: #export (empty? bits)
+(def: #export empty?
(-> Bits Bool)
- (n/= +0 (size bits)))
+ (|>> size (n/= +0)))
(def: #export (get index bits)
(-> Nat Bits Bool)
@@ -58,12 +58,13 @@
output ..empty]
(let [idx|output (dec size|output)]
(if (n/> +0 size|output)
- (case (|> (chunk idx|output input)
+ (case (|> (..chunk idx|output input)
(cond> [(new> (n/= chunk-index idx|output))]
[(<op> bit-index)]
## else
- []))
+ [])
+ .nat)
+0
## TODO: Remove 'no-op' once new-luxc is the official compiler.
(let [no-op (recur (dec size|output) output)]
@@ -73,7 +74,7 @@
(|> (if (is? ..empty output)
(: Bits (array.new size|output))
output)
- (array.write idx|output chunk)
+ (array.write idx|output (.i64 chunk))
(recur (dec size|output))))
output)))))]
@@ -88,9 +89,9 @@
(array.size sample))]
(loop [idx +0]
(if (n/< chunks idx)
- (.or (|> (chunk idx sample)
- (bit.and (chunk idx reference))
- (n/= empty-chunk)
+ (.or (|> (..chunk idx sample)
+ (bit.and (..chunk idx reference))
+ ("lux i64 =" empty-chunk)
.not)
(recur (inc idx)))
false))))
@@ -105,7 +106,7 @@
(loop [size|output size|output
output ..empty]
(let [idx (dec size|output)]
- (case (bit.not (chunk idx input))
+ (case (|> input (..chunk idx) bit.not .nat)
+0
(recur (dec size|output) output)
@@ -114,7 +115,7 @@
(|> (if (is? ..empty output)
(: Bits (array.new size|output))
output)
- (array.write idx chunk)
+ (array.write idx (.i64 chunk))
(recur (dec size|output)))
output))))))
@@ -131,7 +132,9 @@
output ..empty]
(let [idx (dec size|output)]
(if (n/> +0 size|output)
- (case (<op> (chunk idx param) (chunk idx subject))
+ (case (|> (..chunk idx subject)
+ (<op> (..chunk idx param))
+ .nat)
+0
(recur (dec size|output) output)
@@ -139,7 +142,7 @@
(|> (if (is? ..empty output)
(: Bits (array.new size|output))
output)
- (array.write idx chunk)
+ (array.write idx (.i64 chunk))
(recur (dec size|output))))
output)))))]
@@ -150,11 +153,12 @@
(struct: #export _ (Eq Bits)
(def: (= reference sample)
- (let [size|= (n/max (array.size reference)
- (array.size sample))]
+ (let [size (n/max (array.size reference)
+ (array.size sample))]
(loop [idx +0]
- (if (n/< size|= idx)
- (.and (n/= (chunk idx reference)
- (chunk idx sample))
+ (if (n/< size idx)
+ (.and ("lux i64 ="
+ (..chunk idx reference)
+ (..chunk idx sample))
(recur (inc idx)))
true)))))