aboutsummaryrefslogtreecommitdiff
path: root/bootstrap
diff options
context:
space:
mode:
Diffstat (limited to 'bootstrap')
-rwxr-xr-xbootstrap/bootstrap.sh2
-rw-r--r--bootstrap/cgen.c8
-rw-r--r--bootstrap/env.c8
-rw-r--r--bootstrap/parse.c11
4 files changed, 18 insertions, 11 deletions
diff --git a/bootstrap/bootstrap.sh b/bootstrap/bootstrap.sh
index 1cb9f42..7ae3c09 100755
--- a/bootstrap/bootstrap.sh
+++ b/bootstrap/bootstrap.sh
@@ -2,7 +2,7 @@
cd $(dirname "$0")
-./build.sh
+./build.sh || exit 1
if [ x"$CC" == x ]; then
export CC=cc
diff --git a/bootstrap/cgen.c b/bootstrap/cgen.c
index 62a808d..4a80bfb 100644
--- a/bootstrap/cgen.c
+++ b/bootstrap/cgen.c
@@ -634,7 +634,11 @@ gendecl(struct decl *decl, bool toplevel) {
case Dlet:
assert(!toplevel);
break;
- case Ddef: case Dtype: case Dtepl: case Dmacro: case Dlabel:
+ case Dtype:
+ if (decl->ty->t == TYstruct || decl->ty->t == TYunion)
+ for (int i = 0; i < decl->ty->agg.decls.n; ++i)
+ liftdecl(decl->ty->agg.decls.d[i]);
+ case Ddef: case Dtepl: case Dmacro: case Dlabel:
break;
}
}
@@ -716,8 +720,6 @@ defctype(const struct type *ty, void *_) {
pri("_Static_assert(__alignof__(%s) == %U, \"__alignof__(%t) == %U\");\n",
*cname, (u64)ty->align, ty, (u64)ty->align);
}
- for (int i = 0; i < ty->agg.decls.n; ++i)
- liftdecl(ty->agg.decls.d[i]);
break;
case TYeunion:
if (ty->konst) {
diff --git a/bootstrap/env.c b/bootstrap/env.c
index 601b446..2c5e80f 100644
--- a/bootstrap/env.c
+++ b/bootstrap/env.c
@@ -32,13 +32,19 @@ envput(struct env *env, const struct decl *decl) {
static int age;
if ((d0 = envfind(&env_noparent, INT_MAX, decl->name))) {
+ if (decl == d0 || !memcmp(d0, decl, sizeof *d0))
+ return d0;
// modify existing forward declarations?
+ if (d0->t != decl->t)
+ return NULL;
+ if (d0->t == Dmacro && !memcmp(&decl->macro, &d0->macro, sizeof decl->macro))
+ return d0;
for (int kind = TYstruct; kind <= TYunion; ++kind) {
if (d0->t == Dtype && d0->ty->t == kind
&& decl->t == Dtype && decl->ty->t == kind && d0->ty->agg.fwd) {
*(size_t *)&d0->ty->size = decl->ty->size;
*(size_t *)&d0->ty->align = decl->ty->align;
- *(bool *)&d0->ty->agg.fwd = 0;
+ *(bool *)&d0->ty->agg.fwd = decl->ty->agg.fwd;
memcpy((void *)&d0->ty->agg.flds, &decl->ty->agg.flds,
sizeof d0->ty->agg.flds);
memcpy((void *)&d0->ty->agg.decls, &decl->ty->agg.decls,
diff --git a/bootstrap/parse.c b/bootstrap/parse.c
index 8d6fe2c..49f01b1 100644
--- a/bootstrap/parse.c
+++ b/bootstrap/parse.c
@@ -2781,7 +2781,7 @@ getbasedir(const char *path) {
static struct comfile
doimport(struct parser *P, const char *path) {
- static vec_t(const char *) seen;
+ static vec_t(struct entry { const char *s; struct comfile cf; }) seen;
char path2[PATH_MAX], _rpath[PATH_MAX], *rpath;
struct comfile cf = {0};
struct parser P2;
@@ -2791,15 +2791,15 @@ doimport(struct parser *P, const char *path) {
if (!(rpath = realpath(path2, _rpath)))
fatal(P, P->tokspan, "import %q: %s", path, strerror(errno));
for (int i = 0; i < seen.length; ++i)
- if (!strcmp(seen.data[i], rpath))
- return cf;
+ if (!strcmp(seen.data[i].s, rpath))
+ return seen.data[i].cf;
rpath = xstrdup(rpath);
- vec_push(&seen, rpath);
// P2.primenv = P->primenv;
initparser(&P2, xstrdup(path2));
P2.is_header = 1;
parse(&cf, &P2);
+ vec_push(&seen, ((struct entry) { rpath, cf }));
return cf;
}
@@ -3003,7 +3003,7 @@ parsedecl(decl_yielder_t yield, void *yarg, struct parser *P, bool toplevel) {
const char *path;
struct comfile cf;
assert(toplevel);
- path = lexexpect(P, TKstrlit).str;
+ path = (tok = lexexpect(P, TKstrlit)).str;
cf = doimport(P, path);
free((void *)path);
for (int i = 0; i < cf.decls.n; ++i) {
@@ -3011,7 +3011,6 @@ parsedecl(decl_yielder_t yield, void *yarg, struct parser *P, bool toplevel) {
if (yield)
yield(decl, yarg);
}
- free(cf.decls.d);
lexexpect(P, ';');
return;
} else if (lexmatch(P, &tok, TKident)) {