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).
58 lines
1.6 KiB
C
58 lines
1.6 KiB
C
/*
|
|
* 905_nkname_run — execute the lib/ww nkname @test fixture under the
|
|
* C-side `ww run` driver and assert exit 0.
|
|
*
|
|
* Same thin-wrapper shape as 904_tok_run / 904_ascii_run: asttest.ww
|
|
* carries its own `export fn main()` that drives the @test fn and
|
|
* signals which case failed via the exit code. This pins nkname's
|
|
* if-ladder -> switch fold (every nkind + the unknown-kind fallback),
|
|
* which the 990_selfhost wwdump diff only covers for kinds that appear
|
|
* in its corpus.
|
|
*
|
|
* 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>
|
|
#include <unistd.h>
|
|
#include <sys/wait.h>
|
|
|
|
static int
|
|
runwait(const char *cmd)
|
|
{
|
|
int rc = system(cmd);
|
|
if (rc == -1) return -1;
|
|
if (WIFEXITED(rc)) return WEXITSTATUS(rc);
|
|
return 1;
|
|
}
|
|
|
|
int
|
|
main(void)
|
|
{
|
|
const char *bin = getenv("BIN");
|
|
if (!bin) bin = "out/bin";
|
|
char absbin[1024];
|
|
if (bin[0] != '/') {
|
|
char cwd[1024];
|
|
if (getcwd(cwd, sizeof cwd) == NULL) return 1;
|
|
snprintf(absbin, sizeof absbin, "%s/%s", cwd, bin);
|
|
bin = absbin;
|
|
}
|
|
char cwd[1024];
|
|
if (getcwd(cwd, sizeof cwd) == NULL) return 1;
|
|
|
|
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", cwd);
|
|
snprintf(cmd, sizeof cmd, "%s/ww test -I %s %s", bin, inc, path);
|
|
int rc = runwait(cmd);
|
|
if (rc != 0) {
|
|
fprintf(stderr, "nkname_run FAIL: %s exited %d\n", src, rc);
|
|
return 1;
|
|
}
|
|
printf("nkname_run: %s ok\n", src);
|
|
return 0;
|
|
}
|