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.
ADR 0035: Numbers: bit operations on Int, a Float's bits, and U64
Status: Proposed (2026-10-13, issue #143); needs engineering review (#44). Extends ADR 0013 and ADR 0014.
Context
Int had no bit operations, and a Float's IEEE 754 bits couldn't be read or written. So code working on bits couldn't be written in Louise, or only slowly with / and %:
- random generators (SplitMix64, PCG), for
std/randomin Louise (#142); - binary formats (MessagePack, #140): big-endian integers and floats;
- base-N codecs (UUID alphabets, #141);
- hashes and checksums (FNV, CRC32), flags and masks.
Each needed a Rust extern instead.
Decision
std/int: bit operations as named functions
and, or, xor, not, shift_left(n, k), shift_right(n, k), bit_length(n), and in Louise bit(n, k) and low_bits(n, bits).
- Not operators. The lexer has no
&,^or<<,|already separates a row's tail, and>>would clash with nested generics (List<List<Int>>). Named functions need no syntax, as in Gleam. - Semantics: two's complement with infinite sign extension, as num-bigint and Python compute.
-1is all ones,not(n)is-n - 1, andshift_rightrounds towards minus infinity (shift_right(-5, 1)is-3,shift_right(-1, k)is-1). So a small and a big operand give the same result, and promotion stays invisible (ADR 0014). - Panics: a negative shift amount;
shift_leftof a non-zeronby2^32bits or more (the result couldn't be allocated; the same message on both backends instead of running out of memory).shift_rightby a huge amount is 0 or -1. - Fast paths: inline in
louise_rt.hfor two small ints (2x+1):andandorkeep the tag bit (a & b,a | b),xorrestores it ((a ^ b) | 1),notflips every bit but it (a ^ ~1): none can overflow. A shift stays inline while its result is small. Anything else callstl_int_*_slow(num-bigint). - Masks above 62 bits can't be literals (literals are 63-bit):
int.shift_left(1, 64) - 1.
std/float: conversions and bits
from_int(n) (nearest, ties to even; an infinity past the largest Float), to_bits(x) (in [0, 2^64), so -0.0 is 2^63, a big integer), from_bits(n) (the low 64 bits of n), to_bits32(x) (rounded to a single), from_bits32(n) (exact). NaN payloads are kept: the single conversions are written in louise_rt_prims, shared by the runtime and the interpreter, not left to the hardware.
U64: unsigned 64-bit integers that wrap
- Why a type: 64-bit algorithms (SplitMix64, PCG64, FNV-1a 64) overflow 63 bits at every step, so on
Intevery step would promote to a big integer. A fixed-width type with wrapping arithmetic keeps them simple and bounded. - Where:
std/u64declares@builtin pub type U64and its impls (coherence: the type's module). No prelude or type-checker change. No literals:u64.from_int(n)takesnmodulo2^64(from_int(-1)is the largest),to_intgives[0, 2^64). - Traits:
Numwraps (+,-,*,negate);/and%are unsigned and panic on zero.Eq,Ord(unsigned),Hash,ShowandDebug(decimal),Default(0). - Bits:
and,or,xor,not; logicalshift_left,shift_right(64 or more gives 0, a negative amount panics);rotate_left,rotate_right(modulo 64). - Representation: boxed, a
TL_TAG_U64block holding oneuint64_t, like aFloat. It can't be a 63-bit small int, and ADR 0013 keeps one representation for every value: its specialisation turns dictionary calls into direct calls, but never unboxes. So every result allocates. UnboxingU64(andFloat) would come with an unboxing pass, later; the owner accepted the boxed form for now. - No
U32: 32-bit algorithms mask anInt(int.and(a + b, 0xFFFFFFFF)stays small).
Runtime ABI 5: the inline bit operations and TL_TAG_U64.
Consequences
- Generators, codecs and binary formats can be written in Louise, the same on both backends.
U64arithmetic costs an allocation per result, about as much asFloat's.- Bit masks above 62 bits are computed, not written.
Alternatives considered
- Operators (
&,^,<<,>>): they read better in algorithms, but need tokens that clash with|in rows and>>in nested generics. - Wrapping functions on
Int(int.wrapping_mul_u64) instead of a type: no new type, but three quarters of random 64-bit values are above 2^62, so most results would be big integers. - An unboxed
U64now: a representation analysis with boxing at polymorphic boundaries, a much larger compiler change. U64as small-when-it-fits plus boxed: needs a canonical form likeInt's, for little gain over boxing.