From 4cf0918e8e3d8b06d84c3cd3e875c82edb8b87e6 Mon Sep 17 00:00:00 2001 From: ko1 Date: Thu, 28 Feb 2013 14:04:53 +0000 Subject: * compile.c (iseq_compile_each): remove redundant trace(line) instruction. for example, at the following script def m() p:xyzzy 1 2 end compiler ignores `1' because there is no effect. However, `trace(line)' instruction remains in bytecode. This modification removes such redundant trace(line) instruction. * test/ruby/test_iseq.rb: add a test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39539 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_iseq.rb | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) (limited to 'test/ruby') diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb index 230cea9b91..621320c2b0 100644 --- a/test/ruby/test_iseq.rb +++ b/test/ruby/test_iseq.rb @@ -9,6 +9,11 @@ class TestISeq < Test::Unit::TestCase assert_normal_exit('p RubyVM::InstructionSequence.compile("1", "mac", "", 0).to_a', bug5894) end + def lines src + body = RubyVM::InstructionSequence.new(src).to_a[13] + lines = body.find_all{|e| e.kind_of? Fixnum} + end + def test_to_a_lines src = <<-EOS p __LINE__ # 1 @@ -16,9 +21,29 @@ class TestISeq < Test::Unit::TestCase # 3 p __LINE__ # 4 EOS - body = RubyVM::InstructionSequence.new(src).to_a[13] - lines = body.find_all{|e| e.kind_of? Fixnum} - assert_equal [1, 2, 4], lines + assert_equal [1, 2, 4], lines(src) + + src = <<-EOS + # 1 + p __LINE__ # 2 + # 3 + p __LINE__ # 4 + # 5 + EOS + assert_equal [2, 4], lines(src) + + src = <<-EOS + 1 # should be optimized out + 2 # should be optimized out + p __LINE__ # 3 + p __LINE__ # 4 + 5 # should be optimized out + 6 # should be optimized out + p __LINE__ # 7 + 8 # should be optimized out + 9 + EOS + assert_equal [3, 4, 7, 9], lines(src) end def test_unsupport_type -- cgit v1.2.3