From dddbdcbeb41777c1e98e37281dddd6f3c89a1280 Mon Sep 17 00:00:00 2001 From: lemon Date: Mon, 8 Aug 2022 19:31:35 +0200 Subject: ok --- bootstrap/all.h | 1 + bootstrap/cff1 | Bin 21520 -> 22816 bytes bootstrap/cgen.c | 7 +++++-- bootstrap/dump.c | 2 ++ bootstrap/env.c | 4 ++-- bootstrap/obj1/main.cff.o | Bin 4288 -> 5360 bytes bootstrap/obj1/parse.cff.o | Bin 0 -> 3864 bytes bootstrap/parse.c | 8 ++++++++ 8 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 bootstrap/obj1/parse.cff.o (limited to 'bootstrap') diff --git a/bootstrap/all.h b/bootstrap/all.h index 3cadd4c..2996f62 100644 --- a/bootstrap/all.h +++ b/bootstrap/all.h @@ -76,6 +76,7 @@ enum toktype { TKtype, TKexpr, TKlabel, + TKstrify, TKeof, }; diff --git a/bootstrap/cff1 b/bootstrap/cff1 index 7b0e748..6a4b6ff 100755 Binary files a/bootstrap/cff1 and b/bootstrap/cff1 differ diff --git a/bootstrap/cgen.c b/bootstrap/cgen.c index 3151edf..62a808d 100644 --- a/bootstrap/cgen.c +++ b/bootstrap/cgen.c @@ -240,7 +240,7 @@ genexpr(struct expr *ex) { goto intlit; break; case Ezeroini: - if (ty->t == TYarr || ty->t == TYstruct) + if (ty->t == TYarr || ty->t == TYstruct || ty->t == TYunion || ty->t == TYeunion || ty->t == TYslice) pri("((%t){0})", ty); else pri("((%t)0)", ty); @@ -699,12 +699,15 @@ defctype(const struct type *ty, void *_) { *cname = xasprintf("__ty%s%d", ty->agg.name ? ty->agg.name : "", id++); pri("typedef %s %s %s;\n", kind, *cname, *cname); if (!ty->agg.fwd) { + for (int i = 0; i < ty->agg.flds.n; ++i) { + struct aggfield fld = ty->agg.flds.d[i]; + defctype(fld.ty, NULL); + } pri("%s %s {\n", kind, *cname); if (!ty->agg.flds.n) pri("char _;\n"); for (int i = 0; i < ty->agg.flds.n; ++i) { struct aggfield fld = ty->agg.flds.d[i]; - defctype(ty->agg.flds.d[i].ty, NULL); pri("%t %s;\n", fld.ty, fld.name); } pri("};\n"); diff --git a/bootstrap/dump.c b/bootstrap/dump.c index 157b12f..3bd915f 100644 --- a/bootstrap/dump.c +++ b/bootstrap/dump.c @@ -159,6 +159,8 @@ tok2str(struct tok tok) { return ""; } else if (tok.t == TKexpr) { return ""; + } else if (tok.t == TKstrify) { + return "#strify"; } else { snprintf(buf, sizeof buf - 1, "`%c'", tok.t); } diff --git a/bootstrap/env.c b/bootstrap/env.c index b3652fa..601b446 100644 --- a/bootstrap/env.c +++ b/bootstrap/env.c @@ -48,8 +48,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) { - d0->fn.body = decl->fn.body; - return d0; + goto ok; } if (d0->t == Dfn && d0->externp == decl->externp && d0->fn.selfty == decl->fn.selfty && !d0->fn.body) return d0; @@ -61,6 +60,7 @@ envput(struct env *env, const struct decl *decl) { return NULL; } } +ok: decls = xcalloc(1, sizeof *decls); decls->next = env->decls; diff --git a/bootstrap/obj1/main.cff.o b/bootstrap/obj1/main.cff.o index 7264f1c..2210165 100644 Binary files a/bootstrap/obj1/main.cff.o and b/bootstrap/obj1/main.cff.o differ diff --git a/bootstrap/obj1/parse.cff.o b/bootstrap/obj1/parse.cff.o new file mode 100644 index 0000000..87687b9 Binary files /dev/null and b/bootstrap/obj1/parse.cff.o differ diff --git a/bootstrap/parse.c b/bootstrap/parse.c index 67ec66d..180ddea 100644 --- a/bootstrap/parse.c +++ b/bootstrap/parse.c @@ -381,6 +381,14 @@ lex(struct parser *P) { } else if (!strncmp(s, "#'", 2)) { tok.t = TKlabel; tok.str = xstrdup(s); + } else if (!strcmp(s, "#FILE")) { + tok.t = TKstrlit; + tok.str = P->curfile; + tok.strlen = strlen(P->curfile); + } else if (!strcmp(s, "#LINE")) { + tok.t = TKintlit; + tok.ty = ty_uint; + tok.ilit.i = P->tokspan.line; } else { fatal(P, P->tokspan, "invalid #keyword"); } -- cgit v1.2.3