comptime value-params

This commit is contained in:
2026-07-02 19:38:31 +02:00
parent b1ddecfc2e
commit 7cda126924
10 changed files with 579 additions and 56 deletions
+24 -3
View File
@@ -630,11 +630,23 @@
- imports beginning with `@` resolve from the compiler process cwd / project root
- `heap :: import "@std/mem/heap"` works from any package depth without `../../../` path math
27. comptime polymorphism (zig inspired)
27. comptime integer value parameters (implemented; v1)
- `$N` marks an integer comptime parameter in a normal `func` signature:
`make_array func($N usize) [N]u8`
- callers pass a compile-time integer expression; the value specializes the function
and is omitted from the runtime ABI
- inside the specialization, `N` is visible as an immutable compile-time integer in
array counts, types, and body expressions
- v1 intentionally supports integer values only; no comptime branch pruning or
user-function execution
28. comptime execution
27.5 comptime type parameters (deferred)
- planned shape: `max func($T type, a, b T) T`
29. brolang build system (requires comptime execution)
27.6 comptime-evaluable constants/functions (deferred)
- planned shape: `$x :: 32` and `$sum func(a, b int) int { ... }`
28. brolang build system (requires comptime execution)
## A word on multi-unwrap
@@ -1221,6 +1233,15 @@ data :: read_file(path) catch |e| match e {
| `yield :label value` | Provide value from labeled block |
| `return` / `return value` | Exit the current function; in fallible functions, return value dispatches by type |
## A word on comptime
```
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
```
## A word on memory allocation
(NOTE THAT SYNTAX MAY NOT MATCH BROLANG EXACTLY AND SHOULD BE TAKEN WITH A GRAIN OF SALT - INSPIRATION ONLY)