aboutsummaryrefslogtreecommitdiff
path: root/bootstrap/cgen.c
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2022-08-04 15:46:32 +0200
committerlemon <lsof@mailbox.org>2022-08-04 15:46:32 +0200
commitd104761e3c213504f5a6dfb63059fc905fe6799f (patch)
tree5b51d3147ce0506d331e89874033af0d4eb260e3 /bootstrap/cgen.c
parent8a5bde697364ca301c14471196d137c3a53c25fa (diff)
enum
Diffstat (limited to 'bootstrap/cgen.c')
-rw-r--r--bootstrap/cgen.c30
1 files changed, 20 insertions, 10 deletions
diff --git a/bootstrap/cgen.c b/bootstrap/cgen.c
index 4bc6280..aac0893 100644
--- a/bootstrap/cgen.c
+++ b/bootstrap/cgen.c
@@ -27,13 +27,13 @@ gentype(const struct type *ty) {
case TYarr:
assert(ty->length >= 0);
case TYslice:
- assert(ty->_cname);
- pri("%s", ty->_cname);
- return;
case TYfn:
assert(ty->_cname);
pri("%s", ty->_cname);
return;
+ case TYenum:
+ gentype(ty->enu.intty);
+ break;
}
if (ty->konst)
pri(" const");
@@ -97,7 +97,8 @@ pri(const char *fmt, ...) {
fprintf(outfp, "%.20f", va_arg(ap, double));
break;
case 's':
- fprintf(outfp, "%s", va_arg(ap, const char *));
+ S = va_arg(ap, const char *);
+ fprintf(outfp, "%s", S ? S : "(null)");
break;
case 'w':
ws = va_arg(ap, int);
@@ -130,6 +131,7 @@ genexpr(struct expr *ex) {
const struct type *ty = unconstify(ex->ty);
switch (ex->t) {
case Eintlit:
+ intlit:
if (ty == ty_int)
pri("%I", ex->i);
else if (ty == ty_u64)
@@ -184,8 +186,14 @@ genexpr(struct expr *ex) {
genblock(ex->block);
pri(")");
break;
- default:
- assert(0);
+ case Eas:
+ pri("((%t)%e)", ex->ty, ex->child);
+ break;
+ case Eenumval:
+ pri("/*%s:%s*/", ex->ty->enu.name, ex->enu.vname);
+ ty = ex->ty->enu.intty;
+ goto intlit;
+ break;
}
}
@@ -292,6 +300,7 @@ liftnestedex(struct expr *ex) {
switch (ex->t) {
case Eintlit: case Eflolit: case Estrlit:
case Eboolit: case Enullit: case Ename:
+ case Eenumval:
break;
case Eprefix:
liftnestedex(ex->unop.child);
@@ -320,8 +329,9 @@ liftnestedex(struct expr *ex) {
case Eblock:
liftnested(blocktostmt(ex->block));
break;
- default:
- assert(0);
+ case Eas:
+ liftnestedex(ex->child);
+ break;
}
}
@@ -484,9 +494,9 @@ defctype(const struct type *ty, void *_) {
if (ty->fn.variadic)
pri("...");
pri(");\n");
-
-
break;
+ case TYenum:
+ *cname = xasprintf("__ty%d", id++);
}
}