diff options
| author | 2022-08-11 06:51:48 +0200 | |
|---|---|---|
| committer | 2022-08-11 06:51:48 +0200 | |
| commit | 25bf34e2c15b93e1cedab14cc83dddbb08ffcf3b (patch) | |
| tree | 5b57e1d11126a839851ef3038e61a524719b4bfc /bootstrap | |
| parent | 99cb50d4f13d587e3a0e0f2a44485f301409afb4 (diff) | |
more fix
Diffstat (limited to 'bootstrap')
| -rw-r--r-- | bootstrap/cgen.c | 10 | ||||
| -rw-r--r-- | bootstrap/env.c | 3 | ||||
| -rw-r--r-- | bootstrap/parse.c | 6 | ||||
| -rw-r--r-- | bootstrap/util.c | 4 |
4 files changed, 13 insertions, 10 deletions
diff --git a/bootstrap/cgen.c b/bootstrap/cgen.c index 4e4d53f..a00c08f 100644 --- a/bootstrap/cgen.c +++ b/bootstrap/cgen.c @@ -487,7 +487,6 @@ liftnestedex(struct expr *ex) { liftnestedex(ex->get.lhs); break; case Emcall: - liftdecl(container_of(ex->mcall.met, struct decl, fn)); for (int i = 0; i < ex->call.args.n; ++i) liftnestedex(&ex->mcall.args.d[i]); break; @@ -507,6 +506,7 @@ lifttype(const struct type *ty) { if (ty->t == TYstruct || ty->t == TYunion || ty->t == TYeunion) for (int i = 0; i < ty->agg.decls.n; ++i) liftdecl(ty->agg.decls.d[i]); + } static void @@ -514,11 +514,11 @@ liftdecl(struct decl *decl) { static int id; switch (decl->t) { case Dfn: - if (decl->fn.body) { + if (decl->fn.body || (decl->container && !decl->externp)) { if (decl->container) - *decl->_cname = xasprintf("__m%s_%s%d", decl->container->agg.name, decl->fn.name, id++); + *decl->_cname = xasprintf("__m%s_%s%d", decl->container->agg.name, decl->fn.name, decl->fn.id); else - *decl->_cname = xasprintf("__f%s_%d", decl->fn.name, id++); + *decl->_cname = xasprintf("__f%s_%d", decl->fn.name, decl->fn.id); genfn(decl->externp, *decl->_cname, &decl->fn); } break; @@ -533,8 +533,6 @@ liftdecl(struct decl *decl) { liftnestedex(decl->var.ini); break; case Dtype: - lifttype(decl->ty); - break; case Dtepl: for (struct teplcache *cache = decl->tepl.cache; cache; cache = cache->next) { for (int i = 0; i < cache->args.n; ++i) { diff --git a/bootstrap/env.c b/bootstrap/env.c index ec80e62..773550a 100644 --- a/bootstrap/env.c +++ b/bootstrap/env.c @@ -33,6 +33,8 @@ envput(struct env *env, const struct decl *decl) { if ((d0 = envfind(&env_noparent, INT_MAX, decl->name))) { // modify existing forward declarations? + if (decl == d0 || !memcmp(d0, decl, sizeof *d0)) + return d0; if (d0->t == Dmacro && !memcmp(&decl->macro, &d0->macro, sizeof decl->macro)) return d0; if (d0->t == Dtepl && !memcmp(&decl->tepl, &d0->tepl, sizeof decl->tepl)) @@ -52,6 +54,7 @@ envput(struct env *env, const struct decl *decl) { } } if (d0->t == Dfn && d0->externp == decl->externp && d0->fn.selfty == decl->fn.selfty && !d0->fn.body && decl->fn.body) { + *(int *)&decl->fn.id = d0->fn.id; goto ok; } if (d0->t == Dfn && d0->externp == decl->externp && d0->fn.selfty == decl->fn.selfty && !d0->fn.body) diff --git a/bootstrap/parse.c b/bootstrap/parse.c index 297f2a9..daf632d 100644 --- a/bootstrap/parse.c +++ b/bootstrap/parse.c @@ -2371,6 +2371,8 @@ parsefn(struct decl *decl, struct parser *P) { struct tok tok; struct fn *fn = &decl->fn; const char *name = fn->name; + static int id; + memset(fn, 0, sizeof *fn); fn->name = name; @@ -2401,10 +2403,9 @@ parsefn(struct decl *decl, struct parser *P) { fatal(P, tok.span, "return type is incomplete (%t)", fn->retty); } + fn->id = id++; if (!lexmatch(P, &tok, ';')) { struct env *env = xcalloc(1, sizeof *env); - static int id; - fn->id = id++; lexexpect(P, '{'); env->parent = P->curenv; @@ -2646,6 +2647,7 @@ parseagg(struct parser *P, const char *name, int kind, struct decl **retdecl) { struct decl *decl = (struct decl *)envfind(&env_noparent, P->envage, name); if (decl && decl->t == Dtype && decl->ty->t == kind) { pty = decl->ty; + *(bool *)&pty->agg.fwd = 0; } else { pty = interntype((struct type) { kind, .agg.name = name, .agg.id = id++ diff --git a/bootstrap/util.c b/bootstrap/util.c index 20f1772..7755095 100644 --- a/bootstrap/util.c +++ b/bootstrap/util.c @@ -70,14 +70,14 @@ xrealloc(void *p, size_t n) { char * xasprintf(const char *fmt, ...) { va_list ap, aq; - int n = 16, m; + int n = 32, m; char *str = xcalloc(n, 1); va_start(ap, fmt); m = vsnprintf(str, n, fmt, ap) + 1; str = xrealloc(str, m); if (m > n) { va_copy(aq, ap); - vsprintf(str, fmt, ap); + vsprintf(str, fmt, aq); va_end(aq); } va_end(ap); |