diff options
| author | Kevin Newton <kddnewton@gmail.com> | 2024-07-16 13:47:53 -0400 |
|---|---|---|
| committer | Kevin Newton <kddnewton@gmail.com> | 2024-07-16 14:40:20 -0400 |
| commit | b0a99d0da9a11a45a5fd3fd655cab8d246fb27a4 (patch) | |
| tree | 011c0672cdda041f2cf04e63b9406387396168d6 | |
| parent | 90e945a7b7eca49774fe914ab884b46cfab15a34 (diff) | |
[PRISM] Properly compile branch conditions in their own sequence
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/11177
| -rw-r--r-- | prism_compile.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/prism_compile.c b/prism_compile.c index e423e189b8..acdb57661a 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -989,7 +989,26 @@ again: break; } default: { - pm_compile_node(iseq, cond, ret, false, scope_node); + DECL_ANCHOR(cond_seq); + INIT_ANCHOR(cond_seq); + pm_compile_node(iseq, cond, cond_seq, false, scope_node); + + if (LIST_INSN_SIZE_ONE(cond_seq)) { + INSN *insn = (INSN *)ELEM_FIRST_INSN(FIRST_ELEMENT(cond_seq)); + if (insn->insn_id == BIN(putobject)) { + if (RTEST(insn->operands[0])) { + ADD_INSNL(ret, cond, jump, then_label); + // maybe unreachable + return; + } + else { + ADD_INSNL(ret, cond, jump, else_label); + return; + } + } + } + + PUSH_SEQ(ret, cond_seq); break; } } |
