Fold the ~88-arm `if (k == tkind.TK_X) return "..."` ladder in tokname to a single `switch (k)` with the terminal `return "<?>"` as the fall-past default. kwlookup stays an if-ladder: it dispatches on streqn() string compares over distinct literals, which a value-switch can't 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/lex/toktest.ww drives tokname over every tkind plus the out-of-band "<?>" fallback, and kwlookup over every keyword plus non-keywords, wired as 904_tok_run (same `ww run` @test shape as 904_ascii_run). The 990_selfhost wwdump diff only covers kinds that appear in its corpus. Regenerates the w6c + wwdump combined.ww amalgamations (tokname region only).
53 lines
1.4 KiB
C
53 lines
1.4 KiB
C
/*
|
|
* 904_tok_run — execute the lib/ww/lex 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
|
|
* carries its own `export fn main()` that drives the @test fns and
|
|
* signals which case failed via the exit code. This pins tokname's
|
|
* if-ladder -> switch fold (every tkind + the unknown-kind fallback),
|
|
* which the 990_selfhost wwdump diff only covers for kinds that appear
|
|
* in its corpus.
|
|
*/
|
|
#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/lex/toktest.ww";
|
|
char path[1024], cmd[2048];
|
|
snprintf(path, sizeof path, "%s/%s", cwd, src);
|
|
snprintf(cmd, sizeof cmd, "%s/ww run %s", bin, path);
|
|
int rc = runwait(cmd);
|
|
if (rc != 0) {
|
|
fprintf(stderr, "tok_run FAIL: %s exited %d\n", src, rc);
|
|
return 1;
|
|
}
|
|
printf("tok_run: %s ok\n", src);
|
|
return 0;
|
|
}
|