Files
ziran/bootstrap/compiler_ir
waozi 285b51e2e2 Choose a module's compile-time features where it is imported
A module declares parameters as its first declaration,
`#module_parameters(STB := false, CACHE: s32 = 8)`, and an import picks
their values, `#import "fonts"(STB = true)`. Each parameter is an
ordinary constant of the module, so `#if` keeps unchosen code out of C,
Go, ZX, Wasm and native code alike.

One program binds a module's parameters once. Every import has to give
every parameter the same value, so disagreeing imports fail with
module.parameter_conflict instead of compiling a second copy. Unknown
names and values that do not fit their type (integers by range) fail
with module.parameter_unknown and module.parameter_type at the import.
The grammar and literal rules live in compiler_declaration.zi. The
bindings are checked IR, ZirModule.parameters and ZirImport.parameters,
so they port with the checker to Ziran.

Saved .zir becomes version 65. It keeps each import's canonical list and
each module's types, defaults and bound values. A saved import that
disagrees with its module is rejected like source, and so is a bound
value that differs from the module's constant. The unused reserved
import slot is gone.

Also: a constant whose string holds `#import`, such as module source in
#string, is no longer parsed as an import. The C include path now lists
the IR headers first, so a stale copy that another generated module
keeps can't shadow them in an incremental build.

tests/module_parameters_cases.zi runs two programs that share one module
with different choices. They run from source and saved IR on C, Go, the
engine, native code and Wasm, along with the named rejections and edited
saved IR. Grammar cases are in tests/spec/compiler_declaration_test.zi.
2026-11-15 15:40:12 -03:00
..