diff options
| author | 2022-08-08 06:20:24 +0200 | |
|---|---|---|
| committer | 2022-08-08 06:20:24 +0200 | |
| commit | c6ea883724ed389143dbed1806916aa09157b655 (patch) | |
| tree | 313e42900944d8ec5f0c482db4910ab69959c3e0 /bootstrap/cgen.c | |
| parent | 29a059d87af940a232443b59726da900cca83f19 (diff) | |
switch capture by ref
Diffstat (limited to 'bootstrap/cgen.c')
| -rw-r--r-- | bootstrap/cgen.c | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/bootstrap/cgen.c b/bootstrap/cgen.c index 31f2235..8e2fef9 100644 --- a/bootstrap/cgen.c +++ b/bootstrap/cgen.c @@ -368,17 +368,34 @@ genstmt(struct stmt *stmt) { pri("}\n"); break; case Seuswitch: - pri("{ %t __stmp = %e;\n", stmt->euswitch.test.ty, &stmt->euswitch.test); - pri("switch (__stmp.t) {", &stmt->euswitch.test); - for (int i = 0; i < stmt->euswitch.cs.n; ++i) { - struct euswitchcase c = stmt->euswitch.cs.d[i]; - pri("case /* %s */ %d: ", c.fld->name, c.vval); - if (c.capt) - pri("{ %t %s_%d = __stmp.u.%s;\n", c.fld->ty, c.capt, c.captid, c.fld->name); - genblock(c.t); - if (c.capt) - pri("}\n"); - pri("break;\n"); + if (!stmt->euswitch.byptr) { + pri("{ %t __stmp = %e;\n", stmt->euswitch.test.ty, &stmt->euswitch.test); + pri("switch (__stmp.t) {", &stmt->euswitch.test); + for (int i = 0; i < stmt->euswitch.cs.n; ++i) { + struct euswitchcase c = stmt->euswitch.cs.d[i]; + pri("case /* %s */ %d: ", c.fld->name, c.vval); + if (c.capt) + pri("{ %t %s_%d = __stmp.u.%s;\n", c.fld->ty, c.capt, c.captid, c.fld->name); + genblock(c.t); + if (c.capt) + pri("}\n"); + pri("break;\n"); + } + } else { + pri("{ %t *__stmp = &%e;\n", stmt->euswitch.test.ty, &stmt->euswitch.test); + pri("switch (__stmp->t) {", &stmt->euswitch.test); + for (int i = 0; i < stmt->euswitch.cs.n; ++i) { + struct euswitchcase c = stmt->euswitch.cs.d[i]; + pri("case /* %s */ %d: ", c.fld->name, c.vval); + if (c.capt && c.captptr) + pri("{ %t %s_%d = &__stmp->u.%s;\n", c.captty, c.capt, c.captid, c.fld->name); + if (c.capt && !c.captptr) + pri("{ %t %s_%d = __stmp->u.%s;\n", c.captty, c.capt, c.captid, c.fld->name); + genblock(c.t); + if (c.capt) + pri("}\n"); + pri("break;\n"); + } } if (stmt->iswitch.f) { pri("default: "); |