comptime eval

This commit is contained in:
2026-07-02 21:31:53 +02:00
parent b94687c30a
commit e00a4e929a
8 changed files with 500 additions and 36 deletions
+27 -4
View File
@@ -651,7 +651,29 @@
inferred type parameters, first-class type values, or comptime execution
27.6 comptime-evaluable constants/functions
- planned shape: `$x :: 32` and `$sum func(a, b int) int { ... }`
- `$expr` forces comptime evaluation of an expression:
`x :: $32`, `n :: $sum(1, 2)`, and `res :: ${ ... }`
- constant contexts such as array counts and comptime value arguments implicitly
require comptime evaluation; ordinary immutable bindings remain ordinary bindings
- ordinary `func` calls are comptime-evaluable when reached from a comptime context;
do not add a separate `$sum func(...)` declaration form
- v1 evaluator supports integer literals/arithmetic, boolean conditions, immutable
locals, `return`, `if`/`else`, comptime blocks, and direct calls to other evaluable
brolang functions
- broader Zig-style comptime execution is milestone 27.7
27.7 broader Zig-style comptime execution
- extend the comptime evaluator from integer scalars into a real compile-time value
model: bools, floats, strings, arrays/slices, structs/unions/enums, optionals,
fallibles, and pointers to comptime storage
- support mutable comptime locals/assignment, loops with an evaluation quota,
`defer`, `match`, value blocks/`yield`, and `try`/`catch`
- allow calls through comptime-known function values/function pointers; keep external
`c_func` calls runtime-only unless a future compiler intrinsic explicitly models
their behavior
- immutable locals/globals with comptime-known initializers may feed comptime
evaluation; runtime-dependent values remain invalid in comptime contexts
- no runtime side effects during comptime evaluation
28. brolang build system (requires comptime execution)
@@ -1244,9 +1266,10 @@ data :: read_file(path) catch |e| match e {
```
make_array func($N usize) [N]u8 { ... } # implemented: integer comptime value params
max func($T type, a, b T) T { ... } # deferred: comptime type params
$x :: 32 # deferred: comptime evaluable constant
$sum func(a, b int) int { ... } # deferred: comptime evaluable function
max func($T type, a, b T) T { ... } # implemented: comptime type params
x :: $32 # implemented: force comptime expression evaluation
n :: $sum(1, 2) # implemented: ordinary functions can run at comptime
res :: ${ yield 4 } # implemented: comptime value block
```
## A word on memory allocation