Skip to content

Commit

Permalink
vm_invoke_block: move logics around
Browse files Browse the repository at this point in the history
Moved block handler -> captured block conversion from vm_invokeblock to
each vm_invoke_*_block functions.
  • Loading branch information
shyouhei committed Jun 3, 2020
1 parent 87bc95e commit 11c70b3
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions vm_insnhelper.c
Original file line number Diff line number Diff line change
Expand Up @@ -3386,8 +3386,9 @@ vm_yield_setup_args(rb_execution_context_t *ec, const rb_iseq_t *iseq, const int
static VALUE
vm_invoke_iseq_block(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp,
struct rb_calling_info *calling, const struct rb_callinfo *ci,
int is_lambda, const struct rb_captured_block *captured)
int is_lambda, VALUE block_handler)
{
const struct rb_captured_block *captured = VM_BH_TO_ISEQ_BLOCK(block_handler);
const rb_iseq_t *iseq = rb_iseq_check(captured->code.iseq);
const int arg_size = iseq->body->param.size;
VALUE * const rsp = GET_SP() - calling->argc;
Expand All @@ -3409,10 +3410,11 @@ vm_invoke_iseq_block(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp,
static VALUE
vm_invoke_symbol_block(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp,
struct rb_calling_info *calling, const struct rb_callinfo *ci,
VALUE symbol)
VALUE block_handler)
{
VALUE val;
int argc;
VALUE symbol = VM_BH_TO_SYMBOL(block_handler);
CALLER_SETUP_ARG(ec->cfp, calling, ci);
argc = calling->argc;
val = vm_yield_with_symbol(ec, symbol, argc, STACK_ADDR_FROM_TOP(argc), calling->kw_splat, calling->block_handler);
Expand All @@ -3423,10 +3425,11 @@ vm_invoke_symbol_block(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp,
static VALUE
vm_invoke_ifunc_block(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp,
struct rb_calling_info *calling, const struct rb_callinfo *ci,
const struct rb_captured_block *captured)
VALUE block_handler)
{
VALUE val;
int argc;
const struct rb_captured_block *captured = VM_BH_TO_IFUNC_BLOCK(block_handler);
CALLER_SETUP_ARG(ec->cfp, calling, ci);
CALLER_REMOVE_EMPTY_KW_SPLAT(ec->cfp, calling, ci);
argc = calling->argc;
Expand Down Expand Up @@ -3463,21 +3466,15 @@ vm_invoke_block(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp,
again:
switch (vm_block_handler_type(block_handler)) {
case block_handler_type_iseq:
{
const struct rb_captured_block *captured = VM_BH_TO_ISEQ_BLOCK(block_handler);
return vm_invoke_iseq_block(ec, reg_cfp, calling, ci, is_lambda, captured);
}
return vm_invoke_iseq_block(ec, reg_cfp, calling, ci, is_lambda, block_handler);
case block_handler_type_ifunc:
{
const struct rb_captured_block *captured = VM_BH_TO_IFUNC_BLOCK(block_handler);
return vm_invoke_ifunc_block(ec, reg_cfp, calling, ci, captured);
}
return vm_invoke_ifunc_block(ec, reg_cfp, calling, ci, block_handler);
case block_handler_type_proc:
is_lambda = block_proc_is_lambda(VM_BH_TO_PROC(block_handler));
block_handler = vm_proc_to_block_handler(VM_BH_TO_PROC(block_handler));
goto again;
case block_handler_type_symbol:
return vm_invoke_symbol_block(ec, reg_cfp, calling, ci, VM_BH_TO_SYMBOL(block_handler));
return vm_invoke_symbol_block(ec, reg_cfp, calling, ci, block_handler);
}
VM_UNREACHABLE(vm_invoke_block: unreachable);
return Qnil;
Expand Down

0 comments on commit 11c70b3

Please sign in to comment.