ruby-changes:16881
From: mame <ko1@a...>
Date: Thu, 5 Aug 2010 21:32:19 +0900 (JST)
Subject: [ruby-changes:16881] Ruby:r28877 (trunk): * compile.c (NODE_ARGSCAT, NODE_ARGSPUSH): drop unused ARGSCAT
mame 2010-08-05 21:32:02 +0900 (Thu, 05 Aug 2010) New Revision: 28877 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=28877 Log: * compile.c (NODE_ARGSCAT, NODE_ARGSPUSH): drop unused ARGSCAT results when poped is true. [ruby-dev:41933], [Bug #3658] This is retry of r28870 and r28873 which were reverted. Modified files: trunk/ChangeLog trunk/compile.c trunk/test/ruby/test_primitive.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 28876) +++ ChangeLog (revision 28877) @@ -1,3 +1,9 @@ +Thu Aug 5 21:20:31 2010 Yusuke Endoh <mame@t...> + + * compile.c (NODE_ARGSCAT, NODE_ARGSPUSH): drop unused ARGSCAT + results when poped is true. [ruby-dev:41933], [Bug #3658] + This is retry of r28870 and r28873 which were reverted. + Thu Aug 5 20:13:49 2010 Nobuyoshi Nakada <nobu@r...> * README.EXT, README.EXT.ja (String functions): mention Index: compile.c =================================================================== --- compile.c (revision 28876) +++ compile.c (revision 28877) @@ -4521,16 +4521,34 @@ break; } case NODE_ARGSCAT:{ - COMPILE(ret, "argscat head", node->nd_head); - COMPILE(ret, "argscat body", node->nd_body); - ADD_INSN(ret, nd_line(node), concatarray); + if (poped) { + COMPILE(ret, "argscat head", node->nd_head); + ADD_INSN1(ret, nd_line(node), splatarray, Qfalse); + ADD_INSN(ret, nd_line(node), pop); + COMPILE(ret, "argscat body", node->nd_body); + ADD_INSN1(ret, nd_line(node), splatarray, Qfalse); + ADD_INSN(ret, nd_line(node), pop); + } + else { + COMPILE(ret, "argscat head", node->nd_head); + COMPILE(ret, "argscat body", node->nd_body); + ADD_INSN(ret, nd_line(node), concatarray); + } break; } case NODE_ARGSPUSH:{ - COMPILE(ret, "arsgpush head", node->nd_head); - COMPILE(ret, "argspush body", node->nd_body); - ADD_INSN1(ret, nd_line(node), newarray, INT2FIX(1)); - ADD_INSN(ret, nd_line(node), concatarray); + if (poped) { + COMPILE(ret, "arsgpush head", node->nd_head); + ADD_INSN1(ret, nd_line(node), splatarray, Qfalse); + ADD_INSN(ret, nd_line(node), pop); + COMPILE_(ret, "argspush body", node->nd_body, poped); + } + else { + COMPILE(ret, "arsgpush head", node->nd_head); + COMPILE_(ret, "argspush body", node->nd_body, poped); + ADD_INSN1(ret, nd_line(node), newarray, INT2FIX(1)); + ADD_INSN(ret, nd_line(node), concatarray); + } break; } case NODE_SPLAT:{ Index: test/ruby/test_primitive.rb =================================================================== --- test/ruby/test_primitive.rb (revision 28876) +++ test/ruby/test_primitive.rb (revision 28877) @@ -400,4 +400,24 @@ #assert_equal [0,1,2,3,4], [0, *a, 4] end + def test_concatarray_ruby_dev_41933 + bug3658 = '[ruby-dev:41933]' + [0, *x=1] + assert_equal(1, x, bug3658) + [0, *x=1, 2] + assert_equal(1, x, bug3658) + class << (x = Object.new) + attr_accessor :to_a_called + def to_a + @to_a_called = true + [self] + end + end + x.to_a_called = false + [0, *x] + assert(x.to_a_called, bug3658) + x.to_a_called = false + [0, *x, 2] + assert(x.to_a_called, bug3658) + end end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/