diff options
| author | 2022-08-15 12:22:47 +0200 | |
|---|---|---|
| committer | 2022-08-15 12:22:47 +0200 | |
| commit | f906d0b350b0b4ceb747669c9a9845d11bd0e486 (patch) | |
| tree | 5f09a7b714e6ce93f6094a06e5f736513110fb8d /bootstrap | |
| parent | f802bb99263aaa5be492999babd44cd2fdb1c65f (diff) | |
self hosted progress
Diffstat (limited to 'bootstrap')
| -rw-r--r-- | bootstrap/all.h | 4 | ||||
| -rw-r--r-- | bootstrap/env.c | 4 | ||||
| -rw-r--r-- | bootstrap/parse.c | 25 | ||||
| -rw-r--r-- | bootstrap/types.c | 16 | ||||
| -rw-r--r-- | bootstrap/util.c | 3 |
5 files changed, 32 insertions, 20 deletions
diff --git a/bootstrap/all.h b/bootstrap/all.h index e458c15..b86e7f6 100644 --- a/bootstrap/all.h +++ b/bootstrap/all.h @@ -500,7 +500,9 @@ static const struct targ { i32align, i64align, longsize, + longalign, llongsize, + llongalign, sizesize, f32align, f64align, @@ -514,6 +516,8 @@ static const struct targ { .i32align = alignof(int32_t), .i64align = alignof(int64_t), .longsize = sizeof(long), + .longalign = alignof(long), + .llongalign = alignof(long long), .llongsize = sizeof(long long), .sizesize = sizeof(size_t), .f32align = alignof(float), diff --git a/bootstrap/env.c b/bootstrap/env.c index 21d9580..7ab3920 100644 --- a/bootstrap/env.c +++ b/bootstrap/env.c @@ -36,11 +36,11 @@ envput(struct env *env, const struct decl *decl) { if (decl->t != d0->t) return NULL; - if (decl == d0 || !memcmp(d0, decl, sizeof *d0)) + if (decl == d0) return d0; if (d0->t == Ddef && decl->t == Ddef && !memcmp(&d0->var, &decl->var, sizeof d0->var)) return d0; - if (d0->t == Dmacro && !memcmp(&decl->macro, &d0->macro, sizeof decl->macro)) + if (d0->t == Dmacro && decl->macro.cs.d == d0->macro.cs.d) return d0; if (d0->t == Dtype && d0->ty == decl->ty) return d0; diff --git a/bootstrap/parse.c b/bootstrap/parse.c index 0c619fc..0d9ab16 100644 --- a/bootstrap/parse.c +++ b/bootstrap/parse.c @@ -785,7 +785,7 @@ parsetype(struct parser *P) { lexexpect(P, ']'); } else if (!lexmatch(P, &tok, ']')) { struct expr ex = parseexpr(P); - if (!fold(&ex) || ex.t != Eintlit) + if (!fold(&ex) || (ex.t != Eintlit && !(ex.t == Eenumval && ex.ty->enu.lax))) fatal(P, ex.span, "array length should be a compile-time integral expression"); if ((length = ex.i) < 0) @@ -1178,8 +1178,9 @@ pexprimary(struct parser *P) { } else { const struct aggfield *fld; for (i = 0; i < ex.ty->agg.flds.n; ++i) - if (!strcmp((fld = &ex.ty->agg.flds.d[i])->name, vname)) + if (!strcmp((fld = &ex.ty->agg.flds.d[i])->name, vname)) { goto found1; + } fatal(P, tok.span, "tagged union %t contains no variant `%s'", ex.ty, vname); found1: P->used_targty = 1; @@ -1187,6 +1188,7 @@ pexprimary(struct parser *P) { ex.span = tok.span; ex.euini.fnam = fld->name; ex.euini.tag = ex.ty->agg.enumty->enu.vals.d[i].i; + P->targty = fld->ty; if (fld->ty) ex.euini.ini = exprdup(parseexpr(P)); } @@ -1288,7 +1290,7 @@ pexpostfix(struct parser *P) { if (lhs.ty->t != TYarr && lhs.ty->t != TYptr && lhs.ty->t != TYslice) fatal(P, lhs.span, "indexee is not array or pointer type (%t)", lhs.ty); - if (rhs.ty->t != TYint) + if (rhs.ty->t != TYint && !(rhs.ty->t == TYenum && rhs.ty->enu.lax)) fatal(P, lhs.span, "index expression type is not integral (%t)", rhs.ty); if (lexmatch(P, NULL, '::')) { @@ -1474,6 +1476,7 @@ pexpostfix(struct parser *P) { fnam, ex.ty); } } else { + P->used_targty = 0; break; } @@ -1532,7 +1535,7 @@ pexprefix(struct parser *P) { if (ex.ty->t != TYptr) fatal(P, ex.span, "invalid %t operand to dereference, not pointer", ex.ty); if (!completetype(ex.ty->child) && ex.ty->child->t != TYfn) - fatal(P, ex.span, "invalid %t operand to dereference, incomplete", ex.ty); + fatal(P, ex.span, "invalid %t operand to dereference, incomplete"); return (struct expr) { Eprefix, tok.span, ex.ty->child, .unop = { '*', exprdup(ex) @@ -1541,7 +1544,7 @@ pexprefix(struct parser *P) { } else if (lexmatch(P, &tok, '&')) { struct expr ex = pexprefix(P); struct type ty2 = { TYptr, g_targ.ptrsize, .child = ex.ty}; - if (!islvalue(&ex) && !(ex.t == Ename && ex.ref->t == Dfn)) + if (!islvalue(&ex) && !(ex.t == Ename && ex.ref->t == Dfn) && !(ex.t == Ezeroini || ex.t == Eini)) fatal(P, ex.span, "invalid operand to `&': not an lvalue"); return (struct expr) { Eprefix, tok.span, interntype(ty2), .unop = { @@ -1875,7 +1878,7 @@ parsevardecl(decl_yielder_t yield, void *yarg, struct parser *P, bool let, bool fatal(P, tok.span, "incompatible initializer type (%t, expected %t)", ini->ty, ty); - if (ty->t == TYarr && ty->length < 0) { + if (ini && ty->t == TYarr && ty->length < 0) { struct type ty2 = *ty; if (ini->t == Ezeroini) { ty2.length = 0; @@ -1888,7 +1891,7 @@ parsevardecl(decl_yielder_t yield, void *yarg, struct parser *P, bool let, bool ty2.size = ty->child->size * ty2.length; ty2.align = ty->child->align; uninterntype(ty); - ty = interntype(ty2); + ty = ini->ty = interntype(ty2); } if (!completetype(ty) && !(!let && externp)) @@ -2102,8 +2105,8 @@ psteuswitch(struct parser *P, const struct expr *test) { if (lexpeek(P).t != TKident) lexexpect(P, TKident); } + struct env env = {P->curenv}; if (c.fld->ty && lexmatch(P, &tok, TKident)) { - struct env env = {P->curenv}; const struct type *ty = c.fld->ty; c.capt = tok.str; @@ -2227,7 +2230,7 @@ parseexpandmacro(struct parser *P, const struct macro *macro) { vec_t(struct tok) toks = {0}; struct toktree ttoks; - for (;;) { + for (;;) { tok = lex(P); switch (tok.t) { case '[': ++bkbal; break; case ']': --bkbal; break; @@ -2937,8 +2940,8 @@ doimport(struct parser *P, const char *path) { for (int i = 0; i < seen.length; ++i) { if (!strcmp(seen.data[i].s, rpath)) { if (seen.data[i].wip) { - epri("warning: \"%s\": circular import detected: \"%s\" being processed\n", - P->curfile, path); + // epri("warning: \"%s\": circular import detected: \"%s\" being processed\n", + // P->curfile, path); } return seen.data[i].cf; } diff --git a/bootstrap/types.c b/bootstrap/types.c index dce85a6..788f001 100644 --- a/bootstrap/types.c +++ b/bootstrap/types.c @@ -180,6 +180,7 @@ uninterntype(const struct type *key) { } else { types.buckets[idx] = n->next; } + typesvec.data[key->_id] = NULL; free(n); break; } @@ -189,6 +190,7 @@ uninterntype(const struct type *key) { bool completetype(const struct type *ty) { + if (ty->konst) return completetype(unconstify(ty)); if (ty->t == TYvoid) return 0; if (ty->t == TYfn) @@ -241,10 +243,10 @@ putprimtypes(struct env *env) { {"iptrint", &ty_iptrint, {TYint, t.ptrsize, IS}}, {"uptrint", &ty_uptrint, {TYint, t.ptrsize, IU}}, {"c_char", &ty_c_char, {TYint, 1, .int_signed = t.charsigned}}, - {"c_long", &ty_c_long, {TYint, t.longsize, IS}}, - {"c_ulong", &ty_c_ulong, {TYint, t.longsize, IU}}, - {"c_llong", &ty_c_llong, {TYint, t.llongsize, IS}}, - {"c_ullong", &ty_c_ullong, {TYint, t.llongsize, IU}}, + {"c_long", &ty_c_long, {TYint, t.longsize, t.longalign, IS}}, + {"c_ulong", &ty_c_ulong, {TYint, t.longsize, t.longalign, IU}}, + {"c_llong", &ty_c_llong, {TYint, t.llongsize, t.llongalign, IS}}, + {"c_ullong", &ty_c_ullong, {TYint, t.llongsize, t.llongalign, IU}}, {"va_list", &ty_valist, {TYvalist, t.valistsize, t.valistalign}}, #undef IS #undef IU @@ -265,8 +267,10 @@ putprimtypes(struct env *env) { void visittypes(void (*visitor)(const struct type *, void *), void *arg) { int i; const struct type *ty; - vec_foreach(&typesvec, ty, i) - visitor(ty, arg); + vec_foreach(&typesvec, ty, i) { + if (ty) + visitor(ty, arg); + } } const struct type * diff --git a/bootstrap/util.c b/bootstrap/util.c index da838b5..b64485b 100644 --- a/bootstrap/util.c +++ b/bootstrap/util.c @@ -112,7 +112,8 @@ eprifileline(struct span span) { close(fd); return; } - filemmaps[span.fileid] = src = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); + // XXX this maybe causes SIGBUS later if we're at last line + no ending newline + st_size multiple of 4096 + filemmaps[span.fileid] = src = mmap(NULL, st.st_size + 1, PROT_READ, MAP_PRIVATE, fd, 0); assert(src && src != (void *)-1 && "mmap"); close(fd); } |