ruby-changes:37649
From: nobu <ko1@a...>
Date: Wed, 25 Feb 2015 09:20:41 +0900 (JST)
Subject: [ruby-changes:37649] nobu:r49730 (trunk): compile.c: unbalanced massign
nobu 2015-02-25 09:20:35 +0900 (Wed, 25 Feb 2015) New Revision: 49730 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49730 Log: compile.c: unbalanced massign * compile.c (compile_massign): adjust stack for unbalanced massign. Modified files: trunk/compile.c Index: compile.c =================================================================== --- compile.c (revision 49729) +++ compile.c (revision 49730) @@ -2772,6 +2772,17 @@ compile_massign_opt(rb_iseq_t *iseq, LIN https://github.com/ruby/ruby/blob/trunk/compile.c#L2772 return 1; } +static void +adjust_stack(rb_iseq_t *iseq, LINK_ANCHOR *ret, int line, int rlen, int llen) +{ + if (rlen < llen) { + do {ADD_INSN(ret, line, putnil);} while (++rlen < llen); + } + else if (rlen > llen) { + do {ADD_INSN(ret, line, pop);} while (--rlen > llen); + } +} + static int compile_massign(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE *node, int poped) { @@ -2802,15 +2813,22 @@ compile_massign(rb_iseq_t *iseq, LINK_AN https://github.com/ruby/ruby/blob/trunk/compile.c#L2813 INSN *last = (INSN*)ret->last; if (last->link.type == ISEQ_ELEMENT_INSN && last->insn_id == BIN(newarray) && - last->operand_size == 1 && - OPERAND_AT(last, 0) == INT2FIX(llen)) { + last->operand_size == 1) { + int rlen = FIX2INT(OPERAND_AT(last, 0)); /* special case: assign to aset or attrset */ if (llen == 2) { POP_ELEMENT(ret); + adjust_stack(iseq, ret, nd_line(node), rlen, llen); ADD_INSN(ret, nd_line(node), swap); expand = 0; } #if 0 + else if (llen > 2 && llen != rlen) { + POP_ELEMENT(ret); + adjust_stack(iseq, ret, nd_line(node), rlen, llen); + ADD_INSN1(ret, nd_line(node), reverse, INT2FIX(llen)); + expand = 0; + } else if (llen > 2) { last->insn_id = BIN(reverse); expand = 0; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/