diff options
-rw-r--r-- | stdlib/source/lux/data/bit.lux | 8 | ||||
-rw-r--r-- | stdlib/source/lux/data/coll/dict.lux | 2 | ||||
-rw-r--r-- | stdlib/source/lux/data/coll/vector.lux | 12 | ||||
-rw-r--r-- | stdlib/source/lux/data/number.lux | 2 | ||||
-rw-r--r-- | stdlib/source/lux/math/random.lux | 9 | ||||
-rw-r--r-- | stdlib/source/lux/world/blob.jvm.lux | 22 | ||||
-rw-r--r-- | stdlib/test/test/lux/data/bit.lux | 4 |
7 files changed, 28 insertions, 31 deletions
diff --git a/stdlib/source/lux/data/bit.lux b/stdlib/source/lux/data/bit.lux index bb5b4b7bd..ebee21f3c 100644 --- a/stdlib/source/lux/data/bit.lux +++ b/stdlib/source/lux/data/bit.lux @@ -13,8 +13,8 @@ [or "or" "Bitwise or." Nat] [xor "xor" "Bitwise xor." Nat] [shift-left "shift-left" "Bitwise shift-left." Nat] - [shift-right "shift-right" "Bitwise shift-right." Int] - [unsigned-shift-right "unsigned-shift-right" "Bitwise unsigned-shift-right." Nat] + [shift-right "unsigned-shift-right" "Unsigned bitwise shift-right." Nat] + [signed-shift-right "shift-right" "Signed bitwise shift-right." Int] ) (def: #export (count subject) @@ -56,6 +56,6 @@ width) input)))] - [rotate-left shift-left unsigned-shift-right] - [rotate-right unsigned-shift-right shift-left] + [rotate-left shift-left shift-right] + [rotate-right shift-right shift-left] ) diff --git a/stdlib/source/lux/data/coll/dict.lux b/stdlib/source/lux/data/coll/dict.lux index 0af8ed43e..e6c46aa3f 100644 --- a/stdlib/source/lux/data/coll/dict.lux +++ b/stdlib/source/lux/data/coll/dict.lux @@ -162,7 +162,7 @@ (def: (level-index level hash) (-> Level Hash-Code Index) (bit;and hierarchy-mask - (bit;unsigned-shift-right level hash))) + (bit;shift-right level hash))) ## A mechanism to go from indices to bit-positions. (def: (->bit-position index) diff --git a/stdlib/source/lux/data/coll/vector.lux b/stdlib/source/lux/data/coll/vector.lux index c9d223736..23d07068e 100644 --- a/stdlib/source/lux/data/coll/vector.lux +++ b/stdlib/source/lux/data/coll/vector.lux @@ -71,7 +71,7 @@ (if (n.< full-node-size vec-size) +0 (|> (n.dec vec-size) - (bit;unsigned-shift-right branching-exponent) + (bit;shift-right branching-exponent) (bit;shift-left branching-exponent)))) (def: (new-path level tail) @@ -91,7 +91,7 @@ (def: (push-tail size level tail parent) (All [a] (-> Nat Level (Base a) (Hierarchy a) (Hierarchy a))) - (let [sub-idx (branch-idx (bit;unsigned-shift-right level (n.dec size))) + (let [sub-idx (branch-idx (bit;shift-right level (n.dec size))) ## If we're currently on a bottom node sub-node (if (n.= branching-exponent level) ## Just add the tail to it @@ -122,7 +122,7 @@ (def: (put' level idx val hierarchy) (All [a] (-> Level Index a (Hierarchy a) (Hierarchy a))) - (let [sub-idx (branch-idx (bit;unsigned-shift-right level idx))] + (let [sub-idx (branch-idx (bit;shift-right level idx))] (case (array;get sub-idx hierarchy) (#;Some (#Hierarchy sub-node)) (|> (array;clone hierarchy) @@ -140,7 +140,7 @@ (def: (pop-tail size level hierarchy) (All [a] (-> Nat Level (Hierarchy a) (Maybe (Hierarchy a)))) - (let [sub-idx (branch-idx (bit;unsigned-shift-right level (n.- +2 size)))] + (let [sub-idx (branch-idx (bit;shift-right level (n.- +2 size)))] (cond (n.= +0 sub-idx) #;None @@ -208,7 +208,7 @@ ## -------------------------------------------------------- ## Will the root experience an overflow with this addition? (|> (if (n.> (bit;shift-left (get@ #level vec) +1) - (bit;unsigned-shift-right branching-exponent vec-size)) + (bit;shift-right branching-exponent vec-size)) ## If so, a brand-new root must be established, that is ## 1-level taller. (|> vec @@ -236,7 +236,7 @@ (loop [level (get@ #level vec) hierarchy (get@ #root vec)] (case [(n.> branching-exponent level) - (array;get (branch-idx (bit;unsigned-shift-right level idx)) hierarchy)] + (array;get (branch-idx (bit;shift-right level idx)) hierarchy)] [true (#;Some (#Hierarchy sub))] (recur (level-down level) sub) diff --git a/stdlib/source/lux/data/number.lux b/stdlib/source/lux/data/number.lux index 713ee943f..82f8cadbb 100644 --- a/stdlib/source/lux/data/number.lux +++ b/stdlib/source/lux/data/number.lux @@ -822,7 +822,7 @@ [(def: <mask> (|> +1 (bit;shift-left <size>) n.dec (bit;shift-left <offset>))) (def: (<getter> input) (-> Nat Nat) - (|> input (bit;and <mask>) (bit;unsigned-shift-right <offset>)))] + (|> input (bit;and <mask>) (bit;shift-right <offset>)))] [mantissa mantissa-mask mantissa-size +0] [exponent exponent-mask exponent-size mantissa-size] diff --git a/stdlib/source/lux/math/random.lux b/stdlib/source/lux/math/random.lux index 7a0c2963d..f9989be40 100644 --- a/stdlib/source/lux/math/random.lux +++ b/stdlib/source/lux/math/random.lux @@ -20,7 +20,6 @@ ["V" vector])) )) -## [Exports] (type: #export #rec PRNG {#;doc "An abstract way to represent any PRNG."} (-> Unit [PRNG Nat])) @@ -82,7 +81,7 @@ (-> Nat (Random Nat)) (function [prng] (let [[prng output] (prng [])] - [prng (bit;unsigned-shift-right (n.- n +64) output)]))) + [prng (bit;shift-right (n.- n +64) output)]))) (def: #export frac (Random Frac) @@ -239,7 +238,6 @@ (All [a] (-> PRNG (Random a) [PRNG a])) (calc prng)) -## [PRNGs] ## PCG32 http://www.pcg-random.org/ ## Based on this Java implementation: https://github.com/alexeyr/pcg-java @@ -252,8 +250,8 @@ (-> [Nat Nat] PRNG) (function [_] (let [seed' (|> seed (n.* pcg-32-magic-mult) (n.+ inc)) - xor-shifted (|> seed (bit;unsigned-shift-right +18) (bit;xor seed) (bit;unsigned-shift-right +27)) - rot (|> seed (bit;unsigned-shift-right +59))] + xor-shifted (|> seed (bit;shift-right +18) (bit;xor seed) (bit;shift-right +27)) + rot (|> seed (bit;shift-right +59))] [(pcg-32 [inc seed']) (bit;rotate-right rot xor-shifted)] ))) @@ -273,7 +271,6 @@ [(xoroshiro-128+ [s0' s1']) result]) )) -## [Values] (def: (swap from to vec) (All [a] (-> Nat Nat (V;Vector a) (V;Vector a))) (V;put to (default (undefined) diff --git a/stdlib/source/lux/world/blob.jvm.lux b/stdlib/source/lux/world/blob.jvm.lux index 66d4d4a13..4d7f78199 100644 --- a/stdlib/source/lux/world/blob.jvm.lux +++ b/stdlib/source/lux/world/blob.jvm.lux @@ -80,7 +80,7 @@ (-> Nat Nat Blob (R;Result Unit)) (if (n.< (host;array-length blob) (n.+ +1 idx)) (exec (|> blob - (host;array-write idx (host;l2b (:! Int (bit;unsigned-shift-right +8 value)))) + (host;array-write idx (host;l2b (:! Int (bit;shift-right +8 value)))) (host;array-write (n.+ +1 idx) (host;l2b (:! Int value)))) (#R;Success [])) (ex;throw Index-Out-Of-Bounds (%n idx)))) @@ -89,9 +89,9 @@ (-> Nat Nat Blob (R;Result Unit)) (if (n.< (host;array-length blob) (n.+ +3 idx)) (exec (|> blob - (host;array-write idx (host;l2b (:! Int (bit;unsigned-shift-right +24 value)))) - (host;array-write (n.+ +1 idx) (host;l2b (:! Int (bit;unsigned-shift-right +16 value)))) - (host;array-write (n.+ +2 idx) (host;l2b (:! Int (bit;unsigned-shift-right +8 value)))) + (host;array-write idx (host;l2b (:! Int (bit;shift-right +24 value)))) + (host;array-write (n.+ +1 idx) (host;l2b (:! Int (bit;shift-right +16 value)))) + (host;array-write (n.+ +2 idx) (host;l2b (:! Int (bit;shift-right +8 value)))) (host;array-write (n.+ +3 idx) (host;l2b (:! Int value)))) (#R;Success [])) (ex;throw Index-Out-Of-Bounds (%n idx)))) @@ -100,13 +100,13 @@ (-> Nat Nat Blob (R;Result Unit)) (if (n.< (host;array-length blob) (n.+ +7 idx)) (exec (|> blob - (host;array-write idx (host;l2b (:! Int (bit;unsigned-shift-right +56 value)))) - (host;array-write (n.+ +1 idx) (host;l2b (:! Int (bit;unsigned-shift-right +48 value)))) - (host;array-write (n.+ +2 idx) (host;l2b (:! Int (bit;unsigned-shift-right +40 value)))) - (host;array-write (n.+ +3 idx) (host;l2b (:! Int (bit;unsigned-shift-right +32 value)))) - (host;array-write (n.+ +4 idx) (host;l2b (:! Int (bit;unsigned-shift-right +24 value)))) - (host;array-write (n.+ +5 idx) (host;l2b (:! Int (bit;unsigned-shift-right +16 value)))) - (host;array-write (n.+ +6 idx) (host;l2b (:! Int (bit;unsigned-shift-right +8 value)))) + (host;array-write idx (host;l2b (:! Int (bit;shift-right +56 value)))) + (host;array-write (n.+ +1 idx) (host;l2b (:! Int (bit;shift-right +48 value)))) + (host;array-write (n.+ +2 idx) (host;l2b (:! Int (bit;shift-right +40 value)))) + (host;array-write (n.+ +3 idx) (host;l2b (:! Int (bit;shift-right +32 value)))) + (host;array-write (n.+ +4 idx) (host;l2b (:! Int (bit;shift-right +24 value)))) + (host;array-write (n.+ +5 idx) (host;l2b (:! Int (bit;shift-right +16 value)))) + (host;array-write (n.+ +6 idx) (host;l2b (:! Int (bit;shift-right +8 value)))) (host;array-write (n.+ +7 idx) (host;l2b (:! Int value)))) (#R;Success [])) (ex;throw Index-Out-Of-Bounds (%n idx)))) diff --git a/stdlib/test/test/lux/data/bit.lux b/stdlib/test/test/lux/data/bit.lux index 89fdb3bdd..53bebe088 100644 --- a/stdlib/test/test/lux/data/bit.lux +++ b/stdlib/test/test/lux/data/bit.lux @@ -64,6 +64,6 @@ (test "Shift right respect the sign of ints." (let [value (nat-to-int pattern)] (if (i.< 0 value) - (i.< 0 (&;shift-right idx value)) - (i.>= 0 (&;shift-right idx value))))) + (i.< 0 (&;signed-shift-right idx value)) + (i.>= 0 (&;signed-shift-right idx value))))) )) |