Commit 18a2f6a2

18a2f6a25bbcMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 1 file · ~1 modified

Description

redo: re-run the current loop iteration via a labeled goto

RedoNode previously emitted continue, which advanced the iterator instead of re-running the iteration. Now each loop whose body contains a redo targeting it emits a _redo_N: label at the body top and redo jumps there with a goto, re-running the body without re-testing the guard or advancing -- matching Ruby.

  • A redo-label stack (g_redo_stack) tracks the innermost enclosing loop so nested loops resolve to the right label.
  • subtree_has_own_redo decides whether a loop owns a redo (stopping at nested loops/blocks/defs, which own their own), so labels are only emitted where needed.
  • emit_loop_body wraps every loop body: while/until, for-in (range/array), times, step, hash/array each, upto/downto, each_with_index/cons/slice, each_with_object, zip, cycle, loop, and the block-iteration forms.

Fixes test/redo.rb (all 17 loop forms plus the nested case).

Co-Authored-By: Claude Opus 4.8 (1M context) [email protected]

Details

Commit
18a2f6a25bbc
Parent
8051534cb86d

src/codegen.cmodifiedView file

@@ -91,6 +91,12 @@
9191 /* When inside a rescue handler that can `retry`, holds the goto label for the
9292 retry target (just before `sp_exc_top++`). NULL otherwise. */
9393 static const char *g_retry_label = NULL;
94+/* Redo label stack: each enclosing loop that contains a `redo` pushes a fresh
95+ C label id; a RedoNode emits `goto _redo_<top>` to re-run the current
96+ iteration without re-testing the guard or advancing the iterator. */
97+static int g_redo_stack[64];
98+static int g_redo_depth = 0;
99+
94100 /* When set inside a loop-as-expression, BreakNode assigns its value here. */
95101 static const char *g_loop_break_var = NULL;
96102 /* When set, tail positions assign to this var instead of `return`ing
@@ -597,6 +603,8 @@
597603 static int emit_array_mutate_stmt(Compiler *c, int id, Buf *b, int indent);
598604 static int emit_output_call(Compiler *c, int id, Buf *b, int indent);
599605 static int emit_iteration_stmt(Compiler *c, int id, Buf *b, int indent);
606+static void emit_loop_body(Compiler *c, int body, Buf *b, int indent);
607+static int subtree_has_own_redo(const NodeTable *nt, int id);
600608 static int emit_inline_call(Compiler *c, int id, Buf *b, int indent);
601609 static int emit_inline_expr(Compiler *c, int id, Buf *b);
602610 static void emit_cond(Compiler *c, int id, Buf *b);
@@ -3522,7 +3530,7 @@
35223530 }
35233531 /* Body */
35243532 int save_indent = g_indent; g_indent++;
3525- for (int j = 0; j < bn; j++) emit_stmt(c, bb[j], g_pre, g_indent);
3533+ emit_loop_body(c, body, g_pre, g_indent);
35263534 g_indent = save_indent;
35273535 emit_indent(g_pre, g_indent); buf_puts(g_pre, "}\n");
35283536 buf_printf(b, "_t%d", tacc);
@@ -3625,7 +3633,7 @@
36253633 }
36263634 }
36273635 int save_indent = g_indent; g_indent++;
3628- for (int j = 0; j < bn; j++) emit_stmt(c, bb[j], g_pre, g_indent);
3636+ emit_loop_body(c, body, g_pre, g_indent);
36293637 g_indent = save_indent;
36303638 emit_indent(g_pre, g_indent); buf_puts(g_pre, "}\n");
36313639 /* Restore types */
@@ -3672,7 +3680,7 @@
36723680
36733681 /* Body */
36743682 int save_indent = g_indent; g_indent++;
3675- for (int j = 0; j < bn; j++) emit_stmt(c, bb[j], g_pre, g_indent);
3683+ emit_loop_body(c, body, g_pre, g_indent);
36763684 g_indent = save_indent;
36773685
36783686 emit_indent(g_pre, g_indent); buf_puts(g_pre, "}\n");
@@ -11942,6 +11950,46 @@
1194211950 }
1194311951 }
1194411952
11953+/* Does the subtree contain a `redo` that belongs to THIS loop, i.e. one not
11954+ nested inside a deeper loop/block/def (which would own it instead)? */
11955+static int subtree_has_own_redo(const NodeTable *nt, int id) {
11956+ if (id < 0) return 0;
11957+ const char *ty = nt_type(nt, id);
11958+ if (!ty) return 0;
11959+ if (!strcmp(ty, "RedoNode")) return 1;
11960+ /* nested scope/loop boundaries: a redo inside binds to that inner loop */
11961+ if (!strcmp(ty, "DefNode") || !strcmp(ty, "ClassNode") || !strcmp(ty, "ModuleNode") ||
11962+ !strcmp(ty, "WhileNode") || !strcmp(ty, "UntilNode") || !strcmp(ty, "ForNode") ||
11963+ !strcmp(ty, "LambdaNode"))
11964+ return 0;
11965+ if (!strcmp(ty, "CallNode") && nt_ref(nt, id, "block") >= 0) return 0; /* nested iteration */
11966+ int nr = nt_num_refs(nt, id);
11967+ for (int i = 0; i < nr; i++) if (subtree_has_own_redo(nt, nt_ref_at(nt, id, i))) return 1;
11968+ int na = nt_num_arrs(nt, id);
11969+ for (int i = 0; i < na; i++) {
11970+ int n = 0; const int *ids = nt_arr_at(nt, id, i, &n);
11971+ for (int k = 0; k < n; k++) if (subtree_has_own_redo(nt, ids[k])) return 1;
11972+ }
11973+ return 0;
11974+}
11975+
11976+/* Emit a loop body, prefixing a `_redo_N:` label (and pushing it on the redo
11977+ stack) when the body contains a `redo` that targets this loop. The label
11978+ sits at the body top so `redo` re-runs the body without advancing. */
11979+static void emit_loop_body(Compiler *c, int body, Buf *b, int indent) {
11980+ int has_redo = subtree_has_own_redo(c->nt, body);
11981+ int lbl = 0;
11982+ if (has_redo) {
11983+ lbl = ++g_tmp;
11984+ if (g_redo_depth < (int)(sizeof g_redo_stack / sizeof g_redo_stack[0]))
11985+ g_redo_stack[g_redo_depth++] = lbl;
11986+ else has_redo = 0;
11987+ }
11988+ if (has_redo) { emit_indent(b, indent); buf_printf(b, "_redo_%d: ;\n", lbl); }
11989+ emit_stmts(c, body, b, indent);
11990+ if (has_redo) g_redo_depth--;
11991+}
11992+
1194511993 static int emit_iteration_stmt(Compiler *c, int id, Buf *b, int indent) {
1194611994 const NodeTable *nt = c->nt;
1194711995 int block = nt_ref(nt, id, "block");
@@ -11954,7 +12002,7 @@
1195412002 if (recv < 0 && !strcmp(name, "loop")) {
1195512003 int lbody = nt_ref(nt, block, "body");
1195612004 emit_indent(b, indent); buf_puts(b, "for (;;) {\n");
11957- emit_stmts(c, lbody, b, indent + 1);
12005+ emit_loop_body(c, lbody, b, indent + 1);
1195812006 emit_indent(b, indent); buf_puts(b, "}\n");
1195912007 return 1;
1196012008 }
@@ -11974,7 +12022,7 @@
1197412022 buf_printf(b, "for (mrb_int _t%d = 0; _t%d < ", t, t);
1197512023 buf_puts(b, rb.p); buf_printf(b, "; _t%d++) {\n", t);
1197612024 if (p0) { char ts[32]; snprintf(ts, sizeof ts, "_t%d", t); emit_iter_param_assign(c, block, p0_orig, p0, TY_INT, ts, b, indent + 1); }
11977- emit_stmts(c, body, b, indent + 1);
12025+ emit_loop_body(c, body, b, indent + 1);
1197812026 emit_indent(b, indent); buf_puts(b, "}\n");
1197912027 free(rb.p);
1198012028 return 1;
@@ -12001,7 +12049,7 @@
1200112049 buf_printf(b, "; _t%d >= 0 ? _t%d <= _t%d : _t%d >= _t%d; _t%d += _t%d) {\n",
1200212050 ts, t, tl, t, tl, t, ts);
1200312051 if (p0) { char ts2[32]; snprintf(ts2, sizeof ts2, "_t%d", t); emit_iter_param_assign(c, block, p0_orig, p0, TY_INT, ts2, b, indent + 1); }
12004- emit_stmts(c, body, b, indent + 1);
12052+ emit_loop_body(c, body, b, indent + 1);
1200512053 emit_indent(b, indent); buf_puts(b, "}\n");
1200612054 return 1;
1200712055 }
@@ -12022,7 +12070,7 @@
1202212070 emit_indent(b, indent);
1202312071 buf_printf(b, "for (mrb_int _t%d = 0; _t%d <= _t%d; _t%d++) {\n", ti, ti, tn, ti);
1202412072 if (p0) { char fp_expr[64]; snprintf(fp_expr, sizeof fp_expr, "_t%d + _t%d * _t%d", tb, ti, ts); emit_iter_param_assign(c, block, p0_orig, p0, TY_FLOAT, fp_expr, b, indent + 1); }
12025- emit_stmts(c, body, b, indent + 1);
12073+ emit_loop_body(c, body, b, indent + 1);
1202612074 emit_indent(b, indent); buf_puts(b, "}\n");
1202712075 return 1;
1202812076 }
@@ -12054,7 +12102,7 @@
1205412102 buf_puts(b, rb.p); buf_puts(b, ", "); buf_puts(b, rb.p); buf_printf(b, "->order[_t%d]);\n", t);
1205512103 }
1205612104 }
12057- emit_stmts(c, body, b, indent + 1);
12105+ emit_loop_body(c, body, b, indent + 1);
1205812106 emit_indent(b, indent); buf_puts(b, "}\n");
1205912107 free(rb.p);
1206012108 return 1;
@@ -12096,7 +12144,7 @@
1209612144 else buf_puts(b, src);
1209712145 buf_puts(b, ";\n");
1209812146 }
12099- emit_stmts(c, body, b, indent + 1);
12147+ emit_loop_body(c, body, b, indent + 1);
1210012148 emit_indent(b, indent); buf_puts(b, "}\n");
1210112149 free(rb.p);
1210212150 return 1;
@@ -12214,7 +12262,7 @@
1221412262 if (p1_box_poly) buf_printf(b, "lv_%s = sp_box_int(_t%d);\n", p1, t);
1221512263 else buf_printf(b, "lv_%s = _t%d;\n", p1, t);
1221612264 }
12217- emit_stmts(c, body, b, indent + 1);
12265+ emit_loop_body(c, body, b, indent + 1);
1221812266 emit_indent(b, indent); buf_puts(b, "}\n");
1221912267 /* Restore outer variables */
1222012268 if (p0 && ts_p0 > 0) { emit_indent(b, indent); buf_printf(b, "lv_%s = _t%d;\n", p0, ts_p0); }
@@ -12269,7 +12317,7 @@
1226912317 else buf_puts(b, src2);
1227012318 buf_puts(b, ";\n");
1227112319 }
12272- emit_stmts(c, body, b, indent + 1);
12320+ emit_loop_body(c, body, b, indent + 1);
1227312321 emit_indent(b, indent); buf_puts(b, "}\n");
1227412322 if (p0 && zs0 > 0) { emit_indent(b, indent); buf_printf(b, "lv_%s = _t%d;\n", p0, zs0); }
1227512323 if (p1n && zs1 > 0) { emit_indent(b, indent); buf_printf(b, "lv_%s = _t%d;\n", p1n, zs1); }
@@ -12303,7 +12351,7 @@
1230312351 emit_indent(b, indent + 1);
1230412352 buf_printf(b, "lv_%s = sp_poly_each_elem(_t%d, _t%d);\n", p0, ta, ti);
1230512353 }
12306- emit_stmts(c, body, b, indent + 1);
12354+ emit_loop_body(c, body, b, indent + 1);
1230712355 emit_indent(b, indent); buf_puts(b, "}\n");
1230812356 return 1;
1230912357 }
@@ -12355,7 +12403,7 @@
1235512403 buf_printf(b, "lv_%s = sp_PolyArray_get(_t%d, _t%d);\n", p0, ta, t);
1235612404 }
1235712405 }
12358- emit_stmts(c, body, b, indent + 1);
12406+ emit_loop_body(c, body, b, indent + 1);
1235912407 emit_indent(b, indent); buf_puts(b, "}\n");
1236012408 if (outer_pa) { emit_indent(b, indent); buf_printf(b, "lv_%s = _t%d;\n", p0, ts_pa); }
1236112409 return 1;
@@ -12433,7 +12481,7 @@
1243312481 }
1243412482 }
1243512483 each_body:
12436- emit_stmts(c, body, b, indent + 1);
12484+ emit_loop_body(c, body, b, indent + 1);
1243712485 emit_indent(b, indent); buf_puts(b, "}\n");
1243812486 if (outer) { emit_indent(b, indent); buf_printf(b, "lv_%s = _t%d;\n", p0, ts); }
1243912487 free(rb.p);
@@ -12461,7 +12509,7 @@
1246112509 else
1246212510 buf_printf(b, "lv_%s = (sp_IntArray *)_t%d->data[_t%d];\n", p0, tc, ti);
1246312511 }
12464- emit_stmts(c, body, b, indent + 2);
12512+ emit_loop_body(c, body, b, indent + 2);
1246512513 emit_indent(b, indent + 1); buf_puts(b, "}\n");
1246612514 emit_indent(b, indent); buf_puts(b, "}\n");
1246712515 return 1;
@@ -12497,14 +12545,14 @@
1249712545 emit_indent(b, indent + 1); buf_puts(b, "{\n");
1249812546 emit_indent(b, indent + 2); emit_ctype(c, rt, b);
1249912547 buf_printf(b, " lv_%s = sp_%sArray_slice(_t%d, _t%d, _t%d);\n", rpn, k, ta, ti, tnn);
12500- emit_stmts(c, body, b, indent + 2);
12548+ emit_loop_body(c, body, b, indent + 2);
1250112549 emit_indent(b, indent + 1); buf_puts(b, "}\n");
1250212550 clv_ec->type = csaved_ec;
1250312551 }
1250412552 else {
1250512553 emit_indent(b, indent + 1);
1250612554 buf_printf(b, "lv_%s = sp_%sArray_slice(_t%d, _t%d, _t%d);\n", rpn, k, ta, ti, tnn);
12507- emit_stmts(c, body, b, indent + 1);
12555+ emit_loop_body(c, body, b, indent + 1);
1250812556 }
1250912557 }
1251012558 else {
@@ -12513,7 +12561,7 @@
1251312561 emit_indent(b, indent + 1);
1251412562 buf_printf(b, "lv_%s = sp_%sArray_get(_t%d, _t%d + %d);\n", rename_local(pn), k, ta, ti, pj);
1251512563 }
12516- emit_stmts(c, body, b, indent + 1);
12564+ emit_loop_body(c, body, b, indent + 1);
1251712565 }
1251812566 emit_indent(b, indent); buf_puts(b, "}\n");
1251912567 return 1;
@@ -12529,7 +12577,7 @@
1252912577 emit_indent(b, indent);
1253012578 buf_printf(b, "for (lv_%s = _t%d.first; lv_%s <= _t%d.last - _t%d.excl; lv_%s++) {\n",
1253112579 p0, t, p0, t, t, p0);
12532- emit_stmts(c, body, b, indent + 1);
12580+ emit_loop_body(c, body, b, indent + 1);
1253312581 emit_indent(b, indent); buf_puts(b, "}\n");
1253412582 return 1;
1253512583 }
@@ -12548,7 +12596,7 @@
1254812596 buf_printf(b, "for (lv_%s = ", p0); buf_puts(b, lo.p);
1254912597 buf_printf(b, "; lv_%s %s ", p0, up ? "<=" : ">="); buf_puts(b, hi.p);
1255012598 buf_printf(b, "; lv_%s%s) {\n", p0, up ? "++" : "--");
12551- emit_stmts(c, body, b, indent + 1);
12599+ emit_loop_body(c, body, b, indent + 1);
1255212600 emit_indent(b, indent); buf_puts(b, "}\n");
1255312601 free(lo.p); free(hi.p);
1255412602 return 1;
@@ -12568,7 +12616,7 @@
1256812616 emit_indent(b, indent + 1); buf_printf(b, "int _t%d = strcmp(_t%d, _t%d);\n", tcmp, tc, te);
1256912617 emit_indent(b, indent + 1); buf_printf(b, "if (_t%d > 0) break;\n", tcmp);
1257012618 emit_indent(b, indent + 1); buf_printf(b, "lv_%s = _t%d;\n", p0, tc);
12571- emit_stmts(c, body, b, indent + 1);
12619+ emit_loop_body(c, body, b, indent + 1);
1257212620 emit_indent(b, indent + 1); buf_printf(b, "if (_t%d == 0) break;\n", tcmp);
1257312621 emit_indent(b, indent + 1); buf_printf(b, "_t%d = sp_str_succ(_t%d);\n", tc, tc);
1257412622 emit_indent(b, indent); buf_puts(b, "}\n");
@@ -12593,13 +12641,13 @@
1259312641 emit_indent(b, indent); buf_puts(b, "{\n");
1259412642 emit_indent(b, indent + 1); emit_ctype(c, et, b);
1259512643 buf_printf(b, " lv_%s = _t%d;\n", p0, tr);
12596- emit_stmts(c, body, b, indent + 1);
12644+ emit_loop_body(c, body, b, indent + 1);
1259712645 emit_indent(b, indent); buf_puts(b, "}\n");
1259812646 tlv0->type = tsaved0;
1259912647 }
1260012648 else {
1260112649 if (p0) { emit_indent(b, indent); buf_printf(b, "lv_%s = _t%d;\n", p0, tr); }
12602- emit_stmts(c, body, b, indent);
12650+ emit_loop_body(c, body, b, indent);
1260312651 }
1260412652 return 1;
1260512653 }
@@ -12634,14 +12682,14 @@
1263412682 emit_indent(b, innerIndent); buf_puts(b, "{\n"); innerIndent++;
1263512683 emit_indent(b, innerIndent); emit_ctype(c, et, b);
1263612684 buf_printf(b, " lv_%s = sp_%sArray_get(_t%d, _t%d);\n", p0, k, ta, tj);
12637- emit_stmts(c, body, b, innerIndent);
12685+ emit_loop_body(c, body, b, innerIndent);
1263812686 innerIndent--;
1263912687 emit_indent(b, innerIndent); buf_puts(b, "}\n");
1264012688 clv0->type = csaved0;
1264112689 }
1264212690 else {
1264312691 if (p0) { emit_indent(b, innerIndent); buf_printf(b, "lv_%s = sp_%sArray_get(_t%d, _t%d);\n", p0, k, ta, tj); }
12644- emit_stmts(c, body, b, innerIndent);
12692+ emit_loop_body(c, body, b, innerIndent);
1264512693 }
1264612694 emit_indent(b, indent + 1); buf_puts(b, "}\n");
1264712695 emit_indent(b, indent); buf_puts(b, "}\n");
@@ -12678,7 +12726,7 @@
1267812726 emit_indent(b, bodyIndent);
1267912727 buf_printf(b, "lv_%s = sp_%sArray_get(_t%d, _t%d + %d);\n", rename_local(pn), k, ta, ti, pj);
1268012728 }
12681- emit_stmts(c, body, b, bodyIndent);
12729+ emit_loop_body(c, body, b, bodyIndent);
1268212730 }
1268312731 else if (use_shadow_es) {
1268412732 int esb_bn = 0; const int *esb_bb = body >= 0 ? nt_arr(nt, body, "body", &esb_bn) : NULL;
@@ -12687,14 +12735,14 @@
1268712735 emit_indent(b, bodyIndent); buf_puts(b, "{\n"); bodyIndent++;
1268812736 emit_indent(b, bodyIndent); emit_ctype(c, rt, b);
1268912737 buf_printf(b, " lv_%s = sp_%sArray_slice(_t%d, _t%d, _t%d);\n", p0, k, ta, ti, ts);
12690- emit_stmts(c, body, b, bodyIndent);
12738+ emit_loop_body(c, body, b, bodyIndent);
1269112739 bodyIndent--;
1269212740 emit_indent(b, bodyIndent); buf_puts(b, "}\n");
1269312741 clv0->type = csaved0;
1269412742 }
1269512743 else {
1269612744 if (p0) { emit_indent(b, bodyIndent); buf_printf(b, "lv_%s = sp_%sArray_slice(_t%d, _t%d, _t%d);\n", p0, k, ta, ti, ts); }
12697- emit_stmts(c, body, b, bodyIndent);
12745+ emit_loop_body(c, body, b, bodyIndent);
1269812746 }
1269912747 emit_indent(b, indent); buf_puts(b, "}\n");
1270012748 return 1;
@@ -12726,14 +12774,14 @@
1272612774 for (int j = 0; j < scb_bn; j++) infer_type(c, scb_bb[j]);
1272712775 emit_indent(b, bodyIndent); buf_puts(b, "{\n"); bodyIndent++;
1272812776 emit_indent(b, bodyIndent); buf_printf(b, "const char *lv_%s = sp_StrArray_get(_t%d, _t%d);\n", p0, tm, ti);
12729- emit_stmts(c, body, b, bodyIndent);
12777+ emit_loop_body(c, body, b, bodyIndent);
1273012778 bodyIndent--;
1273112779 emit_indent(b, bodyIndent); buf_puts(b, "}\n");
1273212780 clv0->type = csaved0;
1273312781 }
1273412782 else {
1273512783 if (p0) { emit_indent(b, bodyIndent); buf_printf(b, "lv_%s = sp_StrArray_get(_t%d, _t%d);\n", p0, tm, ti); }
12736- emit_stmts(c, body, b, bodyIndent);
12784+ emit_loop_body(c, body, b, bodyIndent);
1273712785 }
1273812786 emit_indent(b, indent); buf_puts(b, "}\n");
1273912787 return 1;
@@ -15084,7 +15132,7 @@
1508415132 if (post_test) {
1508515133 emit_indent(b, indent);
1508615134 buf_puts(b, "do {\n");
15087- emit_stmts(c, body, b, indent + 1);
15135+ emit_loop_body(c, body, b, indent + 1);
1508815136 emit_indent(b, indent);
1508915137 buf_puts(b, "} while (");
1509015138 if (is_until) buf_puts(b, "!(");
@@ -15099,7 +15147,7 @@
1509915147 emit_cond(c, pred, b);
1510015148 if (is_until) buf_puts(b, ")");
1510115149 buf_puts(b, ") {\n");
15102- emit_stmts(c, body, b, indent + 1);
15150+ emit_loop_body(c, body, b, indent + 1);
1510315151 emit_indent(b, indent);
1510415152 buf_puts(b, "}\n");
1510515153 }
@@ -15121,7 +15169,7 @@
1512115169 emit_indent(b, indent + 1);
1512215170 buf_printf(b, "for (lv_%s = ", vn); emit_expr(c, nt_ref(nt, coll, "left"), b);
1512315171 buf_printf(b, "; lv_%s %s _t%d; lv_%s++) {\n", vn, excl ? "<" : "<=", thi, vn);
15124- emit_stmts(c, body, b, indent + 2);
15172+ emit_loop_body(c, body, b, indent + 2);
1512515173 emit_indent(b, indent + 1); buf_puts(b, "}\n");
1512615174 emit_indent(b, indent); buf_puts(b, "}\n");
1512715175 return;
@@ -15162,7 +15210,7 @@
1516215210 else
1516315211 buf_printf(b, "lv_%s = sp_poly_arr_get_hash(_t%d, %d);\n", lnm, tv, i);
1516415212 }
15165- emit_stmts(c, body, b, indent + 2);
15213+ emit_loop_body(c, body, b, indent + 2);
1516615214 emit_indent(b, indent + 1); buf_puts(b, "}\n");
1516715215 emit_indent(b, indent); buf_puts(b, "}\n");
1516815216 return;
@@ -15174,7 +15222,7 @@
1517415222 ti, ti, k ? k : "Poly", ta, ti);
1517515223 emit_indent(b, indent + 2);
1517615224 buf_printf(b, "lv_%s = sp_%sArray_get(_t%d, _t%d);\n", vn, k ? k : "Poly", ta, ti);
15177- emit_stmts(c, body, b, indent + 2);
15225+ emit_loop_body(c, body, b, indent + 2);
1517815226 emit_indent(b, indent + 1); buf_puts(b, "}\n");
1517915227 emit_indent(b, indent); buf_puts(b, "}\n");
1518015228 return;
@@ -16802,7 +16850,12 @@
1680216850 emit_indent(b, indent); buf_puts(b, "break;\n"); return;
1680316851 }
1680416852 if (!strcmp(ty, "NextNode")) { emit_indent(b, indent); buf_puts(b, "continue;\n"); return; }
16805- if (!strcmp(ty, "RedoNode")) { emit_indent(b, indent); buf_puts(b, "continue;\n"); return; }
16853+ if (!strcmp(ty, "RedoNode")) {
16854+ emit_indent(b, indent);
16855+ if (g_redo_depth > 0) buf_printf(b, "goto _redo_%d;\n", g_redo_stack[g_redo_depth - 1]);
16856+ else buf_puts(b, "continue;\n"); /* redo outside a labeled loop: best-effort */
16857+ return;
16858+ }
1680616859 if (!strcmp(ty, "RetryNode")) {
1680716860 if (g_retry_label) { emit_indent(b, indent); buf_printf(b, "goto %s;\n", g_retry_label); }
1680816861 else unsupported(c, id, "retry (outside rescue)");