17#if !defined(_MSC_VER) || !defined(MJIT_HEADER)
61args_extend(
struct args_info *args,
const int min_argc)
68 for (i=args->
argc + RARRAY_LENINT(args->
rest); i<min_argc; i++) {
73 for (i=args->
argc; i<min_argc; i++) {
80args_reduce(
struct args_info *args,
int over_argc)
85 if (
len > over_argc) {
97 args->
argc -= over_argc;
101args_check_block_arg0(
struct args_info *args)
109 else if (args->
argc == 1) {
112 args->
argv[0] = arg0;
160 else if (args->
argc > 0) {
168static inline const VALUE *
191args_kw_argv_to_hash(
struct args_info *args)
197 const int kw_start = args->
argc - kw_len;
198 const VALUE *
const kw_argv = args->
argv + kw_start;
201 args->
argc = kw_start + 1;
202 for (i=0; i<kw_len; i++) {
221 const VALUE *
argv = args_rest_argv(args);
223 for (i=args->
argc, j=0; i<
argc; i++, j++) {
241args_setup_opt_parameters(
struct args_info *args,
int opt_max,
VALUE *locals)
245 if (args->
argc >= opt_max) {
246 args->
argc -= opt_max;
247 args->
argv += opt_max;
256 int len = RARRAY_LENINT(args->
rest);
265 for (j=i; j<opt_max; j++) {
276 *locals = args_rest_array(args);
280make_unknown_kw_hash(
const VALUE *passed_keywords,
int passed_keyword_len,
const VALUE *kw_argv)
285 for (i=0; i<passed_keyword_len; i++) {
286 if (kw_argv[i] !=
Qundef) {
294make_rest_kw_hash(
const VALUE *passed_keywords,
int passed_keyword_len,
const VALUE *kw_argv)
299 for (i=0; i<passed_keyword_len; i++) {
300 if (kw_argv[i] !=
Qundef) {
308args_setup_kw_parameters_lookup(
const ID key,
VALUE *
ptr,
const VALUE *
const passed_keywords,
VALUE *passed_values,
const int passed_keyword_len)
313 for (i=0; i<passed_keyword_len; i++) {
314 if (keyname == passed_keywords[i]) {
315 *
ptr = passed_values[i];
316 passed_values[i] =
Qundef;
324#define KW_SPECIFIED_BITS_MAX (32-1)
328 VALUE *
const passed_values,
const int passed_keyword_len,
const VALUE *
const passed_keywords,
336 int i, di, found = 0;
337 int unspecified_bits = 0;
340 for (i=0; i<req_key_num; i++) {
341 ID key = acceptable_keywords[i];
342 if (args_setup_kw_parameters_lookup(
key, &locals[i], passed_keywords, passed_values, passed_keyword_len)) {
351 if (missing) argument_kw_error(ec, iseq,
"missing", missing);
353 for (di=0; i<key_num; i++, di++) {
354 if (args_setup_kw_parameters_lookup(acceptable_keywords[i], &locals[i], passed_keywords, passed_values, passed_keyword_len)) {
358 if (default_values[di] ==
Qundef) {
362 unspecified_bits |= 0x01 << di;
365 if (
NIL_P(unspecified_bits_value)) {
371 if (unspecified_bits & (0x01 << j)) {
380 locals[i] = default_values[di];
386 const int rest_hash_index = key_num + 1;
387 locals[rest_hash_index] = make_rest_kw_hash(passed_keywords, passed_keyword_len, passed_values);
390 if (found != passed_keyword_len) {
391 VALUE keys = make_unknown_kw_hash(passed_keywords, passed_keyword_len, passed_values);
392 argument_kw_error(ec, iseq,
"unknown", keys);
396 if (
NIL_P(unspecified_bits_value)) {
397 unspecified_bits_value =
INT2FIX(unspecified_bits);
399 locals[key_num] = unspecified_bits_value;
403args_setup_kw_rest_parameter(
VALUE keyword_hash,
VALUE *locals,
int kw_flag)
405 if (
NIL_P(keyword_hash)) {
411 locals[0] = keyword_hash;
438ignore_keyword_hash_p(
VALUE keyword_hash,
const rb_iseq_t *
const iseq,
unsigned int * kw_flag,
VALUE * converted_keyword_hash)
440 if (!RB_TYPE_P(keyword_hash,
T_HASH)) {
449 *converted_keyword_hash = keyword_hash;
465 int opt_pc = 0, allow_autosplat = !kw_flag;
470 VALUE flag_keyword_hash = 0;
471 VALUE converted_keyword_hash = 0;
488 for (i=calling->
argc; i<iseq->body->param.size; i++) {
491 ec->
cfp->
sp = &locals[i];
495 given_argc = args->
argc = calling->
argc;
500 args->
kw_arg = vm_ci_kwarg(ci);
506 args->
argc -= kw_len;
507 given_argc -= kw_len;
512 given_argc = args_kw_argv_to_hash(args);
526 len = RARRAY_LENINT(args->
rest);
527 given_argc +=
len - 1;
530 if (!kw_flag &&
len > 0) {
531 if (RB_TYPE_P(rest_last,
T_HASH) &&
542 if (ignore_keyword_hash_p(rest_last, iseq, &kw_flag, &converted_keyword_hash)) {
549 if (rest_last != converted_keyword_hash) {
550 rest_last = converted_keyword_hash;
552 RARRAY_ASET(args->
rest,
len - 1, rest_last);
556 flag_keyword_hash = rest_last;
562 keyword_hash = rest_last;
570 if (ignore_keyword_hash_p(last_arg, iseq, &kw_flag, &converted_keyword_hash)) {
576 if (last_arg != converted_keyword_hash) {
577 last_arg = converted_keyword_hash;
578 args->
argv[args->
argc-1] = last_arg;
582 flag_keyword_hash = last_arg;
587 keyword_hash = last_arg;
594 if (flag_keyword_hash && RB_TYPE_P(flag_keyword_hash,
T_HASH)) {
607 if (given_argc == (keyword_hash ==
Qnil ? 1 : 2) &&
611 args_check_block_arg0(args)) {
612 given_argc = RARRAY_LENINT(args->
rest);
618 if (given_argc < min_argc) {
621 given_argc = min_argc;
622 args_extend(args, min_argc);
625 argument_arity_error(ec, iseq, given_argc, min_argc, max_argc);
632 args_reduce(args, given_argc - max_argc);
633 given_argc = max_argc;
636 argument_arity_error(ec, iseq, given_argc, min_argc, max_argc);
668 else if (!
NIL_P(keyword_hash)) {
673 arg.vals = arg.keys + kw_len;
677 args_setup_kw_parameters(ec, iseq, arg.vals, kw_len, arg.keys, klocals);
681 args_setup_kw_parameters(ec, iseq,
NULL, 0,
NULL, klocals);
685 args_setup_kw_rest_parameter(keyword_hash, locals + iseq->
body->
param.
keyword->rest_start, kw_flag);
688 argument_kw_error(ec, iseq,
"unknown",
rb_hash_keys(keyword_hash));
704 fprintf(stderr,
"local[%d] = %p\n", i, (
void *)locals[i]);
709 ec->
cfp->
sp = orig_sp;
739 VALUE exc = rb_arity_error_new(miss_argc, min_argc, max_argc);
742 const ID *keywords = kw->table;
743 int req_key_num = kw->required_num;
744 if (req_key_num > 0) {
745 static const char required[] =
"; required keywords";
748 rb_str_cat(mesg, required,
sizeof(required) - 1 - (req_key_num == 1));
754 }
while (--req_key_num);
758 raise_argument_error(ec, iseq, exc);
783 for (i = 0; i <
len; i++) {
786 calling->
argc += i - 1;
793 const VALUE *
const passed_keywords = vm_ci_kwarg(ci)->keywords;
794 const int kw_len = vm_ci_kwarg(ci)->keyword_len;
799 for (i=0; i<kw_len; i++) {
804 cfp->
sp -= kw_len - 1;
805 calling->
argc -= kw_len - 1;
810vm_to_proc(
VALUE proc)
827 "wrong argument type %s (expected Proc)",
864 if (!
NIL_P(blockarg)) {
865 vm_passed_block_handler_set(ec, blockarg);
878 VALUE block_code = *(--reg_cfp->
sp);
880 if (
NIL_P(block_code)) {
884 VM_ASSERT(!VM_CFP_IN_HEAP_P(GET_EC(), reg_cfp));
885 VALUE handler = VM_CF_BLOCK_HANDLER(reg_cfp);
908 return vm_to_proc(block_code);
911 else if (blockiseq !=
NULL) {
914 return VM_BH_FROM_ISEQ_BLOCK(captured);
VALUE rb_ary_new_from_values(long n, const VALUE *elts)
VALUE rb_ary_dup(VALUE ary)
VALUE rb_ary_push(VALUE ary, VALUE item)
VALUE rb_ary_unshift(VALUE ary, VALUE item)
VALUE rb_ary_behead(VALUE ary, long n)
VALUE rb_check_array_type(VALUE ary)
VALUE rb_ary_resize(VALUE ary, long len)
expands or shrinks ary to len elements.
VALUE rb_ary_pop(VALUE ary)
VALUE rb_ary_tmp_new(long capa)
#define MJIT_FUNC_EXPORTED
VALUE rb_ec_backtrace_object(const rb_execution_context_t *ec)
#define RSTRING_LEN(string)
#define RSTRING_PTR(string)
VALUE rb_keyword_error_new(const char *error, VALUE keys)
void rb_raise(VALUE exc, const char *fmt,...)
VALUE rb_exc_set_backtrace(VALUE exc, VALUE bt)
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
VALUE rb_check_convert_type_with_id(VALUE, int, const char *, ID)
VALUE rb_to_hash_type(VALUE hash)
void rb_hash_foreach(VALUE hash, rb_foreach_func *func, VALUE farg)
VALUE rb_hash_new_with_size(st_index_t size)
VALUE rb_hash_keys(VALUE hash)
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
VALUE rb_hash_lookup(VALUE hash, VALUE key)
VALUE rb_hash_dup(VALUE hash)
#define UNLIMITED_ARGUMENTS
VALUE rb_obj_is_proc(VALUE)
VALUE rb_str_resize(VALUE, long)
VALUE rb_str_cat(VALUE, const char *, long)
VALUE rb_str_append(VALUE, VALUE)
#define rb_str_cat_cstr(buf, str)
VALUE rb_attr_get(VALUE, ID)
VALUE rb_ivar_set(VALUE, ID, VALUE)
VALUE rb_func_lambda_new(rb_block_call_func_t func, VALUE val, int min_argc, int max_argc)
void rb_backtrace_use_iseq_first_lineno_for_last_location(VALUE self)
#define rb_method_basic_definition_p(...)
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)
#define MEMCPY(p1, p2, type, n)
#define ALLOCA_N(type, n)
const rb_callable_method_entry_t * rb_callable_method_entry_with_refinements(VALUE klass, ID id, VALUE *defined_class)
const rb_callable_method_entry_t * rb_callable_method_entry(VALUE klass, ID id)
#define RARRAY_AREF(a, i)
#define RARRAY_CONST_PTR_TRANSIENT
const char * rb_obj_classname(VALUE)
#define RB_PASS_CALLED_KEYWORDS
const struct rb_callinfo_kwarg * kw_arg
union rb_captured_block::@198 code
unsigned int ruby2_keywords
unsigned int ambiguous_param0
const struct rb_iseq_constant_body::@188::rb_iseq_param_keyword * keyword
struct rb_iseq_struct * local_iseq
struct rb_iseq_constant_body::@188::@190 flags
unsigned int accepts_no_kwarg
struct rb_iseq_constant_body::@188 param
parameter information
struct rb_iseq_constant_body * body
void error(const char *msg)
VALUE rb_block_param_proxy
const rb_callable_method_entry_t * rb_resolve_refined_method_callable(VALUE refinements, const rb_callable_method_entry_t *me)
#define KW_SPECIFIED_BITS_MAX
#define VM_CALL_KW_SPLAT_MUT
#define VM_CALL_ARGS_BLOCKARG
#define VM_CALL_ARGS_SPLAT
void rb_vm_pop_frame(rb_execution_context_t *ec)
#define CHECK_VM_STACK_OVERFLOW(cfp, margin)
#define VM_BLOCK_HANDLER_NONE
VALUE rb_vm_bh_to_procval(const rb_execution_context_t *ec, VALUE block_handler)
VALUE rb_vm_call0(rb_execution_context_t *ec, VALUE recv, ID id, int argc, const VALUE *argv, const rb_callable_method_entry_t *cme, int kw_splat)
#define vm_check_canary(ec, sp)
#define GET_BLOCK_HANDLER()