diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-10-29 01:09:40 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-10-29 01:09:40 +0000 |
commit | c2011d3a802d8396b38354d52706aab1cfe33ddc (patch) | |
tree | d7e6c0431f0e96313f968d6a0c047f0d0568a34d | |
parent | 64a588e8e0f9a4b739ab26fd305552e40f563eb2 (diff) | |
download | ruby-c2011d3a802d8396b38354d52706aab1cfe33ddc.tar.gz |
compile.c: not flip-flop
* compile.c (iseq_compile_each): turn flip-flop in a not-operator
into a boolean value. fix up r56315
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56521 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | compile.c | 15 | ||||
-rw-r--r-- | test/ruby/test_flip.rb | 2 |
3 files changed, 22 insertions, 0 deletions
@@ -1,3 +1,8 @@ +Sat Oct 29 10:09:38 2016 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * compile.c (iseq_compile_each): turn flip-flop in a not-operator + into a boolean value. fix up r56315 + Sat Oct 29 09:39:14 2016 Nobuyoshi Nakada <nobu@ruby-lang.org> * vm_eval.c (vm_call0_body): follow the original class, not to @@ -5950,6 +5950,21 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) } break; } + case NODE_FLIP2: + case NODE_FLIP3:{ + LABEL *lend = NEW_LABEL(line); + LABEL *ltrue = NEW_LABEL(line); + LABEL *lfalse = NEW_LABEL(line); + compile_branch_condition(iseq, ret, node, ltrue, lfalse); + ADD_INSNL(ret, line, jump, lend); + ADD_LABEL(ret, ltrue); + ADD_INSN1(ret, line, putobject, Qtrue); + ADD_INSNL(ret, line, jump, lend); + ADD_LABEL(ret, lfalse); + ADD_INSN1(ret, line, putobject, Qfalse); + ADD_LABEL(ret, lend); + break; + } case NODE_SELF:{ if (!poped) { ADD_INSN(ret, line, putself); diff --git a/test/ruby/test_flip.rb b/test/ruby/test_flip.rb index 7c805574a8..810fd5d3ae 100644 --- a/test/ruby/test_flip.rb +++ b/test/ruby/test_flip.rb @@ -8,6 +8,8 @@ class TestFlip < Test::Unit::TestCase assert_equal [2], (1..9).select {|n| true if (n==2)..(n%2).zero?} assert_equal [2,3,4], (1..9).select {|n| true if (n==2)...(n%2).zero?} assert_equal [4,5,7,8], (1..9).select {|n| true if (n==4)...(n==5) or (n==7)...(n==8)} + assert_equal [nil, 2, 3, 4, nil], (1..5).map {|x| x if (x==2..x==4)} + assert_equal [1, nil, nil, nil, 5], (1..5).map {|x| x if !(x==2..x==4)} end def test_hidden_key |