Some checks are pending
docs / build-and-deploy (push) Waiting to run
Add `long`, a 64-bit signed integer primitive (i64), threaded through codegen: llty; int<->long coercion (coerce_code/to_long) at let/assign/ return/call-args; i64 arithmetic + comparison promotion in emit_bin; unary negate/~; print via %lld and str()/interpolation via @fn_long_str. Editor vocabulary (syntax header, TextMate grammar, formatter, LSP) synced; check-vocabulary green. Numeric literals stay i32 — build large values by widening (documented on the type page). Complete the Hash.* namespace (issue #17) with both 32- and 64-bit algorithms: Hash.of/fnv1a/crc32/mix/combine (32-bit) and Hash.of64/fnv1a_64/mix64 (64-bit, returning long). Deterministic and C-free; CRC-32 (poly 0xEDB88320) and FNV vectors verified against reference implementations. Tests: selfhost/tests/{hash,long}.ludic. Docs: docs/language/hash/*, type-long.md. Seed reseeded; C-free bootstrap fixpoint holds; 23 selfhost + 45 regression + 29 tooling checks green. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
70 lines
3.6 KiB
Text
70 lines
3.6 KiB
Text
# selfhost_test.ludic — the self-hosting suite: the compiler is correct (compiles
|
|
# diverse programs to working binaries) and self-reproducing (the bootstrap
|
|
# fixpoint). Replaces selfhost/test.sh.
|
|
|
|
# compile selfhost/tests/<name>.ludic with bin/ludicc, assemble, run, compare
|
|
fn sh_case(name: ptr, exp: ptr) -> void {
|
|
let ll = `/tmp/x_sh_{name}.ll`
|
|
let er = `/tmp/x_sh_{name}.err`
|
|
let bn = `/tmp/x_sh_{name}`
|
|
if not shq(`bin/ludicc selfhost/tests/{name}.ludic > {ll} 2>{er}`) {
|
|
bad2(`{name}: self-host errored`, capture_line(`head -1 {er}`)); return
|
|
}
|
|
if not shq(`{cc()} {ll} -o {bn} 2>/dev/null`) { bad(`{name}: IR did not assemble`); return }
|
|
let got = capture_line(`{bn} < /dev/null`)
|
|
if (got == exp) { ok(`{name} ({got})`) } else { bad2(name, `got [{got}] want [{exp}]`) }
|
|
}
|
|
|
|
# compile examples/<name>.ludic as a game and diff its render against the golden
|
|
fn game_case(name: ptr, keys: ptr) -> void {
|
|
if not game_build_ok("bin/ludicc", `examples/{name}.ludic`, `/tmp/x_g_{name}`) { bad(`{name}: build`); return }
|
|
run(`printf '%s' '{keys}' | /tmp/x_g_{name} >/dev/null 2>&1`)
|
|
if shq(`cmp -s selfhost/golden/{name}.ppm out.ppm`) { ok(`{name} matches the golden render`) }
|
|
else { bad(`{name}: differs from golden`) }
|
|
}
|
|
|
|
fn cmd_selfhost_test() -> int {
|
|
PASS = 0
|
|
FAIL = 0
|
|
|
|
print("== build the self-host compiler (from the IR seed, no C) ==")
|
|
ensure_ludicc()
|
|
if is_exec("bin/ludicc") { ok("compiler builds from the IR seed (no C)") }
|
|
else { bad("self-host build"); return report() }
|
|
|
|
print("== the self-host compiler is correct ==")
|
|
sh_case("structs", "7 9 109 2 42")
|
|
sh_case("slices", "0 20 361 777")
|
|
sh_case("control", "55 4 15 1")
|
|
sh_case("match_bits", "1 2 9 16 4 15")
|
|
sh_case("fixed", "2 3 0 6 1")
|
|
sh_case("math", "3 7 5 10 -1 0 1 2 3 3 2 5 25 50")
|
|
sh_case("math2", "1414 3 999 999 499 5 5 25 3142 179 4 2 7 25 30 500")
|
|
sh_case("textlist", "3 10 30 1 0 2 -1 30 10 10 30 30 2 0 11 104 1 0 1 0 1 0 6 -1 42 5 1 4 4")
|
|
sh_case("textlist2", "3 1 1 1 2 1 6 1 1 3 1 1 3 1 4 1 2 99 3 2 0 3 1 9 3")
|
|
sh_case("easecollide", "250 750 500 1000 1000 999 765 -88 1000 1 0 1 0 0 1 0 1 0")
|
|
sh_case("memsys", "65 66 0 99 12345 1")
|
|
sh_case("math3", "45 90 180 -135 30 60 90")
|
|
sh_case("textsplit", "1 1 1 3 1 1 1 1 1 1 1")
|
|
sh_case("hash", "-2128831035 -468965076 114400290 114400290 0 -873187034 1095738169 0 1364076727 -2114883783 -845898438 -845898438 -78065325 -78057399 -3750763034362895579 -5808556873153909620 -4100651535478758590 -4100651535478758590 0 -5451962507482445012 7256831767414464289")
|
|
sh_case("long", "1000000000000 1000000000001 1000000000005 3000000000000 1 1 1 -1000000000000 1000000 13")
|
|
sh_case("color", "16744512 1090486336 1090486336 8355711 8355711 8355711")
|
|
|
|
print("== the self-host compiler compiles real games (vs golden output) ==")
|
|
# the golden PPMs were produced by the original C compiler; the self-hosted
|
|
# compiler must reproduce them exactly.
|
|
game_case("snake", "ddssaawwddss")
|
|
game_case("menu", "ssss")
|
|
game_case("chronorift", "ddddwwwwaassK")
|
|
game_case("draw_prims", "")
|
|
|
|
print("== the bootstrap fixpoint (seeded from bin/ludicc) ==")
|
|
if shq("bin/x bootstrap > /tmp/x_boot.out 2>&1") { ok("gen2.ll == gen3.ll (compiler reproduces itself)") }
|
|
else { bad("fixpoint not reached"); out(capture("cat /tmp/x_boot.out")) }
|
|
|
|
print("== the C-free bootstrap (from the checked-in IR seed, no C compiler) ==")
|
|
if shq("bin/x bootstrap-cfree > /tmp/x_cfree.out 2>&1") { ok("seed.ll rebuilds the compiler and is its own fixed point") }
|
|
else { bad("C-free bootstrap failed (seed stale? run: x reseed)"); out(capture("cat /tmp/x_cfree.out")) }
|
|
|
|
return report()
|
|
}
|