std/comptime
Index
fn TypeAlias(ident: str, t: T)
fn Line(): int
fn File(): comptimeFile
fn Files(): comptimeFiles
fn TypeOf(t: Type): comptimeTypeInfo
fn ValueOf(v: V): comptimeValue
struct comptimeFiles
struct comptimeFile
fn Path(self): str
fn Name(self): str
fn Dir(self): str
struct comptimeDecls
struct comptimeDecl
fn Name(self): str
fn Public(self): bool
fn Binded(self): bool
fn Exceptional(self): bool
fn Mutable(self): bool
fn Variadic(self): bool
fn Reference(self): bool
fn Params(self): comptimeDecls
fn Fields(self): comptimeDecls
fn Methods(self): comptimeDecls
struct comptimeTypeInfos
struct comptimeTypeInfo
fn Strict(self): bool
fn Kind(self): Kind
fn Str(self): str
fn Decl(self): comptimeDecl
fn Bits(self): int
fn Elem(self): comptimeTypeInfo
fn Size(self): int
fn Key(self): comptimeTypeInfo
fn Value(self): comptimeTypeInfo
fn Fields(self): comptimeStructFields | comptimeEnumFields
fn Params(self): comptimeParams
fn Types(self): comptimeTypeInfos
fn Result(self): comptimeTypeInfo
fn Binded(self): bool
fn Ordered(self): bool
fn Comparable(self): bool
fn Mutable(self): bool
fn CanNil(self): bool
fn GC(self): bool
struct comptimeStructFields
struct comptimeStructField
fn Decl(self): comptimeDecl
fn Type(self): comptimeTypeInfo
struct comptimeEnumFields
struct comptimeEnumField
fn Decl(self): comptimeDecl
struct comptimeParams
struct comptimeParam
fn Decl(self): comptimeDecl
fn Recv(self): bool
fn Type(self): comptimeTypeInfo
struct comptimeValue
fn Type(self): comptimeTypeInfo
fn Lvalue(self): bool
fn Mutable(self): bool
fn Const(self): bool
fn Field(self, ident: str): comptimeValue
fn FieldByIndex(self, index: int): comptimeValue
fn Method(self, ident: str): comptimeValue
fn Unwrap(self)
enum Kind
TypeAlias
fn TypeAlias(ident: str, t: T)
Emplaces a type alias declaration to statement which is this function called. Defines a type alias with ident which is alias for t. The parameter t can take type declarations or comptimeTypeInfo only.
Line
fn Line(): int
Returns line number of statement which is this function called. Returns as constant expression.
File
fn File(): comptimeFile
Returns file wrapper of source file which is this function called.
Files
fn Files(): comptimeFiles
Returns file wrappers for source files of package which is this function called.
TypeOf
fn TypeOf(t: T): comptimeTypeInfo
Returns compile-time type information. Cannot assign to memory, just available in compile-time. The expression is evaluated to determine type in compile-time and will not executed at runtime.
INFO
All type information functionalities uses actual type (may there are exception cases). To examine and match actual types, comptime type information handling is useful.
For example:
type ByteSlice: []byte
const t = comptime::TypeOf(ByteSlice)
const match type t.Kind() {
| comptime::Kind.Slice:
const match type t.Elem().Kind() {
| comptime::Kind.Byte:
// ...
}
}
In the example code above, the ByteSlice type is a strict type alias. But we can examine the actual type with comptime type information API.
ValueOf
fn ValueOf(v: V): comptimeValue
Returns compile-time value information. Cannot assign to memory, just available in compile-time. The expression is evaluated to determine and handle value in compile-time and will not executed at runtime.
comptimeFiles
struct comptimeFiles
Private compile-time information wrapper for source files. Supports iterable and indexing implementations. Using with built-in len function returns count of files as constant expression.
comptimeFile
struct comptimeFile
Private compile-time file information wrapper. Provides interface for source file representation of compiler analysis.
Path
fn Path(self): str
Returns path of file as constant expression.
Name
fn Name(self): str
Returns name of file as constant expression.
Dir
fn Dir(self): str
Returns directory of file as constant expression.
comptimeDecls
struct comptimeDecls
Private compile-time information wrapper for comptimeDecl. Supports iterable and indexing implementations. Using with built-in len function returns count of files as constant expression.
comptimeDecl
struct comptimeDecl
Private compile-time declaration information wrapper. Designed for general declarations, not for instantiated/analyzed types.
List of supported types:
- variables
- functions (with parameters)
- traits (with methods)
- enums (with fields)
- type enums
- structs (with fields and methods)
- type aliases
Name
fn Name(self): str
Returns name of declaration. Returns as constant expression.
Public
fn Public(self): bool
Reports whether type is public as constant expression.
Binded
fn Binded(self): bool
Reports whether type is binded as constant expression.
Exceptional
fn Exceptional(self): bool
Reports whether function type is exceptional as constant expression. Only supports function types.
Mutable
fn Mutable(self): bool
Reports whether declaration is mutable as constant expression. Supports variables, fields, and parameters.
Variadic
fn Variadic(self): bool
Reports whether declaration is variadic as constant expression. Supports parameters.
Reference
fn Reference(self): bool
Reports whether declaration is reference as constant expression. Supports variables, and parameters.
Params
fn Params(self): comptimeDecls
Returns declaration information wrappers for function's parameters. Supports only function types.
Fields
fn Fields(self): comptimeDecls
Returns declaration information wrappers for fields. Supports only structure and enum types.
Methods
fn Methods(self): comptimeDecls
Returns declaration information wrappers for methods. Supports only structures and traits.
comptimeTypeInfos
struct comptimeTypeInfos
Private compile-time information wrapper for type infos. Supports iterable and indexing implementations. Using with built-in len function returns count of fields as constant expression.
comptimeTypeInfo
struct comptimeTypeInfo
Private compile-time type information wrapper. Supports the == and != operators to compare types.
Strict
fn Strict(self): bool
Reports whether type is constructed by a strict type alias as constant expression.
Kind
fn Kind(self): Kind
Returns Kind of type. Returns as constant expression.
Str
fn Str(self): str
Returns string value of type (not actual type). Returns as constant expression.
Decl
fn Decl(self): comptimeDecl
Returns declaration information for type. Supports only structs, traits, enums, type enums, and functions. For structures that constructed by the strict type alias, it returns declaration information for the relevant implicit struct declaration.
Bits
fn Bits(self): int
Returns bitsize of type. Supports only primitive integer and floating-point types. Returns as constant expression.
Elem
fn Elem(self): comptimeTypeInfo
Returns comptimeTypeInfo for element type. Supports only raw pointers (except unsafe pointer), smart pointers, arrays, slices, channels, and enums.
Size
fn Size(self): int
Returns size of array. Returns as constant expression. Returns zero if array type is auto-sized declaration.
Key
fn Key(self): comptimeTypeInfo
Returns type information for key type. Supports only map types.
Value
fn Value(self): comptimeTypeInfo
Returns type information for value type. Supports only map types.
Fields
fn Fields(self): comptimeStructFields | comptimeEnumFields
Returns field information for type. Supports only structure and enum types.
Params
fn Params(self): comptimeParams
Returns parameter information for function's parameters. Supports only function types.
Types
fn Types(self): comptimeTypeInfos
Returns comptime-type information for tuple types. Supports only tuple types.
Result
fn Result(self): comptimeTypeInfo
Returns compile-time information data for result type of function. Only supports function types.
Binded
fn Binded(self): bool
Reports whether type is binded as constant expression.
Ordered
fn Ordered(self): bool
Reports whether kind supports ordered constraint as constant expression.
Comparable
fn Comparable(self): bool
Reports whether kind supports comparable constraint as constant expression.
Mutable
fn Mutable(self): bool
Reports whether kind is mutable as constant expression.
CanNil
fn CanNil(self): bool
Reports whether kind is nil-compatible as constant expression.
GC
fn GC(self): bool
Reports whether kind performs garbage collection as constant expression.
comptimeStructFields
struct comptimeStructFields
Private compile-time information wrapper for struct fields. Supports iterable and indexing implementations. Using with built-in len function returns count of fields as constant expression.
comptimeStruct
struct comptimeStructField
Private compile-time struct field information wrapper.
Decl
fn Decl(self): comptimeDecl
Returns declaration information for field.
Type
fn Type(self): comptimeTypeInfo
Returns type information for field.
comptimeEnumFields
struct comptimeEnumFields
Private compile-time information wrapper for enum fields. Supports iterable and indexing implementations. Using with built-in len function returns count of fields as constant expression.
comptimeEnumField
struct comptimeEnumField
Decl
fn Decl(self): comptimeDecl
Returns declaration information for field.
comptimeParams
struct comptimeParams
Private compile-time information wrapper for function parameters. Supports iterable and indexing implementations. Using with built-in len function returns count of fields as constant expression.
comptimeParam
struct comptimeParam
Private compile-time function parameter information wrapper.
Decl
fn Decl(self): comptimeDecl
Returns declaration information for parameter.
Recv
fn Recv(self): bool
Reports whether parameter is receiver as constant expression.
Type
fn Type(self): comptimeTypeInfo
Returns type information for parameter.
comptimeValue
struct comptimeValue
Private compile-time value information wrapper. Only supports classic expressions.
Type
fn Type(self): comptimeTypeInfo
Returns type information for value.
Lvalue
fn Lvalue(self): bool
Reports whether value is lvalue as constant expression.
Mutable
fn Mutable(self): bool
Reports whether value is mutable as constant expression.
Const
fn Const(self): bool
Reports whether value is constant as constant expression.
Field
fn Field(self, ident: str): comptimeValue
Returns comptimeValue for field access expression. Supports only structure types. Parameter ident should be constant. It allows access to private fields.
FieldByIndex
fn FieldByIndex(self, index: int): comptimeValue
Same as the Field method, but takes constant index instead of identifier.
Method
fn Method(self, ident: str): comptimeValue
Returns comptimeValue for method access expression. Supports only structure types. Parameter ident should be constant. It allows access to private methods. It will not use the actual kind, so this method an provide access to methods of the any strict type alias.
Unwrap
fn Unwrap(self)
Unwraps expression for runtime execution.
Kind
enum Kind {
Void, // Void
Int, // int
Uint, // uint
Uintptr, // uinptr
I8, // i8
I16, // i16
I32, // i32
I64, // i64
U8, // u8
U16, // u16
U32, // u32
U64, // u64
F32, // f32
F64, // f64
Str, // str
Bool, // bool
Any, // any
Array, // Array
Slice, // Slice
Map, // Map
Struct, // Structure
Trait, // Trait
Enum, // Enum
TypeEnum, // Type Enum
Ptr, // Raw pointer
UnsafePtr, // Unsafe raw pointer
SmartPtr, // Smart pointer
Func, // Function
Tuple, // Tuple
Chan, // Channel
}
Type kinds.