From 9581954a964c6b20bafd133a19da3e27aa135dce Mon Sep 17 00:00:00 2001 From: normal Date: Wed, 3 Dec 2014 22:16:58 +0000 Subject: mostly fix rb_iseq_load This allows reporters commenters of [Feature #8543] to load instruction sequences directly. Some test cases are still failing but documented in test/-ext-/iseq_load/test_iseq_load.rb. * compile.c (rb_iseq_build_from_exception): entry->sp is unsigned (iseq_build_callinfo_from_hash): account for kw_arg (iseq_build_from_ary_body): update for r35459 (CHECK_STRING, CHECK_INTEGER): remove unused checks (int_param): new function for checking new `params' hash (iseq_build_kw): new function for loading rb_iseq_param_keyword (rb_iseq_build_from_ary): account for `misc' entry and general structure changes [Feature #8543] * iseq.c (CHECK_HASH): new macro (for `misc' and `param' entries) (iseq_load): account for `misc' and `params' hashes (iseq_data_to_ary): add final opt to arg_opt_labels, fix kw support, account for unsigned entry->sp * ext/-test-/iseq_load/iseq_load.c: new ext for test * ext/-test-/iseq_load/extconf.rb: ditto * test/-ext-/iseq_load/test_iseq_load.rb: new test git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48705 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/-ext-/iseq_load/test_iseq_load.rb | 95 ++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 test/-ext-/iseq_load/test_iseq_load.rb (limited to 'test/-ext-') diff --git a/test/-ext-/iseq_load/test_iseq_load.rb b/test/-ext-/iseq_load/test_iseq_load.rb new file mode 100644 index 0000000000..5bbd49efba --- /dev/null +++ b/test/-ext-/iseq_load/test_iseq_load.rb @@ -0,0 +1,95 @@ +require 'test/unit' + +class TestIseqLoad < Test::Unit::TestCase + require '-test-/iseq_load/iseq_load' + ISeq = RubyVM::InstructionSequence + + def test_bug8543 + assert_iseq_roundtrip <<-'end;' + puts "tralivali" + def funct(a, b) + a**b + end + 3.times { |i| puts "Hello, world#{funct(2,i)}!" } + end; + end + + def test_case_when + assert_iseq_roundtrip <<-'end;' + def user_mask(target) + target.each_char.inject(0) do |mask, chr| + case chr + when "u" + mask | 04700 + when "g" + mask | 02070 + when "o" + mask | 01007 + when "a" + mask | 07777 + else + raise ArgumentError, "invalid `who' symbol in file mode: #{chr}" + end + end + end + end; + end + + def test_splatsplat + assert_iseq_roundtrip('def splatsplat(**); end') + end + + def test_hidden + assert_iseq_roundtrip('def x(a, (b, *c), d: false); end') + end + + def assert_iseq_roundtrip(src) + a = ISeq.compile(src).to_a + b = ISeq.iseq_load(a).to_a + warn diff(a, b) if a != b + assert_equal a, b + assert_equal a, ISeq.iseq_load(b).to_a + end + + def test_next_in_block_in_block + skip "failing due to stack_max mismatch" + assert_iseq_roundtrip <<-'end;' + 3.times { 3.times { next } } + end; + end + + def test_break_ensure + skip "failing due to exception entry sp mismatch" + assert_iseq_roundtrip <<-'end;' + def m + bad = true + while true + begin + break + ensure + bad = false + end + end + end + end; + end + + # FIXME: still failing + def test_require_integration + skip "iseq loader require integration tests still failing" + f = File.expand_path(__FILE__) + # $(top_srcdir)/test/ruby/test_....rb + 3.times { f = File.dirname(f) } + Dir[File.join(f, 'ruby', '*.rb')].each do |f| + iseq = ISeq.compile_file(f) + orig = iseq.to_a.freeze + + loaded = ISeq.iseq_load(orig).to_a + if loaded != orig + warn f + warn diff(orig, loaded) + end + #assert_equal orig, loaded + end + end +end -- cgit v1.2.3