runtime mutable global state

This commit is contained in:
2026-07-03 21:48:23 +02:00
parent adf142736c
commit ee41a54e41
11 changed files with 569 additions and 40 deletions
+28 -3
View File
@@ -91,7 +91,7 @@
- operators: `and`, `or`, `!`
- lazy evaluation / short-circuit evaluation
- if statements (implemented). example: `if condition { ... } else if { ... } else { ... }`
- conditions must be `bool`; block-scoped locals with shadowing across blocks
- conditions must be `bool`; block-scoped locals do not escape their blocks
- lowered through new `Label` / `Br` / `Cond_Br` IR opcodes (alloca-backed locals, no phi nodes)
- conditional unwrapping for optionals (`?T`) (implemented): `if val |v| { ... } else { ... }` - unwrap `val` into `v` if it is not `none`
- single immutable binding scoped to the then-block; `v` not visible in `else` or after the `if`
@@ -403,8 +403,7 @@
statements first (a throwaway probe), so a first concrete `yield :blk` that references a
block local still resolves the result to `?T`
- deferred (`// ponytail:`): the same `none`-before-concrete typing in an untyped block (or
loop) whose concrete yield references a local declared *past* the first yield (annotate);
same-label loop/block shadowing resolves innermost-wins
loop) whose concrete yield references a local declared *past* the first yield (annotate)
21. unions and tagged unions (implemented; first pass — native untagged unions only; see below)
- inspired by zig
@@ -683,6 +682,32 @@
stable aggregate serialization, comptime pointers/slices, and calls through
comptime-known function values/function pointers are deferred
27.8 source-defined mutable runtime globals (implemented)
- allow mutable global declarations in Brolang source for process-global runtime
state, matching the writable-global support already needed for imported C globals
- require source type syntax and an initializer; constraints (`int`/`float`/`range`)
and inferred array counts may resolve through the existing inference fixpoint, but
the final type must be concrete runtime storage
- emit source-defined mutable globals as writable globals, not constants
- allow assignment, address-taking, field/index mutation, and pointer passing under
the same mutability rules as other writable locations
- keep mutable globals invalid in comptime evaluation; `$global_var` and writes from
comptime execution must remain runtime-dependent errors
- define initialization order and cycle behavior by reusing the existing global
initializer dependency/cycle system where possible
- reject user-visible name shadowing across imports, named types, globals, functions,
params, locals, comptime params, captures, and labels; `_` remains reusable
27.9 comptime storage and function values
- add a comptime pointer/storage model for pointers, slices, address/deref,
pointer captures, lifetimes, aliasing, mutability, and escape rules
- define what `$&value` and other comptime addresses can legally materialize into,
without exposing compiler-owned memory as runtime memory
- add first-class comptime function values and calls through comptime-known function
pointers
- resolve function-pointer targets during comptime execution, apply ABI/runtime
restrictions, and reliably reject imported/runtime callbacks
28. brolang build system (requires comptime execution)
## A word on multi-unwrap