ludic/examples/lang/checked.ludic
Orkuncakilkaya 57b66bdf47 feat(lang): L4 type checker between parse and emit
selfhost/check/ walks every function, the entry, tests, globals' initializers and
@On listeners with real scopes, and refuses mixed number kinds, text and numbers,
two record types, mismatched slices and fn types, wrong argument counts, wrong
returns and wrong push elements - every mix-up at once, each at its line.
LUDIC_CHECK_REPORT=1 lists them by category. pointer stays untyped (L7's).

What it found is fixed: render3d's HDR scan calling the float-bits extern f_lt
with floats; ludic.shooter's right-stick aim overflowing past half a push;
prof.ludic storing longs in []int; extern arguments now coerced to their
parameters. Text-returning runtime functions say string; Assets.ready says bool.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-24 01:34:49 +03:00

23 lines
906 B
Text

# checked.ludic — L4: what the checker lets through. A decimal literal is whichever of float and
# fixed its slot is, an int widens into a float, a string is a pointer, a []string is a
# []pointer, null is any reference, string(p) says a pointer is text, and a named argument is
# checked against its own parameter.
#
# Running it prints: 7.5 3 12 hi 2 ok
program Checked {
numbers float
property Box { w: float = 0.0 }
function scale(by: float, n: int) -> float { return by * float(n) }
function raw_text() -> pointer { return "hi" }
function count(xs: []pointer) -> int { return len(xs) }
entry {
let f: fixed = 1.5
let x: float = 2.5
var b: Box = null
b = new Box { w: 3 }
let p: pointer = "any string"
let s: string = string(raw_text())
print(`{scale(by: x, n: 3)} {int(b.w)} {int(f * 8)} {s} {count(["a", "b"])} ok`)
if p == null { print("none") }
}
}