louise
The Louise language: compiler, runtime, std, tooling
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#91 · main · 15 min 44 s
0Étoiles
0Forks
40Issues
| 1 | /// `U64`: unsigned 64-bit integers that wrap (ADR 0035). |
| 2 | /// |
| 3 | /// let x = u64.from_int(-1) // 18446744073709551615 |
| 4 | /// x + u64.from_int(1) // 0: arithmetic is modulo 2^64 |
| 5 | /// u64.rotate_left(u64.from_int(1), 65) // 2 |
| 6 | /// |
| 7 | /// For algorithms on 64-bit words (hashes, random generators such as |
| 8 | /// SplitMix64 in `std/prng`), where an `Int` would grow into a big |
| 9 | /// integer. `+`, `-` and `*` wrap; `/` and `%` are unsigned and panic on |
| 10 | /// zero. There are no `U64` literals: use `from_int`. A `U64` is boxed, as |
| 11 | /// a `Float` is: every result allocates. |
| 12 | |
| 13 | /// An unsigned 64-bit integer. |
| 14 | @builtin |
| 15 | pub type U64 |
| 16 | |
| 17 | /// `n` modulo 2^64 (two's complement: `from_int(-1)` is the largest). |
| 18 | @extern c "tl_u64_from_int" |
| 19 | pub fn from_int :: n: Int -> U64 |
| 20 | |
| 21 | /// The value, in `[0, 2^64)` (a big integer above 2^62). |
| 22 | @extern c "tl_u64_to_int" |
| 23 | pub fn to_int :: x: U64 -> Int |
| 24 | |
| 25 | /// 0 |
| 26 | pub fn zero :: -> U64 |
| 27 | { |
| 28 | from_int 0 |
| 29 | } |
| 30 | |
| 31 | /// 2^64 - 1 |
| 32 | pub fn max :: -> U64 |
| 33 | { |
| 34 | from_int (-1) |
| 35 | } |
| 36 | |
| 37 | @extern c "tl_u64_and" |
| 38 | pub fn and :: a: U64 b: U64 -> U64 |
| 39 | |
| 40 | @extern c "tl_u64_or" |
| 41 | pub fn or :: a: U64 b: U64 -> U64 |
| 42 | |
| 43 | @extern c "tl_u64_xor" |
| 44 | pub fn xor :: a: U64 b: U64 -> U64 |
| 45 | |
| 46 | @extern c "tl_u64_not" |
| 47 | pub fn not :: x: U64 -> U64 |
| 48 | |
| 49 | /// Shifted left by `k` bits; 0 when `k` is 64 or more. Panics if `k` is |
| 50 | /// negative. |
| 51 | @extern c "tl_u64_shift_left" |
| 52 | pub fn shift_left :: x: U64 k: Int -> U64 |
| 53 | |
| 54 | /// Shifted right by `k` bits, filling with zeros; 0 when `k` is 64 or more. |
| 55 | /// Panics if `k` is negative. |
| 56 | @extern c "tl_u64_shift_right" |
| 57 | pub fn shift_right :: x: U64 k: Int -> U64 |
| 58 | |
| 59 | /// Rotated left by `k` bits, modulo 64. |
| 60 | @extern c "tl_u64_rotate_left" |
| 61 | pub fn rotate_left :: x: U64 k: Int -> U64 |
| 62 | |
| 63 | /// Rotated right by `k` bits, modulo 64. |
| 64 | @extern c "tl_u64_rotate_right" |
| 65 | pub fn rotate_right :: x: U64 k: Int -> U64 |
| 66 | |
| 67 | @extern c "tl_u64_add" |
| 68 | fn add :: a: U64 b: U64 -> U64 |
| 69 | |
| 70 | @extern c "tl_u64_sub" |
| 71 | fn sub :: a: U64 b: U64 -> U64 |
| 72 | |
| 73 | @extern c "tl_u64_mul" |
| 74 | fn mul :: a: U64 b: U64 -> U64 |
| 75 | |
| 76 | @extern c "tl_u64_div" |
| 77 | fn div :: a: U64 b: U64 -> U64 |
| 78 | |
| 79 | @extern c "tl_u64_rem" |
| 80 | fn rem :: a: U64 b: U64 -> U64 |
| 81 | |
| 82 | @extern c "tl_u64_eq" |
| 83 | fn equal :: a: U64 b: U64 -> Bool |
| 84 | |
| 85 | @extern c "tl_u64_compare" |
| 86 | fn order :: a: U64 b: U64 -> Order |
| 87 | |
| 88 | @extern c "tl_u64_show" |
| 89 | fn decimal :: x: U64 -> String |
| 90 | |
| 91 | @extern c "tl_hash_u64" |
| 92 | fn hash_u64 :: x: U64 -> Int |
| 93 | |
| 94 | impl Num<U64> |
| 95 | { |
| 96 | fn add :: x y |
| 97 | { |
| 98 | add x y |
| 99 | } |
| 100 | fn sub :: x y |
| 101 | { |
| 102 | sub x y |
| 103 | } |
| 104 | fn mul :: x y |
| 105 | { |
| 106 | mul x y |
| 107 | } |
| 108 | fn div :: x y |
| 109 | { |
| 110 | div x y |
| 111 | } |
| 112 | fn rem :: x y |
| 113 | { |
| 114 | rem x y |
| 115 | } |
| 116 | fn negate :: x |
| 117 | { |
| 118 | sub (zero ()) x |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | impl Eq<U64> |
| 123 | { |
| 124 | fn eq :: x y |
| 125 | { |
| 126 | equal x y |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | impl Ord<U64> |
| 131 | { |
| 132 | fn compare :: x y |
| 133 | { |
| 134 | order x y |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | impl Show<U64> |
| 139 | { |
| 140 | fn show :: x |
| 141 | { |
| 142 | decimal x |
| 143 | } |
| 144 | } |
| 145 | |
| 146 | impl Debug<U64> |
| 147 | { |
| 148 | fn debug :: x |
| 149 | { |
| 150 | decimal x |
| 151 | } |
| 152 | } |
| 153 | |
| 154 | impl Hash<U64> |
| 155 | { |
| 156 | fn hash :: x |
| 157 | { |
| 158 | hash_u64 x |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | impl Default<U64> |
| 163 | { |
| 164 | fn default :: |
| 165 | { |
| 166 | zero () |
| 167 | } |
| 168 | } |