lib/ww,wcc: consolidate frontend into one syntax package (Go-compiler model, #74)

The ww compiler frontend was split across packages lex (lex+tok), ww
(ast+sym+typ), and parse — mirroring Hare's ref/hare/hare/{ast,lex,parse}.
That split's only payoff is third-party reuse, which ww has zero of: the
frontend is consumed by exactly one client, the wcc backend. The split's
cost is a wide cross-package export surface — every fn over a sibling
package's type must export it, and under separate compilation that
re-triggers check_exported_type, plus a phantom `import tok;` (tok lives
in package lex). Consolidate into ONE package lib/ww/syntax/, modelled on
Go's cmd/compile/internal/syntax. The 9 files move in (package syntax);
the intra-frontend mutual references become same-package; wcc and the
tool mains import syntax. No cstage C change (the C frontend mangles from
the source package clause). Internal data shapes (AST kinds, token model,
lexer/parser state) still mirror ref/hare/hare per rule 6/12 — only the
module decomposition collapses; the stdlib is untouched.

USER-approved (#74); spec .ai/rob-frontend-reorg.md (drew2 fidelity-
confirmed). Rule-6 carve-out documented in CLAUDE.md. Dissolves the tok
phantom import; collapses the intra-frontend export sprawl. Byte-id
rebaseline (lex.X/parse.X/ww.X -> syntax.X); cs==ww held. The residual
syntax->wcc export surface (10 types) + the unqualified-ref question are
separate follow-ups (#72/#75).
This commit is contained in:
2026-06-16 19:56:34 +09:00
parent 10d005ef58
commit 7a8acfb952
31 changed files with 3647 additions and 3747 deletions

View File

@@ -170,10 +170,10 @@ probe_dump_diff(const char *bin)
{
const char *tok_inputs[] = {
"selfhost/cmd/wcc/err.ww",
"lib/ww/lex/lex.ww",
"lib/ww/lex/tok.ww",
"lib/ww/ast.ww",
"lib/ww/parse/parse.ww", "lib/ww/parse/expr.ww", "lib/ww/parse/stmt.ww", "lib/ww/parse/decl.ww",
"lib/ww/syntax/lex.ww",
"lib/ww/syntax/tok.ww",
"lib/ww/syntax/ast.ww",
"lib/ww/syntax/parse.ww", "lib/ww/syntax/expr.ww", "lib/ww/syntax/stmt.ww", "lib/ww/syntax/decl.ww",
"selfhost/cmd/wwdump/main.ww",
"selfhost/test/smoke.ww",
NULL,
@@ -186,12 +186,12 @@ probe_dump_diff(const char *bin)
const char *ast_inputs[] = {
"selfhost/test/uses.ww",
"selfhost/cmd/wcc/err.ww",
"lib/ww/lex/lex.ww",
"lib/ww/lex/tok.ww",
"lib/ww/ast.ww",
"lib/ww/parse/parse.ww", "lib/ww/parse/expr.ww", "lib/ww/parse/stmt.ww", "lib/ww/parse/decl.ww",
"lib/ww/typ.ww",
"lib/ww/sym.ww",
"lib/ww/syntax/lex.ww",
"lib/ww/syntax/tok.ww",
"lib/ww/syntax/ast.ww",
"lib/ww/syntax/parse.ww", "lib/ww/syntax/expr.ww", "lib/ww/syntax/stmt.ww", "lib/ww/syntax/decl.ww",
"lib/ww/syntax/typ.ww",
"lib/ww/syntax/sym.ww",
"selfhost/cmd/wcc/check.ww",
"selfhost/cmd/wcc/cgen.ww",
"selfhost/cmd/wwdump/main.ww",
@@ -572,7 +572,7 @@ probe_resolve(const char *bin)
if (getcwd(cwd, sizeof cwd) == NULL) return -1;
const char *fixtures[] = {
"selfhost/cmd/wcc/err.ww",
"lib/ww/lex/tok.ww",
"lib/ww/syntax/tok.ww",
"selfhost/test/smoke.ww",
NULL,
};
@@ -747,8 +747,8 @@ probe_ww_links(const char *bin)
runwait(cmd);
/* ww build to get the .combined.ww as a side effect. */
snprintf(cmd, sizeof cmd,
"cd %s && timeout 180 %s/ww build -I %s/lib/ww -I %s/lib/ww/lex -I %s/lib/ww/parse -I %s/selfhost/cmd/wcc %s >/dev/null 2>&1",
tmpdir, bin, cwd, cwd, cwd, cwd, tmpsrc);
"cd %s && timeout 180 %s/ww build -I %s/lib/ww -I %s/selfhost/cmd/wcc %s >/dev/null 2>&1",
tmpdir, bin, cwd, cwd, tmpsrc);
if (runwait(cmd) != 0) {
fprintf(stderr, "ww-links FAIL: ww build %s\n", fix);
fail++;
@@ -817,7 +817,7 @@ static int
probe_cgen_match(const char *bin)
{
const char *files[] = {
"lib/ww/lex/tok.ww",
"lib/ww/syntax/tok.ww",
"selfhost/test/smoke.ww",
NULL,
};