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,24 @@
---
id: screen-circle
name: Screen.circle
category: screen
kind: namespace-method
tokens: Screen.circle
sig: Screen.circle(x, y, radius, color)
tip: Draw a circle outline.
order: 11
ns: Screen
member: circle
---
Draws the outline of a circle centred at <code>(x, y)</code> with the given <code>radius</code> in <code>color</code>. Use it for rings, radii, and selection markers; for a solid disc use <code>Screen.fill_circle</code>.
```ludic
program Demo {
handler DrawWorld phase Render {
Screen.clear(Color.MidnightBlue)
Screen.circle(x: 160, y: 120, radius: 40, color: Color.Cyan)
Screen.show()
}
}
```

View file

@ -0,0 +1,24 @@
---
id: screen-fill_circle
name: Screen.fill_circle
category: screen
kind: namespace-method
tokens: Screen.fill_circle
sig: Screen.fill_circle(x, y, radius, color)
tip: Draw a filled disc.
order: 12
ns: Screen
member: fill_circle
---
Draws a solid disc centred at <code>(x, y)</code> with the given <code>radius</code> in <code>color</code>, one horizontal span per row. Use it for round bodies, bullets, and glows.
```ludic
program Demo {
handler DrawWorld phase Render {
Screen.clear(Color.MidnightBlue)
Screen.fill_circle(x: bx, y: by, radius: 6, color: Color.Gold)
Screen.show()
}
}
```

View file

@ -0,0 +1,24 @@
---
id: screen-fill_triangle
name: Screen.fill_triangle
category: screen
kind: namespace-method
tokens: Screen.fill_triangle
sig: Screen.fill_triangle(x1, y1, x2, y2, x3, y3, color)
tip: Draw a filled triangle.
order: 14
ns: Screen
member: fill_triangle
---
Fills the triangle with corners <code>(x1, y1)</code>, <code>(x2, y2)</code>, <code>(x3, y3)</code> in <code>color</code>, scanning its bounding box with an inside test. The building block for flat-shaded polygons and arrowheads.
```ludic
program Demo {
handler DrawWorld phase Render {
Screen.clear(Color.MidnightBlue)
Screen.fill_triangle(x1: 10, y1: 10, x2: 30, y2: 10, x3: 20, y3: 26, color: Color.Red)
Screen.show()
}
}
```

View file

@ -0,0 +1,24 @@
---
id: screen-line
name: Screen.line
category: screen
kind: namespace-method
tokens: Screen.line
sig: Screen.line(x1, y1, x2, y2, color)
tip: Draw a straight line between two points.
order: 10
ns: Screen
member: line
---
Draws a one-pixel line from <code>(x1, y1)</code> to <code>(x2, y2)</code> in <code>color</code>, using an integer Bresenham walk so it looks the same on every platform. Use it for lasers, tethers, debug rays, and vector art. Draw during the <code>Render</code> phase.
```ludic
program Demo {
handler DrawWorld phase Render {
Screen.clear(Color.MidnightBlue)
Screen.line(x1: px, y1: py, x2: tx, y2: ty, color: Color.White)
Screen.show()
}
}
```

View file

@ -0,0 +1,24 @@
---
id: screen-sprite
name: Screen.sprite
category: screen
kind: namespace-method
tokens: Screen.sprite
sig: Screen.sprite(id, x, y)
tip: Blit a sprite at its natural size.
order: 15
ns: Screen
member: sprite
---
Draws sprite <code>id</code> from the loaded sprite sheet at <code>(x, y)</code>, at its natural 16x16 size. Load the sheet once at start, then draw sprites each frame during <code>Render</code>.
```ludic
program Demo {
handler DrawWorld phase Render {
Screen.clear(Color.MidnightBlue)
Screen.sprite(id: hero_frame, x: px, y: py)
Screen.show()
}
}
```

View file

@ -0,0 +1,24 @@
---
id: screen-sprite_scaled
name: Screen.sprite_scaled
category: screen
kind: namespace-method
tokens: Screen.sprite_scaled
sig: Screen.sprite_scaled(id, x, y, scale)
tip: Blit a sprite at an integer scale.
order: 16
ns: Screen
member: sprite_scaled
---
Draws sprite <code>id</code> at <code>(x, y)</code> enlarged by an integer <code>scale</code> (2 doubles it, and so on) — for chunky pixel-art zoom without blurring.
```ludic
program Demo {
handler DrawWorld phase Render {
Screen.clear(Color.MidnightBlue)
Screen.sprite_scaled(id: boss, x: bx, y: by, scale: 3)
Screen.show()
}
}
```

View file

@ -0,0 +1,24 @@
---
id: screen-triangle
name: Screen.triangle
category: screen
kind: namespace-method
tokens: Screen.triangle
sig: Screen.triangle(x1, y1, x2, y2, x3, y3, color)
tip: Draw a triangle outline.
order: 13
ns: Screen
member: triangle
---
Draws the outline of the triangle with corners <code>(x1, y1)</code>, <code>(x2, y2)</code>, <code>(x3, y3)</code> in <code>color</code> — three lines. Use it for arrows, wedges, and vector shapes.
```ludic
program Demo {
handler DrawWorld phase Render {
Screen.clear(Color.MidnightBlue)
Screen.triangle(x1: 10, y1: 10, x2: 30, y2: 10, x3: 20, y3: 26, color: Color.White)
Screen.show()
}
}
```