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

@@ -117,13 +117,13 @@ $(OBJ)/w6l/%.o: cmd/w6l/%.c cmd/w6l/l.h | $(OBJ)/w6l
$(CC) $(CFLAGS) -Icmd/w6l -c -o $@ $<
# ---- ww-side wwdump (the lexer port, exercised by 990_selfhost) --------
# Built via the user-facing ww driver. The introspection ports (lex,
# tok, ast, parse, typ, sym) live in lib/ww/; the compiler-only bits
# (check, cgen*) stay in selfhost/cmd/wcc/. Output named wwdump_ww
# Built via the user-facing ww driver. The frontend (lex, tok, ast,
# parse, typ, sym) is the `syntax` package in lib/ww/syntax/; the
# compiler-only bits (check, cgen*) stay in selfhost/cmd/wcc/. Output named wwdump_ww
# to avoid colliding with the C-side wwdump in $(BIN).
$(BIN)/wwdump_ww: selfhost/cmd/wwdump/main.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/wcc/cgenexpr.ww \
selfhost/cmd/wcc/cgenstmt.ww selfhost/cmd/wcc/cgenutil.ww \
@@ -134,18 +134,16 @@ $(BIN)/wwdump_ww: selfhost/cmd/wwdump/main.ww \
@mkdir -p $(BIN)/wwdump_ww.d
cd $(BIN)/wwdump_ww.d && $(CURDIR)/$(BIN)/ww build \
-I $(CURDIR)/lib/ww \
-I $(CURDIR)/lib/ww/lex \
-I $(CURDIR)/lib/ww/parse \
-I $(CURDIR)/selfhost/cmd/wcc \
$(CURDIR)/selfhost/cmd/wwdump/main.ww
mv $(BIN)/wwdump_ww.d/main $@
# ---- ww-side w6c (compiler port, exercised by 994_w6c_ww) -------------
# Thin driver: parse + cgen. The frontend (lex/parse/ast/...) lives in
# lib/ww/; cgen + check live in selfhost/cmd/wcc/.
# Thin driver: parse + cgen. The frontend (lex/parse/ast/...) is the
# `syntax` package in lib/ww/syntax/; cgen + check live in selfhost/cmd/wcc/.
$(BIN)/w6c_ww: selfhost/cmd/w6c/main.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/wwi.ww \
selfhost/cmd/wcc/cgen.ww selfhost/cmd/wcc/cgenexpr.ww \
selfhost/cmd/wcc/cgenstmt.ww selfhost/cmd/wcc/cgenutil.ww \
@@ -156,8 +154,6 @@ $(BIN)/w6c_ww: selfhost/cmd/w6c/main.ww \
@mkdir -p $(BIN)/w6c_ww.d
cd $(BIN)/w6c_ww.d && $(CURDIR)/$(BIN)/ww build \
-I $(CURDIR)/lib/ww \
-I $(CURDIR)/lib/ww/lex \
-I $(CURDIR)/lib/ww/parse \
-I $(CURDIR)/selfhost/cmd/wcc \
$(CURDIR)/selfhost/cmd/w6c/main.ww
mv $(BIN)/w6c_ww.d/main $@
@@ -3606,8 +3602,6 @@ nocc:
@# Pass -I $(CURDIR)/lib so `use os` etc. resolve to source.
@cd $(NOCC_BIN) && ./ww build \
-I $(CURDIR)/lib/ww \
-I $(CURDIR)/lib/ww/lex \
-I $(CURDIR)/lib/ww/parse \
-I $(CURDIR)/selfhost/cmd/wcc \
-I $(CURDIR)/lib $(CURDIR)/selfhost/cmd/w6c/main.ww && mv main w6c_ww1
@cd $(NOCC_BIN) && ./ww build -I $(CURDIR)/selfhost/cmd/w6a \