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

ruby-changes:6620

From: nobu <ko1@a...>
Date: Sun, 20 Jul 2008 22:50:30 +0900 (JST)
Subject: [ruby-changes:6620] Ruby:r18136 (trunk): * compile.c (iseq_compile_each): NODE_POSTEXE should set each end

nobu	2008-07-20 22:50:14 +0900 (Sun, 20 Jul 2008)

  New Revision: 18136

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

  Log:
    * compile.c (iseq_compile_each): NODE_POSTEXE should set each end
      procs only once.  [ruby-dev:35596]

  Modified files:
    trunk/ChangeLog
    trunk/compile.c
    trunk/test/ruby/test_beginendblock.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 18135)
+++ ChangeLog	(revision 18136)
@@ -1,3 +1,8 @@
+Sun Jul 20 22:50:11 2008  Nobuyoshi Nakada  <nobu@r...>
+
+	* compile.c (iseq_compile_each): NODE_POSTEXE should set each end
+	  procs only once.  [ruby-dev:35596]
+
 Sun Jul 20 16:00:37 2008  Masaki Suketa  <masaki.suketa@n...>
 
 	* ext/win32ole/win32ole.c (EVENTSINK_Invoke): use rb_protect
Index: compile.c
===================================================================
--- compile.c	(revision 18135)
+++ compile.c	(revision 18136)
@@ -4527,12 +4527,21 @@
 	break;
       }
       case NODE_POSTEXE:{
+	LABEL *lstart = NEW_LABEL(nd_line(node));
+	LABEL *lend = NEW_LABEL(nd_line(node));
 	VALUE block = NEW_CHILD_ISEQVAL(node->nd_body, make_name_for_block(iseq), ISEQ_TYPE_BLOCK);
 
+	ADD_LABEL(ret, lstart);
+	ADD_INSN2(ret, nd_line(node), onceinlinecache, 0, lend);
+	ADD_INSN(ret, nd_line(node), pop);
+
 	ADD_INSN1(ret, nd_line(node), putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
 	ADD_INSN1(ret, nd_line(node), putiseq, block);
 	ADD_SEND (ret, nd_line(node), ID2SYM(id_core_set_postexe), INT2FIX(1));
 
+	ADD_INSN1(ret, nd_line(node), setinlinecache, lstart);
+	ADD_LABEL(ret, lend);
+
 	if (poped) {
 	    ADD_INSN(ret, nd_line(node), pop);
 	}
Index: test/ruby/test_beginendblock.rb
===================================================================
--- test/ruby/test_beginendblock.rb	(revision 18135)
+++ test/ruby/test_beginendblock.rb	(revision 18136)
@@ -14,6 +14,21 @@
     target = File.join(DIR, 'beginmainend.rb')
     result = IO.popen([ruby, target]){|io|io.read}
     assert_equal(%w(b1 b2-1 b2 main b3-1 b3 b4 e1 e4 e3 e2 e4-2 e4-1 e1-1 e4-1-1), result.split)
+
+    input = Tempfile.new(self.class.name)
+    inputpath = input.path
+    input.close
+    result = IO.popen([ruby, "-n", "-eBEGIN{p :begin}", "-eEND{p :end}", inputpath]){|io|io.read}
+    assert_equal(%w(:begin), result.split)
+    result = IO.popen([ruby, "-p", "-eBEGIN{p :begin}", "-eEND{p :end}", inputpath]){|io|io.read}
+    assert_equal(%w(:begin), result.split)
+    input.open
+    input.puts "foo\nbar"
+    input.close
+    result = IO.popen([ruby, "-n", "-eBEGIN{p :begin}", "-eEND{p :end}", inputpath]){|io|io.read}
+    assert_equal(%w(:begin :end), result.split)
+    result = IO.popen([ruby, "-p", "-eBEGIN{p :begin}", "-eEND{p :end}", inputpath]){|io|io.read}
+    assert_equal(%w(:begin foo bar :end), result.split)
   end
 
   def test_begininmethod

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

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