summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2019-11-09 21:40:38 -0800
committerTakashi Kokubun <takashikkbn@gmail.com>2019-11-09 21:40:38 -0800
commit5c168c7e7f73d400db45980115dedab4deefcda7 (patch)
tree9e6ae3df84029eff369e3f83f307124db3d3ed81
parent0483d01f6bdd3d16b31244a7aaadb4c31f6ecee7 (diff)
downloadruby-5c168c7e7f73d400db45980115dedab4deefcda7.tar.gz
Support RB_BUILTIN in ISeq#to_a
-rw-r--r--iseq.c15
-rw-r--r--test/ruby/test_iseq.rb7
-rw-r--r--test/ruby/test_jit.rb4
3 files changed, 24 insertions, 2 deletions
diff --git a/iseq.c b/iseq.c
index 0b19056120..48a4d4b677 100644
--- a/iseq.c
+++ b/iseq.c
@@ -2802,6 +2802,21 @@ iseq_data_to_ary(const rb_iseq_t *iseq)
rb_ary_push(ary, val);
}
break;
+ case TS_BUILTIN:
+ {
+ VALUE val = rb_hash_new();
+#if SIZEOF_VALUE <= SIZEOF_LONG
+ VALUE func_ptr = LONG2NUM((SIGNED_VALUE)((RB_BUILTIN)*seq)->func_ptr);
+#else
+ VALUE func_ptr = LL2NUM((SIGNED_VALUE)((RB_BUILTIN)*seq)->func_ptr);
+#endif
+ rb_hash_aset(val, ID2SYM(rb_intern("func_ptr")), func_ptr);
+ rb_hash_aset(val, ID2SYM(rb_intern("argc")), INT2NUM(((RB_BUILTIN)*seq)->argc));
+ rb_hash_aset(val, ID2SYM(rb_intern("index")), INT2NUM(((RB_BUILTIN)*seq)->index));
+ rb_hash_aset(val, ID2SYM(rb_intern("name")), rb_str_new_cstr(((RB_BUILTIN)*seq)->name));
+ rb_ary_push(ary, val);
+ }
+ break;
default:
rb_bug("unknown operand: %c", insn_op_type(insn, j));
}
diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb
index 30c4c2815d..0120a50887 100644
--- a/test/ruby/test_iseq.rb
+++ b/test/ruby/test_iseq.rb
@@ -559,4 +559,11 @@ class TestISeq < Test::Unit::TestCase
assert_equal iseq1.object_id, iseq2.object_id
}
end
+
+ def test_iseq_builtin_to_a
+ insns = RubyVM::InstructionSequence.of([].method(:pack)).to_a.last
+ invokebuiltin = insns.find { |insn| insn.is_a?(Array) && insn[0] == :invokebuiltin }
+ assert_not_nil(invokebuiltin)
+ assert_equal([:func_ptr, :argc, :index, :name], invokebuiltin[1].keys)
+ end
end
diff --git a/test/ruby/test_jit.rb b/test/ruby/test_jit.rb
index bb5727f5fb..a4c3e32218 100644
--- a/test/ruby/test_jit.rb
+++ b/test/ruby/test_jit.rb
@@ -601,8 +601,8 @@ class TestJIT < Test::Unit::TestCase
end
def test_compile_insn_invokebuiltin
- # insns = collect_insns(RubyVM::InstructionSequence.of([0].method(:pack)).to_a)
- # mark_tested_insn(:invokebuiltin, used_insns: insns)
+ insns = collect_insns(RubyVM::InstructionSequence.of([0].method(:pack)).to_a)
+ mark_tested_insn(:invokebuiltin, used_insns: insns)
assert_eval_with_jit('print [0].pack("c")', stdout: "\x00", success_count: 1)
end