Project

General

Profile

Feature #18835 ยป 0001-Add-InstructionSequence-type-method.patch

tenderlovemaking (Aaron Patterson), 06/16/2022 10:30 PM

View differences:

iseq.c
}
}
static VALUE
iseqw_type(VALUE self)
{
const rb_iseq_t *iseq = iseqw_check(self);
const struct rb_iseq_constant_body *const body = ISEQ_BODY(iseq);
switch(body->type) {
#define CASE_TYPE(t) case ISEQ_TYPE_ ## t: return ID2SYM(rb_intern(#t)); break;
CASE_TYPE(TOP);
CASE_TYPE(METHOD);
CASE_TYPE(BLOCK);
CASE_TYPE(CLASS);
CASE_TYPE(RESCUE);
CASE_TYPE(ENSURE);
CASE_TYPE(EVAL);
CASE_TYPE(MAIN);
CASE_TYPE(PLAIN);
#undef CASE_TYPE
}
}
/*
* Returns the path of this instruction sequence.
*
......
rb_cISeq = rb_define_class_under(rb_cRubyVM, "InstructionSequence", rb_cObject);
rb_undef_alloc_func(rb_cISeq);
rb_define_method(rb_cISeq, "inspect", iseqw_inspect, 0);
rb_define_method(rb_cISeq, "type", iseqw_type, 0);
rb_define_method(rb_cISeq, "disasm", iseqw_disasm, 0);
rb_define_method(rb_cISeq, "disassemble", iseqw_disasm, 0);
rb_define_method(rb_cISeq, "to_a", iseqw_to_a, 0);
test/ruby/test_iseq.rb
end
end
def test_type
iseq = RubyVM::InstructionSequence.of(method(__method__))
assert_equal :METHOD, iseq.type
iseq = RubyVM::InstructionSequence.of(->() { })
assert_equal :BLOCK, iseq.type
end
def test_disasm_encoding
src = "\u{3042} = 1; \u{3042}; \u{3043}"
asm = compile(src).disasm
    (1-1/1)