feat(compiler): list literals, typed compound assignment, file:line diagnostics

- `[a, b, c]` list literals (E_LIST → emit_list); static_type learns
  slice-element, `new T`, list, string and literal kinds
- `x op= y` lowers through the same path as `x = x op y` (emit_bin_vals):
  fixed `*=`/`/=` use the Q16.16 64-bit paths, string `+=` concatenates,
  int→long widens; unary `-` keeps a fixed operand's type (arith_ty)
- one `unescape()` table for "strings", 'chars' and `interpolation`;
  `'\''`, `'\\'`, `'\"'` no longer read as 0; unterminated char literals
  and unexpected characters are errors instead of silently skipped
- every diagnostic is `file:line: error: msg` (g_parse_file / g_err_file,
  Node.file + Node.line set by node()); tok_desc() in expectation errors;
  duplicate `function` names and unknown `phase` names are reported in
  source terms (phase_id used to default unknown phases to Overlay)
- interpolation holes skip braces inside string literals
- hand-IR preludes move from the user `@fn_` prefix to `@lp_` so a user
  `is_ws` / `str_eq` / `path_join` no longer collides at link time
- `@ClearColor(expr)` accepts any constant expression; `Os.pid()` added
  (docs page + inventory); `str_starts()` in support/str
- main.ludic: `else if` flag ladder, char literals, stale script comments
- examples/lang/operators.ludic covers all of the above; os.ludic covers
  Os.pid; docs pages for Os.pid and the Overlay phase; ten changesets
- reseeded: selfhost/ludicc.seed.ll is the new compiler's own fixpoint

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-05 01:12:16 +03:00
parent ad548840c7
commit 647dfec334
88 changed files with 30081 additions and 29179 deletions

View file

@ -24,7 +24,7 @@ program Demo {
model Boom { Blast }
handler Run phase Update {
Blast.timer = Blast.timer + Time.delta()
if Anim.finished(Blast.timer, 15, 6) { despawn(self()) }
if Anim.finished(Blast.timer, 15, 6) { despawn (self()) }
}
}
```

View file

@ -9,7 +9,7 @@ tip: Declare a clear colour so the Render phase auto-clears + auto-presents for
order: 62
---
<code>@ClearColor(N)</code> declares the framebuffer clear colour (a <code>0x00RRGGBB</code> integer) so the engine owns the per-frame clear and present: at the top of the Render phase it clears the framebuffer to <code>N</code>, and after all Render handlers run it presents the frame — so a game's Render handler carries no <code>Screen.clear</code> / <code>Screen.show</code> boilerplate, and the colour is configured declaratively rather than written in the handler body. It is opt-in: a program with no <code>@ClearColor</code> is byte-for-byte identical (it clears and presents itself, or the light system owns the present). Place it on the program's Render handler (or any declaration — it is program-wide).
<code>@ClearColor(N)</code> declares the framebuffer clear colour (a <code>0x00RRGGBB</code> integer) so the engine owns the per-frame clear and present: at the top of the Render phase it clears the framebuffer to <code>N</code>, and after all Render handlers run it presents the frame — so a game's Render handler carries no <code>Screen.clear</code> / <code>Screen.show</code> boilerplate, and the colour is configured declaratively rather than written in the handler body. It is opt-in: a program with no <code>@ClearColor</code> is byte-for-byte identical (it clears and presents itself, or the light system owns the present). Place it on the program's Render handler (or any declaration — it is program-wide). The argument is any constant expression — a hex literal, a `Color.*` name, or a `const` from your palette.
```ludic
program ClearColorDemo {

View file

@ -19,7 +19,7 @@ program DespawnHook {
@OnDespawn(Enemy, reason: teardown_reason) handler DropLoot {
match teardown_reason {
EndReason.Quit => {} # app closing — do not drop loot
EndReason.Quit => { } # app closing — do not drop loot
_ => { print(Loot.gold) } # died in-world — award the gold
}
}

View file

@ -14,7 +14,7 @@ These are the two declarative switches at the top of Ludic's networking: <code>@
```ludic
program SyncedWorld {
@Sync property Position { column: int = 0, row: int = 0 } # every field replicable
property Health { @Sync current: int = 0, maximum: int = 0 } # only current replicable
property Health { @Sync current: int = 0, maximum: int = 0 } # only current replicable
@Owned model Player { @Sync Position, @Sync Health } # participates -> column,row,current
model Scenery { Position } # not @Sync here -> never replicates

View file

@ -24,19 +24,19 @@ program TitleMenu {
}
handler Boot phase Start {
title_font = font_load("/System/Library/Fonts/Supplemental/Arial.ttf")
title_font = Font.load("/System/Library/Fonts/Supplemental/Arial.ttf")
ui_build()
ui_open(UI_MainMenu)
Ui.open(UI_MainMenu)
}
handler Navigate phase Update {
ui_tick(Input.key())
if ui_clicked(UI_Quit) { quit() }
Ui.tick(Input.key())
if Ui.clicked(UI_Quit) { quit() }
}
handler DrawWorld phase Render {
Screen.clear(Color.MidnightBlue)
ui_render()
Ui.render()
Screen.show()
}
}

View file

@ -22,7 +22,7 @@ program Checksum {
let data = "save:level=3;coins=120"
let ck = Hash.crc32(data) # store this next to the save; recompute on load
print(ck)
print(Hash.crc32(data) == ck) # 1 — unchanged data checks out
print(Hash.crc32(data) == ck) # 1 — unchanged data checks out
}
}
```

View file

@ -21,9 +21,9 @@ program Demo {
Screen.clear(0)
Light.ambient(Color.rgb(24, 24, 32))
Light.gel(Color.rgb(40, 60, 160))
Light.point(60, 60, 60, Color.rgb(255, 200, 120), 1.0) # gelled
Light.point(60, 60, 60, Color.rgb(255, 200, 120), 1.0) # gelled
Light.clear_gel()
Light.point(150, 60, 60, Color.rgb(255, 240, 200), 1.0) # flat again
Light.point(150, 60, 60, Color.rgb(255, 240, 200), 1.0) # flat again
Screen.show()
}
}

View file

@ -24,7 +24,7 @@ program Demo {
Screen.clear(0)
Light.ambient(Color.rgb(24, 24, 32))
Light.gel(Color.rgb(40, 60, 160)) # cool blue rim
Light.point(80, 60, 70, Color.rgb(255, 200, 120), 1.0) # warm core
Light.point(80, 60, 70, Color.rgb(255, 200, 120), 1.0) # warm core
Light.clear_gel()
Screen.show()
}

View file

@ -13,5 +13,5 @@ The access operators reach into a compound value. `value.field` reads or writes
```ludic
let head_column: int = segments[0].column
segments[0].column = head_column + 1
let extension: string = file_name[len(file_name) - 4 .. len(file_name)]
let extension: string = file_name[len(file_name) - 4..len(file_name)]
```

View file

@ -0,0 +1,23 @@
---
id: os-pid
name: Os.pid
category: os
kind: namespace-method
tokens: Os.pid
sig: Os.pid() -> int
tip: This process's id.
order: 18
ns: Os
member: pid
---
The operating system's id for this process — unique among the processes alive right now, so it is the natural suffix for scratch files that concurrent runs of the same tool must not share.
```ludic
program Pid {
entry {
let scratch = `{Os.temp_dir()}/mytool_{Os.pid()}.log`
print(len(scratch) > 0)
}
}
```

View file

@ -0,0 +1,41 @@
---
id: phase-overlay
name: Overlay
category: phases
kind: phase
tokens: Overlay
sig: phase Overlay
tip: The HUD pass — runs after Render and after every engine-owned drawing system.
order: 6
---
`Overlay` runs after `Render` and after every engine-owned drawing system (sprites, lights, the scene's `shows` menu), so a `handler … phase Overlay` paints on top of the finished world: health bars, score, prompts, a boss bar. With `@ClearColor` the engine owns the clear and the present, so an `Overlay` handler only draws — no `Screen.clear`, no `Screen.show`. Like `Render`, it should read the world and never change it.
```ludic
program OverlayExample {
property Position { column: int = 0, row: int = 0 }
model Player { Position }
const TILE_SIZE: int = 16
var score: int = 0
handler PlacePlayer phase Start {
spawn Player { Position { column: 5, row: 6 } }
}
@ClearColor(Color.MidnightBlue)
handler DrawWorld phase Render {
for (current_position) in query [Position, {Player}] {
Screen.fill_rectangle(
x: current_position.column * TILE_SIZE,
y: current_position.row * TILE_SIZE,
width: TILE_SIZE, height: TILE_SIZE, color: Color.LimeGreen)
}
}
handler DrawHud phase Overlay {
Screen.draw_text(x: 6, y: 4, text: "SCORE", color: Color.White, scale: 1)
Screen.draw_number(x: 52, y: 4, value: score, color: Color.Gold, scale: 1)
}
}
```

View file

@ -20,6 +20,6 @@ program Demo {
let idx = Random.int(list_count)
}
}
}
}
}
```

View file

@ -20,6 +20,6 @@ program Demo {
let dir = Random.sign()
}
}
}
}
}
```

View file

@ -20,6 +20,6 @@ program Demo {
let t = Random.value()
}
}
}
}
}
```

View file

@ -9,7 +9,7 @@ tip: Declare a retained widget tree as data; the engine lays it out and draws it
order: 50
---
A <code>ui</code> block declares a <b>retained</b> widget tree as data — panels, labels and buttons — and hands layout, drawing and keyboard focus to the engine, so you describe the interface once instead of repainting it every frame. Widget types are `panel` (a container with optional skin/background/border), `col`/`row` (pure stacks), `label`, `button` (focusable), `image` and `spacer`, and their props are evaluated at build time, so `font: title_font` reads a value the program set first. Each `id: Name` mints a `UI_Name` handle you drive from handlers: call `ui_build()` then `ui_open(UI_MainMenu)` at start, `ui_tick(Input.key())` each update to move focus and activate, and `ui_clicked(UI_Name)` to react. Draw it during `Render` with `ui_render()` between `Screen.clear` and `Screen.show()`.
A <code>ui</code> block declares a <b>retained</b> widget tree as data — panels, labels and buttons — and hands layout, drawing and keyboard focus to the engine, so you describe the interface once instead of repainting it every frame. Widget types are `panel` (a container with optional skin/background/border), `col`/`row` (pure stacks), `label`, `button` (focusable), `image` and `spacer`, and their props are evaluated at build time, so `font: title_font` reads a value the program set first. Each `id: Name` mints a `UI_Name` handle you drive from handlers: call `Ui.build()` then `Ui.open(UI_MainMenu)` at start, `Ui.tick(Input.key())` each update to move focus and activate, and `Ui.clicked(UI_Name)` to react. Draw it during `Render` with `Ui.render()` between `Screen.clear` and `Screen.show()`.
```ludic
program TitleScreen {
@ -24,19 +24,19 @@ program TitleScreen {
}
handler Boot phase Start {
title_font = font_load("/System/Library/Fonts/Supplemental/Arial.ttf")
ui_build()
ui_open(UI_MainMenu)
title_font = Font.load("/System/Library/Fonts/Supplemental/Arial.ttf")
Ui.build()
Ui.open(UI_MainMenu)
}
handler Navigate phase Update {
ui_tick(Input.key())
if ui_clicked(UI_Quit) { quit() }
Ui.tick(Input.key())
if Ui.clicked(UI_Quit) { quit() }
}
handler DrawWorld phase Render {
Screen.clear(Color.MidnightBlue)
ui_render()
Ui.render()
Screen.show()
}
}