2.1. Built-in runtime¶
The BUILTIN module contains core runtime functions available in all daslang programs
without explicit require. It includes:
Heap and memory management (
heap_bytes_allocated,heap_report,memory_report)Debug output (
print,debug,stackwalk)Panic and error handling (
panic,terminate,assert)Pointer and memory operations (
intptr,malloc,free)Profiling (
profile)Type conversion (
string)
All functions and symbols are in “builtin” module, use require to get access to it.
require builtin
Example:
[export]
def main() {
print("hello, world!\n")
assert(1 + 1 == 2)
let s = string(42)
print("string(42) = {s}\n")
let name = "daslang"
print("welcome to {name}\n")
var arr : array<int>
arr |> push(10)
arr |> push(20)
print("length = {length(arr)}\n")
print("arr[0] = {arr[0]}\n")
}
// output:
// hello, world!
// string(42) = 42
// welcome to daslang
// length = 2
// arr[0] = 10
2.1.1. Type aliases¶
- bitfield print_flags¶
This bitfield specifies how exactly values are to be printed
- Fields:
escapeString (0x1) - if string is to be escaped
namesAndDimensions (0x2) - names of the fields and dimensions of the arrays
typeQualifiers (0x4) - type qualifiers for the specific types like double and uint64
refAddresses (0x8) - addresses in hexadecimal of each reference value
singleLine (0x10) - human readable vs single line
fixedPoint (0x20) - always output fixed point precision for floating point values
fullTypeInfo (0x40) - show full type info on containers (e.g.
array<int>instead of[],fixed_array<int>instead of[],table<int;string>instead of{},tuple<int;float>instead of())
2.1.2. Constants¶
- DAS_MAX_FUNCTION_ARGUMENTS = 32¶
Maximum number of arguments a function can accept, used to pre-allocate stack space for function call arguments.
- INT_MIN = -2147483648¶
Minimum representable value of a signed 32-bit integer (int), equal to -2147483648.
- INT_MAX = 2147483647¶
Maximum representable value of a signed 32-bit integer (int), equal to 2147483647.
- UINT_MAX = 0xffffffff¶
Maximum representable value of an unsigned 32-bit integer (uint), equal to 4294967295.
- LONG_MIN = -9223372036854775808¶
Minimum representable value of a signed 64-bit integer (int64).
- LONG_MAX = 9223372036854775807¶
Maximum representable value of a signed 64-bit integer (int64).
- ULONG_MAX = 0xffffffffffffffff¶
Maximum representable value of an unsigned 64-bit integer (uint64).
- FLT_MIN = 1.1754944e-38f¶
Smallest positive non-zero normalized value of the float type; for the most negative value use -FLT_MAX.
- FLT_MAX = 3.4028235e+38f¶
Maximum finite representable value of the float (32-bit floating-point) type.
- DBL_MIN = 2.2250738585072014e-308lf¶
Smallest positive non-zero normalized value of the double type; for the most negative value use -DBL_MAX.
- DBL_MAX = 1.7976931348623157e+308lf¶
Maximum finite representable value of the double (64-bit floating-point) type.
- LOG_CRITICAL = 50000¶
Log level constant for critical errors such as panics, fatal failures, and shutdown notifications.
- LOG_ERROR = 40000¶
Log level constant for recoverable error conditions that do not require immediate shutdown.
- LOG_WARNING = 30000¶
Log level constant for warnings about potential problems, API misuse, or non-fatal error conditions.
- LOG_INFO = 20000¶
Log level constant for general informational messages about normal program operation.
- LOG_DEBUG = 10000¶
Log level constant for debug-level diagnostic messages useful during development.
- LOG_TRACE = 0¶
Log level constant for the most verbose tracing and diagnostic output, typically used for detailed debugging.
- VEC_SEP = ","¶
Read-only string constant used as the separator between vector components when printing; defaults to “,”.
- print_flags_debugger = bitfield(0xf)¶
Predefined set of print_flags configured to match the output formatting used by the debug function.
2.1.3. Handled structures¶
- HashBuilder¶
Helper structure to facilitate calculating hash values.
2.1.4. Function annotations¶
- deprecated¶
Marks a function as deprecated, causing a compilation warning when referenced and excluding it from the final compiled context.
- never_alias_cmres¶
Declares that the function never aliases cmres (copy-or-move result), disabling aliasing safety checks for the return value.
- unused_argument¶
Suppresses unused-argument warnings or errors for specific function parameters, providing a workaround when strict code policies are enabled.
- export¶
Forces a function to be exported and retained in the final compiled context, even if it is not directly called.
- jit¶
Explicitly forces the annotated function to be compiled using the JIT compiler, overriding default compilation decisions.
- expect_dim¶
Contract annotation requiring a function argument to be a fixed-size (statically dimensioned) array.
- sideeffects¶
Declares that the function has side effects, preventing the compiler from optimizing away or reordering its calls.
- local_only¶
Restricts a function to accept only local make expressions such as structure initializers and tuple constructors.
- macro_function¶
Marks a function as part of the macro subsystem, excluding it from the final compiled context unless it is explicitly referenced.
- generic¶
Forces a function to be treated as generic regardless of its argument types, causing it to be instanced in each calling module.
- unsafe_outside_of_for¶
Marks a function as unsafe to call outside of a source-level for loop, enforcing iterator-context usage.
- finalize¶
Registers a function to be called automatically when the context is shut down, for cleanup and resource release.
- no_aot¶
Prevents ahead-of-time (AOT) C++ code generation for the annotated function, keeping it interpreted only.
- marker¶
Attaches arbitrary key-value annotation arguments to a function, typically used by macros to tag functions with metadata.
- run¶
Forces the function to be evaluated at compile time, ensuring its body executes during compilation rather than at runtime.
- pinvoke¶
Marks a function as a platform invoke (pinvoke) entry, enabling cross-context calls via invoke_in_context, invoke_debug_agent_method, and invoke_debug_agent_function. The annotation adds a context mutex so the function can be safely invoked from another context (including the single thread-local agent context when the category is ""). Functions called cross-context must also be marked [export].
- expect_ref¶
Contract annotation requiring a function argument to be passed by reference.
- clone¶
Marks named parameters as cloned internally by the function (e.g. [clone(expr)] or [clone(expr, replacement)]). Pure metadata — consumed by the PERF024 perf lint to flag callers that wrap those args in clone_expression / clone_type / clone_function / clone_variable / clone_structure, since the outer clone is redundant when the callee already clones.
- unsafe_operation¶
Marks a function as an unsafe operation, requiring callers to wrap the call in an unsafe block.
- type_function¶
Marks a function as a type function, meaning it operates on types at compile time and does not generate runtime code.
- nodiscard¶
Enforces that the return value of the function must be used by the caller; discarding the result produces a compilation error.
- hybrid¶
Marks a function as a hybrid call target so that AOT generates indirect calls to it, allowing the function to be patched without recompiling dependent AOT code.
- init¶
Registers a function to be called automatically during context initialization, before any user code runs.
- no_jit¶
Prevents JIT compilation for the annotated function, forcing it to run in interpreted mode.
- hint¶
Provides optimization hints to the compiler for the annotated function via annotation arguments.
- _macro¶
Marks a function to be executed during the macro compilation pass, similar to [init] but running at macro time.
- unsafe_when_not_clone_array¶
Marks a function as unsafe to call outside of an array clone operation, restricting its usage context.
- unsafe_deref¶
Optimization annotation that removes null-pointer checks, bounds checks on array and string indexing, and similar safety validations.
- expect_any_vector¶
Contract annotation restricting a function argument to accept only das::vector template types.
- builtin_array_sort¶
Internal function annotation that provides the sorting implementation used by the built-in sort function.
- alias_cmres¶
Declares that the function always aliases cmres (copy-or-move result), disabling cmres return optimizations for it.
- no_lint¶
Skips all lint-pass checks for the annotated function, suppressing any lint warnings or errors it would produce.
2.1.5. Call macros¶
- memzero¶
Fills a region of memory with zeros, used internally for default-initializing values.
- make_function_unsafe¶
Propagates the unsafe requirement to the calling function, making any function that calls it also require an unsafe block.
- verify¶
Assertion that preserves the evaluated expression even when asserts are disabled, ensuring side effects are never optimized out.
- __builtin_table_set_insert¶
Internal function annotation that implements the low-level key insertion for set-style tables (tables with keys only).
- invoke¶
Invokes a block, function pointer, or lambda, dispatching the call through the appropriate calling convention.
- static_assert¶
Compile-time assertion that produces a compilation error with an optional message when the condition is false.
- debug¶
Prints the human-readable representation of a value to the log and returns that same value, allowing inline debugging in expressions.
- assert¶
Runtime assertion that panics with an optional error message when the first argument evaluates to false; can be disabled globally.
- __builtin_table_key_exists¶
Internal function annotation that implements the low-level key presence check for the key_exists operation.
- __builtin_table_find¶
Internal function annotation that implements the low-level table lookup for the find operation.
- __builtin_table_erase¶
Internal function annotation that implements the low-level table entry removal for the erase operation.
- concept_assert¶
Compile-time assertion that reports the error at the call site of the asserted function rather than at the assert line itself.
2.1.6. Reader macros¶
- _esc¶
Reader macro that returns the raw string content without processing escape sequences, e.g. %_esc~nr~%_esc yields the literal four characters `, `n, `, `r.
2.1.7. Typeinfo macros¶
- rtti_classinfo¶
Typeinfo macro that generates RTTI TypeInfo metadata required for class initialization and reflection.
2.1.8. Handled types¶
- clock¶
Handled type wrapping das::Time, which encapsulates the C time_t value for calendar time representation.
- das_string¶
Handled type wrapping das::string (typically std::string), providing heap-allocated mutable string storage.
2.1.9. Structure macros¶
- no_default_initializer¶
Prevents the compiler from generating a default initializer for the annotated structure.
- macro_interface¶
Marks a class hierarchy as a macro interface, preventing it and its descendants from being exported by default.
- cpp_layout¶
Forces the structure to use C++ memory layout rules (alignment and padding) instead of native daslang layout.
- persistent¶
Allocates the structure on the C++ heap (via new) instead of the daslang context heap, allowing it to outlive the context.
- comment¶
No-op structure annotation that holds annotation arguments as metadata without affecting code generation.
- safe_when_uninitialized¶
Declares that the structure is safe to access before explicit initialization, suppressing uninitialized-use errors.
2.1.10. Containers¶
each (lam: lambda<(var arg:auto(argT)):bool>) : iterator<argT>
each_ref (lam: lambda<(var arg:auto(argT)?):bool>) : iterator<argT&>
emplace (var Arr: array<auto(numT)>; var value: numT&) : auto
emplace (var Arr: array<auto(numT)>; var value: numT&; at: int|int64) : auto
emplace (var Arr: array<auto(numT)>; var value: numT[]) : auto
emplace (var Arr: array<auto(numT)[]>; var value: numT[]) : auto
emplace (var Tab: table<auto(keyT), auto(valT)>; at: keyT|keyT#; var val: valT&) : auto
emplace (var Tab: table<auto(keyT), auto(valT)[]>; at: keyT|keyT#; var val: valT[]&) : auto
emplace (var Tab: table<auto, auto>; key: auto; value: auto) : auto
emplace_default (var tab: table<auto(keyT), auto(valT)>; key: keyT|keyT#)
emplace_from (var Arr: array<auto(numT)>; var varr: array<numT>) : auto
emplace_from (var Arr: array<auto(numT)>; var varr: numT[]) : auto
emplace_new (var Arr: array<smart_ptr<auto(numT)>>; var value: smart_ptr<numT>) : auto
erase (var Arr: array<auto(numT)>; at: int64; count: int64) : auto
erase (var Arr: array<auto(numT)>; at: int; count: int) : auto
erase (var Tab: table<auto(keyT), auto(valT)>; at: keyT|keyT#) : bool
erase (var Tab: table<auto(keyT), auto(valT)>; at: string#) : bool
find_index (arr: array<auto(TT)>|array<auto(TT)>#; key: TT) : auto
find_index_if (arr: array<auto(TT)>|array<auto(TT)>#; blk: block<(key:TT):bool>) : auto
find_index_if (arr: auto(TT)[]|auto(TT)[]#; blk: block<(key:TT):bool>) : auto
find_index_if (var arr: iterator<auto(TT)>; blk: block<(key:TT):bool>) : auto
get (Tab: table<auto(keyT), auto(valT)>#; at: keyT|keyT#; blk: block<(p:valT const&#):void>) : auto
get (Tab: table<auto(keyT), auto(valT)>; at: keyT|keyT#; blk: block<(p:valT):void>) : auto
get (Tab: table<auto(keyT), void>; at: keyT|keyT#; blk: block<(var p:void?):void>) : auto
get (var Tab: table<auto(keyT), auto(valT)>; at: keyT|keyT#; blk: block<(var p:valT&):void>) : auto
get_key (a: table<auto(keyT), auto(valT)>; value: valT) : keyT
get_key (a: table<auto(keyT), auto(valT)[]>; value: valT const[-2]) : keyT
get_value (Tab: table<auto(keyT), auto(valT)>; at: keyT|keyT#) : valT
get_value (var Tab: table<auto(keyT), auto(valT)>; at: keyT|keyT#) : valT
get_value (var Tab: table<auto(keyT), auto(valT)[]>; at: keyT|keyT#) : valT[-2]
get_value (var Tab: table<auto(keyT), smart_ptr<auto(valT)>>; at: keyT|keyT#) : smart_ptr<valT>
insert (var Tab: table<auto(keyT), void>; at: keyT|keyT#) : auto
insert_default (var tab: table<auto(TT), auto(QQ)>; key: TT|TT#; var value: QQ ==const|QQ# ==const)
insert_default (var tab: table<auto(keyT), auto(valT)>; key: keyT|keyT#)
key_exists (Tab: table<auto(keyT);auto(valT)>|table<auto(keyT);auto(valT)>#; at: keyT|keyT#) : bool
key_exists (Tab: table<auto(keyT);auto(valT)>|table<auto(keyT);auto(valT)>#; at: string#) : bool
modify (var Tab: table<auto(keyT), auto(valT)>; at: keyT|keyT#; blk: block<(p:valT):valT>)
push (var Arr: array<auto(numT)>; value: numT ==const) : auto
push (var Arr: array<auto(numT)>; value: numT ==const; at: int|int64) : auto
push (var Arr: array<auto(numT)>; var value: numT ==const) : auto
push (var Arr: array<auto(numT)>; var value: numT ==const; at: int|int64) : auto
push (var Arr: array<auto(numT)>; var varr: array<numT>) : auto
push (var Arr: array<auto(numT)[]>; var varr: numT[] ==const) : auto
push (var Arr: array<auto(numT)[]>; varr: numT const[] ==const) : auto
push_clone (var Arr: array<auto(numT)>; value: numT ==const|numT const# ==const) : auto
push_clone (var Arr: array<auto(numT)>; var value: numT ==const|numT# ==const) : auto
push_clone (var Arr: array<auto(numT)>; var value: numT ==const|numT# ==const; at: int|int64) : auto
push_clone (var Arr: array<auto(numT)>; var varr: numT[] ==const) : auto
push_clone (var Arr: array<auto(numT)>; varr: numT const[] ==const) : auto
push_clone (var Arr: array<auto(numT)[]>; var varr: numT[]) : auto
push_clone (var Arr: array<auto(numT)[]>; varr: numT const[] ==const) : auto
push_clone_from (var Arr: array<auto(numT)>; var varr: array<numT>) : auto
push_clone_from (var Arr: array<auto(numT)>; var varr: numT[] ==const) : auto
push_clone_from (var Arr: array<auto(numT)>; varr: array<numT>) : auto
push_clone_from (var Arr: array<auto(numT)>; varr: numT const[] ==const) : auto
push_from (var Arr: array<auto(numT)>; var varr: array<numT>) : auto
push_from (var Arr: array<auto(numT)>; varr: array<numT>) : auto
remove_value (var arr: array<auto(TT)>|array<auto(TT)>#; key: TT) : bool
reserve (var Tab: table<auto(keyT), auto>; newSize: int) : auto
reserve (var Tab: table<auto(keyT), auto>; newSize: int64) : auto
resize_and_init (var Arr: array<auto(numT)>; newSize: int|int64) : auto
resize_and_init (var Arr: array<auto(numT)>; newSize: int|int64; initValue: numT) : auto
resize_no_init (var Arr: array<auto(numT)>; newSize: int) : auto
resize_no_init (var Arr: array<auto(numT)>; newSize: int64) : auto
sort (var a: array<auto(TT)>|array<auto(TT)>#; cmp: block<(x:TT;y:TT):bool>) : auto
sort (var a: auto(TT)[]|auto(TT)[]#; cmp: block<(x:TT;y:TT):bool>) : auto
to_table (a: tuple<auto(keyT);auto(valT)>[]) : table<keyT, valT>
to_table_move (var a: array<tuple<auto(keyT);auto(valT)>>) : table<keyT, valT>
to_table_move (var a: tuple<auto(keyT);auto(valT)>) : table<keyT, valT>
to_table_move (var a: tuple<auto(keyT);auto(valT)>[]) : table<keyT, valT>
values (a: table<auto(keyT);void> ==const|table<auto(keyT);void> const# ==const) : auto
values (var a: table<auto(keyT);void> ==const|table<auto(keyT);void># ==const) : auto
2.1.10.1. back¶
- back(a: array<auto(TT)>#): TT const&#¶
Accesses and returns a const temporary reference to the last element of the temporary dynamic array a.
- Arguments:
a : array<auto(TT)>#!
- back(a: array<auto(TT)>): TT
- back(arr: auto(TT) ==const): auto
- back(a: array<auto(TT)>#): TT&#
- back(a: array<auto(TT)>): TT&
- back(arr: auto(TT) ==const): auto&
2.1.10.2. capacity¶
- capacity(array: array<anything>): int¶
Returns the current capacity of the table — the number of key-value pairs it can hold before triggering a reallocation.
- Arguments:
array : array implicit
- capacity(table: table<anything, anything>): int
2.1.10.3. clear¶
- clear(array: array<anything>)¶
Removes all elements from the dynamic array, leaving it empty with a size of 0.
- Arguments:
array : array implicit
- clear(t: table<auto(KT), auto(VT)>): auto
- copy_to_local(a: auto(TT)): TT¶
Copies the value a and returns it as a new local value on the stack, which can be used to work around aliasing issues where a reference might be invalidated.
- Arguments:
a : auto(TT)
2.1.10.4. each¶
- each(a: array<auto(TT)>#): iterator<TT&#>¶
Creates an iterator that yields temporary references to each element of the temporary dynamic array a.
- Arguments:
a : array<auto(TT)>#
- each(a: array<auto(TT)>): iterator<TT&>
- each(a: auto(TT)[]): iterator<TT&>
- each(lam: lambda<(var arg:auto(argT)):bool>): iterator<argT>
- each(rng: range): iterator<int>
- each(rng: range64): iterator<int64>
- each(rng: urange): iterator<uint>
- each(rng: urange64): iterator<uint64>
- each(str: string): iterator<int>
- each_enum(tt: auto(TT)): iterator<TT>¶
Warning
This function is deprecated.
Creates an iterator that yields every value of the enumeration type inferred from tt, allowing iteration over all members of an enum.
- Arguments:
tt : auto(TT)
- each_ref(lam: lambda<(var arg:auto(argT)?):bool>): iterator<argT&>¶
Wraps a lambda lam — which receives a mutable pointer argument and returns a bool indicating whether to continue — into an iterator that yields references to each value rather than copies.
- Arguments:
lam : lambda<(arg:auto(argT)?):bool>
2.1.10.5. emplace¶
- emplace(Arr: array<auto(numT)>; value: numT&): auto¶
Moves value into the dynamic array Arr using move semantics, appending it to the end.
- Arguments:
Arr : array<auto(numT)>
value : numT&
- emplace(Arr: array<auto(numT)>; value: numT&; at: int|int64): auto
- emplace(Arr: array<auto(numT)>; value: numT[]): auto
- emplace(Arr: array<auto(numT)[]>; value: numT[]): auto
- emplace(Tab: table<auto(keyT), auto(valT)>; at: keyT|keyT#; val: valT&): auto
- emplace(Tab: table<auto(keyT), auto(valT)[]>; at: keyT|keyT#; val: valT[]&): auto
- emplace(Tab: table<auto(keyT), smart_ptr<auto(valT)>>; at: keyT|keyT#; val: smart_ptr<valT>&): auto
- emplace(Tab: table<auto, auto>; key: auto; value: auto): auto
- emplace(a: array<auto>; value: auto): auto
- emplace_default(tab: table<auto(keyT), auto(valT)>; key: keyT|keyT#)¶
Constructs a new default-initialized element in the table tab at the given key, only if that key does not already exist.
- Arguments:
tab : table<auto(keyT);auto(valT)>
key : option<keyT| keyT#>
2.1.10.6. emplace_from¶
- emplace_from(Arr: array<auto(numT)>; varr: array<numT>): auto¶
Bulk-moves every element of source varr (an array or fixed-size C-array) into Arr via <-. Reserves the combined capacity up front; the source is consumed.
- Arguments:
Arr : array<auto(numT)>
varr : array<numT>!
- emplace_from(Arr: array<auto(numT)>; varr: numT[]): auto
2.1.10.7. emplace_new¶
- emplace_new(Arr: array<smart_ptr<auto(numT)>>; value: smart_ptr<numT>): auto¶
Moves a smart pointer value into the end of the array Arr, constructing the entry in-place and returning a reference to it.
- Arguments:
Arr : array<smart_ptr<auto(numT)>>
value : smart_ptr<numT>
- emplace_new(tab: table<auto(kT), smart_ptr<auto(vT)>>; key: kT; value: smart_ptr<vT>): auto
2.1.10.8. empty¶
- empty(a: array<auto>|array<auto>#): bool¶
Checks whether the array a has no elements and returns true if so.
- Arguments:
a : option<array<auto>| array<auto>#>
- empty(a: table<auto;auto>|table<auto;auto>#): bool
- empty(iterator: iterator): bool
- empty(str: das_string): bool
- empty(str: string): bool
2.1.10.9. erase¶
- erase(Arr: array<auto(numT)>; at: int): auto¶
Removes the entry with key at from the table Tab, returning true if the key was found and erased.
- Arguments:
Arr : array<auto(numT)>
at : int
- erase(Arr: array<auto(numT)>; at: int64): auto
- erase(Arr: array<auto(numT)>; at: int64; count: int64): auto
- erase(Arr: array<auto(numT)>; at: int; count: int): auto
- erase(Tab: table<auto(keyT), auto(valT)>; at: keyT|keyT#): bool
- erase(Tab: table<auto(keyT), auto(valT)>; at: string#): bool
- erase_if(arr: array<auto(TT)>; blk: block<(key:TT const):bool>|block<(var key:TT&):bool>): auto¶
Iterates over the array arr and removes all elements for which the block blk returns true.
- Arguments:
arr : array<auto(TT)>
blk : option<block<(key:TT):bool>| block<(key:TT&):bool>>
2.1.10.10. find_index¶
- find_index(arr: array<auto(TT)>|array<auto(TT)>#; key: TT): auto¶
Searches the dynamic array arr for the first occurrence of key and returns its index, or -1 if not found.
- Arguments:
arr : option<array<auto(TT)>| array<auto(TT)>#>
key : TT
- find_index(arr: auto(TT)[]|auto(TT)[]#; key: TT): auto
- find_index(arr: iterator<auto(TT)>; key: TT): auto
2.1.10.11. find_index_if¶
- find_index_if(arr: array<auto(TT)>|array<auto(TT)>#; blk: block<(key:TT):bool>): auto¶
Returns the index of the first element in the fixed array arr for which blk returns true, or -1 if no element matches.
- Arguments:
arr : option<array<auto(TT)>| array<auto(TT)>#>
blk : block<(key:TT):bool>
- find_index_if(arr: auto(TT)[]|auto(TT)[]#; blk: block<(key:TT):bool>): auto
- find_index_if(arr: iterator<auto(TT)>; blk: block<(key:TT):bool>): auto
2.1.10.12. get¶
- get(Tab: table<auto(keyT), auto(valT)>#; at: keyT|keyT#; blk: block<(p:valT const&#):void>): auto¶
Looks up at in the table Tab and, if found, invokes blk with a reference to the value; returns true if the key existed, false otherwise.
- Arguments:
Tab : table<auto(keyT);auto(valT)>#!
at : option<keyT| keyT#>
blk : block<(p:valT&#):void>
- get(Tab: table<auto(keyT), auto(valT)>; at: keyT|keyT#; blk: block<(p:valT):void>): auto
- get(Tab: table<auto(keyT), auto(valT)[]>#; at: keyT|keyT#; blk: block<(p:valT const[-2]&#):void>): auto
- get(Tab: table<auto(keyT), auto(valT)[]>; at: keyT|keyT#; blk: block<(p:valT const[-2]&):void>): auto
- get(Tab: table<auto(keyT), void>; at: keyT|keyT#; blk: block<(var p:void?):void>): auto
- get(Tab: table<auto(keyT), auto(valT)>#; at: keyT|keyT#; blk: block<(var p:valT&#):void>): auto
- get(Tab: table<auto(keyT), auto(valT)>; at: keyT|keyT#; blk: block<(var p:valT&):void>): auto
- get(Tab: table<auto(keyT), auto(valT)[]>#; at: keyT|keyT#; blk: block<(var p:valT[-2]&#):void>): auto
- get(Tab: table<auto(keyT), auto(valT)[]>; at: keyT|keyT#; blk: block<(var p:valT[-2]&):void>): auto
2.1.10.13. get_key¶
- get_key(a: table<auto(keyT), auto(valT)>; value: valT): keyT¶
Returns the key associated with a value reference obtained during table iteration.
The value must be a reference from a values() iterator on the same table.
Computes the key via O(1) pointer arithmetic on the parallel key/value arrays.
Throws an error if the value pointer is not inside the table or points to a deleted slot.
- Arguments:
a : table<auto(keyT);auto(valT)>
value : valT&
- get_key(a: table<auto(keyT), auto(valT)[]>; value: valT const[-2]): keyT
- get_key(a: table<auto(keyT), void>; value: auto): auto
2.1.10.14. get_value¶
- get_value(Tab: table<auto(keyT), auto(valT)>; at: keyT|keyT#): valT¶
Retrieves the value associated with key at from the table Tab.
- Arguments:
Tab : table<auto(keyT);auto(valT)>!
at : option<keyT| keyT#>
- get_value(Tab: table<auto(keyT), auto(valT)>; at: keyT|keyT#): valT
- get_value(Tab: table<auto(keyT), auto(valT)[]>; at: keyT|keyT#): valT[-2]
- get_value(Tab: table<auto(keyT), smart_ptr<auto(valT)>>; at: keyT|keyT#): smart_ptr<valT>
- get_with_default(Tab: table<auto(keyT), auto(valT)>; at: keyT|keyT#; blk: block<(var p:valT&):void>)¶
Looks up key at in the table Tab, inserting a default-initialized entry if the key is absent, then invokes blk with a mutable reference to the value.
- Arguments:
Tab : table<auto(keyT);auto(valT)>!
at : option<keyT| keyT#>
blk : block<(p:valT&):void>
2.1.10.15. has_value¶
- has_value(a: auto; key: auto): auto¶
Consumes elements from the iterator a and returns true if any element equals key.
- Arguments:
a : auto
key : auto
- has_value(a: iterator<auto>; key: auto): auto
2.1.10.16. insert¶
- insert(Tab: table<auto(keyT), auto(valT)>; at: keyT|keyT#; val: valT ==const|valT const# ==const): auto¶
Inserts the value val into the table Tab under key at. If the key already exists, its value is replaced.
- Arguments:
Tab : table<auto(keyT);auto(valT)>
at : option<keyT| keyT#>
val : option<valT!| valT#!>
- insert(Tab: table<auto(keyT), auto(valT)>; at: keyT|keyT#; val: valT ==const|valT# ==const): auto
- insert(Tab: table<auto(keyT), auto(valT)[]>; at: keyT|keyT#; val: valT const[] ==const|valT const[]# ==const): auto
- insert(Tab: table<auto(keyT), auto(valT)[]>; at: keyT|keyT#; val: valT[] ==const|valT[]# ==const): auto
- insert(Tab: table<auto(keyT), void>; at: keyT|keyT#): auto
2.1.10.17. insert_clone¶
- insert_clone(Tab: table<auto(keyT), auto(valT)>; at: keyT|keyT#; val: valT ==const|valT const# ==const): auto¶
Inserts or updates an entry in the table Tab at key at by cloning the mutable value val into the table.
- Arguments:
Tab : table<auto(keyT);auto(valT)>
at : option<keyT| keyT#>
val : option<valT!| valT#!>
- insert_clone(Tab: table<auto(keyT), auto(valT)>; at: keyT|keyT#; val: valT ==const|valT# ==const): auto
- insert_clone(Tab: table<auto(keyT), auto(valT)[]>; at: keyT|keyT#; val: valT const[] ==const|valT const[]# ==const): auto
- insert_clone(Tab: table<auto(keyT), auto(valT)[]>; at: keyT|keyT#; val: valT[] ==const|valT[]# ==const): auto
2.1.10.18. insert_default¶
- insert_default(tab: table<auto(TT), auto(QQ)>; key: TT|TT#; value: QQ ==const|QQ# ==const)¶
Inserts key key with the given const value into table tab only if the key does not already exist; existing entries are left unchanged.
- Arguments:
tab : table<auto(TT);auto(QQ)>
key : option<TT| TT#>
value : option<QQ!| QQ#!>
- insert_default(tab: table<auto(keyT), auto(valT)>; key: keyT|keyT#)
- insert_default(tab: table<auto(keyT), auto(valT)>; key: keyT|keyT#; value: valT ==const|valT const# ==const)
2.1.10.19. key_exists¶
- key_exists(Tab: table<auto(keyT);auto(valT)>|table<auto(keyT);auto(valT)>#; at: keyT|keyT#): bool¶
Checks whether the key at exists in the table Tab and returns true if found.
- Arguments:
Tab : option<table<auto(keyT);auto(valT)>| table<auto(keyT);auto(valT)>#>
at : option<keyT| keyT#>
- key_exists(Tab: table<auto(keyT);auto(valT)>|table<auto(keyT);auto(valT)>#; at: string#): bool
2.1.10.20. keys¶
- keys(a: table<auto(keyT);auto(valT)> ==const|table<auto(keyT);auto(valT)> const# ==const): iterator<keyT>¶
Creates an iterator over all keys of the mutable table a, allowing enumeration of the table’s key set.
- Arguments:
a : option<table<auto(keyT);auto(valT)>!| table<auto(keyT);auto(valT)>#!>
- keys(a: table<auto(keyT);auto(valT)> ==const|table<auto(keyT);auto(valT)># ==const): iterator<keyT>
2.1.10.21. length¶
- length(a: auto|auto#): int¶
Returns the number of elements currently stored in a table or dynamic array a.
- Arguments:
a : option<auto| auto#>
- length(array: array<anything>): int
- length(table: table<anything, anything>): int
2.1.10.22. lock¶
- lock(Tab: table<auto(keyT);auto(valT)>|table<auto(keyT);auto(valT)>#; blk: block<(t:table<keyT, valT>#):void>): auto¶
Locks a constant table for the duration of blk, preventing structural modifications while providing read-only access through a temporary reference.
- Arguments:
Tab : option<table<auto(keyT);auto(valT)>| table<auto(keyT);auto(valT)>#>
blk : block<(t:table<keyT;valT>#):void>
- lock(a: array<auto(TT)> ==const|array<auto(TT)> const# ==const; blk: block<(x:array<TT>#):auto>): auto
- lock(a: array<auto(TT)> ==const|array<auto(TT)># ==const; blk: block<(var x:array<TT>#):auto>): auto
- lock_forever(Tab: table<auto(keyT);auto(valT)>|table<auto(keyT);auto(valT)>#): table<keyT, valT>#¶
Permanently locks a table, preventing any future insertions, deletions, or structural modifications, and returns a temporary reference to it.
- Arguments:
Tab : option<table<auto(keyT);auto(valT)>| table<auto(keyT);auto(valT)>#>
- modify(Tab: table<auto(keyT), auto(valT)>; at: keyT|keyT#; blk: block<(p:valT):valT>)¶
Looks up at in Tab and, if found, invokes blk with the current value, replacing it with the value returned by the block.
- Arguments:
Tab : table<auto(keyT);auto(valT)>!
at : option<keyT| keyT#>
blk : block<(p:valT&):valT>
- move_to_local(a: auto(TT)&): TT¶
Moves the value referenced by a onto the stack as a local copy and returns it, clearing the original; useful for resolving aliasing issues.
- Arguments:
a : auto(TT)&
- move_to_ref(a: auto&; b: auto): auto¶
Moves b into the reference a; if b is a value type rather than a reference, it is copied instead of moved.
- Arguments:
a : auto&
b : auto
- next(it: iterator<auto(TT)>; value: TT&): bool¶
Advances the iterator it and stores the next element in value, returning true if an element was retrieved or false if the iterator is exhausted or null.
- Arguments:
it : iterator<auto(TT)>
value : TT&
- nothing(it: iterator<auto(TT)>): iterator<TT>¶
Produces an empty iterator of the same element type as it that yields no elements.
- Arguments:
it : iterator<auto(TT)>
- pop(Arr: array<auto(numT)>): auto¶
Removes and discards the last element of Arr, reducing its length by one.
- Arguments:
Arr : array<auto(numT)>
2.1.10.23. push¶
- push(Arr: array<auto(numT)>; value: numT ==const): auto¶
Appends a constant value to the end of dynamic array Arr, copying it into place.
- Arguments:
Arr : array<auto(numT)>
value : numT!
- push(Arr: array<auto(numT)>; value: numT ==const; at: int|int64): auto
- push(Arr: array<auto(numT)>; value: numT ==const): auto
- push(Arr: array<auto(numT)>; value: numT ==const; at: int|int64): auto
- push(Arr: array<auto(numT)>; varr: array<numT>): auto
- push(Arr: array<auto(numT)>; varr: array<numT>): auto
- push(Arr: array<auto(numT)>; varr: numT[]): auto
- push(Arr: array<auto(numT)[]>; varr: numT[] ==const): auto
- push(Arr: array<auto(numT)[]>; varr: numT const[] ==const): auto
2.1.10.24. push_clone¶
- push_clone(A: auto(CT); b: auto(TT)|auto(TT)#): auto¶
Clones and appends element b to the container A, using deep copy semantics rather than move or shallow copy.
- Arguments:
A : auto(CT)
b : option<auto(TT)| auto(TT)#>
- push_clone(Arr: array<auto(numT)>; value: numT ==const|numT const# ==const): auto
- push_clone(Arr: array<auto(numT)>; value: numT ==const|numT const# ==const; at: int|int64): auto
- push_clone(Arr: array<auto(numT)>; value: numT ==const|numT# ==const): auto
- push_clone(Arr: array<auto(numT)>; value: numT ==const|numT# ==const; at: int|int64): auto
- push_clone(Arr: array<auto(numT)>; varr: numT[] ==const): auto
- push_clone(Arr: array<auto(numT)>; varr: numT const[] ==const): auto
- push_clone(Arr: array<auto(numT)[]>; varr: numT[]): auto
- push_clone(Arr: array<auto(numT)[]>; varr: numT const[] ==const): auto
2.1.10.25. push_clone_from¶
- push_clone_from(Arr: array<auto(numT)>; varr: array<numT>): auto¶
Bulk-appends every element of source varr (an array or fixed-size C-array) to Arr via clone (:=). Reserves the combined capacity up front; one allocator touch instead of N.
- Arguments:
Arr : array<auto(numT)>
varr : array<numT>!
- push_clone_from(Arr: array<auto(numT)>; varr: numT[] ==const): auto
- push_clone_from(Arr: array<auto(numT)>; varr: array<numT>): auto
- push_clone_from(Arr: array<auto(numT)>; varr: numT const[] ==const): auto
2.1.10.26. push_from¶
- push_from(Arr: array<auto(numT)>; varr: array<numT>): auto¶
Bulk-appends every element of source varr (an array or fixed-size C-array) to Arr via copy. Reserves the combined capacity up front, so an O(N) bulk append touches the allocator once instead of N times.
- Arguments:
Arr : array<auto(numT)>
varr : array<numT>!
- push_from(Arr: array<auto(numT)>; varr: array<numT>): auto
- push_from(Arr: array<auto(numT)>; varr: numT[]): auto
- remove_value(arr: array<auto(TT)>|array<auto(TT)>#; key: TT): bool¶
Searches arr for the first element equal to key and removes it, returning true if an element was found and removed or false otherwise.
- Arguments:
arr : option<array<auto(TT)>| array<auto(TT)>#>
key : TT
2.1.10.27. reserve¶
- reserve(Arr: array<auto(numT)>; newSize: int): auto¶
Pre-allocates memory in Tab to hold at least newSize entries without rehashing, improving performance of subsequent insertions.
- Arguments:
Arr : array<auto(numT)>
newSize : int
- reserve(Arr: array<auto(numT)>; newSize: int64): auto
- reserve(Tab: table<auto(keyT), auto>; newSize: int): auto
- reserve(Tab: table<auto(keyT), auto>; newSize: int64): auto
2.1.10.28. resize¶
- resize(Arr: array<auto(numT)>; newSize: int): auto¶
Resizes dynamic array Arr to newSize elements; new elements beyond the previous length are zero-initialized, and excess elements are removed.
- Arguments:
Arr : array<auto(numT)>
newSize : int
- resize(Arr: array<auto(numT)>; newSize: int64): auto
2.1.10.29. resize_and_init¶
- resize_and_init(Arr: array<auto(numT)>; newSize: int|int64): auto¶
Resizes dynamic array Arr to newSize elements, default-initializing any newly added elements.
- Arguments:
Arr : array<auto(numT)>
newSize : option<int| int64>
- resize_and_init(Arr: array<auto(numT)>; newSize: int|int64; initValue: numT): auto
2.1.10.30. resize_no_init¶
- resize_no_init(Arr: array<auto(numT)>; newSize: int): auto¶
Resizes dynamic array Arr to newSize elements without initializing newly added entries, leaving their memory contents undefined.
- Arguments:
Arr : array<auto(numT)>
newSize : int
- resize_no_init(Arr: array<auto(numT)>; newSize: int64): auto
2.1.10.31. sort¶
- sort(a: array<auto(TT)>|array<auto(TT)>#): auto¶
Sorts a dynamic array in place in ascending order using the default comparison for its element type.
- Arguments:
a : option<array<auto(TT)>| array<auto(TT)>#>
- sort(a: array<auto(TT)>|array<auto(TT)>#; cmp: block<(x:TT;y:TT):bool>): auto
- sort(a: auto(TT)[]|auto(TT)[]#): auto
- sort(a: auto(TT)[]|auto(TT)[]#; cmp: block<(x:TT;y:TT):bool>): auto
2.1.10.32. subarray¶
- subarray(a: array<auto(TT)>; r: range): auto¶
Returns a temporary sub-range of the dynamic array a defined by the signed range r, providing access to elements from r.x up to but not including r.y.
- Arguments:
a : array<auto(TT)>!
r : range
- subarray(a: array<auto(TT)>; r: urange): auto
- subarray(a: auto(TT)[]; r: range): auto
- subarray(a: auto(TT)[]; r: urange): auto
- subarray(a: array<auto(TT)>; r: range): auto
2.1.10.33. to_array¶
- to_array(a: auto(TT)[]): array<TT>¶
Converts a fixed-size array a into a new dynamic array by cloning each element.
- Arguments:
a : auto(TT)[-1]
- to_array(it: iterator<auto(TT)>): array<TT>
2.1.10.34. to_array_move¶
- to_array_move(a: auto(TT) ==const): array<TT>¶
Converts a mutable container a into a new dynamic array, moving elements when possible instead of cloning.
- Arguments:
a : auto(TT)!
- to_array_move(a: auto(TT) ==const): array<TT>
- to_array_move(a: auto(TT)[]): array<TT>
2.1.10.35. to_table¶
- to_table(a: auto(keyT)[]): table<keyT, void>¶
Converts a fixed-size array of key-value tuples a into a table<keyT, valT> by cloning each key and value.
- Arguments:
a : auto(keyT)[-1]
- to_table(a: tuple<auto(keyT);auto(valT)>[]): table<keyT, valT>
2.1.10.36. to_table_move¶
- to_table_move(a: array<auto(keyT)>): table<keyT, void>¶
Converts a mutable dynamic array of keys a into a set-style table<keyT, void>, moving elements when possible.
- Arguments:
a : array<auto(keyT)>
- to_table_move(a: auto(keyT)): table<keyT, void>
- to_table_move(a: auto(keyT)[]): table<keyT, void>
- to_table_move(a: array<tuple<auto(keyT);auto(valT)>>): table<keyT, valT>
- to_table_move(a: tuple<auto(keyT);auto(valT)>): table<keyT, valT>
- to_table_move(a: tuple<auto(keyT);auto(valT)>[]): table<keyT, valT>
2.1.10.37. values¶
- values(a: table<auto(keyT);auto(valT)> ==const|table<auto(keyT);auto(valT)> const# ==const): iterator<valT const&>¶
Returns a read-only iterator over all values in a table<keyT, valT>, yielding each value by const reference.
- Arguments:
a : option<table<auto(keyT);auto(valT)>!| table<auto(keyT);auto(valT)>#!>
- values(a: table<auto(keyT);auto(valT)[]> ==const|table<auto(keyT);auto(valT)[]> const# ==const): iterator<valT const[-2]&>
- values(a: table<auto(keyT);void> ==const|table<auto(keyT);void> const# ==const): auto
- values(a: table<auto(keyT);auto(valT)> ==const|table<auto(keyT);auto(valT)># ==const): iterator<valT&>
- values(a: table<auto(keyT);auto(valT)[]> ==const|table<auto(keyT);auto(valT)[]># ==const): iterator<valT[-2]&>
- values(a: table<auto(keyT);void> ==const|table<auto(keyT);void># ==const): auto
2.1.11. das::string manipulation¶
- peek(src: das_string; block: block<(string#):void>)¶
Provides zero-copy read access to the contents of a das_string by invoking block with a temporary string reference, avoiding allocation.
- Arguments:
src : das_string implicit
block : block<(string#):void> implicit
2.1.12. Heap reporting¶
- heap_allocation_count(): uint64¶
Returns the total number of heap allocations performed by the current context since it was created.
- heap_allocation_stats(): urange64¶
Returns heap allocation statistics as a urange64, where the x component is total bytes allocated and the y component is total bytes freed.
- heap_bytes_allocated(): uint64¶
Returns the number of bytes currently in use on the heap (allocated minus freed), not counting reserved but unused memory.
- heap_collect(string_heap: bool = true; validate: bool = false)¶
Warning
This is unsafe operation.
Triggers garbage collection on the context heap; when string_heap is true the string heap is also collected, and when validate is true additional validation checks are performed.
- Arguments:
string_heap : bool
validate : bool
- heap_depth(): int¶
Returns the number of generations (depth of the allocation chain) in the context’s regular heap.
- heap_report()¶
Prints a diagnostic report of current heap usage and allocation statistics to the output log.
- memory_report(errorsOnly: bool)¶
Prints a report of memory allocations for the current context; when errorsOnly is true, only GC-related errors are included.
- Arguments:
errorsOnly : bool
- string_heap_allocation_count(): uint64¶
Returns the total number of individual string allocations performed on the current context’s string heap.
- string_heap_allocation_stats(): urange64¶
Returns string heap allocation statistics as a urange64 where x is total bytes allocated and y is total bytes deleted.
- string_heap_bytes_allocated(): uint64¶
Returns the total number of bytes currently allocated in the current context’s string heap.
- string_heap_depth(): int¶
Returns the number of generational layers (depth) in the current context’s string heap.
- string_heap_report()¶
Prints a detailed report of string heap usage, including allocation counts and byte statistics, to the log output.
- tag_array(array: array<anything>; name: string)¶
Labels the array’s current heap block with name so it appears under that label in heap reports instead of the generic “array”. The tag survives reallocation via reserve / resize / push. Requires options track_allocations; a no-op otherwise. Intended for narrowing down which of several module-level arrays is leaking.
- Arguments:
array : array implicit
name : string implicit
- tag_table(table: table<anything, anything>; name: string)¶
Labels the table’s current heap block with name so it appears under that label in heap reports instead of the generic “table”. The tag survives rehash / resize. Requires options track_allocations; a no-op otherwise. Intended for narrowing down which of several module-level tables is leaking.
- Arguments:
table : table implicit
name : string implicit
2.1.13. GC0 infrastructure¶
- gc0_reset()¶
Clears the entire gc0 storage, invalidating all previously saved pointers and smart pointers stored within it.
- gc0_restore_ptr(name: string): void?¶
Retrieves a raw pointer previously saved in gc0 storage under the specified name, returning null if not found.
- Arguments:
name : string implicit
- gc0_restore_smart_ptr(name: string): smart_ptr<void>¶
Retrieves a smart_ptr<void> previously saved in gc0 storage under the specified name.
- Arguments:
name : string implicit
- gc0_save_ptr(name: string; data: void?)¶
Stores a raw pointer data into gc0 storage under the specified name, allowing it to be retrieved later with gc0_restore_ptr.
- Arguments:
name : string implicit
data : void? implicit
- gc0_save_smart_ptr(name: string; data: smart_ptr<void>)¶
Stores a smart_ptr<void> data into gc0 storage under the specified name, allowing it to be retrieved later with gc0_restore_smart_ptr.
- Arguments:
name : string implicit
data : smart_ptr<void> implicit
2.1.14. Smart ptr infrastructure¶
2.1.14.1. add_ptr_ref¶
- add_ptr_ref(src: auto(TT)?): smart_ptr<TT>¶
Wraps a raw pointer src of type TT? into a smart_ptr<TT> by incrementing the reference count.
Commonly used to bridge AST node fields (which are raw pointers like Structure?, Enumeration?) to API functions that expect smart_ptr<T>.
The overload accepting smart_ptr<auto(TT)> adds an additional reference to an existing smart pointer, returning a new smart_ptr<TT> that shares ownership.
- Arguments:
src : auto(TT)?
- add_ptr_ref(src: smart_ptr<auto(TT)>): smart_ptr<TT>
- get_const_ptr(src: smart_ptr<auto(TT)>): TT?¶
Extracts a constant raw pointer of type TT? from the given smart_ptr<TT>, without affecting reference counting.
- Arguments:
src : smart_ptr<auto(TT)>
2.1.14.2. get_ptr¶
- get_ptr(src: smart_ptr<auto(TT)> ==const): TT?¶
Extracts a mutable raw pointer of type TT? from the given mutable smart_ptr<TT>, without affecting reference counting.
- Arguments:
src : smart_ptr<auto(TT)>!
- get_ptr(src: smart_ptr<auto(TT)> ==const): TT?
2.1.14.3. move¶
- move(dest: smart_ptr<void>&; src: smart_ptr<void>&)¶
Moves the smart pointer src into the smart pointer dest, nullifying the previous contents of dest and transferring ownership from src.
- Arguments:
dest : smart_ptr<void>& implicit
src : smart_ptr<void>& implicit
- move(dest: smart_ptr<void>&; src: void?)
- move_new(dest: smart_ptr<void>&; src: smart_ptr<void>)¶
Moves a newly constructed smart pointer value src into dest, used to initialize a smart_ptr from a new expression.
- Arguments:
dest : smart_ptr<void>& implicit
src : smart_ptr<void> implicit
2.1.14.4. smart_ptr_clone¶
- smart_ptr_clone(dest: smart_ptr<void>&; src: smart_ptr<void>)¶
Clones the smart pointer src into smart pointer dest, incrementing the internal reference count to share ownership.
- Arguments:
dest : smart_ptr<void>& implicit
src : smart_ptr<void> implicit
- smart_ptr_clone(dest: smart_ptr<void>&; src: void?)
- smart_ptr_is_valid(dest: smart_ptr<void>): bool¶
Checks whether the smart pointer dest holds a non-null reference to valid data, returning true if it does.
- Arguments:
dest : smart_ptr<void> implicit
- smart_ptr_use_count(ptr: smart_ptr<void>): uint¶
Returns the current reference count of the object managed by ptr, indicating how many smart pointers share ownership.
- Arguments:
ptr : smart_ptr<void> implicit
2.1.15. Macro infrastructure¶
- is_compiling(): bool¶
Returns true if the current context is in the process of being compiled, allowing compile-time logic to distinguish from runtime execution.
- is_compiling_macros(): bool¶
Returns true if the current context is being compiled and the compiler is currently executing the macro pass.
- is_compiling_macros_in_module(name: string): bool¶
Returns true if the current context is being compiled during the macro pass and the compiler is processing the module specified by name.
- Arguments:
name : string implicit
- is_folding(): bool¶
Returns true if the compiler is currently performing its constant folding optimization pass.
- is_in_completion(): bool¶
Returns true if the compiler is running in completion mode, generating lexical information for a text editor’s code-completion system.
- is_in_lint_check(): bool¶
Returns true if the program is being compiled in lint-check mode (i.e. CodeOfPolicies.lint_check is set). Modules can use this to skip side effects like debug agent installation during lint-only compilation.
- is_reporting_compilation_errors(): bool¶
Returns true if the context failed to compile and the inference pass is currently reporting compilation errors.
2.1.16. Profiler¶
- collect_profile_info(): string¶
Collects profiling information gathered by the built-in line profiler and returns it as a formatted string containing execution counts and timing data.
- dump_profile_info()¶
Prints the execution counts and timing data for all lines collected by the built-in line profiler to the standard output.
- profile(count: int; category: string; block: block<():void>): float¶
Executes block a total of count times under the given category label, prints the timing, and returns the minimum elapsed time in seconds across all iterations.
- Arguments:
count : int
category : string implicit
block : block<void> implicit
- reset_profiler()¶
Resets all counters and accumulated data in the built-in profiler to zero.
2.1.17. System infrastructure¶
- aot_enabled(): bool¶
Checks whether ahead-of-time (AOT) compilation is enabled for the current program and returns true if it is.
- breakpoint()¶
Triggers a debugger breakpoint by calling os_debugbreakpoint, which is a link-time dependency expected to be provided by the host application or debugger tool.
- error(text: string)¶
Outputs the string text to the context’s error stream, similar to print but directed to the error output channel.
- Arguments:
text : string implicit
- eval_main_loop(block: block<():void>)¶
Executes the application main loop by repeatedly invoking block until it returns false; on Emscripten targets, uses the platform-specific main loop mechanism instead.
- Arguments:
block : block<void> implicit
- feint(text: string)¶
No-op replacement for print. Has the same signature and side-effect annotations as print, but intentionally does nothing. Use feint in tests where print-like behavior is needed to prevent the call from being optimized out, but no actual output is desired.
- Arguments:
text : string implicit
- get_das_root(): string¶
Returns the file-system path to the daslang root directory, where daslib and other standard libraries are located.
- get_das_version(): string¶
Returns the daslang SDK version as a string in “major.minor.patch” format (e.g. “0.6.0”).
- is_in_aot(): bool¶
Returns true if the compiler is currently generating ahead-of-time (AOT) compiled code.
- is_intern_strings(): bool¶
Returns true if string interning is enabled in the current context, meaning identical strings share the same memory.
- panic(text: string)¶
will cause panic. The program will be terminated if there is no recover. Panic is not an error handling mechanism and can not be used as such. It is indeed panic, fatal error. It is not supposed that program can completely correctly recover from panic, recover construction is provided so program can try to correctly shut-down or report fatal error. If there is no recover within the script, it will be called in calling eval (in C++ callee code).
- Arguments:
text : string implicit
- print(text: string)¶
Outputs text to the current context’s log, typically printing to standard output.
- Arguments:
text : string implicit
Returns the file extension used for shared (dynamic) modules on the current platform.
- sprint(value: any; flags: print_flags): string¶
Converts value to its string representation using the specified flags to control formatting, and returns the result as a string.
- Arguments:
value : any
flags : print_flags
- sprint_json(value: any; humanReadable: bool): string¶
Serializes value directly to a JSON string, bypassing intermediate representation for speed; set humanReadable to true for indented output.
- Arguments:
value : any
humanReadable : bool
- sscan_json(json: string; value: any): bool¶
Parses a JSON string directly into value using RTTI type information — no intermediate JsonValue? representation. Returns true on success. Supports structs, pointers, arrays, tables, tuples, variants, enums, bitfields, vector types, and all scalar types. Handles @rename field annotations. Throws an error for handled types.
- Arguments:
json : string
value : any
- stackwalk(args: bool = true; vars: bool = true)¶
Prints the current call stack to the log; set args to include function arguments and vars to include local variable values in the output.
- Arguments:
args : bool
vars : bool
- terminate()¶
Immediately terminates execution of the current daslang context.
- to_compiler_log(text: string)¶
Outputs text to the compiler’s log stream, typically used from within macro code during compilation.
- Arguments:
text : string implicit
- to_log(level: int; text: string)¶
Outputs text to the logging infrastructure at the specified level (e.g. LOG_INFO, LOG_ERROR), rather than to standard output.
- Arguments:
level : int
text : string implicit
2.1.18. Memory manipulation¶
2.1.18.1. hash¶
- hash(data: any): uint64¶
Computes a 64-bit FNV-1a hash of the given int8 value and returns it as uint64.
- Arguments:
data : any
- hash(data: string): uint64
- hash(value: das_string): uint64
- hash(value: double): uint64
- hash(value: float): uint64
- hash(value: int): uint64
- hash(value: int16): uint64
- hash(value: int64): uint64
- hash(value: int8): uint64
- hash(value: uint): uint64
- hash(value: uint16): uint64
- hash(value: uint64): uint64
- hash(value: uint8): uint64
- hash(value: void?): uint64
2.1.18.2. intptr¶
- intptr(p: smart_ptr<auto>): uint64¶
Converts a smart_ptr p to its uint64 integer representation, useful for pointer arithmetic or serialization.
- Arguments:
p : smart_ptr<auto>
- intptr(p: void?): uint64
2.1.18.3. lock_data¶
- lock_data(a: array<auto(TT)> ==const|array<auto(TT)> const# ==const; blk: block<(p:TT const?#;s:int):auto>): auto¶
Locks a constant array and invokes blk with a read-only pointer p to the array’s contiguous data and its size s, allowing direct memory-level read access.
- Arguments:
a : option<array<auto(TT)>!| array<auto(TT)>#!>
blk : block<(p:TT?#;s:int):auto>
- lock_data(a: array<auto(TT)> ==const|array<auto(TT)># ==const; blk: block<(var p:TT?#;s:int):auto>): auto
- map_to_array(data: void?; len: int; blk: block<(var arg:array<auto(TT)>#):auto>): auto¶
Warning
This is unsafe operation.
Constructs a temporary mutable array of type TT over raw memory at data with len elements, and passes it to blk without copying the underlying data.
- Arguments:
data : void?
len : int
blk : block<(arg:array<auto(TT)>#):auto>
- map_to_ro_array(data: void?; len: int; blk: block<(arg:array<auto(TT)>#):auto>): auto¶
Warning
This is unsafe operation.
Constructs a temporary read-only array of type TT over raw memory at data with len elements, and passes it to blk without copying the underlying data.
- Arguments:
data : void?
len : int
blk : block<(arg:array<auto(TT)>#):auto>
- memcmp(left: void?; right: void?; size: int): int¶
Warning
This is unsafe operation.
Compares size bytes of memory at left and right, returning -1 if left is less, 1 if left is greater, or 0 if both regions are identical.
- Arguments:
left : void? implicit
right : void? implicit
size : int
- memcpy(left: void?; right: void?; size: int)¶
Warning
This is unsafe operation.
Copies size bytes of memory from the address pointed to by right into the address pointed to by left.
- Arguments:
left : void? implicit
right : void? implicit
size : int
- set_variant_index(variant: variant<>; index: int)¶
Warning
This is unsafe operation.
Overwrites the internal type discriminator of variant to index, changing which alternative the variant is considered to hold.
- Arguments:
variant : variant<> implicit
index : int
- variant_index(arg0: variant<>): int¶
Returns the zero-based index indicating which alternative the variant currently holds.
- Arguments:
arg0 : variant<> implicit
2.1.19. Binary serializer¶
- binary_load(obj: auto; data: array<uint8>): auto¶
Deserializes obj from the binary representation stored in data (an array of uint8 bytes). Obsolete — use daslib/archive instead.
- Arguments:
obj : auto
data : array<uint8> implicit
- binary_save(obj: auto; subexpr: block<(data:array<uint8>#):void>): auto¶
Serializes obj into a binary representation and passes the resulting uint8 byte array to the block subexpr. Obsolete — use daslib/archive instead.
- Arguments:
obj : auto
subexpr : block<(data:array<uint8>#):void>
2.1.20. Path and command line¶
- get_command_line_arguments(): array<string>¶
Returns an array of strings containing the command-line arguments passed to the program.
- with_argv(new_arguments: array<anything>; block: block<():void>)¶
Sets argc, argv to first argument, for the body block.
- Arguments:
new_arguments : array implicit
block : block<void> implicit
2.1.21. Time and date¶
- get_clock(): clock¶
Returns the current calendar time as a clock value representing the number of seconds since 00:00 UTC, January 1, 1970 (the Unix epoch).
- get_time_nsec(ref: int64): int64¶
Computes the elapsed time in nanoseconds since the reference point ref, which is typically obtained from ref_time_ticks.
- Arguments:
ref : int64
- get_time_usec(ref: int64): int¶
Computes the elapsed time in microseconds since the reference point ref, which is typically obtained from ref_time_ticks.
- Arguments:
ref : int64
- mktime(year: int; month: int; mday: int; hour: int; min: int; sec: int): clock¶
Converts the calendar date and time specified by year, month, mday, hour, min, and sec into a clock value representing time since epoch.
- Arguments:
year : int
month : int
mday : int
hour : int
min : int
sec : int
- ref_time_ticks(): int64¶
Returns a monotonic timestamp in nanoseconds since an unspecified epoch (the same epoch within a process; not comparable across processes or reboots). Use with get_time_usec(ref) / get_time_nsec(ref) for elapsed-interval math; raw subtraction now - then is also valid since the unit is always nanoseconds on every platform.
2.1.22. Platform queries¶
- das_is_dll_build(): bool¶
Checks whether the current build is configured as a DLL (dynamic library) build, which determines if daslib symbols are available for the JIT compiler.
- get_architecture_name(): string¶
Returns the name of the CPU architecture the program is running on, such as “x86_64”, “x86”, “arm64”, “arm”, “wasm32”, or “unknown”.
Returns the use-count of the shared context, which is incremented each time a thread accesses it; useful for tracking concurrent context usage.
- get_platform_name(): string¶
Returns the name of the operating system the program is running on, such as “windows”, “linux”, “darwin”, “emscripten”, or “unknown”.
- is_standalone_exe(): bool¶
Returns true when the current binary was produced by daslang -exe (a standalone executable). Returns false under the interpreter, in-process LLVM JIT, and AOT C++ builds. The LLVM JIT replaces this call with a constant at codegen time, so the value is folded with no runtime cost.
2.1.23. String formatting¶
2.1.23.1. fmt¶
- fmt(format: string; value: double): string¶
Formats a double value as a string using the given format specifier (following libfmt / C++20 std::format syntax).
- Arguments:
format : string implicit
value : double
- fmt(format: string; value: float): string
- fmt(format: string; value: int): string
- fmt(format: string; value: int16): string
- fmt(format: string; value: int64): string
- fmt(format: string; value: int8): string
- fmt(format: string; value: uint): string
- fmt(format: string; value: uint16): string
- fmt(format: string; value: uint64): string
- fmt(format: string; value: uint8): string
2.1.24. Argument consumption¶
- consume_argument(a: auto(TT)&): TT&¶
Marks argument a as consumed, signaling to the compiler that it will not be used after this call, which enables move optimizations and avoids unnecessary clones. Equivalent to the <-arg syntax.
- Arguments:
a : auto(TT)&
2.1.25. Lock checking¶
- lock_count(array: array<anything>): int¶
Returns the current internal lock count for the given array, indicating how many active locks prevent it from being resized.
- Arguments:
array : array implicit
2.1.26. Bit operations¶
2.1.26.1. __bit_set¶
- __bit_set(value: bitfield&; mask: bitfield; on: bool)¶
Sets or clears the bits specified by mask in the 16-bit bitfield value, turning them on if on is true or off if on is false.
- Arguments:
value : bitfield<>& implicit
mask : bitfield<>
on : bool
- __bit_set(value: bitfield16:uint16<>&; mask: bitfield16:uint16<>; on: bool)
- __bit_set(value: bitfield64:uint64<>&; mask: bitfield64:uint64<>; on: bool)
- __bit_set(value: bitfield8:uint8<>&; mask: bitfield8:uint8<>; on: bool)
2.1.26.2. clz¶
- clz(bits: uint): uint¶
Counts the number of leading zero bits in the 64-bit unsigned integer bits, returning 64 if the value is zero.
- Arguments:
bits : uint
- clz(bits: uint64): uint64
2.1.26.3. ctz¶
- ctz(bits: uint): uint¶
Counts the number of trailing zero bits in the 64-bit unsigned integer bits, returning 64 if the value is zero.
- Arguments:
bits : uint
- ctz(bits: uint64): uint64
- mul128(a: uint64; b: uint64): urange64¶
Multiplies two 64-bit unsigned integers a and b, returning the full 128-bit result as a urange64 containing the low and high 64-bit halves.
- Arguments:
a : uint64
b : uint64
2.1.26.4. popcnt¶
- popcnt(bits: uint): uint¶
Counts and returns the number of set (1) bits in the 64-bit unsigned integer bits.
- Arguments:
bits : uint
- popcnt(bits: uint64): uint64
2.1.27. Intervals¶
2.1.27.1. interval¶
- interval(arg0: int64; arg1: int64): range64¶
Constructs a range64 value from the two int64 endpoints arg0 (inclusive) and arg1 (exclusive).
- Arguments:
arg0 : int64
arg1 : int64
- interval(arg0: int; arg1: int): range
- interval(arg0: uint64; arg1: uint64): urange64
- interval(arg0: uint; arg1: uint): urange
2.1.28. RTTI¶
- class_rtti_size(ptr: void?): int¶
Examines the RTTI (runtime type information) associated with the class at ptr and returns the size in bytes of its TypeInfo structure.
- Arguments:
ptr : void? implicit
2.1.29. Initialization and finalization¶
- using(arg0: block<(das_string):void>)¶
Creates a temporary das_string and passes it to the block, automatically managing its lifetime for the duration of the call.
- Arguments:
arg0 : block<( das_string):void> implicit
2.1.30. Algorithms¶
- count(start: int = 0; step: int = 1): iterator<int>¶
Creates an infinite iterator that yields integer values starting from start and incrementing by step on each iteration, intended for use as a counter alongside other sequences in a for loop.
- Arguments:
start : int
step : int
- iter_range(foo: auto): auto¶
Creates a range from 0 to the length of the given iterable foo, useful for index-based iteration over containers.
- Arguments:
foo : auto
- swap(a: auto(TT)&; b: auto(TT)&): auto¶
Exchanges the values of a and b in place, leaving each variable holding the other’s former value.
- Arguments:
a : auto(TT)&
b : auto(TT)&
- ucount(start: uint = 0x0; step: uint = 0x1): iterator<uint>¶
Creates an infinite iterator over unsigned integers beginning at start and incrementing by step on each iteration.
- Arguments:
start : uint
step : uint
2.1.31. Memset¶
- memset128(left: void?; value: uint4; count: int)¶
Warning
This is unsafe operation.
Fills memory at left with count copies of the 128-bit uint4 vector value.
- Arguments:
left : void? implicit
value : uint4
count : int
- memset16(left: void?; value: uint16; count: int)¶
Warning
This is unsafe operation.
Fills memory at left with count copies of the 16-bit value.
- Arguments:
left : void? implicit
value : uint16
count : int
- memset32(left: void?; value: uint; count: int)¶
Warning
This is unsafe operation.
Fills memory at left with count copies of the 32-bit value.
- Arguments:
left : void? implicit
value : uint
count : int
- memset64(left: void?; value: uint64; count: int)¶
Warning
This is unsafe operation.
Fills memory at left with count copies of the 64-bit value.
- Arguments:
left : void? implicit
value : uint64
count : int
- memset8(left: void?; value: uint8; count: int)¶
Warning
This is unsafe operation.
Fills memory at left with count copies of the 8-bit value, equivalent to the C memset function.
- Arguments:
left : void? implicit
value : uint8
count : int
2.1.32. Malloc¶
- free(ptr: void?)¶
Warning
This is unsafe operation.
Frees memory previously allocated with malloc, following C-style manual memory management semantics.
- Arguments:
ptr : void? implicit
- malloc(size: uint64): void?¶
Warning
This is unsafe operation.
Allocates a block of uninitialized memory of the specified size in bytes, C-style, and returns a raw pointer to it; must be freed with free.
- Arguments:
size : uint64
- malloc_usable_size(ptr: void?): uint64¶
Warning
This is unsafe operation.
Returns the usable size in bytes of the memory block pointed to by ptr, as reported by the underlying allocator.
- Arguments:
ptr : void? implicit
2.1.33. Compilation and AOT¶
- compiling_file_name(): string¶
Returns the file name of the source file currently being compiled, useful for compile-time metaprogramming and diagnostics.
- compiling_module_name(): string¶
Returns the name of the module currently being compiled, useful for compile-time metaprogramming and diagnostics.
- get_module_file_name(name: string): string¶
Returns the source file path of the module with the given name, or empty string if the module is not found or has no file (e.g. built-in modules). Pass an empty string to get the main script’s file path. Only works during simulation (global variable initialization); at runtime requires options rtti to keep the program object alive.
- Arguments:
name : string implicit
- reset_aot()¶
Notifies the compiler that ahead-of-time code generation has finished, restoring normal compilation mode.
- set_aot()¶
Notifies the compiler that ahead-of-time code generation is now in progress.
2.1.34. GC¶
- gc_active_root_count(): uint64¶
Returns the number of active GC roots across all threads.
- gc_thread_root_count(): uint64¶
Returns the number of GC roots on the current thread.
- gc_thread_root_report()¶
Prints a summary report of GC roots on the current thread to the log.
- gc_thread_root_report_detailed(max_nodes: uint64 = 0x14)¶
Prints a detailed report of GC roots and their nodes on the current thread to the log. The max_nodes parameter limits how many nodes per root are printed.
- Arguments:
max_nodes : uint64
- gc_total_id(): uint64¶
Returns the total number of GC node IDs allocated since program start. Useful for detecting allocation leaks in tests.
2.1.35. Uncategorized¶
- long_length(array: array<anything>): int64¶
Returns the number of elements currently stored in a dynamic array array, as int64. Unlike length, never panics on arrays with more than INT32_MAX elements.
- Arguments:
array : array implicit
- long_capacity(array: array<anything>): int64¶
Returns the current capacity of a dynamic array — the number of elements it can hold before triggering a reallocation — as int64. Unlike capacity, never panics on arrays with more than INT32_MAX reserved slots.
- Arguments:
array : array implicit
- long_length(table: table<anything, anything>): int64
Returns the number of entries currently stored in a table, as int64. Unlike length, never panics on tables with more than INT32_MAX entries.
- Arguments:
table : table implicit
- long_capacity(table: table<anything, anything>): int64
Returns the current capacity of a table — the number of key-value pairs it can hold before triggering a reallocation — as int64. Unlike capacity, never panics on tables with more than INT32_MAX reserved slots.
- Arguments:
table : table implicit
- long_iter_range(foo: auto): auto¶
Returns an int64 range iterator over the valid indices of an iterable foo (typically an array or table). Same role as iter_range but produces int64 indices so it stays correct when the container holds more than INT32_MAX elements.
- Arguments:
foo : auto
- long_find_index(arr: array<auto(TT)>|array<auto(TT)>#; key: TT): int64¶
Returns the int64 index of the first element in arr equal to key, or -1 if not present. Same semantics as find_index but returns int64 and never panics on arrays larger than INT32_MAX.
- Arguments:
arr : option<array<auto(TT)>| array<auto(TT)>#>
key : TT