- `[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>
40 lines
1.5 KiB
Text
40 lines
1.5 KiB
Text
# 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) }
|
|
}
|
|
}
|