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

@ -37,17 +37,17 @@ function emit_uuid_ns(meth: pointer, e: Node) -> Val {
g_uses_cryptort = true
g_uses_uuidrt = true
if (meth == "new") or (meth == "v4") { # v4: 122 random bits
return val(emit_bind("call ptr @fn_uuid_v4()"), "string")
return val(emit_bind("call ptr @lp_uuid_v4()"), "string")
}
if (meth == "new_v7") or (meth == "v7") { # v7: ms timestamp + random
return val(emit_bind("call ptr @fn_uuid_v7()"), "string")
return val(emit_bind("call ptr @lp_uuid_v7()"), "string")
}
if (meth == "nil") { # the all-zero UUID
return val(emit_bind("call ptr @fn_uuid_nil()"), "string")
return val(emit_bind("call ptr @lp_uuid_nil()"), "string")
}
if (meth == "is_valid") { # well-formed UUID? -> bool
let s = emit_expr(e.kids[0])
return val(emit_bind(`call i32 @fn_uuid_valid(ptr {s.code})`), "bool")
return val(emit_bind(`call i32 @lp_uuid_valid(ptr {s.code})`), "bool")
}
if (meth == "to_text") { # already canonical text: identity
let s = emit_expr(e.kids[0])
@ -55,13 +55,13 @@ function emit_uuid_ns(meth: pointer, e: Node) -> Val {
}
if (meth == "equals") { # case-insensitive equality -> bool
let a = emit_expr(e.kids[0]); let b = emit_expr(e.kids[1])
return val(emit_bind(`call i32 @fn_uuid_eq(ptr {a.code}, ptr {b.code})`), "bool")
return val(emit_bind(`call i32 @lp_uuid_eq(ptr {a.code}, ptr {b.code})`), "bool")
}
# parse(s): normalise an untrusted string to a lowercase UUID, or the nil UUID
# when it is not well-formed. Callers that must reject bad input should gate on
# Uuid.is_valid(s) first; this never faults on garbage.
let s = emit_expr(e.kids[0])
return val(emit_bind(`call ptr @fn_uuid_parse(ptr {s.code})`), "string")
return val(emit_bind(`call ptr @lp_uuid_parse(ptr {s.code})`), "string")
}
# emit_uuid_prelude — the UUID runtime, emitted once per program that uses Uuid.*
@ -71,8 +71,8 @@ function emit_uuid_ns(meth: pointer, e: Node) -> Val {
function emit_uuid_prelude() -> void {
# 16 raw bytes -> a fresh canonical 36-char string. hex-encode all 16 bytes,
# then splice the four hyphens between the 8/4/4/4/12 groups.
emith("define ptr @fn_uuid_format(ptr %b16) {\n")
emith("entry:\n %hex = call ptr @fn_hex_encode(ptr %b16, i64 16)\n %out = call ptr @malloc(i64 37)\n")
emith("define ptr @lp_uuid_format(ptr %b16) {\n")
emith("entry:\n %hex = call ptr @lp_hex_encode(ptr %b16, i64 16)\n %out = call ptr @malloc(i64 37)\n")
emith(" call ptr @memcpy(ptr %out, ptr %hex, i64 8)\n")
emith(" %o8 = getelementptr i8, ptr %out, i64 8\n store i8 45, ptr %o8\n")
emith(" %h8 = getelementptr i8, ptr %hex, i64 8\n %o9 = getelementptr i8, ptr %out, i64 9\n call ptr @memcpy(ptr %o9, ptr %h8, i64 4)\n")
@ -87,18 +87,18 @@ function emit_uuid_prelude() -> void {
# v4: 16 CSPRNG bytes, then set version (0x4x in byte 6) and variant (0b10xx in
# byte 8). 0x80 does not fit an i8 immediate, so it is written as -128.
emith("define ptr @fn_uuid_v4() {\n")
emith("entry:\n %b = alloca [16 x i8]\n %bp = getelementptr [16 x i8], ptr %b, i64 0, i64 0\n call void @fn_secure_bytes(ptr %bp, i64 16)\n")
emith("define ptr @lp_uuid_v4() {\n")
emith("entry:\n %b = alloca [16 x i8]\n %bp = getelementptr [16 x i8], ptr %b, i64 0, i64 0\n call void @lp_secure_bytes(ptr %bp, i64 16)\n")
emith(" %p6 = getelementptr i8, ptr %bp, i64 6\n %v6 = load i8, ptr %p6\n %v6a = and i8 %v6, 15\n %v6b = or i8 %v6a, 64\n store i8 %v6b, ptr %p6\n")
emith(" %p8 = getelementptr i8, ptr %bp, i64 8\n %v8 = load i8, ptr %p8\n %v8a = and i8 %v8, 63\n %v8b = or i8 %v8a, -128\n store i8 %v8b, ptr %p8\n")
emith(" %s = call ptr @fn_uuid_format(ptr %bp)\n ret ptr %s\n}\n")
emith(" %s = call ptr @lp_uuid_format(ptr %bp)\n ret ptr %s\n}\n")
# v7: random fill, then overwrite the first 6 bytes with a 48-bit big-endian
# Unix-millisecond timestamp; set version 7 (0x7x) and the variant. Sub-second
# resolution is derived from time() seconds * 1000 — monotonic per second, with
# the random tail keeping same-millisecond IDs distinct.
emith("define ptr @fn_uuid_v7() {\n")
emith("entry:\n %b = alloca [16 x i8]\n %bp = getelementptr [16 x i8], ptr %b, i64 0, i64 0\n call void @fn_secure_bytes(ptr %bp, i64 16)\n")
emith("define ptr @lp_uuid_v7() {\n")
emith("entry:\n %b = alloca [16 x i8]\n %bp = getelementptr [16 x i8], ptr %b, i64 0, i64 0\n call void @lp_secure_bytes(ptr %bp, i64 16)\n")
emith(" %t = call i64 @time(ptr null)\n %ms = mul i64 %t, 1000\n")
emith(" %s40 = lshr i64 %ms, 40\n %t0 = trunc i64 %s40 to i8\n %q0 = getelementptr i8, ptr %bp, i64 0\n store i8 %t0, ptr %q0\n")
emith(" %s32 = lshr i64 %ms, 32\n %t1 = trunc i64 %s32 to i8\n %q1 = getelementptr i8, ptr %bp, i64 1\n store i8 %t1, ptr %q1\n")
@ -108,10 +108,10 @@ function emit_uuid_prelude() -> void {
emith(" %t5 = trunc i64 %ms to i8\n %q5 = getelementptr i8, ptr %bp, i64 5\n store i8 %t5, ptr %q5\n")
emith(" %p6 = getelementptr i8, ptr %bp, i64 6\n %v6 = load i8, ptr %p6\n %v6a = and i8 %v6, 15\n %v6b = or i8 %v6a, 112\n store i8 %v6b, ptr %p6\n")
emith(" %p8 = getelementptr i8, ptr %bp, i64 8\n %v8 = load i8, ptr %p8\n %v8a = and i8 %v8, 63\n %v8b = or i8 %v8a, -128\n store i8 %v8b, ptr %p8\n")
emith(" %s = call ptr @fn_uuid_format(ptr %bp)\n ret ptr %s\n}\n")
emith(" %s = call ptr @lp_uuid_format(ptr %bp)\n ret ptr %s\n}\n")
# the nil UUID: 36 '0' with hyphens spliced in
emith("define ptr @fn_uuid_nil() {\n")
emith("define ptr @lp_uuid_nil() {\n")
emith("entry:\n %out = call ptr @malloc(i64 37)\n call ptr @memset(ptr %out, i32 48, i64 36)\n")
emith(" %o8 = getelementptr i8, ptr %out, i64 8\n store i8 45, ptr %o8\n")
emith(" %o13 = getelementptr i8, ptr %out, i64 13\n store i8 45, ptr %o13\n")
@ -120,7 +120,7 @@ function emit_uuid_prelude() -> void {
emith(" %o36 = getelementptr i8, ptr %out, i64 36\n store i8 0, ptr %o36\n ret ptr %out\n}\n")
# is %s a well-formed UUID? length 36, hyphens at 8/13/18/23, hex elsewhere.
emith("define i32 @fn_uuid_valid(ptr %s) {\n")
emith("define i32 @lp_uuid_valid(ptr %s) {\n")
emith("entry:\n %n = call i64 @strlen(ptr %s)\n %ne = icmp eq i64 %n, 36\n br i1 %ne, label %go, label %bad\n")
emith("go:\n %ip = alloca i64\n store i64 0, ptr %ip\n br label %cond\n")
emith("cond:\n %i = load i64, ptr %ip\n %lt = icmp ult i64 %i, 36\n br i1 %lt, label %body, label %good\n")
@ -138,7 +138,7 @@ function emit_uuid_prelude() -> void {
emith("bad:\n ret i32 0\n}\n")
# case-insensitive equality of two null-terminated strings -> i32 bool
emith("define i32 @fn_uuid_eq(ptr %a, ptr %b) {\n")
emith("define i32 @lp_uuid_eq(ptr %a, ptr %b) {\n")
emith("entry:\n %la = call i64 @strlen(ptr %a)\n %lb = call i64 @strlen(ptr %b)\n %eq = icmp eq i64 %la, %lb\n br i1 %eq, label %go, label %ne\n")
emith("go:\n %ip = alloca i64\n store i64 0, ptr %ip\n br label %cond\n")
emith("cond:\n %i = load i64, ptr %ip\n %lt = icmp ult i64 %i, %la\n br i1 %lt, label %body, label %eqret\n")
@ -151,8 +151,8 @@ function emit_uuid_prelude() -> void {
emith("ne:\n ret i32 0\n}\n")
# parse: lowercase-normalise a valid UUID, else return the nil UUID.
emith("define ptr @fn_uuid_parse(ptr %s) {\n")
emith("entry:\n %ok = call i32 @fn_uuid_valid(ptr %s)\n %isok = icmp ne i32 %ok, 0\n br i1 %isok, label %dup, label %nilb\n")
emith("define ptr @lp_uuid_parse(ptr %s) {\n")
emith("entry:\n %ok = call i32 @lp_uuid_valid(ptr %s)\n %isok = icmp ne i32 %ok, 0\n br i1 %isok, label %dup, label %nilb\n")
emith("dup:\n %out = call ptr @malloc(i64 37)\n %ip = alloca i64\n store i64 0, ptr %ip\n br label %cond\n")
emith("cond:\n %i = load i64, ptr %ip\n %lt = icmp ult i64 %i, 36\n br i1 %lt, label %body, label %fin\n")
emith("body:\n %p = getelementptr i8, ptr %s, i64 %i\n %c = load i8, ptr %p\n")
@ -160,5 +160,5 @@ function emit_uuid_prelude() -> void {
emith(" %op = getelementptr i8, ptr %out, i64 %i\n store i8 %cl, ptr %op\n")
emith(" %i1 = add i64 %i, 1\n store i64 %i1, ptr %ip\n br label %cond\n")
emith("fin:\n %o36 = getelementptr i8, ptr %out, i64 36\n store i8 0, ptr %o36\n ret ptr %out\n")
emith("nilb:\n %nn = call ptr @fn_uuid_nil()\n ret ptr %nn\n}\n")
emith("nilb:\n %nn = call ptr @lp_uuid_nil()\n ret ptr %nn\n}\n")
}