lib/types limit consts were bare `def`s, so the .wwi (sep-compile's
interface) correctly omitted them while the flat combined.ww let a
cross-package user (lib/strings splitn → types.I32_MAX) reach the
private def — sep-compile then failed (wwstage `asserttyped: dot
'I32_MAX'`; cstage undefined-ref). Hare exports types::I32_MAX and the
whole limit family (ref/hare/types/limits.ha, arch+x86_64.ha); ww not
exporting them was the divergence.
export the 24 existing limit defs ({I,U}{8,16,32,64}_{MIN,MAX},
INT/UINT/SIZE/UINTPTR_{MIN,MAX}) and the existing RUNE_MIN, and add
exported RUNE_MAX. ww's derived machine-word int/uint/size/uintptr
VALUES are kept verbatim (user-ratified 64-bit-int divergence); fidelity
here is the NAME SET + export-visibility, not the values. RUNE_MAX is
written `0x10ffff: rune` — same codepoint as Hare's '\U0010ffff', forced
because ww's lexer has no \u/\U escape (#50).
Exporting the consts made `w6c -I` walk them and fatal on RUNE_MIN
('\0'): the .wwi const-expr unparser had no N_RUNELIT arm. Add one,
both stages (wwi_rune / wwirune), rendering a \xHH-escaped rune literal
(>0xFF fails loud, #50). Const casts need no arm — the checker folds
them to integer literals before the producer runs. 989_m2wwi_run gains
a types.wwi gate (byte-id + re-parse + asserts export def I32_MAX and
RUNE_MAX reach the interface). byte-id-neutral: a def emits no symbol.
48 lines
1.8 KiB
Plaintext
48 lines
1.8 KiB
Plaintext
// types — integer limits. Mirrors Hare's types::limits (I8_MAX, …)
|
|
// platform-fixed for amd64. Numeric helpers live in lib/math, matching
|
|
// Hare's split between types::limits and math::.
|
|
|
|
package types;
|
|
|
|
export def I8_MAX: i8 = 127;
|
|
export def I16_MAX: i16 = 32767;
|
|
export def I32_MAX: i32 = 2147483647;
|
|
export def I64_MAX: i64 = 9223372036854775807;
|
|
|
|
export def I8_MIN: i8 = -128;
|
|
export def I16_MIN: i16 = -32768;
|
|
export def I32_MIN: i32 = -2147483648;
|
|
export def I64_MIN: i64 = -9223372036854775808;
|
|
|
|
export def U8_MAX: u8 = 255;
|
|
export def U16_MAX: u16 = 65535;
|
|
export def U32_MAX: u32 = 4294967295;
|
|
export def U64_MAX: u64 = 18446744073709551615;
|
|
|
|
export def U8_MIN: u8 = 0;
|
|
export def U16_MIN: u16 = 0;
|
|
export def U32_MIN: u32 = 0;
|
|
export def U64_MIN: u64 = 0;
|
|
|
|
// int/uint are machine-word (Go-style, type.c:58); limits derived from
|
|
// size(int) per #114 + user ruling; cf Go math.MaxInt; diverges from
|
|
// Hare's per-arch literal (arch+x86_64.ha) because ww's int is 64-bit.
|
|
export def INT_MAX: int = (1 << (size(int)*8 - 1)) - 1;
|
|
export def INT_MIN: int = -1 << (size(int)*8 - 1);
|
|
export def UINT_MIN: uint = 0;
|
|
export def UINT_MAX: uint = ~(0: uint);
|
|
|
|
// size is 8B on amd64; no cast needed (size ∈ unsigned class per #113).
|
|
export def SIZE_MIN: size = U64_MIN;
|
|
export def SIZE_MAX: size = U64_MAX;
|
|
|
|
// uintptr not in the unsigned class, so the cast is required (Hare's form).
|
|
export def UINTPTR_MIN: uintptr = U64_MIN: uintptr;
|
|
export def UINTPTR_MAX: uintptr = U64_MAX: uintptr;
|
|
|
|
export def RUNE_MIN: rune = '\0';
|
|
// Hare spells this `'\U0010ffff'` (ref/hare/types/limits.ha:57); ww's lexer
|
|
// has no \U/\u escape (cmd/wcc/lex.c escape(): \xHH only, max 0xFF) so the
|
|
// codepoint is written as an int-cast — same value, forced spelling. #50.
|
|
export def RUNE_MAX: rune = 0x10ffff: rune;
|