diff --git a/Makefile b/Makefile index 5b0bc8c6..62649a2d 100644 --- a/Makefile +++ b/Makefile @@ -106,7 +106,7 @@ $(OBJ)/w6l/%.o: cmd/w6l/%.c cmd/w6l/l.h | $(OBJ)/w6l # (mem, 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.ww lib/ww/tok.ww lib/ww/ast.ww \ + lib/ww/lex/lex.ww lib/ww/lex/tok.ww lib/ww/ast.ww \ lib/ww/parse.ww lib/ww/typ.ww lib/ww/sym.ww \ selfhost/cmd/wcc/mem.ww selfhost/cmd/wcc/check.ww \ selfhost/cmd/wcc/cgen.ww selfhost/cmd/wcc/cgenexpr.ww \ @@ -117,6 +117,7 @@ $(BIN)/wwdump_ww: selfhost/cmd/wwdump/main.ww \ $(LIB)/libwwrt.a | $(BIN) cd $(BIN) && ./ww build \ -I $$PWD/../../lib/ww \ + -I $$PWD/../../lib/ww/lex \ -I $$PWD/../../selfhost/cmd/wcc \ $$PWD/../../selfhost/cmd/wwdump/main.ww mv $(BIN)/main $@ @@ -125,7 +126,7 @@ $(BIN)/wwdump_ww: selfhost/cmd/wwdump/main.ww \ # Thin driver: parse + cgen. The frontend (lex/parse/ast/...) lives in # lib/ww/; cgen + check live in selfhost/cmd/wcc/. $(BIN)/w6c_ww: selfhost/cmd/w6c/main.ww \ - lib/ww/lex.ww lib/ww/tok.ww lib/ww/ast.ww \ + lib/ww/lex/lex.ww lib/ww/lex/tok.ww lib/ww/ast.ww \ lib/ww/parse.ww lib/ww/typ.ww lib/ww/sym.ww \ selfhost/cmd/wcc/mem.ww selfhost/cmd/wcc/check.ww \ selfhost/cmd/wcc/cgen.ww selfhost/cmd/wcc/cgenexpr.ww \ @@ -136,6 +137,7 @@ $(BIN)/w6c_ww: selfhost/cmd/w6c/main.ww \ $(LIB)/libwwrt.a | $(BIN) cd $(BIN) && ./ww build \ -I $$PWD/../../lib/ww \ + -I $$PWD/../../lib/ww/lex \ -I $$PWD/../../selfhost/cmd/wcc \ $$PWD/../../selfhost/cmd/w6c/main.ww mv $(BIN)/main $@ @@ -397,6 +399,7 @@ 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)/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 \ diff --git a/lib/ww/lex.ww b/lib/ww/lex/lex.ww similarity index 99% rename from lib/ww/lex.ww rename to lib/ww/lex/lex.ww index eb2e1259..f3ea3e69 100644 --- a/lib/ww/lex.ww +++ b/lib/ww/lex/lex.ww @@ -1,4 +1,4 @@ -// lib/ww/lex.ww — port of cmd/wcc/lex.c. +// lib/ww/lex/lex.ww — port of cmd/wcc/lex.c. // // The DFA, the helpers, and the order of decisions all mirror the C // version exactly. The 990_selfhost test diffs the resulting token diff --git a/lib/ww/tok.ww b/lib/ww/lex/tok.ww similarity index 99% rename from lib/ww/tok.ww rename to lib/ww/lex/tok.ww index ae47d3e1..a531adc9 100644 --- a/lib/ww/tok.ww +++ b/lib/ww/lex/tok.ww @@ -1,4 +1,4 @@ -// lib/ww/tok.ww — port of cmd/wcc/tok.c plus the Tkind / +// lib/ww/lex/tok.ww — port of cmd/wcc/tok.c plus the Tkind / // Tok / Pos shapes from cmd/wcc/ww.h. // // Token kind values must stay numerically equal to the C side: the diff --git a/selfhost/cmd/w6c/main.combined.ww b/selfhost/cmd/w6c/main.combined.ww index 1103a388..bb1c8272 100644 --- a/selfhost/cmd/w6c/main.combined.ww +++ b/selfhost/cmd/w6c/main.combined.ww @@ -437,8 +437,8 @@ export fn parseu64(s: str) (u64 | str) = { return v; }; -// MODULE: ww -// lib/ww/tok.ww — port of cmd/wcc/tok.c plus the Tkind / +// MODULE: lex +// lib/ww/lex/tok.ww — port of cmd/wcc/tok.c plus the Tkind / // Tok / Pos shapes from cmd/wcc/ww.h. // // Token kind values must stay numerically equal to the C side: the @@ -927,8 +927,8 @@ export fn toupper(c: u8) u8 = { return c; }; -// MODULE: ww -// lib/ww/lex.ww — port of cmd/wcc/lex.c. +// MODULE: lex +// lib/ww/lex/lex.ww — port of cmd/wcc/lex.c. // // The DFA, the helpers, and the order of decisions all mirror the C // version exactly. The 990_selfhost test diffs the resulting token diff --git a/selfhost/cmd/wwdump/main.combined.ww b/selfhost/cmd/wwdump/main.combined.ww index fd009659..8064ab09 100644 --- a/selfhost/cmd/wwdump/main.combined.ww +++ b/selfhost/cmd/wwdump/main.combined.ww @@ -437,8 +437,8 @@ export fn parseu64(s: str) (u64 | str) = { return v; }; -// MODULE: ww -// lib/ww/tok.ww — port of cmd/wcc/tok.c plus the Tkind / +// MODULE: lex +// lib/ww/lex/tok.ww — port of cmd/wcc/tok.c plus the Tkind / // Tok / Pos shapes from cmd/wcc/ww.h. // // Token kind values must stay numerically equal to the C side: the @@ -927,8 +927,8 @@ export fn toupper(c: u8) u8 = { return c; }; -// MODULE: ww -// lib/ww/lex.ww — port of cmd/wcc/lex.c. +// MODULE: lex +// lib/ww/lex/lex.ww — port of cmd/wcc/lex.c. // // The DFA, the helpers, and the order of decisions all mirror the C // version exactly. The 990_selfhost test diffs the resulting token diff --git a/test/wcc/990_selfhost.c b/test/wcc/990_selfhost.c index e18a417a..564cebb0 100644 --- a/test/wcc/990_selfhost.c +++ b/test/wcc/990_selfhost.c @@ -171,8 +171,8 @@ probe_dump_diff(const char *bin) const char *tok_inputs[] = { "selfhost/cmd/wcc/mem.ww", "selfhost/cmd/wcc/err.ww", - "lib/ww/lex.ww", - "lib/ww/tok.ww", + "lib/ww/lex/lex.ww", + "lib/ww/lex/tok.ww", "lib/ww/ast.ww", "lib/ww/parse.ww", "selfhost/cmd/wwdump/main.ww", @@ -188,8 +188,8 @@ probe_dump_diff(const char *bin) "selfhost/test/uses.ww", "selfhost/cmd/wcc/err.ww", "selfhost/cmd/wcc/mem.ww", - "lib/ww/lex.ww", - "lib/ww/tok.ww", + "lib/ww/lex/lex.ww", + "lib/ww/lex/tok.ww", "lib/ww/ast.ww", "lib/ww/parse.ww", "lib/ww/typ.ww", @@ -435,7 +435,7 @@ probe_resolve(const char *bin) const char *complete[] = { "selfhost/cmd/wcc/err.ww", "selfhost/cmd/wcc/mem.ww", - "lib/ww/tok.ww", + "lib/ww/lex/tok.ww", "selfhost/test/smoke.ww", NULL, }; @@ -656,8 +656,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 && %s/ww build -I %s/lib/ww -I %s/selfhost/cmd/wcc %s >/dev/null 2>&1", - tmpdir, bin, cwd, cwd, tmpsrc); + "cd %s && %s/ww build -I %s/lib/ww -I %s/lib/ww/lex -I %s/selfhost/cmd/wcc %s >/dev/null 2>&1", + tmpdir, bin, cwd, cwd, cwd, tmpsrc); if (runwait(cmd) != 0) { fprintf(stderr, "ww-links FAIL: ww build %s\n", fix); fail++; @@ -717,7 +717,7 @@ probe_cgen_match(const char *bin) const char *files[] = { "selfhost/cmd/wcc/mem.ww", "selfhost/cmd/wcc/err.ww", - "lib/ww/tok.ww", + "lib/ww/lex/tok.ww", "selfhost/test/smoke.ww", NULL, }; diff --git a/test/wcc/993_ww_ww.c b/test/wcc/993_ww_ww.c index 21ce1f55..13589a1d 100644 --- a/test/wcc/993_ww_ww.c +++ b/test/wcc/993_ww_ww.c @@ -59,10 +59,15 @@ slurp_eq(const char *a, const char *b) * the build directory. Returns 0 on success. */ static int build_via(const char *bin, const char *driver, const char *src, - const char *workdir, const char *includes_a, const char *includes_b) + const char *workdir, const char *includes_a, const char *includes_b, + const char *includes_c) { char cmd[4096]; - if (includes_b && includes_b[0]) { + if (includes_c && includes_c[0]) { + snprintf(cmd, sizeof cmd, + "cd %s && %s/%s build -I %s -I %s -I %s %s 2>/dev/null", + workdir, bin, driver, includes_a, includes_b, includes_c, src); + } else if (includes_b && includes_b[0]) { snprintf(cmd, sizeof cmd, "cd %s && %s/%s build -I %s -I %s %s 2>/dev/null", workdir, bin, driver, includes_a, includes_b, src); @@ -81,7 +86,7 @@ build_via(const char *bin, const char *driver, const char *src, static int diff_one(const char *bin, const char *cwd, const char *label, const char *src, const char *out_basename, - const char *inc_a, const char *inc_b) + const char *inc_a, const char *inc_b, const char *inc_c) { char dc[64], dw[64]; snprintf(dc, sizeof dc, "/tmp/ww_d_%d_c", getpid()); @@ -91,11 +96,11 @@ diff_one(const char *bin, const char *cwd, const char *label, snprintf(cmd, sizeof cmd, "rm -rf %s %s && mkdir -p %s %s", dc, dw, dc, dw); if (runwait(cmd) != 0) return -1; - if (build_via(bin, "ww", src, dc, inc_a, inc_b) != 0) { + if (build_via(bin, "ww", src, dc, inc_a, inc_b, inc_c) != 0) { fprintf(stderr, "ww_ww FAIL: C ww errored on %s\n", label); return -1; } - if (build_via(bin, "ww_ww", src, dw, inc_a, inc_b) != 0) { + if (build_via(bin, "ww_ww", src, dw, inc_a, inc_b, inc_c) != 0) { fprintf(stderr, "ww_ww FAIL: ww ww errored on %s\n", label); return -1; } @@ -142,27 +147,31 @@ main(void) const char *out; /* basename of expected output */ const char *inc_a; const char *inc_b; + const char *inc_c; } cases[] = { - { "hello", "/tmp/ww_d_hello.ww", "ww_d_hello", "", "" }, - { "wwdump", NULL, "main", NULL, NULL }, /* filled in below */ - { NULL, NULL, NULL, NULL, NULL }, + { "hello", "/tmp/ww_d_hello.ww", "ww_d_hello", "", "", "" }, + { "wwdump", NULL, "main", NULL, NULL, NULL }, /* filled in below */ + { NULL, NULL, NULL, NULL, NULL, NULL }, }; /* wwdump case: absolute paths so the driver finds the imports * regardless of the per-driver workdir. */ - static char wwdump_src[2048], wwdump_inc_a[2048], wwdump_inc_b[2048]; + static char wwdump_src[2048], wwdump_inc_a[2048], wwdump_inc_b[2048], wwdump_inc_c[2048]; snprintf(wwdump_src, sizeof wwdump_src, "%s/selfhost/cmd/wwdump/main.ww", cwd); snprintf(wwdump_inc_a, sizeof wwdump_inc_a, "%s/lib/ww", cwd); - snprintf(wwdump_inc_b, sizeof wwdump_inc_b, "%s/selfhost/cmd/wcc", cwd); + snprintf(wwdump_inc_b, sizeof wwdump_inc_b, "%s/lib/ww/lex", cwd); + snprintf(wwdump_inc_c, sizeof wwdump_inc_c, "%s/selfhost/cmd/wcc", cwd); cases[1].src = wwdump_src; cases[1].inc_a = wwdump_inc_a; cases[1].inc_b = wwdump_inc_b; + cases[1].inc_c = wwdump_inc_c; int fail = 0; int n = 0; for (int i = 0; cases[i].label; i++) { if (diff_one(bin, cwd, cases[i].label, cases[i].src, - cases[i].out, cases[i].inc_a, cases[i].inc_b) != 0) + cases[i].out, cases[i].inc_a, cases[i].inc_b, + cases[i].inc_c) != 0) fail++; n++; } diff --git a/test/wcc/995_self_rebuild.c b/test/wcc/995_self_rebuild.c index dee85ba7..b66abddf 100644 --- a/test/wcc/995_self_rebuild.c +++ b/test/wcc/995_self_rebuild.c @@ -77,14 +77,14 @@ rebuild_one(const char *bin, const char *cwd, const char *tool, if (inc_local && inc_local[0]) { snprintf(cmd, sizeof cmd, - "cd %s && %s/ww_ww build -I %s/%s -I %s/lib/ww -I %s/selfhost/cmd/wcc " + "cd %s && %s/ww_ww build -I %s/%s -I %s/lib/ww -I %s/lib/ww/lex -I %s/selfhost/cmd/wcc " "%s/%s >/dev/null 2>&1", - workdir, bin, cwd, inc_local, cwd, cwd, cwd, src_rel); + workdir, bin, cwd, inc_local, cwd, cwd, cwd, cwd, src_rel); } else { snprintf(cmd, sizeof cmd, - "cd %s && %s/ww_ww build -I %s/lib/ww -I %s/selfhost/cmd/wcc " + "cd %s && %s/ww_ww build -I %s/lib/ww -I %s/lib/ww/lex -I %s/selfhost/cmd/wcc " "%s/%s >/dev/null 2>&1", - workdir, bin, cwd, cwd, cwd, src_rel); + workdir, bin, cwd, cwd, cwd, cwd, src_rel); } if (runwait(cmd) != 0) { fprintf(stderr, "self-rebuild FAIL: ww_ww build errored on %s\n", tool);