Skip to content

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

jule
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

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

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.

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): str

Returns path of file as constant expression.

Name

jule
fn Name(self): str

Returns name of file as constant expression.

Dir

jule
fn Dir(self): str

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): str

Returns name of declaration. Returns as constant expression.

Public

jule
fn Public(self): bool

Reports whether type is public as constant expression.

Binded

jule
fn Binded(self): bool

Reports whether type is binded as constant expression.

Exceptional

jule
fn Exceptional(self): bool

Reports whether function type is exceptional 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.

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.

Strict

jule
fn Strict(self): bool

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

Kind

jule
fn Kind(self): Kind

Returns Kind of type. Returns as constant expression.

Str

jule
fn Str(self): str

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.

Elem

jule
fn Elem(self): comptimeTypeInfo

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

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 map types.

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.

Binded

jule
fn Binded(self): bool

Reports whether type is binded 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, 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

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

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

Method

jule
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

jule
fn Unwrap(self)

Unwraps expression for runtime execution.

Kind

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