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

@ -0,0 +1,7 @@
---
id: mem
title: Mem
order: 6
---
Raw memory — allocate byte and word buffers, copy and fill regions, and peek/poke individual bytes. The low-level escape hatch.

View file

@ -0,0 +1,14 @@
---
id: mem-bytes
name: Mem.bytes
category: mem
kind: namespace-method
tokens: Mem.bytes
sig: Mem.bytes(n) -> ptr
tip: Allocate n bytes.
order: 0
ns: Mem
member: bytes
---
Allocates an <code>n</code>-byte buffer and returns a pointer to it.

View file

@ -0,0 +1,14 @@
---
id: mem-copy
name: Mem.copy
category: mem
kind: namespace-method
tokens: Mem.copy
sig: Mem.copy(dst, src, n) -> void
tip: Copy n bytes between buffers.
order: 2
ns: Mem
member: copy
---
Copies <code>n</code> bytes from <code>src</code> to <code>dst</code> (regions must not overlap).

View file

@ -0,0 +1,14 @@
---
id: mem-fill
name: Mem.fill
category: mem
kind: namespace-method
tokens: Mem.fill
sig: Mem.fill(buf, value, n) -> void
tip: Set n bytes to a value.
order: 3
ns: Mem
member: fill
---
Sets the first <code>n</code> bytes of <code>buf</code> to the byte <code>value</code>.

View file

@ -0,0 +1,14 @@
---
id: mem-peek
name: Mem.peek
category: mem
kind: namespace-method
tokens: Mem.peek
sig: Mem.peek(buf, i) -> int
tip: Read one byte.
order: 4
ns: Mem
member: peek
---
Returns the byte at <code>buf[i]</code> as an int in 0..255.

View file

@ -0,0 +1,14 @@
---
id: mem-poke
name: Mem.poke
category: mem
kind: namespace-method
tokens: Mem.poke
sig: Mem.poke(buf, i, value) -> void
tip: Write one byte.
order: 5
ns: Mem
member: poke
---
Stores the low byte of <code>value</code> at <code>buf[i]</code>.

View file

@ -0,0 +1,14 @@
---
id: mem-words
name: Mem.words
category: mem
kind: namespace-method
tokens: Mem.words
sig: Mem.words(n) -> words
tip: Allocate n 32-bit words.
order: 1
ns: Mem
member: words
---
Allocates a buffer of <code>n</code> 32-bit integer words, indexable as <code>w[i]</code>.