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

rename functions and clean parameters.

* internal.h (rb_yield_lambda): rename to rb_yield_force_blockarg()
  because this function prohibt lambda arg setup (strict setup).

* vm.c (invoke_iseq_block_from_c): remove splattable argument because
  it is not used.

* vm.c (invoke_block_from_c_splattable): rename to invoke_block_from_c_bh()
  because `splattable` doesn't make sense on current this function.

  Also accept `force_blockarg' parameter instead of `splattable` parameter.
  It is more clear.

* vm.c (invoke_block_from_c_unsplattable): rename to
  invoke_block_from_c_proc() and accept `proc` instead of `block'.
  This function is used only by proc block invocation.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59016 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2017-06-05 06:15:28 +00:00
parent 88c85c8817
commit ff18933b72
4 changed files with 39 additions and 33 deletions

4
enum.c
View file

@ -43,7 +43,7 @@ static VALUE
enum_yield(int argc, VALUE ary)
{
if (argc > 1)
return rb_yield_lambda(ary);
return rb_yield_force_blockarg(ary);
if (argc == 1)
return rb_yield(ary);
return rb_yield_values2(0, 0);
@ -55,7 +55,7 @@ enum_yield_array(VALUE ary)
long len = RARRAY_LEN(ary);
if (len > 1)
return rb_yield_lambda(ary);
return rb_yield_force_blockarg(ary);
if (len == 1)
return rb_yield(RARRAY_AREF(ary, 0));
return rb_yield_values2(0, 0);

View file

@ -1741,7 +1741,7 @@ VALUE rb_check_funcall_with_hook(VALUE recv, ID mid, int argc, const VALUE *argv
VALUE rb_check_funcall_default(VALUE, ID, int, const VALUE *, VALUE);
VALUE rb_catch_protect(VALUE t, rb_block_call_func *func, VALUE data, int *stateptr);
VALUE rb_yield_1(VALUE val);
VALUE rb_yield_lambda(VALUE values);
VALUE rb_yield_force_blockarg(VALUE values);
/* vm_insnhelper.c */
VALUE rb_equal_opt(VALUE obj1, VALUE obj2);

60
vm.c
View file

@ -1004,7 +1004,7 @@ invoke_bmethod(rb_thread_t *th, const rb_iseq_t *iseq, VALUE self, const struct
static inline VALUE
invoke_iseq_block_from_c(rb_thread_t *th, const struct rb_captured_block *captured,
VALUE self, int argc, const VALUE *argv, VALUE passed_block_handler,
const rb_cref_t *cref, const int splattable, int is_lambda)
const rb_cref_t *cref, int is_lambda)
{
const rb_iseq_t *iseq = rb_iseq_check(captured->code.iseq);
int i, opt_pc;
@ -1033,10 +1033,10 @@ invoke_iseq_block_from_c(rb_thread_t *th, const struct rb_captured_block *captur
}
static inline VALUE
invoke_block_from_c_splattable(rb_thread_t *th, VALUE block_handler,
int argc, const VALUE *argv,
VALUE passed_block_handler, const rb_cref_t *cref,
int splattable, int is_lambda)
invoke_block_from_c_bh(rb_thread_t *th, VALUE block_handler,
int argc, const VALUE *argv,
VALUE passed_block_handler, const rb_cref_t *cref,
int is_lambda, int force_blockarg)
{
again:
switch (vm_block_handler_type(block_handler)) {
@ -1045,16 +1045,19 @@ invoke_block_from_c_splattable(rb_thread_t *th, VALUE block_handler,
const struct rb_captured_block *captured = VM_BH_TO_ISEQ_BLOCK(block_handler);
return invoke_iseq_block_from_c(th, captured, captured->self,
argc, argv, passed_block_handler,
cref, splattable, is_lambda);
cref, is_lambda);
}
case block_handler_type_ifunc:
return vm_yield_with_cfunc(th, VM_BH_TO_IFUNC_BLOCK(block_handler), VM_BH_TO_IFUNC_BLOCK(block_handler)->self,
return vm_yield_with_cfunc(th, 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), argc, argv, passed_block_handler);
return vm_yield_with_symbol(th, VM_BH_TO_SYMBOL(block_handler),
argc, argv, passed_block_handler);
case block_handler_type_proc:
if (!splattable)
if (force_blockarg == FALSE) {
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;
}
@ -1077,42 +1080,45 @@ 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)
{
return invoke_block_from_c_splattable(th, check_block_handler(th),
argc, argv, VM_BLOCK_HANDLER_NONE,
cref, FALSE, is_lambda);
return invoke_block_from_c_bh(th, check_block_handler(th),
argc, argv, VM_BLOCK_HANDLER_NONE,
cref, is_lambda, FALSE);
}
static VALUE
vm_yield(rb_thread_t *th, int argc, const VALUE *argv)
{
return invoke_block_from_c_splattable(th, check_block_handler(th),
argc, argv, VM_BLOCK_HANDLER_NONE,
NULL, FALSE, FALSE);
return invoke_block_from_c_bh(th, check_block_handler(th),
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)
{
return invoke_block_from_c_splattable(th, check_block_handler(th),
argc, argv, block_handler,
NULL, FALSE, FALSE);
return invoke_block_from_c_bh(th, check_block_handler(th),
argc, argv, block_handler,
NULL, FALSE, FALSE);
}
static VALUE
vm_yield_lambda_splattable(rb_thread_t *th, VALUE args)
vm_yield_force_blockarg(rb_thread_t *th, VALUE args)
{
return invoke_block_from_c_splattable(th, check_block_handler(th), 1, &args, VM_BLOCK_HANDLER_NONE, NULL, TRUE, FALSE);
return invoke_block_from_c_bh(th, check_block_handler(th), 1, &args,
VM_BLOCK_HANDLER_NONE, NULL, FALSE, TRUE);
}
static inline VALUE
invoke_block_from_c_unsplattable(rb_thread_t *th, const struct rb_block *block,
VALUE self, int argc, const VALUE *argv,
VALUE passed_block_handler, int is_lambda)
invoke_block_from_c_proc(rb_thread_t *th, const rb_proc_t *proc,
VALUE self, int argc, const VALUE *argv,
VALUE passed_block_handler, int is_lambda)
{
const struct rb_block *block = &proc->block;
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, FALSE, is_lambda);
return invoke_iseq_block_from_c(th, &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);
case block_type_symbol:
@ -1122,7 +1128,7 @@ invoke_block_from_c_unsplattable(rb_thread_t *th, const struct rb_block *block,
block = vm_proc_block(block->as.proc);
goto again;
}
VM_UNREACHABLE(invoke_block_from_c_unsplattable);
VM_UNREACHABLE(invoke_block_from_c_proc);
return Qundef;
}
@ -1137,7 +1143,7 @@ vm_invoke_proc(rb_thread_t *th, rb_proc_t *proc, VALUE self,
TH_PUSH_TAG(th);
if ((state = EXEC_TAG()) == 0) {
th->safe_level = proc->safe_level;
val = invoke_block_from_c_unsplattable(th, &proc->block, self, argc, argv, passed_block_handler, proc->is_lambda);
val = invoke_block_from_c_proc(th, proc, self, argc, argv, passed_block_handler, proc->is_lambda);
}
TH_POP_TAG();
@ -1153,7 +1159,7 @@ static VALUE
vm_invoke_bmethod(rb_thread_t *th, rb_proc_t *proc, VALUE self,
int argc, const VALUE *argv, VALUE block_handler)
{
return invoke_block_from_c_unsplattable(th, &proc->block, self, argc, argv, block_handler, TRUE);
return invoke_block_from_c_proc(th, proc, self, argc, argv, block_handler, TRUE);
}
VALUE

View file

@ -19,7 +19,7 @@ static inline VALUE method_missing(VALUE obj, ID id, int argc, const VALUE *argv
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_lambda_splattable(rb_thread_t *th, VALUE args);
static inline VALUE vm_yield_force_blockarg(rb_thread_t *th, 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(rb_thread_t *th, const VALUE *dfp, const struct local_var_list *vars);
@ -1067,9 +1067,9 @@ rb_yield_splat(VALUE values)
}
VALUE
rb_yield_lambda(VALUE values)
rb_yield_force_blockarg(VALUE values)
{
return vm_yield_lambda_splattable(GET_THREAD(), values);
return vm_yield_force_blockarg(GET_THREAD(), values);
}
VALUE