aboutsummaryrefslogtreecommitdiff
path: root/bootstrap
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2022-08-13 13:00:37 +0200
committerlemon <lsof@mailbox.org>2022-08-13 13:00:37 +0200
commita4ddca68662f4bc0531763357b4bc00b6c50b456 (patch)
tree97f83407da049732ec97dd2d32ee34e0cd3c8c0f /bootstrap
parent5b95abb249604e7df9be1d63b1f3dc85b8f5990b (diff)
target
Diffstat (limited to 'bootstrap')
-rw-r--r--bootstrap/cgen.c10
-rw-r--r--bootstrap/env.c3
-rw-r--r--bootstrap/fold.c4
-rw-r--r--bootstrap/parse.c4
4 files changed, 16 insertions, 5 deletions
diff --git a/bootstrap/cgen.c b/bootstrap/cgen.c
index 14f36f1..8b7b710 100644
--- a/bootstrap/cgen.c
+++ b/bootstrap/cgen.c
@@ -146,9 +146,15 @@ geniniex(struct expr *ex) {
for (int i = 0; i < ex->ini.args.n; ++i) {
struct iniarg *arg = &ex->ini.args.d[i];
if (ex->ty->t == TYarr)
- pri("[%I] = %e, ", arg->idx, &arg->ex);
+ if (arg->ex.t == Eini)
+ pri("[%I] = %n, ", arg->idx, &arg->ex);
+ else
+ pri("[%I] = %e, ", arg->idx, &arg->ex);
else
- pri(".%s_ = %e, ", arg->fld, &arg->ex);
+ if (arg->ex.t == Eini)
+ pri(".%s_ = %n, ", arg->fld, &arg->ex);
+ else
+ pri(".%s_ = %e, ", arg->fld, &arg->ex);
}
pri("}");
diff --git a/bootstrap/env.c b/bootstrap/env.c
index ff2929f..40392b9 100644
--- a/bootstrap/env.c
+++ b/bootstrap/env.c
@@ -33,6 +33,9 @@ envput(struct env *env, const struct decl *decl) {
if ((d0 = envfind(&env_noparent, INT_MAX, decl->name))) {
// modify existing forward declarations?
+ if (decl->t != d0->t)
+ return NULL;
+
if (decl == d0 || !memcmp(d0, decl, sizeof *d0))
return d0;
if (d0->t == Ddef && decl->t == Ddef && !memcmp(&d0->var, &decl->var, sizeof d0->var))
diff --git a/bootstrap/fold.c b/bootstrap/fold.c
index efe1f83..cd72415 100644
--- a/bootstrap/fold.c
+++ b/bootstrap/fold.c
@@ -5,9 +5,9 @@ int fold(struct expr *ex);
static void
numcast(struct expr *ex, const struct type *to) {
- enum typetype t0 = ex->ty->t;
enum typetype t1 = to->t;
- const struct type *from = ex->ty;
+ const struct type *from = ex->ty->t == TYenum ? ex->ty->enu.intty : ex->ty;
+ enum typetype t0 = from->t;
const struct type *uto = unconstify(to);
const struct type *ufrom = unconstify(from);
int size = to->size;
diff --git a/bootstrap/parse.c b/bootstrap/parse.c
index 197b61b..7a35f09 100644
--- a/bootstrap/parse.c
+++ b/bootstrap/parse.c
@@ -1360,6 +1360,8 @@ pexpostfix(struct parser *P) {
const struct type *ty = ex.ty;
if (ty->t == TYptr)
ty = ty->child;
+ bool konst = ty->konst;
+ ty = unconstify(ty);
if (ty->t == TYstruct || ty->t == TYunion || ty->t == TYeunion) {
int idx = structfldnam2idx(ty, fnam);
struct aggfield *fld = &ty->agg.flds.d[idx];
@@ -1371,7 +1373,7 @@ pexpostfix(struct parser *P) {
ex.get.lhs = exprdup(ex);
ex.t = Eget;
ex.span = tok.span;
- ex.ty = ex.ty->konst ? constify(fld->ty) : fld->ty;
+ ex.ty = konst ? constify(fld->ty) : fld->ty;
ex.get.fld = fnam;
} else {
fatal(P, tok.span, "cannot access `%s': left-hand-side is not an aggregate (%t)",