lib/ww/ast: nkname if-ladder -> switch (Wave-2 structural)
Fold the 69-arm `if (k == nkind.N_X) return "..."` ladder in nkname to a single `switch (k)` with the terminal `return "?"` as the fall-past default. The other ast.ww ladders stay: pr()'s kind dispatch is side-effecting (emits output, recurses) and uses ||-grouped multi-kind predicates, not a pure value->value mapping a switch can express. Not byte-id-neutral (if-chain -> switch dispatch changes the asm), so the ladder->switch equivalence is pinned by a new table-driven test: lib/ww/asttest.ww drives nkname over every nkind plus the out-of-band "?" fallback, wired as 905_nkname_run (same `ww run` @test shape as 904_tok_run). The 990_selfhost wwdump diff only covers kinds that appear in its corpus. Regenerates the w6c + wwdump combined.ww amalgamations (nkname region only).
This commit is contained in:
57
test/wcc/905_nkname_run.c
Normal file
57
test/wcc/905_nkname_run.c
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* 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 `ast` (package ww), whose
|
||||
* printer references tok's tkind/tokname, so the run needs
|
||||
* `-I lib/ww/lex` to resolve that transitive import.
|
||||
*/
|
||||
#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/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(cmd, sizeof cmd, "%s/ww run -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;
|
||||
}
|
||||
Reference in New Issue
Block a user