ludic/tools/x/main.ludic
Orkuncakilkaya 9ed0070039
All checks were successful
bootstrap / cfree-fixpoint (push) Successful in 16s
ci / build-and-test (push) Successful in 1m4s
commit-lint / conventional-commits (push) Successful in 3s
docs / build-and-deploy (push) Successful in 17s
feat(tooling): port the docgen site generator to Ludic (no Python) (#41)
Follow-up to #31: the doc/lint/grammar checks moved to Ludic there; this ports
the remaining docgen piece (gen.py / check.py / palette.py) so nothing in the
documentation pipeline is Python any more.

Three new `x` subcommands, all in Ludic and compiled by Ludic:

  - x docs-gen [--out DIR]  the static-site generator: parses docs/language/**
    front-matter + bodies (fences, Parameters:), builds the section/symbol
    model, reads the asset templates, and emits every page + ns/color/api pages
    + the landing page + ludic-highlight.js + symbols.json + .nojekyll.
  - x docs-check [DIR]      the coverage / integrity guard (required files, a
    page per inventory.json symbol, duplicate-token and one-dir-per-namespace
    guards, highlighter link targets).
  - x docs-palette          the named-colour source of truth: the palette table
    moved into tools/x/docgen.ludic, emitting emit_color.ludic (pointer, not
    ptr) + palette.json.

Verified against the Python oracle: `x docs-gen` reproduces all 466 output files
BYTE-FOR-BYTE (a Ludic json.dumps/html.escape/front-matter port — ordered dicts,
indent=2 vs compact, ensure_ascii \uXXXX, codepoint-aware truncation), and
`x docs-check` matches check.py's pass/fail output. Wired into `x test` as a
gate (docs-gen -> docs-check on a fresh site; docs-palette stays byte-identical).

CI swap: ci.yml and docs.yml call the Ludic generator; docs.yml drops the
python:3.12 container and bootstraps the toolchain from the IR seed instead.
tools/docgen/{gen,check,palette}.py deleted; only assets/ + inventory.json
remain. Completes #31's criterion 3.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-08-31 02:12:32 +03:00

113 lines
5.7 KiB
Text

# x — the Ludic task runner. One native binary (bin/x) that replaces every
# build/test/bootstrap shell script in the repo. It is written in Ludic and
# compiled by Ludic; the unix tools and clang it drives are invoked through the
# `run` intrinsic, the same way the old *.sh files shelled out.
#
# Bootstrap it once from a clean checkout (the only step Ludic cannot do for
# itself, since compiling Ludic needs a compiler):
#
# clang selfhost/ludicc.seed.ll -o bin/ludicc && bin/ludicc tools/x/main.ludic -o bin/x
#
# Thereafter `bin/x build` rebuilds the whole toolchain — including bin/x itself.
# Always run x from the repository root.
program X {
import "prelude.ludic"
import "selfhost.ludic"
import "build.ludic"
import "tools.ludic"
import "selfhost_test.ludic"
import "test.ludic"
import "json.ludic"
import "checks.ludic"
import "docgen.ludic"
import "docgen_gen.ludic"
import "docgen_check.ludic"
import "release.ludic"
function usage() -> void {
print("x — the Ludic task runner (run from the repository root)")
print("")
print("build & run:")
print(" x build build the whole toolchain into bin/ (ludicc, ludic, x, ludic-fmt, ludic-lsp)")
print(" x build-cli build just bin/ludicc and bin/ludic from the IR seed")
print(" x app <file.ludic> [--headless] [--save-temps]")
print(" compile a Ludic program to a native app in build/")
print(" x tools [--install] [--test] build the editor toolchain (ludic-fmt, ludic-lsp)")
print(" x clean remove build/ (incl. build/out.ppm) and stray artifacts (keeps bin/)")
print("")
print("test:")
print(" x test the full regression suite")
print(" x selfhost-test the self-hosting suite (correctness + bootstrap fixpoints)")
print(" x test-tools the editor-toolchain suite")
print(" x golden regenerate selfhost/golden/renders.sha256 (review with git diff)")
print("")
print("doc / lint checks (Ludic, no Python):")
print(" x check-docs every ```ludic doc fence parses (or is marked skip/expect-error)")
print(" x check-impl every implemented feature has a docs/language page")
print(" x check-vocabulary the vocabulary is in sync across grammar / lexer / header / parser")
print(" x lint-asset <file> validate one editor .json / .xml asset")
print(" x docs-gen [--out DIR] generate the documentation site (default build/pages)")
print(" x docs-check [DIR] coverage/integrity guard over a generated docs site")
print(" x docs-palette regenerate emit_color.ludic + palette.json from the palette table")
print("")
print("release:")
print(" x version print the toolchain version (ludicc --version)")
print(" x release [major|minor|patch] [--publish]")
print(" cut a release: CHANGELOG + VERSION bump + tag (+ Forgejo release)")
print("")
print("self-host internals:")
print(" x selfhost-build [ludicc] [out] assemble + compile the self-host compiler")
print(" x bootstrap the self-hosting fixpoint proof (seeded from bin/ludicc)")
print(" x bootstrap-cfree rebuild the compiler from the seed with no C compiler")
print(" x reseed regenerate selfhost/ludicc.seed.ll after a compiler change")
print(" x game-build <ludicc> <game.ludic> <out> compile a Ludic game (headless)")
print(" x sh-compile <ludicc> <in.ludic> <out> compile + link one .ludic file")
}
# a positional argument, or a default when absent
function argn(i: int, dflt: pointer) -> pointer {
if (i < arg_count()) { return arg(i) }
return dflt
}
entry {
if (arg_count() < 2) { usage(); exit(1) }
let cmd = arg(1)
if (cmd == "build") { exit(cmd_build()) }
if (cmd == "build-cli") { exit(cmd_build_cli()) }
if (cmd == "app") { exit(cmd_app()) }
if (cmd == "tools") { exit(cmd_tools()) }
if (cmd == "clean") { exit(cmd_clean()) }
if (cmd == "test") { exit(cmd_test()) }
if (cmd == "selfhost-test") { exit(cmd_selfhost_test()) }
if (cmd == "test-tools") { exit(cmd_test_tools()) }
if (cmd == "check-docs") { exit(cmd_check_docs()) }
if (cmd == "check-impl") { exit(cmd_check_impl()) }
if (cmd == "check-vocabulary") { exit(cmd_check_vocab()) }
if (cmd == "lint-asset") { exit(cmd_lint_asset()) }
if (cmd == "docs-palette") { exit(cmd_docs_palette()) }
if (cmd == "docs-gen") { exit(cmd_docs_gen()) }
if (cmd == "docs-check") { exit(cmd_docs_check()) }
if (cmd == "golden") { exit(cmd_golden()) }
if (cmd == "bootstrap") { exit(cmd_bootstrap()) }
if (cmd == "bootstrap-cfree") { exit(cmd_bootstrap_cfree()) }
if (cmd == "reseed") { exit(cmd_reseed()) }
if (cmd == "selfhost-build") { exit(cmd_selfhost_build(argn(2, "bin/ludicc"), argn(3, "build/selfhost"))) }
if (cmd == "sh-compile") {
if (arg_count() < 5) { err("usage: x sh-compile <ludicc> <in.ludic> <out>\n"); exit(1) }
exit(cmd_sh_compile(arg(2), arg(3), arg(4)))
}
if (cmd == "game-build") {
if (arg_count() < 5) { err("usage: x game-build <ludicc> <game.ludic> <out>\n"); exit(1) }
exit(cmd_game_build(arg(2), arg(3), arg(4)))
}
if (cmd == "version") or (cmd == "--version") or (cmd == "-v") { exit(cmd_version()) }
if (cmd == "release") { exit(cmd_release()) }
if (cmd == "help") or (cmd == "--help") or (cmd == "-h") { usage(); exit(0) }
err(`x: unknown command '{cmd}'\n`)
usage()
exit(1)
}
}