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>
This commit is contained in:
parent
0677aee93f
commit
57b66bdf47
52 changed files with 27005 additions and 11844 deletions
23
examples/lang/checked.ludic
Normal file
23
examples/lang/checked.ludic
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
# 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") }
|
||||
}
|
||||
}
|
||||
11
examples/rejected/every_error.ludic
Normal file
11
examples/rejected/every_error.ludic
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
# L4: every mix-up in a program is reported at once, not only the first
|
||||
program EveryError {
|
||||
function half(n: int) -> int { return n / 2 }
|
||||
function name() -> int { return "seven" }
|
||||
entry {
|
||||
let on = true
|
||||
print(on + 1)
|
||||
print(half(1, 2))
|
||||
print(name())
|
||||
}
|
||||
}
|
||||
10
examples/rejected/float_into_int.ludic
Normal file
10
examples/rejected/float_into_int.ludic
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# L4: a float computed into an int slot is refused - write int(x)
|
||||
program FloatIntoInt {
|
||||
numbers float
|
||||
entry {
|
||||
let speed: float = 3.2
|
||||
var metres: int = 0
|
||||
metres = speed * 2.0
|
||||
print(metres)
|
||||
}
|
||||
}
|
||||
9
examples/rejected/record_as_text.ludic
Normal file
9
examples/rejected/record_as_text.ludic
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
# L4: a record is not text; say which of its fields is meant
|
||||
program RecordAsText {
|
||||
property Trail { name: string = "Crater Lake" }
|
||||
function sign(s: string) -> string { return "To " + s }
|
||||
entry {
|
||||
let t = new Trail
|
||||
print(sign(t))
|
||||
}
|
||||
}
|
||||
10
examples/rejected/record_mixup.ludic
Normal file
10
examples/rejected/record_mixup.ludic
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
# L4: one record is not another, whatever their fields
|
||||
program RecordMixup {
|
||||
property Door { open: bool = false }
|
||||
property Key { cut: int = 0 }
|
||||
entry {
|
||||
let k = new Key
|
||||
let d: Door = k
|
||||
print(d.open)
|
||||
}
|
||||
}
|
||||
7
examples/rejected/text_plus_number.ludic
Normal file
7
examples/rejected/text_plus_number.ludic
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
# L4: text joins text only; a number is written with string(n) or a template
|
||||
program TextPlusNumber {
|
||||
entry {
|
||||
let n = 3
|
||||
print("apples: " + n)
|
||||
}
|
||||
}
|
||||
5
examples/rejected/wrong_arity.ludic
Normal file
5
examples/rejected/wrong_arity.ludic
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# L4: a call gives as many arguments as the function has parameters
|
||||
program WrongArity {
|
||||
function area(w: int, h: int) -> int { return w * h }
|
||||
entry { print(area(3)) }
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue