[前][次][番号順一覧][スレッド一覧]

ruby-changes:14126

From: yugui <ko1@a...>
Date: Fri, 27 Nov 2009 11:54:20 +0900 (JST)
Subject: [ruby-changes:14126] Ruby:r25940 (ruby_1_9_1): merges r24761 and r24999 from trunk into ruby_1_9_1.

yugui	2009-11-27 11:54:02 +0900 (Fri, 27 Nov 2009)

  New Revision: 25940

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=25940

  Log:
    merges r24761 and r24999 from trunk into ruby_1_9_1.
    --
    * compile.c (iseq_compile_each): op_asgn to aref should return rhs.
      [ruby-core:25387]
    --
    * compile.c (iseq_compile_each), parse.y (stmt, arg): arg_concat()
      on op_asgn was inversed.  [ruby-core:25629] [Bug #2050]

  Modified files:
    branches/ruby_1_9_1/ChangeLog
    branches/ruby_1_9_1/compile.c
    branches/ruby_1_9_1/parse.y
    branches/ruby_1_9_1/test/ruby/test_assignment.rb
    branches/ruby_1_9_1/test/ruby/test_basicinstructions.rb
    branches/ruby_1_9_1/version.h

Index: ruby_1_9_1/ChangeLog
===================================================================
--- ruby_1_9_1/ChangeLog	(revision 25939)
+++ ruby_1_9_1/ChangeLog	(revision 25940)
@@ -1,3 +1,13 @@
+Fri Sep 18 16:15:04 2009  Nobuyoshi Nakada  <nobu@r...>
+
+	* compile.c (iseq_compile_each), parse.y (stmt, arg): arg_concat()
+	  on op_asgn was inversed.  [ruby-core:25629] [Bug #2050]
+
+Sat Sep  5 15:21:13 2009  Nobuyoshi Nakada  <nobu@r...>
+
+ * compile.c (iseq_compile_each): op_asgn to aref should return rhs.
+   [ruby-core:25387]
+
 Sun Feb 15 03:50:21 2009  Yusuke Endoh  <mame@t...>
 
 	* hash.c (rb_hash): always return a fixnum value because a return
Index: ruby_1_9_1/compile.c
===================================================================
--- ruby_1_9_1/compile.c	(revision 25939)
+++ ruby_1_9_1/compile.c	(revision 25940)
@@ -3736,13 +3736,16 @@
 	/*
 	 * a[x] (op)= y
 	 *
-	 * eval a    # a
-	 * eval x    # a x
-	 * dupn 2    # a x a x
-	 * send :[]  # a x a[x]
-	 * eval y    # a x a[x] y
-	 * send op   # a x a[x]+y
-	 * send []=  # ret
+         * nil       # nil
+	 * eval a    # nil a
+	 * eval x    # nil a x
+	 * dupn 2    # nil a x a x
+	 * send :[]  # nil a x a[x]
+	 * eval y    # nil a x a[x] y
+	 * send op   # nil a x ret
+         * setn 3    # ret a x ret
+	 * send []=  # ret ?
+         * pop       # ret
 	 */
 
 	/*
@@ -3753,10 +3756,13 @@
 	 *              nd_mid
 	 */
 
+	if (!poped) {
+	    ADD_INSN(ret, nd_line(node), putnil);
+	}
 	COMPILE(ret, "NODE_OP_ASGN1 recv", node->nd_recv);
-	if (nd_type(node->nd_args->nd_body) != NODE_ZARRAY) {
+	if (nd_type(node->nd_args->nd_head) != NODE_ZARRAY) {
 	    INIT_ANCHOR(args);
-	    argc = setup_args(iseq, args, node->nd_args->nd_body, &flag);
+	    argc = setup_args(iseq, args, node->nd_args->nd_head, &flag);
 	    ADD_SEQ(ret, args);
 	}
 	else {
@@ -3791,7 +3797,10 @@
 		ADD_INSN(ret, nd_line(node), pop);
 	    }
 
-	    COMPILE(ret, "NODE_OP_ASGN1 args->head: ", node->nd_args->nd_head);
+	    COMPILE(ret, "NODE_OP_ASGN1 args->body: ", node->nd_args->nd_body);
+	    if (!poped) {
+		ADD_INSN1(ret, nd_line(node), setn, INT2FIX(3));
+	    }
 	    if (flag & VM_CALL_ARGS_SPLAT_BIT) {
 		ADD_INSN1(ret, nd_line(node), newarray, INT2FIX(1));
 		ADD_INSN(ret, nd_line(node), concatarray);
@@ -3802,15 +3811,21 @@
 		ADD_SEND_R(ret, nd_line(node), ID2SYM(idASET),
 			   INT2FIX(FIX2INT(argc) + 1), Qfalse, LONG2FIX(flag));
 	    }
+	    ADD_INSN(ret, nd_line(node), pop);
 	    ADD_INSNL(ret, nd_line(node), jump, lfin);
 	    ADD_LABEL(ret, label);
-	    ADD_INSN1(ret, nd_line(node), setn, INT2FIX(FIX2INT(argc) + 1));
-	    ADD_INSN1(ret, nd_line(node), adjuststack, INT2FIX(FIX2INT(argc) + 1));
+	    if (!poped) {
+		ADD_INSN1(ret, nd_line(node), setn, INT2FIX(FIX2INT(argc) + 2));
+	    }
+	    ADD_INSN1(ret, nd_line(node), adjuststack, INT2FIX(FIX2INT(argc) + 2));
 	    ADD_LABEL(ret, lfin);
 	}
 	else {
-	    COMPILE(ret, "NODE_OP_ASGN1 args->head: ", node->nd_args->nd_head);
+	    COMPILE(ret, "NODE_OP_ASGN1 args->body: ", node->nd_args->nd_body);
 	    ADD_SEND(ret, nd_line(node), ID2SYM(id), INT2FIX(1));
+	    if (!poped) {
+		ADD_INSN1(ret, nd_line(node), setn, INT2FIX(FIX2INT(argc) + 2));
+	    }
 	    if (flag & VM_CALL_ARGS_SPLAT_BIT) {
 		ADD_INSN1(ret, nd_line(node), newarray, INT2FIX(1));
 		ADD_INSN(ret, nd_line(node), concatarray);
@@ -3821,9 +3836,7 @@
 		ADD_SEND_R(ret, nd_line(node), ID2SYM(idASET),
 			   INT2FIX(FIX2INT(argc) + 1), Qfalse, LONG2FIX(flag));
 	    }
-	}
 
-	if (poped) {
 	    ADD_INSN(ret, nd_line(node), pop);
 	}
 
Index: ruby_1_9_1/parse.y
===================================================================
--- ruby_1_9_1/parse.y	(revision 25939)
+++ ruby_1_9_1/parse.y	(revision 25940)
@@ -1100,7 +1100,7 @@
 
 			value_expr($6);
 			if (!$3) $3 = NEW_ZARRAY();
-			args = arg_concat($6, $3);
+			args = arg_concat($3, $6);
 			if ($5 == tOROP) {
 			    $5 = 0;
 			}
@@ -1935,7 +1935,7 @@
 
 			value_expr($6);
 			if (!$3) $3 = NEW_ZARRAY();
-			args = arg_concat($6, $3);
+			args = arg_concat($3, $6);
 			if ($5 == tOROP) {
 			    $5 = 0;
 			}
Index: ruby_1_9_1/version.h
===================================================================
--- ruby_1_9_1/version.h	(revision 25939)
+++ ruby_1_9_1/version.h	(revision 25940)
@@ -1,5 +1,5 @@
 #define RUBY_VERSION "1.9.1"
-#define RUBY_PATCHLEVEL 341
+#define RUBY_PATCHLEVEL 342
 #define RUBY_VERSION_MAJOR 1
 #define RUBY_VERSION_MINOR 9
 #define RUBY_VERSION_TEENY 1
Index: ruby_1_9_1/test/ruby/test_basicinstructions.rb
===================================================================
--- ruby_1_9_1/test/ruby/test_basicinstructions.rb	(revision 25939)
+++ ruby_1_9_1/test/ruby/test_basicinstructions.rb	(revision 25940)
@@ -505,6 +505,14 @@
       :Bug1996
     end
     Bug1996 = '[ruby-dev:39163], [ruby-core:25143]'
+    def [](i)
+      @x
+    end
+    def []=(i, x)
+      @x = x
+      :Bug2050
+    end
+    Bug2050 = '[ruby-core:25387]'
   end
 
   def test_opassign2_1
@@ -575,6 +583,23 @@
     assert_equal 4, a[0]
   end
 
+  def test_opassign1_2
+    x = OP.new
+    x[0] = nil
+    assert_equal 1, x[0] ||= 1, OP::Bug2050
+    assert_equal 1, x[0]
+    assert_equal 2, x[0] &&= 2, OP::Bug2050
+    assert_equal 2, x[0]
+    assert_equal 2, x[0] ||= 3, OP::Bug2050
+    assert_equal 2, x[0]
+    assert_equal 4, x[0] &&= 4, OP::Bug2050
+    assert_equal 4, x[0]
+    assert_equal 5, x[0] += 1, OP::Bug2050
+    assert_equal 5, x[0]
+    assert_equal 4, x[0] -= 1, OP::Bug2050
+    assert_equal 4, x[0]
+  end
+
   def test_backref
     /re/ =~ 'not match'
     assert_nil $~
Index: ruby_1_9_1/test/ruby/test_assignment.rb
===================================================================
--- ruby_1_9_1/test/ruby/test_assignment.rb	(revision 25939)
+++ ruby_1_9_1/test/ruby/test_assignment.rb	(revision 25940)
@@ -77,6 +77,14 @@
     a,b,*c = *[*[]]; assert_equal([nil,nil,[]], [a,b,c])
     a,b,*c = *[*[1]]; assert_equal([1,nil,[]], [a,b,c])
     a,b,*c = *[*[1,2]]; assert_equal([1,2,[]], [a,b,c])
+
+    bug2050 = '[ruby-core:25629]'
+    a = Hash.new {[]}
+    b = [1, 2]
+    assert_equal([1, 2, 3], a[:x] += [*b, 3], bug2050)
+    assert_equal([1, 2, 3], a[:x], bug2050)
+    assert_equal([1, 2, 3, [1, 2, 3]], a[:x] <<= [*b, 3], bug2050)
+    assert_equal([1, 2, 3, [1, 2, 3]], a[:x], bug2050)
   end
 
   def test_yield

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]