From 215c18ebc86b116827d3af19ca0779316e1a0e15 Mon Sep 17 00:00:00 2001 From: lemon Date: Mon, 8 Aug 2022 08:48:21 +0200 Subject: break & continue --- bootstrap/cgen.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'bootstrap/cgen.c') diff --git a/bootstrap/cgen.c b/bootstrap/cgen.c index db477fd..433a5a0 100644 --- a/bootstrap/cgen.c +++ b/bootstrap/cgen.c @@ -324,7 +324,7 @@ genstmt(struct stmt *stmt) { if (decl.externp) genstatic(1, decl.name, &decl.var); break; - case Ddef: case Dtype: case Dmacro: case Dtepl: + case Ddef: case Dtype: case Dmacro: case Dtepl: case Dlabel: break; } break; @@ -337,8 +337,9 @@ genstmt(struct stmt *stmt) { } break; case Swhile: - pri("while (%e) ", &stmt->loop.test); + pri("while (%e) {", &stmt->loop.test); genblock(stmt->loop.body); + pri("_cont%d:;} _brk%d:;\n", stmt->loop.id, stmt->loop.id); break; case Sfor: pri("{\n"); @@ -348,9 +349,10 @@ genstmt(struct stmt *stmt) { pri("%e;", &stmt->loop.test); if (stmt->loop.next) pri(" %e", stmt->loop.next); - pri(")"); + pri(") {"); genblock(stmt->loop.body); - pri("}\n"); + pri("_cont%d:; }", stmt->loop.id); + pri("} _brk%d:;\n", stmt->loop.id); break; case Siswitch: pri("switch (%e) {", &stmt->iswitch.test); @@ -409,6 +411,12 @@ genstmt(struct stmt *stmt) { pri(" %e", stmt->retex); pri(";\n"); break; + case Sbreak: + pri("goto _brk%d;\n", stmt->brkcon.id); + break; + case Scontinue: + pri("goto _cont%d;\n", stmt->brkcon.id); + break; } } @@ -563,6 +571,8 @@ liftnested(struct stmt *stmt) { if (stmt->euswitch.f) liftnested(blocktostmt(*stmt->euswitch.f)); break; + case Sbreak: case Scontinue: + break; } } @@ -618,7 +628,7 @@ gendecl(struct decl *decl, bool toplevel) { case Dlet: assert(!toplevel); break; - case Ddef: case Dtype: case Dtepl: case Dmacro: + case Ddef: case Dtype: case Dtepl: case Dmacro: case Dlabel: break; } } -- cgit v1.2.3