Language: named colors, namespaced Screen/Input/Random/Map API, named args

An opinionated, game-facing surface for the language:
- Color.<Name>: 221 named colors resolved to 0xRRGGBB at compile time
  (selfhost/emit_color.ludic).
- Namespaced builtins Screen.* / Input.key / Random.* / Map.*, so calls read as
  subject.action; present() -> Screen.show(), clear -> Screen.clear,
  fill_rect -> Screen.fill_rectangle, etc.
- Named arguments, e.g. Screen.fill_rectangle(x:, y:, width:, height:, color:),
  reordered to the callee's parameters at emit time.
- machine/become can run over a named program-scope var, not just a register.
- Migrate examples off numeric registers to named vars; snake/menu/chronorift
  render byte-identical to the goldens and the bootstrap fixpoint is preserved.
- Regenerate the checked-in seed (selfhost/ludicc.seed.ll).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-08-29 16:05:55 +03:00
parent 9e4837428c
commit a3a1e4d160
14 changed files with 11784 additions and 7493 deletions

View file

@ -1,10 +1,25 @@
# emit_machine.ludic — `machine <reg> { state Name = v { .. } }` dispatches on a
# register's value; `become Name` stores the target state's value back. Both are
# reg()/set_reg() calls, resolved to the runtime like any other builtin.
# emit_machine.ludic — `machine <state> { state Name = v { .. } }` dispatches on
# an int state store; `become Name` writes the target state's value back. The
# store is either a named program-scope `var` (loaded/stored directly) or, for
# older code, a register index (reg()/set_reg()).
# If `a` names a program-scope `var`, return it; else null (a register index).
fn machine_var(a: Node) -> Node {
if a.kind == E_ID {
let g = find_global(a.s)
if (g != null) { if g.kind == N_VAR { return g } }
}
return null
}
fn emit_machine(st: Node) -> void {
let regv = emit_expr(st.a)
let s = emit_bind(`call i32 @fn_rt_reg(i32 {regv.code})`)
let gv = machine_var(st.a)
var s = ""
if (gv != null) { s = emit_bind(`load i32, ptr @g_{st.a.s}`) }
else {
let regv = emit_expr(st.a)
s = emit_bind(`call i32 @fn_rt_reg(i32 {regv.code})`)
}
if nmach < len(mach_stk) { mach_stk[nmach] = st } else { push(mach_stk, st) }
nmach = nmach + 1
let endl = lbl("smend")
@ -37,9 +52,14 @@ fn emit_become(st: Node) -> void {
var i = 0
while i < len(m.kids) { if (m.kids[i].s == st.s) { target = m.kids[i] }; i = i + 1 }
if (target != null) {
let regv = emit_expr(m.a)
let gv = machine_var(m.a)
let sv = emit_expr(target.b)
emit(" call void @fn_rt_set_reg(i32 "); emit(regv.code); emit(", i32 "); emit(sv.code); emit(")\n")
if (gv != null) {
emit(" store i32 "); emit(sv.code); emit(", ptr @g_"); emit(m.a.s); emit("\n")
} else {
let regv = emit_expr(m.a)
emit(" call void @fn_rt_set_reg(i32 "); emit(regv.code); emit(", i32 "); emit(sv.code); emit(")\n")
}
return
}
}