diff options
author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-10-31 13:04:32 +0000 |
---|---|---|
committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-10-31 13:04:32 +0000 |
commit | 5beab8043a7a6fe238240ea73b9c8d735ef8e726 (patch) | |
tree | 345626c7cb060dcd898f32f8f12ccdd3c5e644fa | |
parent | 9ee8113113fb7189b563f9177b9301309c810286 (diff) |
merges r24757 and r24758 from trunk into ruby_1_9_1.
--
* compile.c (iseq_compile_each): &&= and ||= should return rhs.
[ruby-dev:39163] (#1996), [ruby-core:25143]
--
* compile.c (iseq_compile_each): &&= and ||= should return rhs.
[ruby-dev:39163] (#1996), [ruby-core:25143]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_1@25589 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | compile.c | 32 | ||||
-rw-r--r-- | test/ruby/test_basicinstructions.rb | 65 | ||||
-rw-r--r-- | version.h | 2 |
4 files changed, 73 insertions, 31 deletions
@@ -1,3 +1,8 @@ +Sat Sep 5 10:38:46 2009 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * compile.c (iseq_compile_each): &&= and ||= should return rhs. + [ruby-dev:39163] (#1996), [ruby-core:25143] + Fri Sep 4 04:46:08 2009 Nobuyoshi Nakada <nobu@ruby-lang.org> * lib/webrick/httpservlet/abstract.rb (do_OPTIONS): method names @@ -3847,22 +3847,26 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) if lcfin # r o pop # r eval v # r v - send a= # v - jump lfin # v + swap # v r + topn 1 # v r v + send a= # v ? + jump lfin # v ? lcfin: # r o swap # o r - pop # o - lfin: # v + lfin: # o ? + pop # o # and dup # r o o unless lcfin pop # r eval v # r v - send a= # v - jump lfin # v + swap # v r + topn 1 # v r v + send a= # v ? + jump lfin # v ? # others eval v # r o v @@ -3886,26 +3890,32 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) } ADD_INSN(ret, nd_line(node), pop); COMPILE(ret, "NODE_OP_ASGN2 val", node->nd_value); + ADD_INSN(ret, nd_line(node), swap); + ADD_INSN1(ret, nd_line(node), topn, INT2FIX(1)); ADD_SEND(ret, nd_line(node), ID2SYM(node->nd_next->nd_aid), INT2FIX(1)); ADD_INSNL(ret, nd_line(node), jump, lfin); ADD_LABEL(ret, lcfin); ADD_INSN(ret, nd_line(node), swap); - ADD_INSN(ret, nd_line(node), pop); ADD_LABEL(ret, lfin); + ADD_INSN(ret, nd_line(node), pop); + if (poped) { + /* we can apply more optimize */ + ADD_INSN(ret, nd_line(node), pop); + } } else { COMPILE(ret, "NODE_OP_ASGN2 val", node->nd_value); ADD_SEND(ret, nd_line(node), ID2SYM(node->nd_next->nd_mid), INT2FIX(1)); + if (!poped) { + ADD_INSN(ret, nd_line(node), swap); + ADD_INSN1(ret, nd_line(node), topn, INT2FIX(1)); + } ADD_SEND(ret, nd_line(node), ID2SYM(node->nd_next->nd_aid), INT2FIX(1)); - } - - if (poped) { - /* we can apply more optimize */ ADD_INSN(ret, nd_line(node), pop); } break; diff --git a/test/ruby/test_basicinstructions.rb b/test/ruby/test_basicinstructions.rb index 6ac93e037a..90b034a90b 100644 --- a/test/ruby/test_basicinstructions.rb +++ b/test/ruby/test_basicinstructions.rb @@ -499,52 +499,79 @@ class TestBasicInstructions < Test::Unit::TestCase end class OP - attr_accessor :x + attr_reader :x + def x=(x) + @x = x + :Bug1996 + end + Bug1996 = '[ruby-dev:39163], [ruby-core:25143]' end - def test_opassign + def test_opassign2_1 x = nil - x ||= 1 + assert_equal 1, x ||= 1 assert_equal 1, x - x &&= 2 + assert_equal 2, x &&= 2 assert_equal 2, x - x ||= 3 + assert_equal 2, x ||= 3 assert_equal 2, x - x &&= 4 + assert_equal 4, x &&= 4 + assert_equal 4, x + assert_equal 5, x += 1 + assert_equal 5, x + assert_equal 4, x -= 1 assert_equal 4, x + end + def test_opassign2_2 y = OP.new y.x = nil - y.x ||= 1 + assert_equal 1, y.x ||= 1, OP::Bug1996 assert_equal 1, y.x - y.x &&= 2 + assert_equal 2, y.x &&= 2, OP::Bug1996 assert_equal 2, y.x - y.x ||= 3 + assert_equal 2, y.x ||= 3 assert_equal 2, y.x - y.x &&= 4 + assert_equal 4, y.x &&= 4, OP::Bug1996 + assert_equal 4, y.x + assert_equal 5, y.x += 1, OP::Bug1996 + assert_equal 5, y.x + assert_equal 4, y.x -= 1, OP::Bug1996 assert_equal 4, y.x + end + def test_opassign2_3 z = OP.new - z.x = y + z.x = OP.new z.x.x = nil - z.x.x ||= 1 + assert_equal 1, z.x.x ||= 1, OP::Bug1996 assert_equal 1, z.x.x - z.x.x &&= 2 + assert_equal 2, z.x.x &&= 2, OP::Bug1996 assert_equal 2, z.x.x - z.x.x ||= 3 + assert_equal 2, z.x.x ||= 3 assert_equal 2, z.x.x - z.x.x &&= 4 + assert_equal 4, z.x.x &&= 4, OP::Bug1996 + assert_equal 4, z.x.x + assert_equal 5, z.x.x += 1, OP::Bug1996 + assert_equal 5, z.x.x + assert_equal 4, z.x.x -= 1, OP::Bug1996 assert_equal 4, z.x.x + end + def test_opassign1_1 a = [] a[0] = nil - a[0] ||= 1 + assert_equal 1, a[0] ||= 1 assert_equal 1, a[0] - a[0] &&= 2 + assert_equal 2, a[0] &&= 2 assert_equal 2, a[0] - a[0] ||= 3 + assert_equal 2, a[0] ||= 3 assert_equal 2, a[0] - a[0] &&= 4 + assert_equal 4, a[0] &&= 4 + assert_equal 4, a[0] + assert_equal 5, a[0] += 1 + assert_equal 5, a[0] + assert_equal 4, a[0] -= 1 assert_equal 4, a[0] end @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.1" -#define RUBY_PATCHLEVEL 314 +#define RUBY_PATCHLEVEL 315 #define RUBY_VERSION_MAJOR 1 #define RUBY_VERSION_MINOR 9 #define RUBY_VERSION_TEENY 1 |