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

ruby-changes:44448

From: nobu <ko1@a...>
Date: Sat, 29 Oct 2016 10:09:46 +0900 (JST)
Subject: [ruby-changes:44448] nobu:r56521 (trunk): compile.c: not flip-flop

nobu	2016-10-29 10:09:40 +0900 (Sat, 29 Oct 2016)

  New Revision: 56521

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56521

  Log:
    compile.c: not flip-flop
    
    * compile.c (iseq_compile_each): turn flip-flop in a not-operator
      into a boolean value.  fix up r56315

  Modified files:
    trunk/ChangeLog
    trunk/compile.c
    trunk/test/ruby/test_flip.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 56520)
+++ ChangeLog	(revision 56521)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Oct 29 10:09:38 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@r...>
 
 	* vm_eval.c (vm_call0_body): follow the original class, not to
Index: test/ruby/test_flip.rb
===================================================================
--- test/ruby/test_flip.rb	(revision 56520)
+++ test/ruby/test_flip.rb	(revision 56521)
@@ -8,6 +8,8 @@ class TestFlip < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_flip.rb#L8
     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
Index: compile.c
===================================================================
--- compile.c	(revision 56520)
+++ compile.c	(revision 56521)
@@ -5950,6 +5950,21 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ https://github.com/ruby/ruby/blob/trunk/compile.c#L5950
 	}
 	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);

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

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