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

@ -13,8 +13,8 @@ tools/ludic-tools/ the actual language knowledge, in C, no dependenci
ludic_index.h error-tolerant reader: declarations, bindings, scopes
ludic_workspace.h multi-file model: imports, compilation units, Markdown
ludic_json.h just enough JSON for LSP
ludic_fmt_main.c -> build/ludic-fmt
ludic_lsp.c -> build/ludic-lsp
ludic_fmt_main.c -> bin/ludic-fmt
ludic_lsp.c -> bin/ludic-lsp
tools/editors/
shared/ TextMate grammar + Markdown injection + language config
@ -26,11 +26,11 @@ tools/editors/
## Build it
```bash
./tools/build-tools.sh
bin/x tools
```
Produces `build/ludic-fmt` and `build/ludic-lsp`. Add `--install` to symlink both
into `~/.local/bin`, `--test` to run `tools/test-tools.sh` afterwards.
Produces `bin/ludic-fmt` and `bin/ludic-lsp`. Add `--install` to symlink both
into `~/.local/bin`, `--test` to run `bin/x test-tools` afterwards.
## What you get, in any editor
@ -53,7 +53,7 @@ and otherwise keywords, builtins, and everything in scope.
## Per-editor setup
- **VS Code** — [`vscode/`](vscode/). `npm install && npx @vscode/vsce package`, then
install the `.vsix`. Finds the binaries under `build/` on its own.
install the `.vsix`. Finds the binaries under `bin/` on its own.
- **JetBrains** — [`jetbrains/`](jetbrains/). `./gradlew buildPlugin`, then install the
zip from disk. Uses LSP4IJ rather than the paid-IDE LSP API, so it works in
Community editions too.
@ -65,9 +65,9 @@ and otherwise keywords, builtins, and everything in scope.
- **Anything else** that speaks LSP:
```
command: build/ludic-lsp --stdio
command: bin/ludic-lsp --stdio
languages: ludic, markdown
initializationOptions: { "compilerPath": "build/ludicc", "compilerDiagnostics": true, "indentSize": 2 }
initializationOptions: { "compilerPath": "bin/ludicc", "compilerDiagnostics": true, "indentSize": 2 }
```
## Markdown
@ -98,8 +98,8 @@ prose:
The formatter handles Markdown too, which keeps documentation honest:
```bash
build/ludic-fmt --check LANGUAGE.md README.md # CI: fail if a fence is unformatted
build/ludic-fmt -w LANGUAGE.md # reformat the fences, leave the prose
bin/ludic-fmt --check LANGUAGE.md README.md # CI: fail if a fence is unformatted
bin/ludic-fmt -w LANGUAGE.md # reformat the fences, leave the prose
```
## Keeping a tree formatted
@ -109,8 +109,8 @@ ln -sf ../../tools/git-hooks/pre-commit .git/hooks/pre-commit
```
The hook runs `ludic-fmt --check` over the staged `.ludic` and `.md` files only,
and does nothing at all when `build/ludic-fmt` has not been built — so it never
blocks a commit on a machine that has not run `build-tools.sh`.
and does nothing at all when `bin/ludic-fmt` has not been built — so it never
blocks a commit on a machine that has not run `bin/x tools`.
## Why the formatter is not `ludicc --fmt`
@ -132,7 +132,7 @@ both spellings are what the language documents and uses:
(`const R_DIR: int = 0 # 0 up`) survive a save;
- `id=Root` inside a `ui` block and `{Enemy}` inside a query stay tight.
`tools/test-tools.sh` checks the property that matters: formatting every file in
`bin/x test-tools` checks the property that matters: formatting every file in
the tree and re-running the *compiler's* canonical dump produces byte-identical
output. The formatter cannot change what a program means.
@ -142,7 +142,7 @@ The vocabulary is written down in five places that cannot include each other —
the compiler's two tables, `ludic_syntax.h`, the TextMate grammar (JSON), and the
JetBrains lexer (Kotlin). Adding a builtin and forgetting the rest is silent
failure, so `tools/check-vocabulary.py` compares all five and
`tools/test-tools.sh` runs it.
`bin/x test-tools` runs it.
When you add a keyword or builtin: put it in `ludic_syntax.h`, then run
`./tools/test-tools.sh` and let it tell you which copies still need it.
`bin/x test-tools` and let it tell you which copies still need it.

View file

@ -43,7 +43,7 @@ The first build downloads an IntelliJ IDEA Community distribution (over 1 GB),
so expect it to take a while; later builds take seconds. Once the cache is warm,
```bash
LUDIC_TEST_JETBRAINS=1 ./tools/test-tools.sh
LUDIC_TEST_JETBRAINS=1 bin/x test-tools
```
includes the plugin build in the toolchain's own test run.
@ -54,5 +54,5 @@ LSP4IJ is a required dependency; the IDE offers to install it for you.
## Settings
**Settings -> Languages & Frameworks -> Ludic** — the path to `ludic-lsp` and to
`ludicc`. Both default to `build/` under the project root, which is where
`tools/build-tools.sh` puts them.
`ludicc`. Both default to `bin/` under the project root, which is where
`bin/x tools` puts them.

View file

@ -37,11 +37,11 @@ class LudicConfigurable(private val project: Project) : Configurable {
panel = FormBuilder.createFormBuilder()
.addLabeledComponent(JBLabel("Language server (ludic-lsp):"), serverField, 1, false)
.addComponentToRightColumn(
JBLabel("Leave empty to use build/ludic-lsp under the project, then PATH.")
JBLabel("Leave empty to use bin/ludic-lsp under the project, then PATH.")
)
.addLabeledComponent(JBLabel("Compiler (ludicc):"), compilerField, 1, false)
.addComponentToRightColumn(
JBLabel("Used for authoritative diagnostics. Empty means build/ludicc.")
JBLabel("Used for authoritative diagnostics. Empty means bin/ludicc.")
)
.addComponent(diagnostics)
.addLabeledComponent(JBLabel("Formatter indent:"), indent, 1, false)

View file

@ -146,8 +146,8 @@ internal fun serverCommand(root: String?, configured: String): List<String>? {
}
/** Where the toolchain is looked for, relative to the project root. */
internal val SERVER_SUBDIRS = listOf("build", "tools/build", "bin", ".")
internal val COMPILER_SUBDIRS = listOf("build", "bin", ".")
internal val SERVER_SUBDIRS = listOf("bin", "build", "tools/build", ".")
internal val COMPILER_SUBDIRS = listOf("bin", "build", ".")
class LudicLanguageServerFactory : LanguageServerFactory {
override fun createConnectionProvider(project: Project): StreamConnectionProvider =

View file

@ -15,7 +15,7 @@
<li>Highlighting of <code>```ludic</code> fenced blocks in Markdown.</li>
</ul>
<p>Set the paths under <b>Settings &rarr; Languages &amp; Frameworks &rarr; Ludic</b>, or leave
them blank to use <code>build/ludic-lsp</code> and <code>build/ludicc</code> under the
them blank to use <code>bin/ludic-lsp</code> and <code>bin/ludicc</code> under the
project root.</p>
]]></description>

View file

@ -23,10 +23,10 @@ for the language reference.
Build the toolchain once, from the repository root:
```bash
./tools/build-tools.sh
bin/x tools
```
That produces `build/ludic-lsp` and `build/ludic-fmt`, which the extension finds
That produces `bin/ludic-lsp` and `bin/ludic-fmt`, which the extension finds
on its own. If you keep them elsewhere, set `ludic.server.path`.
Format on save:
@ -37,7 +37,7 @@ Format on save:
## Settings
- `ludic.server.path` — where `ludic-lsp` lives. Empty = search `build/`, then `PATH`.
- `ludic.server.path` — where `ludic-lsp` lives. Empty = search `bin/`, then `PATH`.
- `ludic.server.enabled` — turn the server off and keep only static highlighting.
- `ludic.compilerPath` — where `ludicc` lives, for on-save diagnostics.
- `ludic.compilerDiagnostics` — whether to run the compiler at all.

View file

@ -24,7 +24,7 @@ function resolveServer(folders) {
const names = ['ludic-lsp', 'ludic-lsp.exe'];
for (const folder of folders) {
const root = folder.uri.fsPath;
for (const rel of ['build', 'tools/build', 'bin', '.']) {
for (const rel of ['bin', 'build', 'tools/build', '.']) {
for (const name of names) {
const p = path.join(root, rel, name);
if (isExecutable(p)) return p;
@ -45,8 +45,10 @@ function resolveCompiler(folders) {
const configured = vscode.workspace.getConfiguration('ludic').get('compilerPath');
if (configured) return expand(configured);
for (const folder of folders) {
const p = path.join(folder.uri.fsPath, 'build', 'ludicc');
if (isExecutable(p)) return p;
for (const rel of ['bin', 'build']) {
const p = path.join(folder.uri.fsPath, rel, 'ludicc');
if (isExecutable(p)) return p;
}
}
return '';
}
@ -74,7 +76,7 @@ async function start(context) {
// Not an error worth a modal: the grammar still highlights, and plenty of
// people open a .ludic file without having built the toolchain.
output.appendLine(
'ludic-lsp not found. Build it with tools/build-tools.sh, or set "ludic.server.path". ' +
'ludic-lsp not found. Build it with `bin/x tools`, or set "ludic.server.path". ' +
'Syntax highlighting works without it; completion and diagnostics do not.'
);
return;