th
-> ec
for block related functions.
* vm.c: the following functions accept `ec` instead of `th`. * invoke_block * invoke_bmethod * invoke_iseq_block_from_c * invoke_block_from_c_bh * check_block_handler * vm_yield_with_cref * vm_yield * vm_yield_with_block * vm_yield_force_blockarg * invoke_block_from_c_proc * vm_invoke_proc * vm_invoke_bmethod * rb_vm_invoke_proc * vm_insnhelper.c: ditto. * vm_yield_with_cfunc * vm_yield_with_symbol * vm_callee_setup_block_arg * vm_yield_setup_args * vm_invoke_iseq_block * vm_invoke_symbol_block * vm_invoke_ifunc_block * vm_invoke_block git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60476 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
91f3700296
commit
88910e94a8
2
cont.c
2
cont.c
@ -1422,7 +1422,7 @@ rb_fiber_start(void)
|
||||
th->ec->root_svar = Qfalse;
|
||||
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_FIBER_SWITCH, th->self, 0, 0, 0, Qnil);
|
||||
cont->value = rb_vm_invoke_proc(th, proc, argc, argv, VM_BLOCK_HANDLER_NONE);
|
||||
cont->value = rb_vm_invoke_proc(th->ec, proc, argc, argv, VM_BLOCK_HANDLER_NONE);
|
||||
}
|
||||
EC_POP_TAG();
|
||||
|
||||
|
@ -969,7 +969,7 @@ invokeblock
|
||||
calling.block_handler = VM_BLOCK_HANDLER_NONE;
|
||||
calling.recv = GET_SELF();
|
||||
|
||||
val = vm_invoke_block(th, GET_CFP(), &calling, ci);
|
||||
val = vm_invoke_block(th->ec, GET_CFP(), &calling, ci);
|
||||
if (val == Qundef) {
|
||||
RESTORE_REGS();
|
||||
NEXT_INSN();
|
||||
|
6
proc.c
6
proc.c
@ -884,7 +884,7 @@ rb_proc_call(VALUE self, VALUE args)
|
||||
VALUE vret;
|
||||
rb_proc_t *proc;
|
||||
GetProcPtr(self, proc);
|
||||
vret = rb_vm_invoke_proc(GET_THREAD(), proc,
|
||||
vret = rb_vm_invoke_proc(GET_EC(), proc,
|
||||
check_argc(RARRAY_LEN(args)), RARRAY_CONST_PTR(args),
|
||||
VM_BLOCK_HANDLER_NONE);
|
||||
RB_GC_GUARD(self);
|
||||
@ -901,11 +901,11 @@ proc_to_block_handler(VALUE procval)
|
||||
VALUE
|
||||
rb_proc_call_with_block(VALUE self, int argc, const VALUE *argv, VALUE passed_procval)
|
||||
{
|
||||
rb_thread_t *th = GET_THREAD();
|
||||
rb_execution_context_t *ec = GET_EC();
|
||||
VALUE vret;
|
||||
rb_proc_t *proc;
|
||||
GetProcPtr(self, proc);
|
||||
vret = rb_vm_invoke_proc(th, proc, argc, argv, proc_to_block_handler(passed_procval));
|
||||
vret = rb_vm_invoke_proc(ec, proc, argc, argv, proc_to_block_handler(passed_procval));
|
||||
RB_GC_GUARD(self);
|
||||
return vret;
|
||||
}
|
||||
|
2
thread.c
2
thread.c
@ -585,7 +585,7 @@ thread_do_start(rb_thread_t *th, VALUE args)
|
||||
th->ec->root_lep = rb_vm_proc_local_ep(th->first_proc);
|
||||
th->ec->root_svar = Qfalse;
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_THREAD_BEGIN, th->self, 0, 0, 0, Qundef);
|
||||
th->value = rb_vm_invoke_proc(th, proc,
|
||||
th->value = rb_vm_invoke_proc(th->ec, proc,
|
||||
(int)RARRAY_LEN(args), RARRAY_CONST_PTR(args),
|
||||
VM_BLOCK_HANDLER_NONE);
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_THREAD_END, th->self, 0, 0, 0, Qundef);
|
||||
|
104
vm.c
104
vm.c
@ -291,11 +291,8 @@ static void vm_collect_usage_register(int reg, int isset);
|
||||
#endif
|
||||
|
||||
static VALUE vm_make_env_object(const rb_execution_context_t *ec, rb_control_frame_t *cfp);
|
||||
|
||||
static VALUE vm_invoke_bmethod(rb_thread_t *th, rb_proc_t *proc, VALUE self,
|
||||
int argc, const VALUE *argv, VALUE block_handler);
|
||||
static VALUE vm_invoke_proc(rb_thread_t *th, rb_proc_t *proc, VALUE self,
|
||||
int argc, const VALUE *argv, VALUE block_handler);
|
||||
static VALUE vm_invoke_bmethod(rb_execution_context_t *ec, rb_proc_t *proc, VALUE self, int argc, const VALUE *argv, VALUE block_handler);
|
||||
static VALUE vm_invoke_proc(rb_execution_context_t *ec, rb_proc_t *proc, VALUE self, int argc, const VALUE *argv, VALUE block_handler);
|
||||
|
||||
#include "vm_insnhelper.h"
|
||||
#include "vm_exec.h"
|
||||
@ -972,53 +969,54 @@ rb_binding_add_dynavars(VALUE bindval, rb_binding_t *bind, int dyncount, const I
|
||||
/* C -> Ruby: block */
|
||||
|
||||
static inline VALUE
|
||||
invoke_block(rb_thread_t *th, const rb_iseq_t *iseq, VALUE self, const struct rb_captured_block *captured, const rb_cref_t *cref, VALUE type, int opt_pc)
|
||||
invoke_block(rb_execution_context_t *ec, const rb_iseq_t *iseq, VALUE self, const struct rb_captured_block *captured, const rb_cref_t *cref, VALUE type, int opt_pc)
|
||||
{
|
||||
int arg_size = iseq->body->param.size;
|
||||
|
||||
vm_push_frame(th->ec, iseq, type | VM_FRAME_FLAG_FINISH, self,
|
||||
vm_push_frame(ec, iseq, type | VM_FRAME_FLAG_FINISH, self,
|
||||
VM_GUARDED_PREV_EP(captured->ep),
|
||||
(VALUE)cref, /* cref or method */
|
||||
iseq->body->iseq_encoded + opt_pc,
|
||||
th->ec->cfp->sp + arg_size,
|
||||
ec->cfp->sp + arg_size,
|
||||
iseq->body->local_table_size - arg_size,
|
||||
iseq->body->stack_max);
|
||||
return vm_exec(th);
|
||||
return vm_exec(rb_ec_thread_ptr(ec));
|
||||
}
|
||||
|
||||
static VALUE
|
||||
invoke_bmethod(rb_thread_t *th, const rb_iseq_t *iseq, VALUE self, const struct rb_captured_block *captured, const rb_callable_method_entry_t *me, VALUE type, int opt_pc)
|
||||
invoke_bmethod(rb_execution_context_t *ec, const rb_iseq_t *iseq, VALUE self, const struct rb_captured_block *captured, const rb_callable_method_entry_t *me, VALUE type, int opt_pc)
|
||||
{
|
||||
/* bmethod */
|
||||
int arg_size = iseq->body->param.size;
|
||||
VALUE ret;
|
||||
|
||||
vm_push_frame(th->ec, iseq, type | VM_FRAME_FLAG_BMETHOD, self,
|
||||
vm_push_frame(ec, iseq, type | VM_FRAME_FLAG_BMETHOD, self,
|
||||
VM_GUARDED_PREV_EP(captured->ep),
|
||||
(VALUE)me,
|
||||
iseq->body->iseq_encoded + opt_pc,
|
||||
th->ec->cfp->sp + arg_size,
|
||||
ec->cfp->sp + arg_size,
|
||||
iseq->body->local_table_size - arg_size,
|
||||
iseq->body->stack_max);
|
||||
|
||||
RUBY_DTRACE_METHOD_ENTRY_HOOK(th, me->owner, me->def->original_id);
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_CALL, self, me->def->original_id, me->called_id, me->owner, Qnil);
|
||||
VM_ENV_FLAGS_SET(th->ec->cfp->ep, VM_FRAME_FLAG_FINISH);
|
||||
ret = vm_exec(th);
|
||||
EXEC_EVENT_HOOK(th, RUBY_EVENT_RETURN, self, me->def->original_id, me->called_id, me->owner, ret);
|
||||
RUBY_DTRACE_METHOD_RETURN_HOOK(th, me->owner, me->def->original_id);
|
||||
RUBY_DTRACE_METHOD_ENTRY_HOOK(rb_ec_thread_ptr(ec), me->owner, me->def->original_id);
|
||||
EXEC_EVENT_HOOK(rb_ec_thread_ptr(ec), RUBY_EVENT_CALL, self, me->def->original_id, me->called_id, me->owner, Qnil);
|
||||
VM_ENV_FLAGS_SET(ec->cfp->ep, VM_FRAME_FLAG_FINISH);
|
||||
ret = vm_exec(rb_ec_thread_ptr(ec));
|
||||
EXEC_EVENT_HOOK(rb_ec_thread_ptr(ec), RUBY_EVENT_RETURN, self, me->def->original_id, me->called_id, me->owner, ret);
|
||||
RUBY_DTRACE_METHOD_RETURN_HOOK(rb_ec_thread_ptr(ec), me->owner, me->def->original_id);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline VALUE
|
||||
invoke_iseq_block_from_c(rb_thread_t *th, const struct rb_captured_block *captured,
|
||||
invoke_iseq_block_from_c(rb_execution_context_t *ec, const struct rb_captured_block *captured,
|
||||
VALUE self, int argc, const VALUE *argv, VALUE passed_block_handler,
|
||||
const rb_cref_t *cref, int is_lambda)
|
||||
{
|
||||
rb_thread_t *th = rb_ec_thread_ptr(ec);
|
||||
const rb_iseq_t *iseq = rb_iseq_check(captured->code.iseq);
|
||||
int i, opt_pc;
|
||||
VALUE type = VM_FRAME_MAGIC_BLOCK | (is_lambda ? VM_FRAME_FLAG_LAMBDA : 0);
|
||||
rb_control_frame_t *cfp = th->ec->cfp;
|
||||
rb_control_frame_t *cfp = ec->cfp;
|
||||
VALUE *sp = cfp->sp;
|
||||
const rb_callable_method_entry_t *me = th->passed_bmethod_me;
|
||||
th->passed_bmethod_me = NULL;
|
||||
@ -1030,20 +1028,20 @@ invoke_iseq_block_from_c(rb_thread_t *th, const struct rb_captured_block *captur
|
||||
sp[i] = argv[i];
|
||||
}
|
||||
|
||||
opt_pc = vm_yield_setup_args(th, iseq, argc, sp, passed_block_handler,
|
||||
opt_pc = vm_yield_setup_args(ec, iseq, argc, sp, passed_block_handler,
|
||||
(is_lambda ? arg_setup_method : arg_setup_block));
|
||||
cfp->sp = sp;
|
||||
|
||||
if (me == NULL) {
|
||||
return invoke_block(th, iseq, self, captured, cref, type, opt_pc);
|
||||
return invoke_block(ec, iseq, self, captured, cref, type, opt_pc);
|
||||
}
|
||||
else {
|
||||
return invoke_bmethod(th, iseq, self, captured, me, type, opt_pc);
|
||||
return invoke_bmethod(ec, iseq, self, captured, me, type, opt_pc);
|
||||
}
|
||||
}
|
||||
|
||||
static inline VALUE
|
||||
invoke_block_from_c_bh(rb_thread_t *th, VALUE block_handler,
|
||||
invoke_block_from_c_bh(rb_execution_context_t *ec, VALUE block_handler,
|
||||
int argc, const VALUE *argv,
|
||||
VALUE passed_block_handler, const rb_cref_t *cref,
|
||||
int is_lambda, int force_blockarg)
|
||||
@ -1053,16 +1051,16 @@ invoke_block_from_c_bh(rb_thread_t *th, VALUE block_handler,
|
||||
case block_handler_type_iseq:
|
||||
{
|
||||
const struct rb_captured_block *captured = VM_BH_TO_ISEQ_BLOCK(block_handler);
|
||||
return invoke_iseq_block_from_c(th, captured, captured->self,
|
||||
return invoke_iseq_block_from_c(ec, captured, captured->self,
|
||||
argc, argv, passed_block_handler,
|
||||
cref, is_lambda);
|
||||
}
|
||||
case block_handler_type_ifunc:
|
||||
return vm_yield_with_cfunc(th, VM_BH_TO_IFUNC_BLOCK(block_handler),
|
||||
return vm_yield_with_cfunc(ec, VM_BH_TO_IFUNC_BLOCK(block_handler),
|
||||
VM_BH_TO_IFUNC_BLOCK(block_handler)->self,
|
||||
argc, argv, passed_block_handler);
|
||||
case block_handler_type_symbol:
|
||||
return vm_yield_with_symbol(th, VM_BH_TO_SYMBOL(block_handler),
|
||||
return vm_yield_with_symbol(ec, VM_BH_TO_SYMBOL(block_handler),
|
||||
argc, argv, passed_block_handler);
|
||||
case block_handler_type_proc:
|
||||
if (force_blockarg == FALSE) {
|
||||
@ -1076,9 +1074,9 @@ invoke_block_from_c_bh(rb_thread_t *th, VALUE block_handler,
|
||||
}
|
||||
|
||||
static inline VALUE
|
||||
check_block_handler(rb_thread_t *th)
|
||||
check_block_handler(rb_execution_context_t *ec)
|
||||
{
|
||||
VALUE block_handler = VM_CF_BLOCK_HANDLER(th->ec->cfp);
|
||||
VALUE block_handler = VM_CF_BLOCK_HANDLER(ec->cfp);
|
||||
vm_block_handler_verify(block_handler);
|
||||
if (UNLIKELY(block_handler == VM_BLOCK_HANDLER_NONE)) {
|
||||
rb_vm_localjump_error("no block given", Qnil, 0);
|
||||
@ -1088,38 +1086,38 @@ check_block_handler(rb_thread_t *th)
|
||||
}
|
||||
|
||||
static VALUE
|
||||
vm_yield_with_cref(rb_thread_t *th, int argc, const VALUE *argv, const rb_cref_t *cref, int is_lambda)
|
||||
vm_yield_with_cref(rb_execution_context_t *ec, int argc, const VALUE *argv, const rb_cref_t *cref, int is_lambda)
|
||||
{
|
||||
return invoke_block_from_c_bh(th, check_block_handler(th),
|
||||
return invoke_block_from_c_bh(ec, check_block_handler(ec),
|
||||
argc, argv, VM_BLOCK_HANDLER_NONE,
|
||||
cref, is_lambda, FALSE);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
vm_yield(rb_thread_t *th, int argc, const VALUE *argv)
|
||||
vm_yield(rb_execution_context_t *ec, int argc, const VALUE *argv)
|
||||
{
|
||||
return invoke_block_from_c_bh(th, check_block_handler(th),
|
||||
return invoke_block_from_c_bh(ec, check_block_handler(ec),
|
||||
argc, argv, VM_BLOCK_HANDLER_NONE,
|
||||
NULL, FALSE, FALSE);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
vm_yield_with_block(rb_thread_t *th, int argc, const VALUE *argv, VALUE block_handler)
|
||||
vm_yield_with_block(rb_execution_context_t *ec, int argc, const VALUE *argv, VALUE block_handler)
|
||||
{
|
||||
return invoke_block_from_c_bh(th, check_block_handler(th),
|
||||
return invoke_block_from_c_bh(ec, check_block_handler(ec),
|
||||
argc, argv, block_handler,
|
||||
NULL, FALSE, FALSE);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
vm_yield_force_blockarg(rb_thread_t *th, VALUE args)
|
||||
vm_yield_force_blockarg(rb_execution_context_t *ec, VALUE args)
|
||||
{
|
||||
return invoke_block_from_c_bh(th, check_block_handler(th), 1, &args,
|
||||
return invoke_block_from_c_bh(ec, check_block_handler(ec), 1, &args,
|
||||
VM_BLOCK_HANDLER_NONE, NULL, FALSE, TRUE);
|
||||
}
|
||||
|
||||
static inline VALUE
|
||||
invoke_block_from_c_proc(rb_thread_t *th, const rb_proc_t *proc,
|
||||
invoke_block_from_c_proc(rb_execution_context_t *ec, const rb_proc_t *proc,
|
||||
VALUE self, int argc, const VALUE *argv,
|
||||
VALUE passed_block_handler, int is_lambda)
|
||||
{
|
||||
@ -1128,11 +1126,11 @@ invoke_block_from_c_proc(rb_thread_t *th, const rb_proc_t *proc,
|
||||
again:
|
||||
switch (vm_block_type(block)) {
|
||||
case block_type_iseq:
|
||||
return invoke_iseq_block_from_c(th, &block->as.captured, self, argc, argv, passed_block_handler, NULL, is_lambda);
|
||||
return invoke_iseq_block_from_c(ec, &block->as.captured, self, argc, argv, passed_block_handler, NULL, is_lambda);
|
||||
case block_type_ifunc:
|
||||
return vm_yield_with_cfunc(th, &block->as.captured, self, argc, argv, passed_block_handler);
|
||||
return vm_yield_with_cfunc(ec, &block->as.captured, self, argc, argv, passed_block_handler);
|
||||
case block_type_symbol:
|
||||
return vm_yield_with_symbol(th, block->as.symbol, argc, argv, passed_block_handler);
|
||||
return vm_yield_with_symbol(ec, block->as.symbol, argc, argv, passed_block_handler);
|
||||
case block_type_proc:
|
||||
is_lambda = block_proc_is_lambda(block->as.proc);
|
||||
block = vm_proc_block(block->as.proc);
|
||||
@ -1143,47 +1141,47 @@ invoke_block_from_c_proc(rb_thread_t *th, const rb_proc_t *proc,
|
||||
}
|
||||
|
||||
static VALUE
|
||||
vm_invoke_proc(rb_thread_t *th, rb_proc_t *proc, VALUE self,
|
||||
vm_invoke_proc(rb_execution_context_t *ec, rb_proc_t *proc, VALUE self,
|
||||
int argc, const VALUE *argv, VALUE passed_block_handler)
|
||||
{
|
||||
VALUE val = Qundef;
|
||||
enum ruby_tag_type state;
|
||||
volatile int stored_safe = th->ec->safe_level;
|
||||
volatile int stored_safe = ec->safe_level;
|
||||
|
||||
EC_PUSH_TAG(th->ec);
|
||||
EC_PUSH_TAG(ec);
|
||||
if ((state = EXEC_TAG()) == TAG_NONE) {
|
||||
th->ec->safe_level = proc->safe_level;
|
||||
val = invoke_block_from_c_proc(th, proc, self, argc, argv, passed_block_handler, proc->is_lambda);
|
||||
ec->safe_level = proc->safe_level;
|
||||
val = invoke_block_from_c_proc(ec, proc, self, argc, argv, passed_block_handler, proc->is_lambda);
|
||||
}
|
||||
EC_POP_TAG();
|
||||
|
||||
th->ec->safe_level = stored_safe;
|
||||
ec->safe_level = stored_safe;
|
||||
|
||||
if (state) {
|
||||
EC_JUMP_TAG(th->ec, state);
|
||||
EC_JUMP_TAG(ec, state);
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
vm_invoke_bmethod(rb_thread_t *th, rb_proc_t *proc, VALUE self,
|
||||
vm_invoke_bmethod(rb_execution_context_t *ec, rb_proc_t *proc, VALUE self,
|
||||
int argc, const VALUE *argv, VALUE block_handler)
|
||||
{
|
||||
return invoke_block_from_c_proc(th, proc, self, argc, argv, block_handler, TRUE);
|
||||
return invoke_block_from_c_proc(ec, proc, self, argc, argv, block_handler, TRUE);
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_vm_invoke_proc(rb_thread_t *th, rb_proc_t *proc,
|
||||
rb_vm_invoke_proc(rb_execution_context_t *ec, rb_proc_t *proc,
|
||||
int argc, const VALUE *argv, VALUE passed_block_handler)
|
||||
{
|
||||
VALUE self = vm_block_self(&proc->block);
|
||||
vm_block_handler_verify(passed_block_handler);
|
||||
|
||||
if (proc->is_from_method) {
|
||||
return vm_invoke_bmethod(th, proc, self, argc, argv, passed_block_handler);
|
||||
return vm_invoke_bmethod(ec, proc, self, argc, argv, passed_block_handler);
|
||||
}
|
||||
else {
|
||||
return vm_invoke_proc(th, proc, self, argc, argv, passed_block_handler);
|
||||
return vm_invoke_proc(ec, proc, self, argc, argv, passed_block_handler);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1499,7 +1499,7 @@ void rb_iseq_pathobj_set(const rb_iseq_t *iseq, VALUE path, VALUE realpath);
|
||||
|
||||
int rb_thread_method_id_and_class(rb_thread_t *th, ID *idp, ID *called_idp, VALUE *klassp);
|
||||
|
||||
VALUE rb_vm_invoke_proc(rb_thread_t *th, rb_proc_t *proc, int argc, const VALUE *argv, VALUE block_handler);
|
||||
VALUE rb_vm_invoke_proc(rb_execution_context_t *ec, rb_proc_t *proc, int argc, const VALUE *argv, VALUE block_handler);
|
||||
VALUE rb_vm_make_proc_lambda(const rb_execution_context_t *ec, const struct rb_captured_block *captured, VALUE klass, int8_t is_lambda);
|
||||
VALUE rb_vm_make_proc(const rb_execution_context_t *ec, const struct rb_captured_block *captured, VALUE klass);
|
||||
VALUE rb_vm_make_binding(rb_thread_t *th, const rb_control_frame_t *src_cfp);
|
||||
|
36
vm_eval.c
36
vm_eval.c
@ -16,10 +16,10 @@ struct local_var_list {
|
||||
};
|
||||
|
||||
static inline VALUE method_missing(VALUE obj, ID id, int argc, const VALUE *argv, enum method_missing_reason call_status);
|
||||
static inline VALUE vm_yield_with_cref(rb_thread_t *th, int argc, const VALUE *argv, const rb_cref_t *cref, int is_lambda);
|
||||
static inline VALUE vm_yield(rb_thread_t *th, int argc, const VALUE *argv);
|
||||
static inline VALUE vm_yield_with_block(rb_thread_t *th, int argc, const VALUE *argv, VALUE block_handler);
|
||||
static inline VALUE vm_yield_force_blockarg(rb_thread_t *th, VALUE args);
|
||||
static inline VALUE vm_yield_with_cref(rb_execution_context_t *ec, int argc, const VALUE *argv, const rb_cref_t *cref, int is_lambda);
|
||||
static inline VALUE vm_yield(rb_execution_context_t *ec, int argc, const VALUE *argv);
|
||||
static inline VALUE vm_yield_with_block(rb_execution_context_t *ec, int argc, const VALUE *argv, VALUE block_handler);
|
||||
static inline VALUE vm_yield_force_blockarg(rb_execution_context_t *ec, VALUE args);
|
||||
static VALUE vm_exec(rb_thread_t *th);
|
||||
static void vm_set_eval_stack(rb_thread_t * th, const rb_iseq_t *iseq, const rb_cref_t *cref, const struct rb_block *base_block);
|
||||
static int vm_collect_local_variables_in_heap(const VALUE *dfp, const struct local_var_list *vars);
|
||||
@ -183,7 +183,7 @@ vm_call0_body(rb_execution_context_t *ec, struct rb_calling_info *calling, const
|
||||
{
|
||||
rb_proc_t *proc;
|
||||
GetProcPtr(calling->recv, proc);
|
||||
ret = rb_vm_invoke_proc(rb_ec_thread_ptr(ec), proc, calling->argc, argv, calling->block_handler);
|
||||
ret = rb_vm_invoke_proc(ec, proc, calling->argc, argv, calling->block_handler);
|
||||
goto success;
|
||||
}
|
||||
default:
|
||||
@ -966,7 +966,7 @@ rb_f_public_send(int argc, VALUE *argv, VALUE recv)
|
||||
static inline VALUE
|
||||
rb_yield_0(int argc, const VALUE * argv)
|
||||
{
|
||||
return vm_yield(GET_THREAD(), argc, argv);
|
||||
return vm_yield(GET_EC(), argc, argv);
|
||||
}
|
||||
|
||||
VALUE
|
||||
@ -1031,13 +1031,13 @@ rb_yield_splat(VALUE values)
|
||||
VALUE
|
||||
rb_yield_force_blockarg(VALUE values)
|
||||
{
|
||||
return vm_yield_force_blockarg(GET_THREAD(), values);
|
||||
return vm_yield_force_blockarg(GET_EC(), values);
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_yield_block(VALUE val, VALUE arg, int argc, const VALUE *argv, VALUE blockarg)
|
||||
{
|
||||
return vm_yield_with_block(GET_THREAD(), argc, argv,
|
||||
return vm_yield_with_block(GET_EC(), argc, argv,
|
||||
NIL_P(blockarg) ? VM_BLOCK_HANDLER_NONE : blockarg);
|
||||
}
|
||||
|
||||
@ -1544,8 +1544,8 @@ rb_eval_cmd(VALUE cmd, VALUE arg, int level)
|
||||
static VALUE
|
||||
yield_under(VALUE under, VALUE self, int argc, const VALUE *argv)
|
||||
{
|
||||
rb_thread_t *th = GET_THREAD();
|
||||
rb_control_frame_t *cfp = th->ec->cfp;
|
||||
rb_execution_context_t *ec = GET_EC();
|
||||
rb_control_frame_t *cfp = ec->cfp;
|
||||
VALUE block_handler = VM_CF_BLOCK_HANDLER(cfp);
|
||||
VALUE new_block_handler = 0;
|
||||
const struct rb_captured_block *captured = NULL;
|
||||
@ -1579,18 +1579,18 @@ yield_under(VALUE under, VALUE self, int argc, const VALUE *argv)
|
||||
new_captured.self = self;
|
||||
ep = captured->ep;
|
||||
|
||||
VM_FORCE_WRITE_SPECIAL_CONST(&VM_CF_LEP(th->ec->cfp)[VM_ENV_DATA_INDEX_SPECVAL], new_block_handler);
|
||||
VM_FORCE_WRITE_SPECIAL_CONST(&VM_CF_LEP(ec->cfp)[VM_ENV_DATA_INDEX_SPECVAL], new_block_handler);
|
||||
}
|
||||
|
||||
cref = vm_cref_push(th->ec, under, ep, TRUE);
|
||||
return vm_yield_with_cref(th, argc, argv, cref, is_lambda);
|
||||
cref = vm_cref_push(ec, under, ep, TRUE);
|
||||
return vm_yield_with_cref(ec, argc, argv, cref, is_lambda);
|
||||
}
|
||||
|
||||
VALUE
|
||||
rb_yield_refine_block(VALUE refinement, VALUE refinements)
|
||||
{
|
||||
rb_thread_t *th = GET_THREAD();
|
||||
VALUE block_handler = VM_CF_BLOCK_HANDLER(th->ec->cfp);
|
||||
rb_execution_context_t *ec = GET_EC();
|
||||
VALUE block_handler = VM_CF_BLOCK_HANDLER(ec->cfp);
|
||||
|
||||
if (vm_block_handler_type(block_handler) != block_handler_type_iseq) {
|
||||
rb_bug("rb_yield_refine_block: an iseq block is required");
|
||||
@ -1600,11 +1600,11 @@ rb_yield_refine_block(VALUE refinement, VALUE refinements)
|
||||
struct rb_captured_block new_captured = *captured;
|
||||
VALUE new_block_handler = VM_BH_FROM_ISEQ_BLOCK(&new_captured);
|
||||
const VALUE *ep = captured->ep;
|
||||
rb_cref_t *cref = vm_cref_push(th->ec, refinement, ep, TRUE);
|
||||
rb_cref_t *cref = vm_cref_push(ec, refinement, ep, TRUE);
|
||||
CREF_REFINEMENTS_SET(cref, refinements);
|
||||
VM_FORCE_WRITE_SPECIAL_CONST(&VM_CF_LEP(th->ec->cfp)[VM_ENV_DATA_INDEX_SPECVAL], new_block_handler);
|
||||
VM_FORCE_WRITE_SPECIAL_CONST(&VM_CF_LEP(ec->cfp)[VM_ENV_DATA_INDEX_SPECVAL], new_block_handler);
|
||||
new_captured.self = refinement;
|
||||
return vm_yield_with_cref(th, 0, NULL, cref, FALSE);
|
||||
return vm_yield_with_cref(ec, 0, NULL, cref, FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1964,7 +1964,7 @@ vm_call_bmethod_body(rb_execution_context_t *ec, struct rb_calling_info *calling
|
||||
/* control block frame */
|
||||
rb_ec_thread_ptr(ec)->passed_bmethod_me = cc->me;
|
||||
GetProcPtr(cc->me->def->body.proc, proc);
|
||||
val = vm_invoke_bmethod(rb_ec_thread_ptr(ec), proc, calling->recv, calling->argc, argv, calling->block_handler);
|
||||
val = vm_invoke_bmethod(ec, proc, calling->recv, calling->argc, argv, calling->block_handler);
|
||||
|
||||
return val;
|
||||
}
|
||||
@ -2068,7 +2068,7 @@ vm_call_opt_call(rb_execution_context_t *ec, rb_control_frame_t *cfp, struct rb_
|
||||
MEMCPY(argv, cfp->sp - argc, VALUE, argc);
|
||||
cfp->sp -= argc + 1;
|
||||
|
||||
return rb_vm_invoke_proc(rb_ec_thread_ptr(ec), proc, argc, argv, calling->block_handler);
|
||||
return rb_vm_invoke_proc(ec, proc, argc, argv, calling->block_handler);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
@ -2499,10 +2499,11 @@ block_proc_is_lambda(const VALUE procval)
|
||||
}
|
||||
|
||||
static VALUE
|
||||
vm_yield_with_cfunc(rb_thread_t *th,
|
||||
vm_yield_with_cfunc(rb_execution_context_t *ec,
|
||||
const struct rb_captured_block *captured,
|
||||
VALUE self, int argc, const VALUE *argv, VALUE block_handler)
|
||||
{
|
||||
rb_thread_t *th = rb_ec_thread_ptr(ec);
|
||||
int is_lambda = FALSE; /* TODO */
|
||||
VALUE val, arg, blockarg;
|
||||
const struct vm_ifunc *ifunc = captured->code.ifunc;
|
||||
@ -2519,24 +2520,24 @@ vm_yield_with_cfunc(rb_thread_t *th,
|
||||
arg = argv[0];
|
||||
}
|
||||
|
||||
blockarg = rb_vm_bh_to_procval(th->ec, block_handler);
|
||||
blockarg = rb_vm_bh_to_procval(ec, block_handler);
|
||||
|
||||
vm_push_frame(th->ec, (const rb_iseq_t *)captured->code.ifunc,
|
||||
vm_push_frame(ec, (const rb_iseq_t *)captured->code.ifunc,
|
||||
VM_FRAME_MAGIC_IFUNC | VM_FRAME_FLAG_CFRAME,
|
||||
self,
|
||||
VM_GUARDED_PREV_EP(captured->ep),
|
||||
(VALUE)me,
|
||||
0, th->ec->cfp->sp, 0, 0);
|
||||
0, ec->cfp->sp, 0, 0);
|
||||
val = (*ifunc->func)(arg, ifunc->data, argc, argv, blockarg);
|
||||
rb_vm_pop_frame(th->ec);
|
||||
rb_vm_pop_frame(ec);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
vm_yield_with_symbol(rb_thread_t *th, VALUE symbol, int argc, const VALUE *argv, VALUE block_handler)
|
||||
vm_yield_with_symbol(rb_execution_context_t *ec, VALUE symbol, int argc, const VALUE *argv, VALUE block_handler)
|
||||
{
|
||||
return rb_sym_proc_call(SYM2ID(symbol), argc, argv, rb_vm_bh_to_procval(th->ec, block_handler));
|
||||
return rb_sym_proc_call(SYM2ID(symbol), argc, argv, rb_vm_bh_to_procval(ec, block_handler));
|
||||
}
|
||||
|
||||
static inline int
|
||||
@ -2568,10 +2569,10 @@ vm_callee_setup_block_arg_arg0_check(VALUE *argv)
|
||||
}
|
||||
|
||||
static int
|
||||
vm_callee_setup_block_arg(rb_thread_t *th, struct rb_calling_info *calling, const struct rb_call_info *ci, const rb_iseq_t *iseq, VALUE *argv, const enum arg_setup_type arg_setup_type)
|
||||
vm_callee_setup_block_arg(rb_execution_context_t *ec, struct rb_calling_info *calling, const struct rb_call_info *ci, const rb_iseq_t *iseq, VALUE *argv, const enum arg_setup_type arg_setup_type)
|
||||
{
|
||||
if (simple_iseq_p(iseq)) {
|
||||
rb_control_frame_t *cfp = th->ec->cfp;
|
||||
rb_control_frame_t *cfp = ec->cfp;
|
||||
VALUE arg0;
|
||||
|
||||
CALLER_SETUP_ARG(cfp, calling, ci); /* splat arg */
|
||||
@ -2597,19 +2598,19 @@ vm_callee_setup_block_arg(rb_thread_t *th, struct rb_calling_info *calling, cons
|
||||
}
|
||||
}
|
||||
else {
|
||||
argument_arity_error(th->ec, iseq, calling->argc, iseq->body->param.lead_num, iseq->body->param.lead_num);
|
||||
argument_arity_error(ec, iseq, calling->argc, iseq->body->param.lead_num, iseq->body->param.lead_num);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return setup_parameters_complex(th->ec, iseq, calling, ci, argv, arg_setup_type);
|
||||
return setup_parameters_complex(ec, iseq, calling, ci, argv, arg_setup_type);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
vm_yield_setup_args(rb_thread_t *th, const rb_iseq_t *iseq, const int argc, VALUE *argv, VALUE block_handler, enum arg_setup_type arg_setup_type)
|
||||
vm_yield_setup_args(rb_execution_context_t *ec, const rb_iseq_t *iseq, const int argc, VALUE *argv, VALUE block_handler, enum arg_setup_type arg_setup_type)
|
||||
{
|
||||
struct rb_calling_info calling_entry, *calling;
|
||||
struct rb_call_info ci_entry, *ci;
|
||||
@ -2621,24 +2622,24 @@ vm_yield_setup_args(rb_thread_t *th, const rb_iseq_t *iseq, const int argc, VALU
|
||||
ci_entry.flag = 0;
|
||||
ci = &ci_entry;
|
||||
|
||||
return vm_callee_setup_block_arg(th, calling, ci, iseq, argv, arg_setup_type);
|
||||
return vm_callee_setup_block_arg(ec, calling, ci, iseq, argv, arg_setup_type);
|
||||
}
|
||||
|
||||
/* ruby iseq -> ruby block */
|
||||
|
||||
static VALUE
|
||||
vm_invoke_iseq_block(rb_thread_t *th, rb_control_frame_t *reg_cfp,
|
||||
vm_invoke_iseq_block(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp,
|
||||
struct rb_calling_info *calling, const struct rb_call_info *ci,
|
||||
int is_lambda, const struct rb_captured_block *captured)
|
||||
{
|
||||
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;
|
||||
int opt_pc = vm_callee_setup_block_arg(th, calling, ci, iseq, rsp, is_lambda ? arg_setup_method : arg_setup_block);
|
||||
int opt_pc = vm_callee_setup_block_arg(ec, calling, ci, iseq, rsp, is_lambda ? arg_setup_method : arg_setup_block);
|
||||
|
||||
SET_SP(rsp);
|
||||
|
||||
vm_push_frame(th->ec, iseq,
|
||||
vm_push_frame(ec, iseq,
|
||||
VM_FRAME_MAGIC_BLOCK | (is_lambda ? VM_FRAME_FLAG_LAMBDA : 0),
|
||||
captured->self,
|
||||
VM_GUARDED_PREV_EP(captured->ep), 0,
|
||||
@ -2650,29 +2651,29 @@ vm_invoke_iseq_block(rb_thread_t *th, rb_control_frame_t *reg_cfp,
|
||||
}
|
||||
|
||||
static VALUE
|
||||
vm_invoke_symbol_block(rb_thread_t *th, rb_control_frame_t *reg_cfp,
|
||||
vm_invoke_symbol_block(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp,
|
||||
struct rb_calling_info *calling, const struct rb_call_info *ci,
|
||||
VALUE symbol)
|
||||
{
|
||||
VALUE val;
|
||||
int argc;
|
||||
CALLER_SETUP_ARG(th->ec->cfp, calling, ci);
|
||||
CALLER_SETUP_ARG(ec->cfp, calling, ci);
|
||||
argc = calling->argc;
|
||||
val = vm_yield_with_symbol(th, symbol, argc, STACK_ADDR_FROM_TOP(argc), VM_BLOCK_HANDLER_NONE);
|
||||
val = vm_yield_with_symbol(ec, symbol, argc, STACK_ADDR_FROM_TOP(argc), VM_BLOCK_HANDLER_NONE);
|
||||
POPN(argc);
|
||||
return val;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
vm_invoke_ifunc_block(rb_thread_t *th, rb_control_frame_t *reg_cfp,
|
||||
vm_invoke_ifunc_block(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp,
|
||||
struct rb_calling_info *calling, const struct rb_call_info *ci,
|
||||
const struct rb_captured_block *captured)
|
||||
{
|
||||
VALUE val;
|
||||
int argc;
|
||||
CALLER_SETUP_ARG(th->ec->cfp, calling, ci);
|
||||
CALLER_SETUP_ARG(ec->cfp, calling, ci);
|
||||
argc = calling->argc;
|
||||
val = vm_yield_with_cfunc(th, captured, captured->self, argc, STACK_ADDR_FROM_TOP(argc), VM_BLOCK_HANDLER_NONE);
|
||||
val = vm_yield_with_cfunc(ec, captured, captured->self, argc, STACK_ADDR_FROM_TOP(argc), VM_BLOCK_HANDLER_NONE);
|
||||
POPN(argc); /* TODO: should put before C/yield? */
|
||||
return val;
|
||||
}
|
||||
@ -2697,7 +2698,7 @@ vm_proc_to_block_handler(VALUE procval)
|
||||
}
|
||||
|
||||
static VALUE
|
||||
vm_invoke_block(rb_thread_t *th, rb_control_frame_t *reg_cfp, struct rb_calling_info *calling, const struct rb_call_info *ci)
|
||||
vm_invoke_block(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, struct rb_calling_info *calling, const struct rb_call_info *ci)
|
||||
{
|
||||
VALUE block_handler = VM_CF_BLOCK_HANDLER(reg_cfp);
|
||||
VALUE type = GET_ISEQ()->body->local_iseq->body->type;
|
||||
@ -2713,19 +2714,19 @@ vm_invoke_block(rb_thread_t *th, rb_control_frame_t *reg_cfp, struct rb_calling_
|
||||
case block_handler_type_iseq:
|
||||
{
|
||||
const struct rb_captured_block *captured = VM_BH_TO_ISEQ_BLOCK(block_handler);
|
||||
return vm_invoke_iseq_block(th, reg_cfp, calling, ci, is_lambda, captured);
|
||||
return vm_invoke_iseq_block(ec, reg_cfp, calling, ci, is_lambda, captured);
|
||||
}
|
||||
case block_handler_type_ifunc:
|
||||
{
|
||||
const struct rb_captured_block *captured = VM_BH_TO_IFUNC_BLOCK(block_handler);
|
||||
return vm_invoke_ifunc_block(th, reg_cfp, calling, ci, captured);
|
||||
return vm_invoke_ifunc_block(ec, reg_cfp, calling, ci, captured);
|
||||
}
|
||||
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(th, reg_cfp, calling, ci, VM_BH_TO_SYMBOL(block_handler));
|
||||
return vm_invoke_symbol_block(ec, reg_cfp, calling, ci, VM_BH_TO_SYMBOL(block_handler));
|
||||
}
|
||||
VM_UNREACHABLE(vm_invoke_block: unreachable);
|
||||
return Qnil;
|
||||
|
Loading…
x
Reference in New Issue
Block a user