feat(lang): def REGISTRY from "file.lres" - a game fills an open registry from its own file

The entries are read and checked against the registry's record as a
registry ... from file is, errors at the resource file's line, and they
are defs of the module that wrote the line: the registry must be open to
it, and they take that module's place in the stable order. Reseed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-25 07:22:05 +03:00
parent a09b622a1d
commit a5f52c4581
13 changed files with 43732 additions and 43470 deletions

View file

@ -75,9 +75,16 @@ function parse_registry() -> void {
if from != null { res_read(v, from) }
}
# def REGISTRY key { field: value, ... }
# def REGISTRY from "file.lres" - every entry of a resource file, as defs of this file's module
function parse_def() -> void {
pi += 1
let reg = eat_id()
if is_id("from") and toks[pi + 1].kind == TK_STR {
let from = toks[pi + 1].text
pi += 2
res_read_into(reg, from, `def {reg} from`)
return
}
let key = eat_id()
skipnl()
let rec = record()

View file

@ -16,9 +16,14 @@ function res_path(from: pointer, declaring: pointer) -> pointer {
return join_path(dir_of(declaring), from)
}
function res_read(v: Node, from: pointer) -> void {
res_read_into(v.s, from, `registry {v.s}`)
}
# the entries of a resource file into registry `reg`, as defs of the reading file's module: a
# registry's own file, or `def REG from "file.lres"` in a module that extends an open registry
function res_read_into(reg: pointer, from: pointer, who: pointer) -> void {
let path = res_path(from, g_parse_file)
let src = read_file(path)
if src == null { perr(`registry {v.s}: cannot read the resource file {from}`) }
if src == null { perr(`{who}: cannot read the resource file {from}`) }
let saved_toks = toks
let saved_pi = pi
let saved_file = g_parse_file
@ -36,7 +41,7 @@ function res_read(v: Node, from: pointer) -> void {
let key = eat_id()
skipnl()
let rec = record()
push(g_df_reg, v.s)
push(g_df_reg, reg)
push(g_df_key, key)
push(g_df_rec, rec)
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff