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>
41 lines
1.6 KiB
Text
41 lines
1.6 KiB
Text
program T {
|
|
entry {
|
|
# ---- Text builders (upper/lower/trim/repeat/pad) ----
|
|
print(Text.length(Text.upper("abc"))) # 3
|
|
print(Text.equals(Text.upper("aBc"), "ABC")) # 1
|
|
print(Text.equals(Text.lower("aBc"), "abc")) # 1
|
|
print(Text.equals(Text.trim(" hi "), "hi")) # 1
|
|
print(Text.length(Text.trim(" hi "))) # 2
|
|
print(Text.equals(Text.repeat("ab", 3), "ababab")) # 1
|
|
print(Text.length(Text.repeat("ab", 3))) # 6
|
|
print(Text.equals(Text.pad_left("7", 3), " 7")) # 1
|
|
print(Text.equals(Text.pad_right("7", 3), "7 ")) # 1
|
|
print(Text.length(Text.pad_left("7", 3))) # 3
|
|
print(Text.equals(Text.pad_left("toolong", 3), "toolong")) # 1
|
|
|
|
# ---- List insert/remove_at/remove/sort ----
|
|
let xs = new []int
|
|
push(xs, 3); push(xs, 1); push(xs, 2)
|
|
List.sort(xs)
|
|
print(List.first(xs)) # 1
|
|
print(List.last(xs)) # 3
|
|
print(List.index_of(xs, 2)) # 1
|
|
List.insert(xs, 1, 99)
|
|
print(List.len(xs)) # 4
|
|
print(List.index_of(xs, 99)) # 1
|
|
print(List.index_of(xs, 2)) # 2
|
|
List.remove_at(xs, 0)
|
|
print(List.first(xs)) # 99
|
|
print(List.len(xs)) # 3
|
|
List.remove(xs, 2)
|
|
print(List.len(xs)) # 2
|
|
print(List.contains(xs, 2)) # 0
|
|
print(List.last(xs)) # 3
|
|
let ys = new []int
|
|
push(ys, 5); push(ys, 2); push(ys, 8); push(ys, 1); push(ys, 9); push(ys, 3)
|
|
List.sort(ys)
|
|
print(List.first(ys)) # 1
|
|
print(List.last(ys)) # 9
|
|
print(List.index_of(ys, 5)) # 3
|
|
}
|
|
}
|