feat(types): Dict + Set string-keyed containers (#54)
Types phase 4 — containers. A splice-on-demand open-addressing hash table (runtime/native/dict.ludic, FNV-1a, linear probing, tombstones, grow at 0.7) behind two namespaces: - Dict.* — string -> int map: new/set/get/get_or/has/remove/size/clear/keys. Resource counts, id/name registries. O(1) average vs a linear list scan. - Set.* — set of strings: new/add/has/remove/size/clear/members. Tags, unlocked achievements, visited tiles. Shares the same table. Values are int (also an entity handle / small id); Value.* covers richer maps. [T; N] inline fixed arrays remain future work — typed buffers and []T slices already cover heap-backed arrays. Wired: parser splice trigger (g_uses_dict), emit_call dispatch, reseeded seed, a self-asserting example (examples/library/containers.ludic + feat_case), and per-symbol docs + inventory. All suites green incl. golden renders byte- identical and the bootstrap fixpoint. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
bd6b12d2ea
commit
539f258d92
26 changed files with 22484 additions and 20936 deletions
|
|
@ -365,6 +365,30 @@ function emit_ns_call(ns: pointer, meth: pointer, e: Node) -> Val {
|
|||
if (meth == "rescale") { bare = "decimal_rescale"; push(labels, "d"); push(labels, "places") }
|
||||
if (meth == "str") { bare = "decimal_str"; push(labels, "d") }
|
||||
}
|
||||
# Dict.* / Set.* -> the hash-table engine (runtime/native/dict.ludic, spliced
|
||||
# on demand). Ordinary Ludic functions, so the generic call path resolves them
|
||||
# to @fn_dict_* / @fn_set_* and keeps their return types (Dict / int / bool /
|
||||
# []pointer).
|
||||
if (ns == "Dict") {
|
||||
if (meth == "new") { bare = "dict_new" }
|
||||
if (meth == "set") { bare = "dict_set"; push(labels, "d"); push(labels, "key"); push(labels, "value") }
|
||||
if (meth == "get") { bare = "dict_get"; push(labels, "d"); push(labels, "key") }
|
||||
if (meth == "get_or") { bare = "dict_get_or"; push(labels, "d"); push(labels, "key"); push(labels, "fallback") }
|
||||
if (meth == "has") { bare = "dict_has"; push(labels, "d"); push(labels, "key") }
|
||||
if (meth == "remove") { bare = "dict_remove"; push(labels, "d"); push(labels, "key") }
|
||||
if (meth == "size") { bare = "dict_size"; push(labels, "d") }
|
||||
if (meth == "clear") { bare = "dict_clear"; push(labels, "d") }
|
||||
if (meth == "keys") { bare = "dict_keys"; push(labels, "d") }
|
||||
}
|
||||
if (ns == "Set") {
|
||||
if (meth == "new") { bare = "set_new" }
|
||||
if (meth == "add") { bare = "set_add"; push(labels, "s"); push(labels, "key") }
|
||||
if (meth == "has") { bare = "set_has"; push(labels, "s"); push(labels, "key") }
|
||||
if (meth == "remove") { bare = "set_remove"; push(labels, "s"); push(labels, "key") }
|
||||
if (meth == "size") { bare = "set_size"; push(labels, "s") }
|
||||
if (meth == "clear") { bare = "set_clear"; push(labels, "s") }
|
||||
if (meth == "members") { bare = "set_members"; push(labels, "s") }
|
||||
}
|
||||
if (ns == "Grid") {
|
||||
if (meth == "line") { bare = "grid_line"; push(labels, "x0"); push(labels, "y0"); push(labels, "x1"); push(labels, "y1") }
|
||||
if (meth == "blocked") { bare = "grid_blocked"; push(labels, "x"); push(labels, "y"); push(labels, "wall") }
|
||||
|
|
|
|||
|
|
@ -176,6 +176,7 @@ function p_postfix() -> Node {
|
|||
if is_op(".") { pi = pi + 1; let m = node(E_MEMBER); m.a = e; m.s = eat_id(); e = m
|
||||
if e.a.kind == E_ID and e.a.s == "Regex" { g_uses_regex = true } # splice the regex runtime on demand
|
||||
if e.a.kind == E_ID and (e.a.s == "BigInt" or e.a.s == "Decimal") { g_uses_bignum = true } # splice the bignum runtime on demand
|
||||
if e.a.kind == E_ID and (e.a.s == "Dict" or e.a.s == "Set") { g_uses_dict = true } # splice the hash-table runtime on demand
|
||||
if e.a.kind == E_ID and e.a.s == "Query" { g_uses_query = true } # splice the ECS spatial-query runtime on demand
|
||||
if e.a.kind == E_ID and e.a.s == "Reflect" { g_uses_reflect = true } # force-emit the reflection ABI (Reflect.* reads the world schema)
|
||||
if e.a.kind == E_ID and e.a.s == "Light" { g_uses_light = true } # splice the 2D light-accumulation pass on demand
|
||||
|
|
@ -423,6 +424,7 @@ var loaded_paths: []pointer
|
|||
var cur_dir: pointer
|
||||
var g_uses_regex: bool = false # a program mentioned Regex.* -> splice the regex runtime
|
||||
var g_uses_bignum: bool = false # a program mentioned BigInt.*/Decimal.* -> splice the bignum runtime
|
||||
var g_uses_dict: bool = false # a program mentioned Dict.*/Set.* -> splice the hash-table runtime
|
||||
var g_uses_query: bool = false # a program mentioned Query.* -> splice the query runtime + reflection ABI
|
||||
var g_uses_reflect: bool = false # a program mentioned Reflect.* -> force-emit the reflection ABI
|
||||
var g_uses_light: bool = false # a program mentioned Light.* -> splice the 2D light pass
|
||||
|
|
@ -608,6 +610,13 @@ function maybe_splice_runtime() -> void {
|
|||
do_import("runtime/native/bignum.ludic")
|
||||
cur_dir = saved
|
||||
}
|
||||
# any program that uses Dict.*/Set.* gets the hash-table engine spliced in
|
||||
# (self-contained — only compiler intrinsics — so a plain tool works too).
|
||||
if g_uses_dict {
|
||||
cur_dir = ""
|
||||
do_import("runtime/native/dict.ludic")
|
||||
cur_dir = saved
|
||||
}
|
||||
# any program that uses Query.* gets the ECS spatial-query helpers spliced in;
|
||||
# they read entity state through the reflection ABI (emit_decl force-emits it
|
||||
# for a Query program even when it declares no events).
|
||||
|
|
@ -723,6 +732,7 @@ function parse_program() -> void {
|
|||
g_toggled_layers = new []pointer
|
||||
g_uses_regex = false
|
||||
g_uses_bignum = false
|
||||
g_uses_dict = false
|
||||
g_uses_query = false
|
||||
g_uses_reflect = false
|
||||
g_uses_esys = false
|
||||
|
|
|
|||
42785
selfhost/ludicc.seed.ll
42785
selfhost/ludicc.seed.ll
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue