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:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* 904_tok_run — execute the lib/ww/lex tokname/kwlookup @test fixture
|
||||
* 904_tok_run — execute the lib/ww/syntax tokname/kwlookup @test fixture
|
||||
* under the C-side `ww run` driver and assert exit 0.
|
||||
*
|
||||
* Same thin-wrapper shape as 904_ascii_run / 967_bytes_run: toktest.ww
|
||||
@@ -38,10 +38,11 @@ main(void)
|
||||
char cwd[1024];
|
||||
if (getcwd(cwd, sizeof cwd) == NULL) return 1;
|
||||
|
||||
const char *src = "lib/ww/lex/toktest.ww";
|
||||
char path[1024], cmd[2048];
|
||||
const char *src = "lib/ww/syntax/toktest.ww";
|
||||
char path[1024], inc[1024], cmd[3072];
|
||||
snprintf(path, sizeof path, "%s/%s", cwd, src);
|
||||
snprintf(cmd, sizeof cmd, "%s/ww test %s", bin, path);
|
||||
snprintf(inc, sizeof inc, "%s/lib/ww", cwd);
|
||||
snprintf(cmd, sizeof cmd, "%s/ww test -I %s %s", bin, inc, path);
|
||||
int rc = runwait(cmd);
|
||||
if (rc != 0) {
|
||||
fprintf(stderr, "tok_run FAIL: %s exited %d\n", src, rc);
|
||||
|
||||
@@ -9,9 +9,9 @@
|
||||
* which the 990_selfhost wwdump diff only covers for kinds that appear
|
||||
* in its corpus.
|
||||
*
|
||||
* Unlike 904_tok_run, the fixture imports `ast` (package ww), whose
|
||||
* printer references tok's tkind/tokname, so the run needs
|
||||
* `-I lib/ww/lex` to resolve that transitive import.
|
||||
* Unlike 904_tok_run, the fixture imports the `syntax` package, whose
|
||||
* printer references the token tkind/tokname, so the run needs
|
||||
* `-I lib/ww` to resolve the `import syntax` directory package.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -42,10 +42,10 @@ main(void)
|
||||
char cwd[1024];
|
||||
if (getcwd(cwd, sizeof cwd) == NULL) return 1;
|
||||
|
||||
const char *src = "lib/ww/asttest.ww";
|
||||
const char *src = "lib/ww/syntax/asttest.ww";
|
||||
char path[1024], inc[1024], cmd[3072];
|
||||
snprintf(path, sizeof path, "%s/%s", cwd, src);
|
||||
snprintf(inc, sizeof inc, "%s/lib/ww/lex", cwd);
|
||||
snprintf(inc, sizeof inc, "%s/lib/ww", cwd);
|
||||
snprintf(cmd, sizeof cmd, "%s/ww test -I %s %s", bin, inc, path);
|
||||
int rc = runwait(cmd);
|
||||
if (rc != 0) {
|
||||
|
||||
@@ -150,10 +150,10 @@ static const struct ent ents[] = {
|
||||
{ .fixture = "lib/os/stattest.ww",
|
||||
.mode = M_DIVERGE, .cite = "#59.9" },
|
||||
/* #59.10 stoftest graduated to M_ID above (#62 fix) */
|
||||
{ .fixture = "lib/ww/lex/toktest.ww",
|
||||
{ .fixture = "lib/ww/syntax/toktest.ww", .inc = "lib/ww",
|
||||
.mode = M_ID, .cite = "#59.11 graduated by #146 str==" },
|
||||
/* asttest resolves `import tok` via -I lib/ww/lex, cf 905 */
|
||||
{ .fixture = "lib/ww/asttest.ww", .inc = "lib/ww/lex",
|
||||
/* toktest/asttest resolve `import syntax` via -I lib/ww, cf 905 */
|
||||
{ .fixture = "lib/ww/syntax/asttest.ww", .inc = "lib/ww",
|
||||
.mode = M_ID, .cite = "#59.12 graduated by #146 str==" },
|
||||
/* -------- wwstage front-end gaps (task #59) -------------- */
|
||||
{ .fixture = "lib/crypto/sha256/sha256_test.ww",
|
||||
@@ -373,7 +373,7 @@ out:
|
||||
* and the corpus rots silently as lib/ grows. */
|
||||
static const char *covered[] = {
|
||||
/* selfhost-embedded: byte-id'd by the 990-997 gates */
|
||||
"lib/io", "lib/math", "lib/rt", "lib/types", "lib/ww/parse",
|
||||
"lib/io", "lib/math", "lib/rt", "lib/types",
|
||||
/* module body dragged into the lib/strconv/test fixtures */
|
||||
"lib/strconv",
|
||||
/* #17: the @test runner is AUTO-BUNDLED into every -T combined, so
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
|
||||
@@ -242,8 +242,8 @@ main(void)
|
||||
static char wwdump_src[2048], wwdump_incs[4096];
|
||||
snprintf(wwdump_src, sizeof wwdump_src, "%s/selfhost/cmd/wwdump/main.ww", cwd);
|
||||
snprintf(wwdump_incs, sizeof wwdump_incs,
|
||||
"%s/lib/ww:%s/lib/ww/lex:%s/lib/ww/parse:%s/lib/encoding/utf8:%s/selfhost/cmd/wcc",
|
||||
cwd, cwd, cwd, cwd, cwd);
|
||||
"%s/lib/ww:%s/lib/encoding/utf8:%s/selfhost/cmd/wcc",
|
||||
cwd, cwd, cwd);
|
||||
cases[1].src = wwdump_src;
|
||||
cases[1].incs = wwdump_incs;
|
||||
|
||||
|
||||
@@ -102,16 +102,16 @@ spawn_build(const char *bin, const char *cwd, struct buildjob *j)
|
||||
if (j->inc_local && j->inc_local[0]) {
|
||||
snprintf(cmd, sizeof cmd,
|
||||
"cd %s && timeout 180 %s/ww_ww build -o %s/main -I %s/%s "
|
||||
"-I %s/lib/ww -I %s/lib/ww/lex -I %s/lib/ww/parse "
|
||||
"-I %s/lib/ww "
|
||||
"-I %s/selfhost/cmd/wcc %s/%s >/dev/null 2>%s/build.err",
|
||||
j->workdir, bin, j->workdir, cwd, j->inc_local,
|
||||
cwd, cwd, cwd, cwd, cwd, j->src_rel, j->workdir);
|
||||
cwd, cwd, cwd, j->src_rel, j->workdir);
|
||||
} else {
|
||||
snprintf(cmd, sizeof cmd,
|
||||
"cd %s && timeout 180 %s/ww_ww build -o %s/main "
|
||||
"-I %s/lib/ww -I %s/lib/ww/lex -I %s/lib/ww/parse "
|
||||
"-I %s/lib/ww "
|
||||
"-I %s/selfhost/cmd/wcc %s/%s >/dev/null 2>%s/build.err",
|
||||
j->workdir, bin, j->workdir, cwd, cwd, cwd, cwd, cwd, j->src_rel, j->workdir);
|
||||
j->workdir, bin, j->workdir, cwd, cwd, cwd, j->src_rel, j->workdir);
|
||||
}
|
||||
|
||||
pid_t p = fork();
|
||||
|
||||
Reference in New Issue
Block a user