A field-like access on a builtin INTEGER type name folds to a compile-time
constant of the queried type, driven by (width, signedness) arithmetic:
sN: min=-(2^(N-1)), max=2^(N-1)-1; uN: min=0, max=2^N-1
for every width s1..s64 / u1..u64 (not just power-of-two), plus usize/isize.
- type_resolver.zig: extract the single width parser (parseWidthInt) reused by
resolveNamed AND the new accessors (no second parser — issue-0083 class);
add resolveBuiltinName / integerWidthSign / integerLimitBits / integerLimitFor.
- lower.zig: lowerNumericLimit intercept beside the error.X / Struct.CONST /
pack-arity identifier-receiver intercepts; folds ints via constInt, emits a
clean diagnostic for a non-numeric receiver (bool/string/void/Any/noreturn),
falls through for floats (NL.2).
- expr_typer.zig: mirror the result type so inferExprType reports the queried type.
- program_index.zig: recognize the accessors in the comptime-int / array-dim path
so [u8.max]T (255) / [s16.max]T (32767) work; [u64.max]T is rejected oversized.
- u64.max / usize.max stored as the all-ones bit pattern with TYPE u64 (i64 -1),
asserted via union { u: u64; s: s64 } reinterpret.
Docs: specs.md numeric-limits subsection (formulas + result-type + u64 note);
readme.md language overview. Examples 0148 (positive) / 0149 (negative-receiver).
Unit tests for the value computation in type_resolver.test.zig.
Gate: zig build, zig build test (359/359), tests/run_examples.sh (416 ok, 0 failed).
19 lines
433 B
Plaintext
19 lines
433 B
Plaintext
s1.min=-1 s1.max=0
|
|
s2.min=-2 s2.max=1
|
|
s3.max=3
|
|
u1.min=0 u1.max=1
|
|
u2.max=3
|
|
s8.min=-128 s8.max=127
|
|
u8.max=255
|
|
s32.min=-2147483648 s32.max=2147483647
|
|
s64.max=9223372036854775807
|
|
s64.min+1 == -(s64.max): true
|
|
s64.min + s64.max == -1: true
|
|
u64.max as s64 == -1: true
|
|
usize.max as s64 == -1: true
|
|
usize.max == u64.max: true
|
|
isize.min == s64.min: true
|
|
typed: m3=3 mu=255 ms=-128
|
|
[u8.max]u8 len=255 a[254]=7
|
|
[s16.max]u8 len=32767 b[32766]=9
|