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:
parent
ff15c4e01d
commit
a38195128f
235 changed files with 24676 additions and 7762 deletions
21
docs/language/structure/kw-entry.md
Normal file
21
docs/language/structure/kw-entry.md
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
---
|
||||
id: kw-entry
|
||||
name: entry
|
||||
category: structure
|
||||
kind: keyword
|
||||
tokens: entry
|
||||
sig: entry { … }
|
||||
tip: The program's main block — runs once, top to bottom.
|
||||
order: 10
|
||||
---
|
||||
|
||||
<code>entry</code> declares the program's entry point: a single block that runs once when the program starts, in order, and then the program exits. It is the counterpart to the ECS game loop — where a game is built from <code>handler</code>s driven by phases each frame, an <code>entry</code> program is a straight-line script, which is why the compiler and tools in this repo are written with it. Use it for command-line programs and one-shot tools; use <code>program</code> with handlers for interactive games.
|
||||
|
||||
```ludic
|
||||
program Greet {
|
||||
entry {
|
||||
print("hello")
|
||||
print(2 + 2)
|
||||
}
|
||||
}
|
||||
```
|
||||
24
docs/language/structure/kw-new.md
Normal file
24
docs/language/structure/kw-new.md
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
---
|
||||
id: kw-new
|
||||
name: new
|
||||
category: structure
|
||||
kind: keyword
|
||||
tokens: new
|
||||
sig: new Record { … } new []T
|
||||
tip: Allocate a property record or an empty slice on the heap.
|
||||
order: 12
|
||||
---
|
||||
|
||||
<code>new</code> constructs a heap value and returns a reference to it. <code>new Record { field: value, … }</code> allocates a property (or struct) record, filling any omitted fields with their declared defaults; <code>new []T</code> allocates an empty growable slice of element type <code>T</code>, ready for <code>List.push</code>. Because both are references, passing one around shares the same underlying object. Use <code>new</code> for standalone data your code holds directly — as opposed to <code>spawn</code>, which creates a full ECS entity the world tracks and queries.
|
||||
|
||||
```ludic
|
||||
program Build {
|
||||
property Point { x: int = 0, y: int = 0 }
|
||||
|
||||
entry {
|
||||
let origin = new Point { x: 3 } # y defaults to 0
|
||||
let items = new []int # empty, then grow it
|
||||
List.push(items, origin.x)
|
||||
}
|
||||
}
|
||||
```
|
||||
23
docs/language/structure/kw-public.md
Normal file
23
docs/language/structure/kw-public.md
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
---
|
||||
id: kw-public
|
||||
name: public
|
||||
category: structure
|
||||
kind: keyword
|
||||
tokens: public
|
||||
sig: scene Name start public { … }
|
||||
tip: Expose a declaration's lifecycle on the public event bus.
|
||||
order: 11
|
||||
---
|
||||
|
||||
<code>public</code> marks a <code>scene</code>, <code>layer</code>, or <code>event</code> as part of the game's public surface, so its lifecycle is emitted as named events other systems and mods can react to with <code>@On</code>. A <code>public</code> scene fires <code>scene_<Name>_enter</code> and <code>scene_<Name>_exit</code>; a <code>public</code> layer fires <code>layer_<Name>_show</code> / <code>_hide</code>. It is the declaration-level counterpart to the <code>@Public</code> annotation that promotes a model or handler's lifecycle hooks. Keep it off by default and add it only where the modding surface genuinely needs the hook.
|
||||
|
||||
```ludic
|
||||
program Flow {
|
||||
@On(scene_Menu_enter) handler Greet { print(1) }
|
||||
|
||||
scene Menu start public {
|
||||
on enter { print(10) } # entering Menu prints 10, then fires scene_Menu_enter
|
||||
on exit { print(20) }
|
||||
}
|
||||
}
|
||||
```
|
||||
Loading…
Add table
Add a link
Reference in a new issue