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

@ -81,6 +81,7 @@ over the compiler's built-in loopback transport with zero foreign code.
| [`lang/toggle.ludic`](lang/toggle.ludic) | enable/disable at the three ECS scopes. |
| [`lang/scenes.ludic`](lang/scenes.ludic) | One active scene at a time, handlers grouped into layers. |
| [`lang/strings.ludic`](lang/strings.ludic) | Strings as values: compare, join, interpolate, slice. |
| [`lang/operators.ludic`](lang/operators.ludic) | Compound assignment on every type, unary minus, char escapes, list literals. |
| [`lang/rng_demo.ludic`](lang/rng_demo.ludic) | The `Random.*` extensions (value/int/sign). |
| [`lang/time_demo.ludic`](lang/time_demo.ludic) | `Time.frame` / `elapsed` / `delta`. |
| [`lang/offline_rewards.ludic`](lang/offline_rewards.ludic) | A worked idle-game example over the Time/Date/Duration stdlib. |

View file

@ -24,10 +24,10 @@ program RPG2D {
# Move every Actor whose scale is positive and that is actually moving. The
# query is the decorator; each bound property is addressed by its own name.
@Queries(these: [Transform{scale > 0}, Velocity{dx > 0 or dy > 0}], on: Actor)
@Queries(these: [Transform { scale > 0 }, Velocity { dx > 0 or dy > 0 }], on: Actor)
handler Move phase Update {
Transform.x = Transform.x + Velocity.dx
Transform.y = Transform.y + Velocity.dy
Transform.x += Velocity.dx
Transform.y += Velocity.dy
}
handler Report phase Render {

View file

@ -0,0 +1,40 @@
# operators.ludic — compound assignment (`+= -= *= /=`) is exactly `x = x op y`,
# whatever the type: Q16.16 `fixed` multiplies through the 64-bit path, strings
# concatenate, an `int` added to a `long` widens. Unary minus keeps its operand's
# type, character literals accept the same escapes as strings, and `[a, b, c]`
# builds a slice in place. Running it prints: 1 2 3 4 5 6 7 8 9 10
program Operators {
entry {
var f: fixed = 1.5
f *= 2.0
if f == 3.0 { print(1) } # fixed *= is a Q16.16 multiply, not a raw mul
f /= 4.0
if f == 0.75 { print(2) }
let neg: fixed = -f
if neg + f == 0.0 { print(3) } # -fixed is still a fixed
var s = "ab"
s += "cd"
if s == "abcd" { print(4) } # string += concatenates
var n = 40
n += 2
n -= 1
n *= 2
n /= 3
if n == 27 { print(5) }
var big: long = 1
big += n # int widens into the long
if big == 28 { print(6) }
if '\'' == 39 and '\\' == 92 and '\n' == 10 { print(7) } # char escapes mirror string escapes
if "q\"b\\c" == `q"b\\c` { print(8) } # "…" and `…` share one escape table
if `{Text.length("{")}{Text.length("}")}` != "11" { print(0) } # braces inside a hole's string are text
let primes = [2, 3, 5, 7] # a list literal is a fresh slice
if len(primes) == 4 and primes[3] == 7 { print(9) }
let names = ["ember", "depths"]
if names[1] == "depths" { print(10) }
}
}

View file

@ -22,7 +22,7 @@ program QueryDecl {
# a per-property constraint `Battle{...}` qualifies its bare fields to that
# property; `on: Foe` adds the {Foe} kind filter.
@Queries(these: [Battle{hp <= 0 and side == 1}, Pos], on: Foe)
@Queries(these: [Battle { hp <= 0 and side == 1 }, Pos], on: Foe)
handler CleanBattle phase LateUpdate {
print(Pos.x)
despawn self()

View file

@ -24,7 +24,7 @@ program SceneDemo {
on exit { print(2) }
layer Main {
handler Tick phase Update {
counter = counter + 1
counter += 1
print(100 + counter)
if counter >= 2 { become Play }
}
@ -36,7 +36,7 @@ program SceneDemo {
on exit { print(4) }
layer World {
handler Step phase Update {
counter = counter + 1
counter += 1
print(200 + counter)
if counter >= 2 { quit() }
}

View file

@ -1,5 +1,5 @@
# strings.ludic — strings are values: compare with ==/!=, join with +, or (best)
# interpolate with `backticks {expr}`. Running it prints: 1 2 3 4 5 6 7
# interpolate with `backticks {expr}`. Running it prints: 1 2 3 4 5 6 7 8 9
program Strings {
entry {
let greeting = "hello"
@ -13,7 +13,7 @@ program Strings {
# build up a string in a loop
var line = ""
var i = 0
while i < 3 { line = line + "ab"; i = i + 1 }
while i < 3 { line += "ab"; i += 1 }
if line == "ababab" { print(4) }
if (greeting + who) != greeting { print(5) }

View file

@ -2,7 +2,7 @@
# host input, so instead of fixed answers we assert the invariants that must hold
# regardless of where it runs: an env var round-trips, env_or falls back when a
# var is unset, unset removes it, args() agrees with arg_count(), and the host
# facts and known folders are all non-empty. Running it prints: 1 2 3 4 5 6 7 8 9 10 11 12 13
# facts and known folders are all non-empty. Running it prints: 1 2 3 4 5 6 7 8 9 10 11 12 13 14
program Os {
entry {
# environment variables round-trip through set/get
@ -30,8 +30,11 @@ program Os {
if len(Os.save_dir("MyGame")) > 0 { print(11) }
if len(Os.temp_dir()) > 0 { print(12) }
# the process id is a live, positive OS handle
if Os.pid() > 0 { print(13) }
# diagnostics go to stderr, so they never disturb this program's stdout
Os.stderr_write("os.ludic: hello from stderr\n")
print(13)
print(14)
}
}