std/comptime
Index
Variables
fn TypeAlias(name: 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 Bind(*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): int
fn Str(*self): str
fn Decl(*self): comptimeDecl
fn Bits(*self): int
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 Bind(*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, name: str): comptimeValue
fn FieldByIndex(*self, index: int): comptimeValue
fn Method(*self, name: str): comptimeValue
fn Unwrap(*self)
enum Kind
Variables
const (
Void = iota // 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
Cmplx64 // cmplx64
Cmplx128 // cmplx128
)Type kinds.
TypeAlias
fn TypeAlias(name: str, t: T)Emplaces a type alias declaration to statement which is this function called. Defines a type alias with identifier which is alias for t. The parameter t can take type declarations or comptimeTypeInfo only.
Line
fn Line(): intReturns line number of statement which is this function called. Returns as constant expression.
File
fn File(): comptimeFileReturns file wrapper of source file which is this function called.
Files
fn Files(): comptimeFilesReturns file wrappers for source files of package which is this function called.
TypeOf
fn TypeOf(t: T): comptimeTypeInfoReturns 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::Slice:
const match type t.Value().Kind() {
| comptime::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): comptimeValueReturns 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 comptimeFilesPrivate 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 comptimeFilePrivate compile-time file information wrapper. Provides interface for source file representation of compiler analysis.
Path
fn Path(*self): strReturns path of file as constant expression.
Name
fn Name(*self): strReturns name of file as constant expression.
Dir
fn Dir(*self): strReturns directory of file as constant expression.
comptimeDecls
struct comptimeDeclsPrivate 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 comptimeDeclPrivate 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): strReturns name of declaration. Returns as constant expression.
Public
fn Public(*self): boolReports whether type is public as constant expression.
Bind
fn Bind(*self): boolReports whether type is bind as constant expression.
Exceptional
fn Exceptional(*self): boolReports whether function type is exceptional as constant expression. Only supports function types.
Mutable
fn Mutable(*self): boolReports whether declaration is mutable as constant expression. Supports variables, fields, and parameters.
Variadic
fn Variadic(*self): boolReports whether declaration is variadic as constant expression. Supports parameters.
Reference
fn Reference(*self): boolReports whether declaration is reference as constant expression. Supports variables, and parameters.
Params
fn Params(*self): comptimeDeclsReturns declaration information wrappers for function's parameters. Supports only function types.
Fields
fn Fields(*self): comptimeDeclsReturns declaration information wrappers for fields. Supports only structure and enum types.
Methods
fn Methods(*self): comptimeDeclsReturns declaration information wrappers for methods. Supports only structures and traits.
fn Tags(*self): intReturns count of tags as constant expression. Supports only structure fields.
Tag
fn Tag(*self, key: str): strReturns the value of the tag corresponding to the key as a constant expression. Supports only structure fields. Parameter key should be constant. Returns empty string if key is not exist in the tags.
IsTag
fn IsTag(*self, key: str): boolReports whether the key is exist in tags as a constant expression. Supports only structure fields. Parameter key should be constant.
comptimeTypeInfos
struct comptimeTypeInfosPrivate 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 comptimeTypeInfoPrivate compile-time type information wrapper. Supports the == and != operators to compare types.
Hash
fn Hash(*self): uintptrReturns unique hash for type as constant uintptr expression. Hash value is not fixed, it changes with each compilation.
Strict
fn Strict(*self): boolReports whether type is constructed by a strict type alias as constant expression.
Source
fn Source(*self): comptimeTypeInfoReturns source type of strict type alias.
ActualSource
fn ActualSource(*self): comptimeTypeInfoReturns actual source type of strict type alias.
Kind
fn Kind(*self): KindReturns Kind of type. Returns as constant expression.
Str
fn Str(*self): strReturns string value of type (not actual type). Returns as constant expression.
Decl
fn Decl(*self): comptimeDeclReturns 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): intReturns bitsize of type. Supports only primitive integer and floating-point types. Returns as constant expression.
Size
fn Size(*self): intReturns size of array. Returns as constant expression. Returns zero if array type is auto-sized declaration.
Key
fn Key(*self): comptimeTypeInfoReturns type information for key type. Supports only map types.
Value
fn Value(*self): comptimeTypeInfoReturns type information for value type. Supports only raw pointers (except unsafe pointer), smart pointers, arrays, slices, channels, enums, and maps.
Fields
fn Fields(*self): comptimeStructFields | comptimeEnumFieldsReturns field information for type. Supports only structure and enum types.
Params
fn Params(*self): comptimeParamsReturns parameter information for function's parameters. Supports only function types.
Types
fn Types(*self): comptimeTypeInfosReturns comptime-type information for tuple types. Supports only tuple types.
Result
fn Result(*self): comptimeTypeInfoReturns compile-time information data for result type of function. Only supports function types.
Bind
fn Bind(*self): boolReports whether type is bind as constant expression.
Ordered
fn Ordered(*self): boolReports whether kind supports ordered constraint as constant expression.
Comparable
fn Comparable(*self): boolReports whether kind supports comparable constraint as constant expression.
Mutable
fn Mutable(*self): boolReports whether kind is mutable as constant expression.
CanNil
fn CanNil(*self): boolReports whether kind is nil-compatible as constant expression.
GC
fn GC(*self): boolReports whether kind performs garbage collection as constant expression.
comptimeStructFields
struct comptimeStructFieldsPrivate 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 comptimeStructFieldPrivate compile-time struct field information wrapper.
Decl
fn Decl(*self): comptimeDeclReturns declaration information for field.
Type
fn Type(*self): comptimeTypeInfoReturns type information for field.
comptimeEnumFields
struct comptimeEnumFieldsPrivate 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 comptimeEnumFieldDecl
fn Decl(*self): comptimeDeclReturns declaration information for field.
comptimeParams
struct comptimeParamsPrivate 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 comptimeParamPrivate compile-time function parameter information wrapper.
Decl
fn Decl(*self): comptimeDeclReturns declaration information for parameter.
Recv
fn Recv(*self): boolReports whether parameter is receiver as constant expression.
Type
fn Type(*self): comptimeTypeInfoReturns type information for parameter.
comptimeValue
struct comptimeValuePrivate compile-time value information wrapper. Only supports classic expressions.
Type
fn Type(*self): comptimeTypeInfoReturns type information for value.
Lvalue
fn Lvalue(*self): boolReports whether value is lvalue as constant expression.
Mutable
fn Mutable(*self): boolReports whether value is mutable as constant expression.
Const
fn Const(*self): boolReports whether value is constant as constant expression.
Field
fn Field(*self, name: str): comptimeValueReturns comptimeValue for field access expression. Supports only structure types. Parameter name should be constant. It allows access to private fields.
FieldByIndex
fn FieldByIndex(*self, index: int): comptimeValueSame as the Field method, but takes constant index instead of name.
Method
fn Method(*self, name: str): comptimeValueReturns comptimeValue for method access expression. Supports only structure types. Parameter name 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.