From 0decfd4edd7483f2bb8d5bb489af5a74f1bf097a Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Wed, 3 May 2017 19:53:32 -0400 Subject: - Small refactorings. - Added the width of bit-patterns. --- stdlib/source/lux/data/bit.lux | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'stdlib/source') diff --git a/stdlib/source/lux/data/bit.lux b/stdlib/source/lux/data/bit.lux index 4e87a23dc..29b01e370 100644 --- a/stdlib/source/lux/data/bit.lux +++ b/stdlib/source/lux/data/bit.lux @@ -1,5 +1,7 @@ (;module: [lux #- and or not]) +(def: #export width Nat +64) + ## [Values] (do-template [ ] [(def: #export ( param subject) @@ -7,18 +9,12 @@ (-> Nat ) (_lux_proc ["bit" ] [subject param]))] - [and "and" - "Bitwise and." Nat] - [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] + [and "and" "Bitwise and." Nat] + [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] ) (def: #export (count subject) @@ -52,14 +48,12 @@ (-> Nat Nat Bool) (|> input (;;and (shift-left idx +1)) (n.= +0) ;not)) -(def: rot-top Nat +64) - (do-template [
] [(def: #export ( distance input) (-> Nat Nat Nat) (;;or (
distance input) - ( (n.- (n.% rot-top distance) - rot-top) + ( (n.- (n.% width distance) + width) input)))] [rotate-left shift-left unsigned-shift-right] -- cgit v1.2.3