This library is in flux. APIs may change without notice. Generated from source with koruc 0.1.7 on 11/4/2026.
Types
import std/typesKoru Standard Library: Type Declarations
types.kz · 7 tors · ~[comptime]· ~[runtime]
Koru Standard Library: Type Declarations · 16 more lines
// COMPTIME FIELD REFLECTION
// `fields-of(T)` — a comptime traversal SOURCE over an existing type's fields.
// Iteration is EMERGENT: like `for`, it pulses `! each f` (each `f` a reflected
// field, `.name` / `.type`) rather than handing an iterator to a loop. Round one is
// consumed by std/constructor's struct terminal (lowered to Zig `@typeInfo`); a
// standalone lowering — `fields-of` traversing outside a constructor — is the later
// generalization, and the surface where Koru-level type reflection eventually lands.
~[comptime] pub tor fields-of { expr: Expression }
! each *
| ?done// NOMINAL PRIMITIVE TYPES
//
// PROTO ENTRIES
// `proto(Name) { field: type, ... }` declares a COMPILE-TIME registry entry —
// layout-silent, with no emission of its own: the first consumer derives what
// it needs (std/list:new synthesizes the element struct plus its
// `List_<Name>` container from these fields; the vector/table consumers are
// later rungs on the same entry). Registration is the AST scans' job: the
// checker and the type registry read the declaration flow FROM THE PRE-TRANSFORM
// AST (the same copy they read `struct`/nominal declarations from), and this
// transform self-erases the site into a comment so nothing runtime is emitted.
//
// USAGE:
// std/types:proto(Car) { rpm: i32, serial: string }
//
// RULED 2026-08-23 (frag-type-system-design, proto rung): the entry is the
// identity — two registrants of the same name are a loud collision, and values
// over two different protos must not interchange (both refused at the KORU
// layer by the nominal-distinctness gate; see scanDeclaredTypes + the
// container registration it derives).
~[keyword|comptime|transform] pub tor proto {
expr: Expression,
source: Source,
item: std/compiler:*const Item,
allocator: std.mem.Allocator,
reporter: std/compiler:*ErrorReporter
} -> SiteResult~[keyword|comptime|transform] pub tor string {
expr: Expression,
item: std/compiler:*const Item,
program: std/compiler:*const Program,
allocator: std.mem.Allocator
} -> SiteResult// Declare a nominal integer type (wraps i64)
~[keyword|comptime|transform] pub tor int {
expr: Expression,
item: std/compiler:*const Item,
program: std/compiler:*const Program,
allocator: std.mem.Allocator
} -> SiteResult// Declare a nominal float type (wraps f64)
~[keyword|comptime|transform] pub tor float {
expr: Expression,
item: std/compiler:*const Item,
program: std/compiler:*const Program,
allocator: std.mem.Allocator
} -> SiteResult// Declare a nominal bool type (wraps bool)
~[keyword|comptime|transform] pub tor bool {
expr: Expression,
item: std/compiler:*const Item,
program: std/compiler:*const Program,
allocator: std.mem.Allocator
} -> SiteResult~part fields koru_std/types.fields.kz
Koru Standard Library: the `fields` part of types.kz. Joined via `~part fields` in types.kz; merged into the koru_types module. The proto entry grammar, applied once per block at the `std/types:proto` door: a field line is ONE `name: type` entry, and one block binds each name once. This is the same walk proto.fields.kz serves the std/proto module — a second honest copy, per the block-grammar ruling: the entry law is shared, the module boundary is not worth a premature shared scanner. The caller owns the refusal's wrapper (a SiteResult at the door).
~part enum koru_std/types.enum.kz
Koru Standard Library: the `enum` part of types — closed tag-set mints. Joined via `~part enum` in types.kz; merged into the types module. `std/types:enum(ThreatLevel) { low, medium, high }` mints a NOMINAL closed tag set — the first materialization rung under the post-dissolution registry: the entry IS its tag list, so nothing is projected from a proto (there are no fields to inherit); the mint stands alone. What it emits is a host enum the tag names survive into — `{{ level:t }}` prints `high`, the C# `$"{s.ThreatLevel}"` parity the LINQ-shaped examples need (`:s` refuses at the Zig layer — a slice spec on an enum — so tag-name printing spells `:t`; a Koru-layer diagnostic for `:s`-on-enum is a later rung) — plus a `// proto-terminal` marker so field-type resolution (`level: ThreatLevel` in a compound) answers like any other terminal: the terminal's host material is its own name, and consumers re-emitting it land on the minted const. Rung 1 is bare tags only — implicit ordinals, `i64` backing; explicit values and width args are later rungs and refuse loudly here rather than half-parse.
// Koru Standard Library: the `enum` part of types — closed tag-set mints.
// Joined via `~part enum` in types.kz; merged into the types module.
//
// `std/types:enum(ThreatLevel) { low, medium, high }` mints a NOMINAL closed
// tag set — the first materialization rung under the post-dissolution
// registry: the entry IS its tag list, so nothing is projected from a proto
// (there are no fields to inherit); the mint stands alone. What it emits is
// a host enum the tag names survive into — `{{ level:t }}` prints `high`,
// the C# `$"{s.ThreatLevel}"` parity the LINQ-shaped examples need (`:s`
// refuses at the Zig layer — a slice spec on an enum — so tag-name printing
// spells `:t`; a Koru-layer diagnostic for `:s`-on-enum is a later rung) —
// plus a `// proto-terminal` marker so field-type resolution
// (`level: ThreatLevel` in a compound) answers like any other terminal: the
// terminal's host material is its own name, and consumers re-emitting it
// land on the minted const. Rung 1 is bare tags only — implicit ordinals,
// `i64` backing; explicit values and width args are later rungs and refuse
// loudly here rather than half-parse.
~[comptime|transform] pub tor enum {
expr: Expression,
source: Source,
item: std/compiler:*const Item,
program: std/compiler:*const Program,
allocator: std.mem.Allocator,
reporter: std/compiler:*ErrorReporter
} -> SiteResult