This library is in flux. APIs may change without notice. Generated from source with koruc 0.1.7 on 11/4/2026.

List

import std/list

std/list — JavaScript implementation facet.

list.kjs · 13 tors

std/list — JavaScript implementation facet. · 37 more lines
std/list — JavaScript implementation facet. Events are declared in the `list.kz` companion (merged at import, because same-stem facets are one module). This file holds only the `|js` proc bodies. THE REPRESENTATION: Zig JavaScript --------------------------- -------------------------------- *List_i64 a js array std.ArrayList(i64).items the same array — there is no inner handle allocator absent — GC is the implementation `List_i64` in `list.kz` is `struct { items: ArrayList(i64), allocator }`. Both fields exist to make a growable buffer out of a fixed one; JS arrays are already growable, so the whole struct collapses to the array. Nothing reads the handle's fields from Koru — every access in the module goes through a proc — so there is no `data`-style field the representation is forced to carry (contrast the `.kjs` for std/string, where two declarative events pin the shape). `new` is NOT here, and must not be. It is `~[comptime|transform]pub tor new` (list.kz:33): a compile-time call-site rewrite from `new(i64)` to `new-i64`, whose body manipulates the compiler's own `ast.Invocation` and `ast.Item` in the compiler's own address space. A transform's body is Zig on EVERY target — porting one means a `|js` variant that EMITS JavaScript, written in Zig, staying in the `.kz`. This transform emits no host code at all; it only renames a call, so the single `|zig` body is already correct for the JS target and there is nothing to port. The annotation sits on the `tor`, not on the `~proc new|zig` line below it — reading the proc line alone would have classified it a runtime port and produced a JavaScript body for a compiler pass. Construction The Zig facet's `| err "allocation failed"` arm is unreachable here; it stays in the contract because that facet needs it.

Phantom lifecycles

Derived from the phantom labels in the declarations below — state! issues an obligation the compiler will chase, !state discharges it, a bare state holds it without moving it. Nothing here is hand-drawn.

List_i64 1 state list!

~part new koru_std/list.new.kz

Koru Standard Library: the `new` part of list.kz. Joined via `~part new` in list.kz; merged into the list module at load.

new

comptimetransform koru_std/list.new.kz:4

new-i64

<list!> koru_std/list.new.kz:109

~part push koru_std/list.push.kz

Koru Standard Library: the `push` part of list.kz. Joined via `~part push` in list.kz; merged into the list module at load. container's constructor mints alongside it (see the synthesis section). The unified overload-by-container dispatch is the post-milestone gap (660_026 red pin), not this rung's surface.

push

comptimetransform koru_std/list.push.kz:7

push-i64

<list> koru_std/list.push.kz:19

~part len koru_std/list.len.kz

Koru Standard Library: the `len` part of list.kz. Joined via `~part len` in list.kz; merged into the list module at load. Current length as a scalar. (The `xs.len` expression form rides a separate bridge; this tor is the plain call form.)

len

comptimetransform koru_std/list.len.kz:6

~part get koru_std/list.get.kz

Koru Standard Library: the `get` part of list.kz. Joined via `~part get` in list.kz; merged into the list module at load. Random access by index. <list> borrow — read, list untouched. `out-of-bounds` when i is past the end.

get

comptimetransform koru_std/list.get.kz:6

~part pop koru_std/list.pop.kz

Koru Standard Library: the `pop` part of list.kz. Joined via `~part pop` in list.kz; merged into the list module at load. binding keeps <list!>), so it can be popped again or freed. `empty` when there is nothing to pop. For scalar elements the popped value carries no obligation.

pop

comptimetransform koru_std/list.pop.kz:6

~part protos koru_std/list.protos.kz

Koru Standard Library: proto-resolution machinery for the list module — joined via `~part protos` in list.kz; members land in koru_list. Reads proto declaration flows (live and erased-marker) out of the program AST and flattens their field sets — `<:` parents merge ahead of the block (proto.resolve.kz owns the declaration-side gate). Bare entry name a proto-qualified element expression names, or null for a primitive. `i64` -> null; `Engine` -> "Engine"; `app/car:Engine` -> "Engine".

~part synth koru_std/list.synth.kz

Koru Standard Library: the `synth` part of list.kz. Joined via `~part synth` in list.kz; merged into the list module at load. Container synthesis for proto elements: synthesizeContainer mints the element record + List_<Name> handle struct + the six op tors (new/push/len/get/pop/free) into the CALLER's module. For a `ref(T)` field it enforces the home contract at the push boundary through the store module's shared enumeration (RefHomeQuery.homesOf) — the rule lives once, in the library that understands what mints handles. The name a proto door's first argument DECLARES. `<:` extension rides the labeled-arg split — `std/proto(Dog <: Animal)` arrives as (name: "Dog <", value: "Animal") — so the entry is the label minus '<', not the value. A plain value is a plain name. A synthesized tor decl + its `|zig` proc, appended as two Items.

~part fieldkit koru_std/list.fieldkit.kz

Koru Standard Library: the `fieldkit` part of list.kz — the small field/branch constructors the container synthesizers share. Joined via `~part fieldkit` in list.kz; merged into the list module at load. `ref(X)` inner name — the same spelling StoreRefs.inner parses in the store module; kept local because detection must run even when no std/store import exists — the no-home refusal is this consumer's job.

~part free koru_std/list.free.kz

Koru Standard Library: the `free` part of list.kz. Joined via `~part free` in list.kz; merged into the list module at load.

free

comptimetransform koru_std/list.free.kz:4

free-i64

<!list> koru_std/list.free.kz:16

~part explain koru_std/list.explain.kz

Koru Standard Library: the `explain` part of list — joined via `~part explain` in list.kz; members land in koru_list. The consumer's explainer — the enforcement half of the facet story. std/refine reports what was DECLARED on a type; this reports what std/list ENFORCES at its boundary: for every `std/list:new(X)` site, the element's met facet is asked from refine's own fold (`metFields`) — the same producer the transform reads, so the report cannot drift from what push actually guards — plus the branch contract the push signature declares (`| ?ok` / `| ?!violated` / `| ?!oom`). One distinct element type and how many `new` sites construct it.

explain-list

comptimeexplainer koru_std/list.explain.kz:59