feat(lang): L8 registries by declaration - registry and def

registry NAME of RECORD [as PREFIX] is a global table; def NAME key { ... } in
any file is one entry, collected in source order and filled before any code
runs. Each entry gets an index constant (PREFIX_KEY), the table PREFIX_COUNT,
and a record with a key field gets it filled and a NAME_find(key). A record
literal naming a field its record lacks is now an error everywhere; a global's
initializer is lowered as its own file's code (its errors, and what its module
may see, were whichever statement came last).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-24 13:34:51 +03:00
parent b0b0b62bce
commit 7e7f3ab297
15 changed files with 48231 additions and 44362 deletions

View file

@ -0,0 +1,24 @@
# registry.ludic — L8: registration by declaration. A registry is a table of records; each `def`
# is one entry, written where it belongs - in any file, in source order - rather than as a call
# in an init function. The compiler fills the table before any code runs, gives every entry an
# index constant (the prefix and the key: HF_CRATE), a count (HF_COUNT), fills a `key` field
# when the record has one, and adds a lookup by key (furnishings_find).
#
# Running it prints: 3 Crate true 2 fire_ring -1
program Registry {
def Furnishings bench { name: "Bench", cost: 90, seat: true }
property Furnishing {
key: string = ""
name: string = ""
cost: int = 0
seat: bool = false
}
registry Furnishings of Furnishing as HF
def Furnishings crate { name: "Crate", cost: 30 }
def Furnishings fire_ring { name: "Fire ring", cost: 120 }
entry {
var seat = "false"
if Furnishings[HF_BENCH].seat { seat = "true" }
print(`{HF_COUNT} {Furnishings[HF_CRATE].name} {seat} {furnishings_find("fire_ring")} {Furnishings[2].key} {furnishings_find("nope")}`)
}
}

View file

@ -0,0 +1,10 @@
# L8: Furnishing has no field colour
program R {
property Furnishing {
key: string = ""
cost: int = 0
}
registry Furnishings of Furnishing
def Furnishings crate { colour: 3 }
entry { print(FURNISHINGS_COUNT) }
}

View file

@ -0,0 +1,11 @@
# L8: def Furnishings crate is declared twice
program R {
property Furnishing {
key: string = ""
cost: int = 0
}
registry Furnishings of Furnishing
def Furnishings crate { cost: 1 }
def Furnishings crate { cost: 2 }
entry { print(FURNISHINGS_COUNT) }
}

View file

@ -0,0 +1,10 @@
# L8: there is no registry Tables
program R {
property Furnishing {
key: string = ""
cost: int = 0
}
registry Furnishings of Furnishing
def Tables x { cost: 1 }
entry { print(FURNISHINGS_COUNT) }
}