ww: preserve command package identities

This commit is contained in:
2026-08-13 03:37:08 +09:00
parent 10d24a3237
commit 4377634bb9
10 changed files with 348 additions and 43 deletions

View File

@@ -31,13 +31,14 @@ struct importin {
static Node *
parseinput(Arena *a, const char *file, char *buf, u64 len,
const char *mod, const char *testsupport, int *bad)
const char *mod, const char *testsupport, int commandpackage, int *bad)
{
Lex l;
Parser p;
lexinit(&l, a, file, buf, len);
parserinit(&p, a, &l);
p.testmodule = testsupport;
p.commandpackage = commandpackage;
if (mod != NULL) {
p.pathmod = mod;
p.curmod = mod;
@@ -66,6 +67,7 @@ main(int argc, char **argv)
const char *testsupport = NULL;
int testmode = 0;
int testpackage = 0;
int commandpackage = 0;
int entrymode = 0;
int sepmode = 0; /* -c: #22 M3 separate-compile / primary-
* only codegen (emit imported==0 decls
@@ -86,6 +88,8 @@ main(int argc, char **argv)
testmode = 1;
} else if (strcmp(a, "--test-package") == 0) {
testpackage = 1;
} else if (strcmp(a, "--command-package") == 0) {
commandpackage = 1;
} else if (strcmp(a, "--entry") == 0) {
entrymode = 1;
} else if (strcmp(a, "--test-support-module") == 0) {
@@ -115,7 +119,7 @@ main(int argc, char **argv)
}
}
if (src == NULL) {
fputs("usage: w6c [-T|--test-package] [--entry] [-c] [-I out.wwi] "
fputs("usage: w6c [-T|--test-package] [--command-package] [--entry] [-c] [-I out.wwi] "
"[--import path dep.wwi]... [-o out.s] file.ww\n", stderr);
return 2;
}
@@ -123,8 +127,8 @@ main(int argc, char **argv)
fputs("w6c: --import requires -c\n", stderr);
return 2;
}
if ((entrymode || testpackage) && !sepmode) {
fputs("w6c: --entry and --test-package require -c\n", stderr);
if ((entrymode || testpackage || commandpackage) && !sepmode) {
fputs("w6c: --entry, --test-package, and --command-package require -c\n", stderr);
return 2;
}
if (testmode && testpackage) {
@@ -162,7 +166,7 @@ main(int argc, char **argv)
}
int bad = 0;
Node *f = parseinput(a, imports[i].file, imports[i].buf,
imports[i].len, imports[i].path, testsupport, &bad);
imports[i].len, imports[i].path, testsupport, 0, &bad);
if (bad) return 1;
appendnodes(&head, &tail, f->list);
}
@@ -174,7 +178,11 @@ main(int argc, char **argv)
return 1;
}
int bad = 0;
Node *file = parseinput(a, src, buf, len, NULL, testsupport, &bad);
/* --entry classifies an ordinary selected command. The separate
* --command-package marker carries the same parser-only fact for command
* test variants whose code generation must not expose bare main. */
Node *file = parseinput(a, src, buf, len, NULL, testsupport,
commandpackage || entrymode, &bad);
if (bad) return 1;
if (head != NULL) {
tail->next = file->list;