diff options
| author | 2022-08-08 05:33:56 +0200 | |
|---|---|---|
| committer | 2022-08-08 05:33:56 +0200 | |
| commit | cbed5a14aa8c1624f6f350d92c1de0c9ef55e40c (patch) | |
| tree | fc0c7a6877baa50bdac78e898866a0f241ed1cb6 /bootstrap/cgen.c | |
| parent | 96ef1857bac446f4e065e7c10530213e361d726a (diff) | |
basic pattern matching
Diffstat (limited to 'bootstrap/cgen.c')
| -rw-r--r-- | bootstrap/cgen.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/bootstrap/cgen.c b/bootstrap/cgen.c index 8bea8bc..769d2e9 100644 --- a/bootstrap/cgen.c +++ b/bootstrap/cgen.c @@ -367,6 +367,25 @@ 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 */ %I: ", 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->iswitch.f) { + pri("default: "); + genblock(*stmt->iswitch.f); + } + pri("}\n"); pri("}\n"); + break; case Sreturn: pri("return"); if (stmt->retex) @@ -519,6 +538,14 @@ liftnested(struct stmt *stmt) { if (stmt->retex) liftnestedex(stmt->retex); break; + case Seuswitch: + liftnestedex(&stmt->euswitch.test); + for (int i = 0; i < stmt->euswitch.cs.n; ++i) { + liftnested(blocktostmt(stmt->euswitch.cs.d[i].t)); + } + if (stmt->euswitch.f) + liftnested(blocktostmt(*stmt->euswitch.f)); + break; } } |