LANGUAGE CONTRACT · 13.5.0
Compile-time code
Use comptime to calculate code before it runs. Version 13.5 adds for over range(start,end) and local pure functions. Fuel runs out; recursion stops; the host stays off-limits.
Bounded for loops
Inside comptime, the supported iterable is exactly range(start, end). The end is exclusive, the step is +1, and the bounds are compile-time integers. The index is scoped to the loop.
comptime {
let total: int = 0
for index in range(0, 7):
total = total + 6
if total == 42:
emit_source("pub fn answer() -> i32:\n return " + str(total) + "\n")
else:
emit_source("pub fn answer() -> i32:\n return 0\n")
}
pub fn main() -> i32:
return answer()
Source: examples/ctfe_for_range_v135.dby. Invalid argument counts or types, unsupported iterators, or excessive ranges are rejected with E_CTFE_* diagnostics.
Pure local functions
Declare fn directly inside a top-level comptime block. Signatures require explicit int, i64, bool or str parameter/return types. Forward references and bounded recursion are permitted. Pure function bodies admit local declarations, assignments, Boolean if/else and return, but not arbitrary I/O, host calls or loops.
comptime {
fn factorial(n: int) -> int:
if n <= 1:
return 1
else:
return n * factorial(n - 1)
let answer: int = factorial(4) + 18
emit_source("pub fn answer() -> i32:\n return " + str(answer) + "\n")
}
pub fn main() -> i32:
return answer()
Source: examples/ctfe_pure_fn_v135.dby, verified as a native executable with exit code 42.
Hard limits
| Resource | Limit |
|---|---|
| Shared evaluation fuel | 1,000,000 steps |
| Nested pure function calls | 32 active frames; 33 rejected |
| Parameters per function | 16 |
| Local function declarations per block | 128 |
| Cumulative strings | 8 MiB |
| Generated source | 1 MiB |
Nested-call overflow reports E_CTFE_RECURSION; exhausted shared fuel reports E_CTFE_FUEL. Compile-time functions cannot access the filesystem, processes, network, clock or environment.
Tests and missing pieces
The release verification includes positive native examples, forward references, boundary-depth tests and negative fail-closed cases on Windows and Debian WSL. This is software evidence, not physical BIOSTAR qualification or proof that the full compiler is self-hosted.
Additional exact boundaries
range(start,end) takes two compile-time i64 expressions with an exclusive end and +1 step. Empty or reversed ranges execute zero times; negative bounds are supported. Too-large ranges fail before iteration.
Generated declarations are capped at 1,024, expansion depth at 16, and statement/expression nesting at 64. Compile-time pure functions have no capture of enclosing local variables and cannot run loops inside their bodies. Authority: docs/CTFE_FOR_V135.md and docs/CTFE_PURE_FUNCTIONS_V135.md at Git tag v13.5.0.