Intrinsic Constants
Alongside the constants you declare, the compiler exposes a set of intrinsic values through the build context. Each is a field of an intrinsic — #source, #build, #target, #compiler, or #config — that you import from the standard Rux package and read with .. Because every one is fixed at compile time, it can initialize an ordinary const or serve as a default argument, at no run-time cost.
import Core::{ #source, #build };
Print(#source.file); // e.g. "Main.rux"
Print(#source.line); // the line number of this call
Common Compile-Time Values
| Value | Type | Expands to |
|---|---|---|
#source.file | Slice<char8> | Current source file name |
#source.line | uint | Current line number |
#source.column | uint | Current column number |
#source.function | Slice<char8> | Enclosing function name |
#source.module | Slice<char8> | Enclosing module path |
#build.date | Slice<char8> | Date the program was compiled |
#build.time | Slice<char8> | Time the program was compiled |
See Build Context for the complete set, including #target, #compiler, and #config.
These replace the earlier standalone
#file,#line,#date, and#timeconstants, which are now fields of#sourceand#build.
Substitution at the Point of Use
A build-context value expands where it is written. #source.line on line 40 evaluates to 40; #source.function inside func Parse evaluates to "Parse". The value is a plain literal by the time the program runs.
Build Stamps
Because #build.date and #build.time are constant expressions, they can initialize a regular const — a convenient way to embed a build stamp:
import Core::{ #build };
const BuildDate: Slice<char8> = #build.date;
const BuildTime: Slice<char8> = #build.time;
Source Location as a Default Argument
When a #source field is the default value of a parameter, it expands at the call site, so a function learns where it was called from without the caller passing anything — the pattern behind Assert and Panic. See Source Location as a Default Argument for the full example.
See Also
- Build Context — every compiler-provided value in one place
- Intrinsics — how these values are declared and imported
- Constants — declaring your own compile-time constants
Overview
A constant binds a name to a value evaluated at compile time. Constants are declared with const, are always immutable, and must have an explicit type annotation. Unlike let bindings, they may be declared at module scope, which makes them the natural home for shared limits and mathematical values.
Overview
An operation combines one or more values with an operator to produce a result. Rux groups its operators into the categories below; each has a dedicated page with the full operator list, semantics, and examples.