Commit 8feecda0

8feecda0ae69Merged

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

Description

Statement-form rescue modifier (expr rescue fallback)

Emit a bare expr rescue fallback statement under the setjmp exception guard, falling through to the rescue expression on any raise. The expression-assignment form (x = a rescue b) is handled separately.

Co-Authored-By: Claude Opus 4.8 [email protected]

Details

Commit
8feecda0ae69
Parent
32b80581f87a

src/codegen.cmodifiedView file

@@ -5492,6 +5492,22 @@
54925492 if (!strcmp(ty, "RedoNode")) { emit_indent(b, indent); buf_puts(b, "continue;\n"); return; }
54935493 if (!strcmp(ty, "CaseNode")) { emit_case(c, id, b, indent); return; }
54945494 if (!strcmp(ty, "BeginNode")) { emit_begin(c, id, b, indent, NULL); return; }
5495+ if (!strcmp(ty, "RescueModifierNode")) {
5496+ /* `expr rescue fallback` as a statement: run expr under a setjmp guard,
5497+ fall through to the rescue expression on any exception. */
5498+ int e = nt_ref(nt, id, "expression");
5499+ int r = nt_ref(nt, id, "rescue_expression");
5500+ emit_indent(b, indent); buf_puts(b, "sp_exc_top++;\n");
5501+ emit_indent(b, indent); buf_puts(b, "if (setjmp(sp_exc_stack[sp_exc_top-1]) == 0) {\n");
5502+ if (e >= 0) emit_stmt(c, e, b, indent + 1);
5503+ emit_indent(b, indent + 1); buf_puts(b, "sp_exc_top--;\n");
5504+ emit_indent(b, indent); buf_puts(b, "}\n");
5505+ emit_indent(b, indent); buf_puts(b, "else {\n");
5506+ emit_indent(b, indent + 1); buf_puts(b, "sp_exc_top--;\n");
5507+ if (r >= 0) emit_stmt(c, r, b, indent + 1);
5508+ emit_indent(b, indent); buf_puts(b, "}\n");
5509+ return;
5510+ }
54955511 if (!strcmp(ty, "ReturnNode")) { emit_return(c, id, b, indent); return; }
54965512 if (!strcmp(ty, "DefNode")) { return; } /* emitted separately */
54975513