From c0451a484a303f4fb9c9579e1e4ed0b02f8eac37 Mon Sep 17 00:00:00 2001 From: pjh456 <147148383@qq.com> Date: Fri, 11 Sep 2026 09:46:29 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20do-while=20=E7=9A=84=20continue=20?= =?UTF-8?q?=E7=9B=AE=E6=A0=87=E9=94=99=E6=8C=87=E4=BD=93=E9=A6=96=E2=80=94?= =?UTF-8?q?=E2=80=94=E6=94=B9=E6=8C=87=E6=9D=A1=E4=BB=B6=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?=E4=BD=BF=E6=9D=A1=E4=BB=B6=E5=8F=AF=E8=A2=AB=E6=B1=82=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/oxide_emit/src/stmt/iteration/do_while.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/crates/oxide_emit/src/stmt/iteration/do_while.rs b/crates/oxide_emit/src/stmt/iteration/do_while.rs index 0fb5d241..cf96dcb1 100644 --- a/crates/oxide_emit/src/stmt/iteration/do_while.rs +++ b/crates/oxide_emit/src/stmt/iteration/do_while.rs @@ -12,11 +12,15 @@ impl Emitter { return Ok(None); }; let start_label = ctx.next_label_id(); + let cont_label = ctx.next_label_id(); let end_label = ctx.next_label_id(); ctx.labels.set_label_pos(start_label, ctx.insts.len()); - ctx.push_loop(end_label, start_label, crate::emit_ctx::LoopKind::Plain); - let n_labeled = ctx.take_pending_loop_labels(end_label, start_label); + // continue 目标是条件位置:体先执行,continue 须绕过体直接去求值条件, + // 不能指回体首(否则条件永不被求值)。 + ctx.push_loop(end_label, cont_label, crate::emit_ctx::LoopKind::Plain); + let n_labeled = ctx.take_pending_loop_labels(end_label, cont_label); self.emit_statement(&dw.body, ctx)?; + ctx.labels.set_label_pos(cont_label, ctx.insts.len()); let test_reg = self.emit_expression(&dw.test, ctx)?; ctx.inst(Inst::jmp_if_true(test_reg, start_label)); ctx.labels.set_label_pos(end_label, ctx.insts.len());