diff options
Diffstat (limited to 'bootstrap/cgen.c')
| -rw-r--r-- | bootstrap/cgen.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/bootstrap/cgen.c b/bootstrap/cgen.c index 8a01e09..7315876 100644 --- a/bootstrap/cgen.c +++ b/bootstrap/cgen.c @@ -209,7 +209,8 @@ genexpr(struct expr *ex) { pri(")"); break; case Eindex: - pri("%e[%e]", ex->index.lhs, ex->index.rhs); + pri("%e%s[%e]", ex->index.lhs, + ex->index.lhs->ty->t == TYslice ? ".ptr" : "", ex->index.rhs); break; case Eblock: pri("(\n"); @@ -247,6 +248,17 @@ genexpr(struct expr *ex) { } pri(")"); break; + case Eslice: + ;static int id; + // TODO range assertions + pri("({ %t __start%d = %e; ", ex->slice.start->ty, id, ex->slice.start); + pri("(%t) { %e%s + __start%d, %e - __start%d }; })", + ex->ty, ex->slice.lhs, ex->slice.lhs->ty->t == TYslice ? ".ptr" : "", id, ex->slice.end, id); + ++id; + break; + case Elen: + pri("%e.len", ex->child); + break; } } @@ -360,7 +372,7 @@ static void liftdecl(struct decl *decl); static void liftnestedex(struct expr *ex) { - switch (ex->t) { + if (ex) switch (ex->t) { case Eintlit: case Eflolit: case Estrlit: case Eboolit: case Enullit: case Ename: case Ezeroini: @@ -393,7 +405,7 @@ liftnestedex(struct expr *ex) { case Eblock: liftnested(blocktostmt(ex->block)); break; - case Eas: + case Eas: case Elen: liftnestedex(ex->child); break; case Eini: @@ -403,11 +415,16 @@ liftnestedex(struct expr *ex) { case Eget: liftnestedex(ex->get.lhs); break; - case Emcall: + 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; + case Eslice: + liftnestedex(ex->slice.lhs); + liftnestedex(ex->slice.start); + liftnestedex(ex->slice.end); + break; } } |