Skip to content

std/comptime ​

Index ​

Variables
fn TypeAlias(name: string, t: T)
fn Line(): int
fn File(): comptimeFile
fn Files(): comptimeFiles
fn Typeof(t: Type): comptimeTypeInfo
fn Valueof(v: V): comptimeValue
fn IncludeBytes(path: string): []string
fn IncludeString(path: string): []string
fn HasTag(tag: string): bool
struct comptimeFiles
struct comptimeFile
    fn Path(*self): string
    fn Name(*self): string
    fn Dir(*self): string
struct comptimeDecls
struct comptimeDecl
    fn Name(*self): string
    fn Public(*self): bool
    fn Extern(*self): bool
    fn Fallible(*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 String(*self): string
    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 Extern(*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: string): comptimeValue
    fn FieldByIndex(*self, index: int): comptimeValue
    fn Method(*self, name: string): comptimeValue
    fn Unwrap(*self)
enum Kind

Variables ​

jule
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
	String      // string
	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 ​

jule
fn TypeAlias(name: string, 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 ​

jule
fn Line(): int

Returns line number of statement which is this function called. Returns as constant expression.

File ​

jule
fn File(): comptimeFile

Returns file wrapper of source file which is this function called.

Files ​

jule
fn Files(): comptimeFiles

Returns file wrappers for source files of package which is this function called.

Typeof ​

jule
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:

jule
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 ​

jule
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.

IncludeBytes ​

jule
fn IncludeBytes(path: string): []byte

Returns the contents of the file at path as a byte slice. The file path is resolved relative to the file path of the package in which the function is called. In other words, the file is searched for in the directory of the package that contains the source file calling the function.

IncludeString ​

jule
fn IncludeString(path: string): []byte

Returns the contents of the file at path as constant string. The file path is resolved relative to the file path of the package in which the function is called. In other words, the file is searched for in the directory of the package that contains the source file calling the function.

HasTag ​

jule
fn HasTag(tag: string): bool

Reports whether constant tag string is defined as constant expression.

comptimeFiles ​

jule
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 ​

jule
struct comptimeFile

Private compile-time file information wrapper. Provides interface for source file representation of compiler analysis.

Path ​

jule
fn Path(*self): string

Returns path of file as constant expression.

Name ​

jule
fn Name(*self): string

Returns name of file as constant expression.

Dir ​

jule
fn Dir(*self): string

Returns directory of file as constant expression.

comptimeDecls ​

jule
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 ​

jule
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 ​

jule
fn Name(*self): string

Returns name of declaration. Returns as constant expression.

Public ​

jule
fn Public(*self): bool

Reports whether type is public as constant expression.

Extern ​

jule
fn Extern(*self): bool

Reports whether type is external as constant expression.

Fallible ​

jule
fn Fallible(*self): bool

Reports whether function type is fallible as constant expression. Only supports function types.

Mutable ​

jule
fn Mutable(*self): bool

Reports whether declaration is mutable as constant expression. Supports variables, fields, and parameters.

Variadic ​

jule
fn Variadic(*self): bool

Reports whether declaration is variadic as constant expression. Supports parameters.

Reference ​

jule
fn Reference(*self): bool

Reports whether declaration is reference as constant expression. Supports variables, and parameters.

Params ​

jule
fn Params(*self): comptimeDecls

Returns declaration information wrappers for function's parameters. Supports only function types.

Fields ​

jule
fn Fields(*self): comptimeDecls

Returns declaration information wrappers for fields. Supports only structure and enum types.

Methods ​

jule
fn Methods(*self): comptimeDecls

Returns declaration information wrappers for methods. Supports only structures and traits.

​

jule
fn Tags(*self): int

Returns count of tags as constant expression. Supports only structure fields.

Tag ​

jule
fn Tag(*self, key: string): string

Returns 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 ​

jule
fn IsTag(*self, key: string): bool

Reports whether the key is exist in tags as a constant expression. Supports only structure fields. Parameter key should be constant.

comptimeTypeInfos ​

jule
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 ​

jule
struct comptimeTypeInfo

Private compile-time type information wrapper. Supports the == and != operators to compare types.

Hash ​

jule
fn Hash(*self): uintptr

Returns unique hash for type as constant uintptr expression. Hash value is not fixed, it changes with each compilation.

Strict ​

jule
fn Strict(*self): bool

Reports whether type is constructed by a strict type alias as constant expression.

Source ​

jule
fn Source(*self): comptimeTypeInfo

Returns source type of strict type alias.

ActualSource ​

jule
fn ActualSource(*self): comptimeTypeInfo

Returns actual source type of strict type alias.

Kind ​

jule
fn Kind(*self): Kind

Returns Kind of type. Returns as constant expression.

String ​

jule
fn String(*self): string

Returns string value of type (not actual type). Returns as constant expression.

Decl ​

jule
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 ​

jule
fn Bits(*self): int

Returns bitsize of type. Supports only primitive integer and floating-point types. Returns as constant expression.

Size ​

jule
fn Size(*self): int

Returns size of array. Returns as constant expression. Returns zero if array type is auto-sized declaration.

Key ​

jule
fn Key(*self): comptimeTypeInfo

Returns type information for key type. Supports only map types.

Value ​

jule
fn Value(*self): comptimeTypeInfo

Returns type information for value type. Supports only raw pointers (except unsafe pointer), smart pointers, arrays, slices, channels, enums, and maps.

Fields ​

jule
fn Fields(*self): comptimeStructFields | comptimeEnumFields

Returns field information for type. Supports only structure and enum types.

Params ​

jule
fn Params(*self): comptimeParams

Returns parameter information for function's parameters. Supports only function types.

Types ​

jule
fn Types(*self): comptimeTypeInfos

Returns comptime-type information for tuple types. Supports only tuple types.

Result ​

jule
fn Result(*self): comptimeTypeInfo

Returns compile-time information data for result type of function. Only supports function types.

Extern ​

jule
fn Extern(*self): bool

Reports whether type is external as constant expression.

Ordered ​

jule
fn Ordered(*self): bool

Reports whether kind supports ordered constraint as constant expression.

Comparable ​

jule
fn Comparable(*self): bool

Reports whether kind supports comparable constraint as constant expression.

Mutable ​

jule
fn Mutable(*self): bool

Reports whether kind is mutable as constant expression.

CanNil ​

jule
fn CanNil(*self): bool

Reports whether kind is nil-compatible as constant expression.

GC ​

jule
fn GC(*self): bool

Reports whether kind performs garbage collection as constant expression.

comptimeStructFields ​

jule
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 ​

jule
struct comptimeStructField

Private compile-time struct field information wrapper.

Decl ​

jule
fn Decl(*self): comptimeDecl

Returns declaration information for field.

Type ​

jule
fn Type(*self): comptimeTypeInfo

Returns type information for field.

comptimeEnumFields ​

jule
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 ​

jule
struct comptimeEnumField

Decl ​

jule
fn Decl(*self): comptimeDecl

Returns declaration information for field.

comptimeParams ​

jule
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 ​

jule
struct comptimeParam

Private compile-time function parameter information wrapper.

Decl ​

jule
fn Decl(*self): comptimeDecl

Returns declaration information for parameter.

Recv ​

jule
fn Recv(*self): bool

Reports whether parameter is receiver as constant expression.

Type ​

jule
fn Type(*self): comptimeTypeInfo

Returns type information for parameter.

comptimeValue ​

jule
struct comptimeValue

Private compile-time value information wrapper. Only supports classic expressions.

Type ​

jule
fn Type(*self): comptimeTypeInfo

Returns type information for value.

Lvalue ​

jule
fn Lvalue(*self): bool

Reports whether value is lvalue as constant expression.

Mutable ​

jule
fn Mutable(*self): bool

Reports whether value is mutable as constant expression.

Const ​

jule
fn Const(*self): bool

Reports whether value is constant as constant expression.

Field ​

jule
fn Field(*self, name: string): comptimeValue

Returns comptimeValue for field access expression. Supports only structure types. Parameter name should be constant. It allows access to private fields.

FieldByIndex ​

jule
fn FieldByIndex(*self, index: int): comptimeValue

Same as the Field method, but takes constant index instead of name.

Method ​

jule
fn Method(*self, name: string): comptimeValue

Returns 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 ​

jule
fn Unwrap(*self)

Unwraps expression for runtime execution.