Intrinsics provide compile-time metadata, reflection, and type manipulation — accessed via the @ prefix.
// Check type kind
let isPrim = (T is @primitive); // bool, i32, f64, etc.
let isStr = (T is @struct); // struct
let isComp = (T is @component); // component
let isUn = (T is @union); // union
let isEn = (T is @enum); // enum
// Check nullability
let nullable = (T is @nullable); // ?T
// Iterate fields of a struct
for (member in @members(MyStruct)) {
@println("{}: {}", member.name, member.type);
}
// Get field visibility
for (field in @fields(MyStruct)) {
@println("{}: {}", field.name, field.visibility); // pub, mod, private
}
You can create types and modify them before they are "finalised":
// Create a new type
type Custom = @struct;
// Add fields — allowed while type is not yet returned/instantiated
@appendField Custom, x: i32;
@appendField Custom, y: f32;
// Add methods
@appendMethod Custom, fn distance(self): f32 { sqrt(self.x*self.x + self.y*self.y) }
// Type is "done" once returned or instantiated
let p: Custom = Custom { x: 1, y: 2.0 };
ℹ Note: Primitive aliases are immutable — you cannot add fields to type Celsius = i32.
let pack = @pack closure; // extract the capture pack from a closure
@pack closure = pack; // inject a pack into a closure
const ARRAY_SIZE = @sizeOf([10]i32) / @sizeOf(i32); // evaluated at compile time
const MEM_LAYOUT = @members(MyStruct); // struct member info
| Intrinsic | Description |
|---|---|
@primitive |
Check if a type is a primitive |
@struct |
Check if a type is a struct |
@component |
Check if a type is a component |
@union |
Check if a type is a union |
@enum |
Check if a type is an enum |
@nullable |
Check if a type is ?T |
@members(T) |
Iterate struct fields (name, type) |
@fields(T) |
Iterate struct fields with visibility |
@appendField T, name: type |
Add a field to a type at compile time |
@appendMethod T, fn ... |
Add a method to a type at compile time |
@pack closure |
Extract / inject a closure's capture pack |
@allocate(T, init) |
Allocate within the current scene |
@sizeOf(T) |
Size of type in bytes |
See also: Spec: Comptime
Related: Type System | Functions