Intrinsics
The routines the compiler itself provides.
Examples: res\examples\language\intrinsics holds small, commented programs for this page's features, each listing the output it prints; run one with adam build <file> -r.
The intrinsics are declared in a system scope outside every module, not reserved: a C library's size or print can still be declared and called, and a declaration in an inner scope hides them. The Intrinsics lists each one.
module exe intrinsics_bits;
type
Mode = choices(Fast, Small);
begin
println("{} {}", size(int64), len("four"));
println("{} {} {}", popcount(uint8(0b1011)), leadingzeros(uint32(1)), trailingzeros(uint32(8)));
println("{:x}", byteswap(uint16(0x1234)));
println("{}", nameof(Mode.Small));
println("{}", hash("adam") = hash("adam"));
println("{}", FormatStr("{:05}", 42));
end.
8 4
3 31 3
3412
Small
true
00042
Sizes and bits
size(T) is the size of a type in bytes and len(X) the length of a string or an array; len of a string literal counts its characters, never a terminator, and len([1, 2, 3]) of a bare bracket literal its elements (3; len([]) is SM0773). popcount, leadingzeros and trailingzeros count the set bits, the zeros above the highest set bit and below the lowest one, and byteswap reverses the bytes; each takes any integer type at its own width, and a zero gives its width.
Names and hashes
nameof(X) is a string: the name of a choice value as declared, or a type's name. hash(X) is a uint64, the same on every target and every run, and two values that are = give one hash; a record or an object hashes through the operator hash its type declares.
Text
print, println and FormatStr take a format string with {} placeholders by C++'s std::format rules. A literal format is checked when the program is built, any other when the call runs.
Exceptions, memory and the command line
raise(M)andraisecode(C, M)raise an exception, and in itsexceptexcmsg()andexccode()give its message and code (Exceptions).getmem,resizememandfreememmanage raw memory;create(P)allocates a zeroed record or overlay behind a pointer, anddestroy(P)frees it and sets P to nil.paramcount()andparamstr(I)read the program's command line.