more comptime eval

This commit is contained in:
2026-07-03 15:54:28 +02:00
parent e00a4e929a
commit adf142736c
7 changed files with 2266 additions and 481 deletions
+23 -13
View File
@@ -650,30 +650,38 @@
- v1 intentionally keeps `type` contextual to comptime parameter declarations; no
inferred type parameters, first-class type values, or comptime execution
27.6 comptime-evaluable constants/functions
27.6 comptime-evaluable constants/functions (implemented)
- `$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
- v1 evaluator supported 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
- broader typed 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
27.7 broader Zig-style comptime execution (implemented; v1)
- `compiler/checker/comptime.odin` owns checker-local evaluator state, typed
comptime values, execution, and HIR materialization; `checker.odin` keeps type
checking, inference, specialization, and build orchestration
- typed `$` values cover bools, integers, floats, strings, arrays, structs, tagged
unions, enums, optionals, and fallibles
- supports mutable comptime locals/assignment, `if`, `while`, `for`,
`break`/`continue`, `defer`, `match`, value blocks/`yield`, direct calls to
bodyful Brolang functions, and `try`/`catch`
- successful `$` results materialize back into ordinary HIR expressions so lowering
and LLVM stay unchanged
- evaluation uses a fixed `100_000` step quota
- 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
- runtime-only behavior is rejected in comptime: external/bodyless `c_func`,
writable globals, pointers/slices, address/deref storage APIs, pointer captures,
and function-pointer calls
- v1 keeps integer-only `$N` specialization keys; aggregate comptime parameters,
stable aggregate serialization, comptime pointers/slices, and calls through
comptime-known function values/function pointers are deferred
28. brolang build system (requires comptime execution)
@@ -1270,6 +1278,8 @@ 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
p :: $Point { x = 1, y = 2 } # implemented: typed aggregate comptime values
total :: $sum_loop(4) # implemented: mutable locals/loops/defer/match/try/catch
```
## A word on memory allocation