Types phase 4: containers — map / set + fixed arrays [T; N] #54

Closed
opened 2026-08-31 17:30:50 +02:00 by orkun · 1 comment
Owner

Follow-up to #1 (proposal), phase 4 of the phasing.

map<K,V> — lookups by id/name (loot tables, entity registries, config), like Go map / C# Dictionary.

set — membership (tags, visited tiles, unlocked achievements).

[T; N] fixed arrays — grids, inventories, per-entity slots with no heap; already a design target in LANGUAGE.md.

grid — a tilemap of any element type (today Map.* is a fixed char grid); could be sugar over [T; W*H].

These need a generics-lite mechanism in the front end; scope that first.

Phase 1 (IVec2 + Rect) shipped in the #1 thread.

Follow-up to #1 (proposal), phase 4 of the phasing. **map<K,V>** — lookups by id/name (loot tables, entity registries, config), like Go `map` / C# `Dictionary`. **set<T>** — membership (tags, visited tiles, unlocked achievements). **[T; N] fixed arrays** — grids, inventories, per-entity slots with no heap; already a design target in LANGUAGE.md. **grid<T>** — a tilemap of any element type (today `Map.*` is a fixed char grid); could be sugar over `[T; W*H]`. These need a generics-lite mechanism in the front end; scope that first. Phase 1 (IVec2 + Rect) shipped in the #1 thread.
orkun added the
proposal
priority:medium
area:types
labels 2026-08-31 17:30:50 +02:00
Author
Owner

Shipped — Dict + Set (539f258)

Types phase 4, containers, is done. One open-addressing hash table (runtime/native/dict.ludic — FNV-1a hash, linear probing, tombstone deletes, grows at load factor 0.7) is spliced in on demand and exposed as two namespaces:

  • Dict.* — a map from string keys to int values. new / set / get / get_or / has / remove / size / clear / keys. For resource counts and id/name registries (loot tables, entity registries, config). O(1) average lookup instead of the linear scan a list would give.
  • Set.* — a set of string members. new / add / has / remove / size / clear / members. For tags, unlocked achievements and visited tiles. Shares the same table (a Set is a Dict whose values are ignored).

Values are int, which also holds an entity handle or any small id.

Scope notes for this phase:

  • Richer / heterogeneous maps are already served by the Value.* tree (#44) — a string→Value object — so Dict/Set deliberately specialise to the fast, common string→int case rather than reinventing a generic container without a generics mechanism in the front end.
  • [T; N] inline fixed arrays and grid<T> remain future work: they need parser/type-system support for a new array syntax. The typed buffers words / fixeds / pointers plus []T slices already cover heap-backed arrays today, and Grid.* (#24) covers char tilemaps. I have left this out rather than ship a half-generic array type.

Wired end to end: parser splice trigger (g_uses_dict), emit_call dispatch, reseeded C-free seed, a self-asserting example (examples/library/containers.ludic, 14 assertions incl. a rehash-growth check, in the regression suite), and per-symbol docs + section + inventory. All suites green: x test 83/83, x selfhost-test 30/30 (golden renders byte-identical, bootstrap fixpoint holds), x test-tools 30/30, check-impl/check-vocabulary/check-docs.

Closing phase 4. Phases 3 and 5 remain in #53 / #55.

## Shipped — `Dict` + `Set` (539f258) Types phase 4, containers, is done. One open-addressing hash table (`runtime/native/dict.ludic` — FNV-1a hash, linear probing, tombstone deletes, grows at load factor 0.7) is spliced in on demand and exposed as two namespaces: - **`Dict.*`** — a map from string keys to `int` values. `new` / `set` / `get` / `get_or` / `has` / `remove` / `size` / `clear` / `keys`. For resource counts and id/name registries (loot tables, entity registries, config). O(1) average lookup instead of the linear scan a list would give. - **`Set.*`** — a set of string members. `new` / `add` / `has` / `remove` / `size` / `clear` / `members`. For tags, unlocked achievements and visited tiles. Shares the same table (a Set is a Dict whose values are ignored). Values are `int`, which also holds an `entity` handle or any small id. Scope notes for this phase: - **Richer / heterogeneous maps** are already served by the `Value.*` tree (#44) — a string→Value object — so `Dict`/`Set` deliberately specialise to the fast, common string→int case rather than reinventing a generic container without a generics mechanism in the front end. - **`[T; N]` inline fixed arrays** and **`grid<T>`** remain future work: they need parser/type-system support for a new array syntax. The typed buffers `words` / `fixeds` / `pointers` plus `[]T` slices already cover heap-backed arrays today, and `Grid.*` (#24) covers char tilemaps. I have left this out rather than ship a half-generic array type. Wired end to end: parser splice trigger (`g_uses_dict`), `emit_call` dispatch, reseeded C-free seed, a self-asserting example (`examples/library/containers.ludic`, 14 assertions incl. a rehash-growth check, in the regression suite), and per-symbol docs + section + inventory. All suites green: `x test` 83/83, `x selfhost-test` 30/30 (golden renders byte-identical, bootstrap fixpoint holds), `x test-tools` 30/30, `check-impl`/`check-vocabulary`/`check-docs`. Closing phase 4. Phases 3 and 5 remain in #53 / #55.
orkun closed this issue 2026-08-31 17:51:59 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: workshopsoft/ludic#54
No description provided.