From 7293bfe1bf8a696bd218a52582e9026e5e638458 Mon Sep 17 00:00:00 2001 From: Alan Wu Date: Tue, 4 Oct 2022 22:48:05 -0400 Subject: YJIT: add support for calling bmethods (#6489) * YJIT: fix a parameter name * YJIT: add support for calling bmethods This commit adds support for the VM_METHOD_TYPE_BMETHOD method type in YJIT. You can get these type of methods from facilities like Kernel#define_singleton_method and Module#define_method. Even though the body of these methods are blocks, the parameter setup for them is exactly the same as VM_METHOD_TYPE_ISEQ, so we can reuse the same logic in gen_send_iseq(). You can see this from how vm_call_bmethod() eventually calls setup_parameters_complex() with arg_setup_method. Bmethods do need their frame environment to be setup differently. We handle this by allowing callers of gen_send_iseq() to control the iseq, the frame flag, and the prev_ep. The `prev_ep` goes into the same location as the block handler would go into in an iseq method frame. Co-authored-by: John Hawthorn Co-authored-by: John Hawthorn --- yjit.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'yjit.c') diff --git a/yjit.c b/yjit.c index d3ec27ab1e..cc64cccac3 100644 --- a/yjit.c +++ b/yjit.c @@ -425,6 +425,14 @@ rb_RSTRING_PTR(VALUE str) return RSTRING_PTR(str); } +rb_proc_t * +rb_yjit_get_proc_ptr(VALUE procv) +{ + rb_proc_t *proc; + GetProcPtr(procv, proc); + return proc; +} + // This is defined only as a named struct inside rb_iseq_constant_body. // By giving it a separate typedef, we make it nameable by rust-bindgen. // Bindgen's temp/anon name isn't guaranteed stable. @@ -549,6 +557,13 @@ rb_get_def_iseq_ptr(rb_method_definition_t *def) return def_iseq_ptr(def); } +VALUE +rb_get_def_bmethod_proc(rb_method_definition_t *def) +{ + RUBY_ASSERT(def->type == VM_METHOD_TYPE_BMETHOD); + return def->body.bmethod.proc; +} + const rb_iseq_t * rb_get_iseq_body_local_iseq(const rb_iseq_t *iseq) { -- cgit v1.2.3