1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Support RB_BUILTIN in ISeq#to_a

This commit is contained in:
Takashi Kokubun 2019-11-09 21:40:38 -08:00
parent 0483d01f6b
commit 5c168c7e7f
No known key found for this signature in database
GPG key ID: 6FFC433B12EE23DD
3 changed files with 24 additions and 2 deletions

15
iseq.c
View file

@ -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));
}

View file

@ -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

View file

@ -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