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:
parent
ad548840c7
commit
647dfec334
88 changed files with 30081 additions and 29179 deletions
|
|
@ -3,7 +3,7 @@
|
|||
# repeat/pad. Emitted once per program that uses them (g_uses_textrt). Plain
|
||||
# libc (strlen/malloc/memcpy), deterministic, C-string in and out.
|
||||
function emit_text_prelude() -> void {
|
||||
emith("define ptr @fn_str_upper(ptr %s) {\n")
|
||||
emith("define ptr @lp_str_upper(ptr %s) {\n")
|
||||
emith("entry:\n")
|
||||
emith(" %n = call i64 @strlen(ptr %s)\n")
|
||||
emith(" %sz = add i64 %n, 1\n")
|
||||
|
|
@ -33,7 +33,7 @@ function emit_text_prelude() -> void {
|
|||
emith(" store i8 0, ptr %tp\n")
|
||||
emith(" ret ptr %out\n")
|
||||
emith("}\n")
|
||||
emith("define ptr @fn_str_lower(ptr %s) {\n")
|
||||
emith("define ptr @lp_str_lower(ptr %s) {\n")
|
||||
emith("entry:\n")
|
||||
emith(" %n = call i64 @strlen(ptr %s)\n")
|
||||
emith(" %sz = add i64 %n, 1\n")
|
||||
|
|
@ -63,7 +63,7 @@ function emit_text_prelude() -> void {
|
|||
emith(" store i8 0, ptr %tp\n")
|
||||
emith(" ret ptr %out\n")
|
||||
emith("}\n")
|
||||
emith("define ptr @fn_str_trim(ptr %s) {\n")
|
||||
emith("define ptr @lp_str_trim(ptr %s) {\n")
|
||||
emith("entry:\n")
|
||||
emith(" %n = call i64 @strlen(ptr %s)\n")
|
||||
emith(" %sp = alloca i64\n")
|
||||
|
|
@ -79,7 +79,7 @@ function emit_text_prelude() -> void {
|
|||
emith("lchk:\n")
|
||||
emith(" %p0 = getelementptr i8, ptr %s, i64 %a0\n")
|
||||
emith(" %c0 = load i8, ptr %p0\n")
|
||||
emith(" %ws0 = call i1 @fn_is_ws(i8 %c0)\n")
|
||||
emith(" %ws0 = call i1 @lp_is_ws(i8 %c0)\n")
|
||||
emith(" br i1 %ws0, label %linc, label %rcond\n")
|
||||
emith("linc:\n")
|
||||
emith(" %a1 = add i64 %a0, 1\n")
|
||||
|
|
@ -94,7 +94,7 @@ function emit_text_prelude() -> void {
|
|||
emith(" %em1 = sub i64 %e2, 1\n")
|
||||
emith(" %p1 = getelementptr i8, ptr %s, i64 %em1\n")
|
||||
emith(" %c1 = load i8, ptr %p1\n")
|
||||
emith(" %ws1 = call i1 @fn_is_ws(i8 %c1)\n")
|
||||
emith(" %ws1 = call i1 @lp_is_ws(i8 %c1)\n")
|
||||
emith(" br i1 %ws1, label %rdec, label %build\n")
|
||||
emith("rdec:\n")
|
||||
emith(" store i64 %em1, ptr %ep\n")
|
||||
|
|
@ -111,7 +111,7 @@ function emit_text_prelude() -> void {
|
|||
emith(" store i8 0, ptr %tp\n")
|
||||
emith(" ret ptr %out\n")
|
||||
emith("}\n")
|
||||
emith("define i1 @fn_is_ws(i8 %c) {\n")
|
||||
emith("define i1 @lp_is_ws(i8 %c) {\n")
|
||||
emith(" %a = icmp eq i8 %c, 32\n")
|
||||
emith(" %b = icmp eq i8 %c, 9\n")
|
||||
emith(" %d = icmp eq i8 %c, 10\n")
|
||||
|
|
@ -121,7 +121,7 @@ function emit_text_prelude() -> void {
|
|||
emith(" %r = or i1 %ab, %de\n")
|
||||
emith(" ret i1 %r\n")
|
||||
emith("}\n")
|
||||
emith("define ptr @fn_str_repeat(ptr %s, i32 %n32) {\n")
|
||||
emith("define ptr @lp_str_repeat(ptr %s, i32 %n32) {\n")
|
||||
emith("entry:\n")
|
||||
emith(" %nneg = icmp slt i32 %n32, 0\n")
|
||||
emith(" %nn = select i1 %nneg, i32 0, i32 %n32\n")
|
||||
|
|
@ -149,7 +149,7 @@ function emit_text_prelude() -> void {
|
|||
emith(" store i8 0, ptr %tp\n")
|
||||
emith(" ret ptr %out\n")
|
||||
emith("}\n")
|
||||
emith("define ptr @fn_str_pad(ptr %s, i32 %w32, i1 %left) {\n")
|
||||
emith("define ptr @lp_str_pad(ptr %s, i32 %w32, i1 %left) {\n")
|
||||
emith("entry:\n")
|
||||
emith(" %L = call i64 @strlen(ptr %s)\n")
|
||||
emith(" %w0 = sext i32 %w32 to i64\n")
|
||||
|
|
@ -169,20 +169,20 @@ function emit_text_prelude() -> void {
|
|||
emith(" %out = call ptr @malloc(i64 %sz)\n")
|
||||
emith(" br i1 %left, label %padleft, label %padright\n")
|
||||
emith("padleft:\n")
|
||||
emith(" call void @fn_fill_sp(ptr %out, i64 0, i64 %pad)\n")
|
||||
emith(" call void @lp_fill_sp(ptr %out, i64 0, i64 %pad)\n")
|
||||
emith(" %dstL = getelementptr i8, ptr %out, i64 %pad\n")
|
||||
emith(" call ptr @memcpy(ptr %dstL, ptr %s, i64 %L)\n")
|
||||
emith(" br label %term\n")
|
||||
emith("padright:\n")
|
||||
emith(" call ptr @memcpy(ptr %out, ptr %s, i64 %L)\n")
|
||||
emith(" call void @fn_fill_sp(ptr %out, i64 %L, i64 %pad)\n")
|
||||
emith(" call void @lp_fill_sp(ptr %out, i64 %L, i64 %pad)\n")
|
||||
emith(" br label %term\n")
|
||||
emith("term:\n")
|
||||
emith(" %tp = getelementptr i8, ptr %out, i64 %w0\n")
|
||||
emith(" store i8 0, ptr %tp\n")
|
||||
emith(" ret ptr %out\n")
|
||||
emith("}\n")
|
||||
emith("define void @fn_fill_sp(ptr %buf, i64 %start, i64 %count) {\n")
|
||||
emith("define void @lp_fill_sp(ptr %buf, i64 %start, i64 %count) {\n")
|
||||
emith("entry:\n")
|
||||
emith(" %ip = alloca i64\n")
|
||||
emith(" store i64 0, ptr %ip\n")
|
||||
|
|
@ -208,7 +208,7 @@ function emit_text_prelude() -> void {
|
|||
# program that uses them (g_uses_textrt2). Slices are the {data,len,cap}
|
||||
# %LSlice with str (ptr) elements.
|
||||
function emit_text2_prelude() -> void {
|
||||
emith("define ptr @fn_str_replace(ptr %s, ptr %from, ptr %to) {\n")
|
||||
emith("define ptr @lp_str_replace(ptr %s, ptr %from, ptr %to) {\n")
|
||||
emith("entry:\n")
|
||||
emith(" %lf = call i64 @strlen(ptr %from)\n")
|
||||
emith(" %lz = icmp eq i64 %lf, 0\n")
|
||||
|
|
@ -277,7 +277,7 @@ function emit_text2_prelude() -> void {
|
|||
emith(" call ptr @memcpy(ptr %dst3, ptr %src3, i64 %remp1)\n")
|
||||
emith(" ret ptr %out\n")
|
||||
emith("}\n")
|
||||
emith("define ptr @fn_str_join(ptr %h, ptr %sep) {\n")
|
||||
emith("define ptr @lp_str_join(ptr %h, ptr %sep) {\n")
|
||||
emith("entry:\n")
|
||||
emith(" %lp = getelementptr inbounds %LSlice, ptr %h, i32 0, i32 1\n")
|
||||
emith(" %len32 = load i32, ptr %lp\n")
|
||||
|
|
@ -347,7 +347,7 @@ function emit_text2_prelude() -> void {
|
|||
emith(" store i8 0, ptr %dsf\n")
|
||||
emith(" ret ptr %out\n")
|
||||
emith("}\n")
|
||||
emith("define ptr @fn_str_split(ptr %s, ptr %sep) {\n")
|
||||
emith("define ptr @lp_str_split(ptr %s, ptr %sep) {\n")
|
||||
emith("entry:\n")
|
||||
emith(" %lsep = call i64 @strlen(ptr %sep)\n")
|
||||
emith(" %cntp = alloca i64\n")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue