feat(stdlib): namespaced standard library (issue #2)

Implement the bulk of the namespaced-stdlib proposal (workshopsoft/ludic#2):
156 namespace methods across Math, Text, List, Ease, Collide, World, Net,
Sys, Save, Mem, extended Screen, Color functions, extended Random, and Time.
All deterministic fixed-point; self-hosting (C-free bootstrap fixpoint holds).

Compiler (selfhost/):
- Math.*: sqrt/sin/cos/tan/atan2/asin/acos (fixed-point runtime prelude —
  bit-by-bit isqrt, 256-entry interpolated sine table, Ross atan2), plus
  hypot/dist/dist2/deg_to_rad/rad_to_deg/posmod/wrap/ping_pong/snapped/
  move_toward/smoothstep/lerp/remap/sign/floor/ceil/round.
- Text.* (complete): upper/lower/trim/repeat/pad, split/join/replace,
  and the libc-backed queries.
- List.* (complete): insert/remove_at/remove/sort plus the earlier ops.
- Ease.* (in/out/in_out/back/bounce) and Collide.* (rects/point_rect/
  circles/rect_circle).
- Phase 3: World/Net/Sys/Save namespaced over the bare builtins (byte-
  identical IR) and Mem.* (bytes/words/copy/fill/peek/poke).
- Screen.* extended (line/circle/fill_circle/triangle/fill_triangle via new
  runtime primitives; sprite/sprite_scaled aliases), Color.* functions,
  Random.* (value/int/sign), Time.* (frame/delta/elapsed/now — new
  game-loop frame counter).
- Fix a lexer bug: fixed-point literals with >4 fractional digits overflowed.

Docs & tooling:
- 129 new per-symbol doc pages; gen.py made data-driven (namespaces
  discovered from the docs, no hardcoded list); new check-impl.py enforces
  that every implemented namespace method / keyword / type / phase has a
  doc page, wired into `x test-tools`. Document the previously-undocumented
  keywords (break/continue/where/entry/new/public + and/or/not tokens).
- LSP: namespaced signature help (ns_method_sig) covering every namespace.

Tests: 12 new self-host/regression tests + a golden render for the drawing
primitives. All suites green (selfhost 21, regression 45, tools 29).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-08-30 00:26:19 +03:00
parent ff15c4e01d
commit a38195128f
235 changed files with 24676 additions and 7762 deletions

View file

@ -11,7 +11,7 @@
# 25 @OnDetach(Shield): reads the outgoing amount 5, prints 5 + 20
# 0 the Shield is gone — nothing matches
#
# ./selfhost/game-build.sh build/ludicc examples/detach.ludic /tmp/detach
# bin/x game-build bin/ludicc examples/detach.ludic /tmp/detach
# /tmp/detach </dev/null
program Detach {
property Tag { v: int = 0 }

13
examples/draw_prims.ludic Normal file
View file

@ -0,0 +1,13 @@
# draw_prims.ludic — exercises the extended Screen.* drawing primitives
# (line/circle/fill_circle/triangle/fill_triangle) for the golden render suite.
program DrawPrims {
handler DrawWorld phase Render {
Screen.clear(0x0d1020)
Screen.line(x1: 4, y1: 4, x2: 120, y2: 60, color: 0xFF4040)
Screen.circle(x: 200, y: 60, radius: 30, color: 0x40FF40)
Screen.fill_circle(x: 80, y: 150, radius: 24, color: 0x4060FF)
Screen.triangle(x1: 160, y1: 120, x2: 230, y2: 130, x3: 190, y3: 200, color: 0xFFD040)
Screen.fill_triangle(x1: 250, y1: 150, x2: 300, y2: 160, x3: 270, y3: 210, color: 0xFF40FF)
Screen.show()
}
}

View file

@ -14,7 +14,7 @@
# 5. rt_receive() — the client reconciles to the authoritative x=5
#
# Prints 5 / 999 / 5. Build & run with the Ludic toolchain only:
# ./build.sh examples/net_demo.ludic --headless && ./build/net_demo_headless
# bin/x app examples/net_demo.ludic --headless && ./build/net_demo_headless
import "net_rt.ludic"
program NetDemo {

View file

@ -9,7 +9,7 @@
# 503 Enemy A despawned in-world (Despawned): drop its loot, 3 + 500
# 1009 Enemy B outlived the run; at quit (Quit) it skips loot, 9 + 1000
#
# ./selfhost/game-build.sh build/ludicc examples/reason.ludic /tmp/reason
# bin/x game-build bin/ludicc examples/reason.ludic /tmp/reason
# /tmp/reason </dev/null
program Reasons {
property Health { hp: int = 0 }

13
examples/rng_demo.ludic Normal file
View file

@ -0,0 +1,13 @@
# rng_demo.ludic — exercises the Random.* extensions (value/int/sign) with a
# fixed seed, so the sequence is deterministic for the regression suite.
program RngDemo {
handler Seed phase Start { Random.seed(value: 1) }
handler Once phase Update {
print(Random.int(100))
print(Random.int(100))
print(Math.floor(Random.value() * 10.0))
print(Random.sign())
print(Random.int(0)) # 0 (max <= 0)
quit()
}
}

11
examples/time_demo.ludic Normal file
View file

@ -0,0 +1,11 @@
program TimeDemo {
handler Tick phase Update {
let f = Time.frame()
print(f)
if f >= 3 {
print(Math.floor(Time.elapsed() * 100.0))
print(Math.floor(Time.delta() * 1000.0))
quit()
}
}
}