Ruby 4.1.0dev (2026-10-13 revision 98fd04f76ca291242cc40c62338ba075cfe2ba4c)
vm_args.c (98fd04f76ca291242cc40c62338ba075cfe2ba4c)
1/**********************************************************************
2
3 vm_args.c - process method call arguments. Included into vm.c.
4
5 $Author$
6
7 Copyright (C) 2014- Yukihiro Matsumoto
8
9**********************************************************************/
10
11NORETURN(static void raise_argument_error(rb_execution_context_t *ec, const rb_iseq_t *iseq, const rb_callable_method_entry_t *cme, const VALUE exc));
12NORETURN(static void argument_arity_error(rb_execution_context_t *ec, const rb_iseq_t *iseq, const rb_callable_method_entry_t *cme, const int miss_argc, const int min_argc, const int max_argc));
13NORETURN(static void argument_kw_error(rb_execution_context_t *ec, const rb_iseq_t *iseq, const rb_callable_method_entry_t *cme, const char *error, const VALUE keys));
14VALUE rb_keyword_error_new(const char *error, VALUE keys); /* class.c */
15static VALUE set_error_backtrace(rb_execution_context_t *ec, const rb_iseq_t *iseq, const rb_callable_method_entry_t *cme, const VALUE exc);
16
17static VALUE method_missing(rb_execution_context_t *ec, VALUE obj, ID id, int argc, const VALUE *argv,
18 enum method_missing_reason call_status, int kw_splat);
19const rb_callable_method_entry_t *rb_resolve_refined_method_callable(VALUE refinements, const rb_callable_method_entry_t *me);
20
21struct args_info {
22 /* basic args info */
23 VALUE *argv;
24 int argc;
25
26 /* additional args info */
27 int rest_index;
28 int rest_dupped;
29 const struct rb_callinfo_kwarg *kw_arg;
30 VALUE *kw_argv;
31 VALUE rest;
32};
33
34enum arg_setup_type {
35 arg_setup_method,
36 arg_setup_block
37};
38
39static inline void
40arg_rest_dup(struct args_info *args)
41{
42 if (!args->rest_dupped) {
43 args->rest = rb_ary_dup(args->rest);
44 args->rest_dupped = TRUE;
45 }
46}
47
48static inline int
49args_argc(struct args_info *args)
50{
51 if (args->rest == Qfalse) {
52 return args->argc;
53 }
54 else {
55 return args->argc + RARRAY_LENINT(args->rest) - args->rest_index;
56 }
57}
58
59static inline void
60args_extend(struct args_info *args, const int min_argc)
61{
62 int i;
63
64 if (args->rest) {
65 arg_rest_dup(args);
66 VM_ASSERT(args->rest_index == 0);
67 for (i=args->argc + RARRAY_LENINT(args->rest); i<min_argc; i++) {
68 rb_ary_push(args->rest, Qnil);
69 }
70 }
71 else {
72 for (i=args->argc; i<min_argc; i++) {
73 args->argv[args->argc++] = Qnil;
74 }
75 }
76}
77
78static inline void
79args_reduce(struct args_info *args, int over_argc)
80{
81 if (args->rest) {
82 const rb_len_t len = RARRAY_LEN(args->rest);
83
84 if (len > over_argc) {
85 arg_rest_dup(args);
86 rb_ary_resize(args->rest, len - over_argc);
87 return;
88 }
89 else {
90 args->rest = Qfalse;
91 over_argc -= len;
92 }
93 }
94
95 VM_ASSERT(args->argc >= over_argc);
96 args->argc -= over_argc;
97}
98
99static inline int
100args_check_block_arg0(struct args_info *args)
101{
102 VALUE ary = Qnil;
103
104 if (args->rest && RARRAY_LEN(args->rest) == 1) {
105 VALUE arg0 = RARRAY_AREF(args->rest, 0);
106 ary = rb_check_array_type(arg0);
107 }
108 else if (args->argc == 1) {
109 VALUE arg0 = args->argv[0];
110 ary = rb_check_array_type(arg0);
111 args->argv[0] = arg0; /* see: https://bugs.ruby-lang.org/issues/8484 */
112 }
113
114 if (!NIL_P(ary)) {
115 args->rest = ary;
116 args->rest_index = 0;
117 args->argc = 0;
118 return TRUE;
119 }
120
121 return FALSE;
122}
123
124static inline void
125args_copy(struct args_info *args)
126{
127 if (args->rest != Qfalse) {
128 int argc = args->argc;
129 args->argc = 0;
130 arg_rest_dup(args);
131
132 /*
133 * argv: [m0, m1, m2, m3]
134 * rest: [a0, a1, a2, a3, a4, a5]
135 * ^
136 * rest_index
137 *
138 * #=> first loop
139 *
140 * argv: [m0, m1]
141 * rest: [m2, m3, a2, a3, a4, a5]
142 * ^
143 * rest_index
144 *
145 * #=> 2nd loop
146 *
147 * argv: [] (argc == 0)
148 * rest: [m0, m1, m2, m3, a2, a3, a4, a5]
149 * ^
150 * rest_index
151 */
152 while (args->rest_index > 0 && argc > 0) {
153 RARRAY_ASET(args->rest, --args->rest_index, args->argv[--argc]);
154 }
155 while (argc > 0) {
156 rb_ary_unshift(args->rest, args->argv[--argc]);
157 }
158 }
159 else if (args->argc > 0) {
160 args->rest = rb_ary_new_from_values(args->argc, args->argv);
161 args->rest_index = 0;
162 args->rest_dupped = TRUE;
163 args->argc = 0;
164 }
165}
166
167static inline const VALUE *
168args_rest_argv(struct args_info *args)
169{
170 return RARRAY_CONST_PTR(args->rest) + args->rest_index;
171}
172
173static inline VALUE
174args_rest_array(struct args_info *args)
175{
176 VALUE ary;
177
178 if (args->rest) {
179 ary = rb_ary_behead(args->rest, args->rest_index);
180 args->rest_index = 0;
181 args->rest = 0;
182 }
183 else {
184 ary = rb_ary_new();
185 }
186 return ary;
187}
188
189static int
190args_kw_argv_to_hash(struct args_info *args)
191{
192 const struct rb_callinfo_kwarg *kw_arg = args->kw_arg;
193 const VALUE *const passed_keywords = kw_arg->keywords;
194 const int kw_len = kw_arg->keyword_len;
195 VALUE h = rb_hash_new_capa(kw_len);
196 const int kw_start = args->argc - kw_len;
197 const VALUE * const kw_argv = args->argv + kw_start;
198 int i;
199
200 args->argc = kw_start + 1;
201 for (i=0; i<kw_len; i++) {
202 rb_hash_aset(h, passed_keywords[i], kw_argv[i]);
203 }
204
205 args->argv[args->argc - 1] = h;
206
207 return args->argc;
208}
209
210static inline void
211args_setup_lead_parameters(struct args_info *args, int argc, VALUE *locals)
212{
213 if (args->argc >= argc) {
214 /* do noting */
215 args->argc -= argc;
216 args->argv += argc;
217 }
218 else {
219 int i, j;
220 const VALUE *argv = args_rest_argv(args);
221
222 for (i=args->argc, j=0; i<argc; i++, j++) {
223 locals[i] = argv[j];
224 }
225 args->rest_index += argc - args->argc;
226 args->argc = 0;
227 }
228}
229
230static inline void
231args_setup_post_parameters(struct args_info *args, int argc, VALUE *locals)
232{
234 len = RARRAY_LEN(args->rest);
235 MEMCPY(locals, RARRAY_CONST_PTR(args->rest) + len - argc, VALUE, argc);
236 rb_ary_resize(args->rest, len - argc);
237}
238
239static inline int
240args_setup_opt_parameters(struct args_info *args, int opt_max, VALUE *locals)
241{
242 int i;
243
244 if (args->argc >= opt_max) {
245 args->argc -= opt_max;
246 args->argv += opt_max;
247 i = opt_max;
248 }
249 else {
250 int j;
251 i = args->argc;
252 args->argc = 0;
253
254 if (args->rest) {
255 int len = RARRAY_LENINT(args->rest);
256 const VALUE *argv = RARRAY_CONST_PTR(args->rest);
257
258 for (; i<opt_max && args->rest_index < len; i++, args->rest_index++) {
259 locals[i] = argv[args->rest_index];
260 }
261 }
262
263 /* initialize by nil */
264 for (j=i; j<opt_max; j++) {
265 locals[j] = Qnil;
266 }
267 }
268
269 return i;
270}
271
272static inline void
273args_setup_rest_parameter(struct args_info *args, VALUE *locals)
274{
275 *locals = args_rest_array(args);
276}
277
278static VALUE
279make_unknown_kw_hash(const VALUE *passed_keywords, int passed_keyword_len, const VALUE *kw_argv)
280{
281 int i;
282 VALUE obj = rb_ary_hidden_new(1);
283
284 for (i=0; i<passed_keyword_len; i++) {
285 if (!UNDEF_P(kw_argv[i])) {
286 rb_ary_push(obj, passed_keywords[i]);
287 }
288 }
289 return obj;
290}
291
292static VALUE
293make_rest_kw_hash(const VALUE *passed_keywords, int passed_keyword_len, const VALUE *kw_argv)
294{
295 int i;
296 VALUE obj = rb_hash_new_capa(passed_keyword_len);
297
298 for (i=0; i<passed_keyword_len; i++) {
299 if (!UNDEF_P(kw_argv[i])) {
300 rb_hash_aset(obj, passed_keywords[i], kw_argv[i]);
301 }
302 }
303 return obj;
304}
305
306static inline int
307args_setup_kw_parameters_lookup(const ID key, VALUE *ptr, const VALUE *const passed_keywords, VALUE *passed_values, const int passed_keyword_len)
308{
309 int i;
310 const VALUE keyname = ID2SYM(key);
311
312 for (i=0; i<passed_keyword_len; i++) {
313 if (keyname == passed_keywords[i]) {
314 *ptr = passed_values[i];
315 passed_values[i] = Qundef;
316 return TRUE;
317 }
318 }
319
320 return FALSE;
321}
322
323static inline void
324args_setup_kw_parameters_not_found(const VALUE *default_values, VALUE *locals, int i, int di,
325 int *unspecified_bits, VALUE *unspecified_bits_value)
326{
327 if (UNDEF_P(default_values[di])) {
328 locals[i] = Qnil;
329
330 if (LIKELY(i < VM_KW_SPECIFIED_BITS_MAX)) {
331 *unspecified_bits |= 0x01 << di;
332 }
333 else {
334 VALUE bits_value = *unspecified_bits_value;
335 if (NIL_P(bits_value)) {
336 /* fixnum -> hash */
337 int bits = *unspecified_bits;
338 *unspecified_bits_value = bits_value = rb_ident_set_new();
339
340 for (int j=0; j<VM_KW_SPECIFIED_BITS_MAX; j++) {
341 if (bits & (0x01 << j)) {
342 rb_set_add_no_check(bits_value, INT2FIX(j));
343 }
344 }
345 }
346 rb_set_add_no_check(bits_value, INT2FIX(di));
347 }
348 }
349 else {
350 locals[i] = default_values[di];
351 }
352}
353
354static void
355args_setup_kw_parameters(rb_execution_context_t *const ec, const rb_iseq_t *const iseq, const rb_callable_method_entry_t *cme,
356 VALUE *const passed_values, const int passed_keyword_len, const VALUE *const passed_keywords,
357 VALUE *const locals)
358{
359 const ID *acceptable_keywords = ISEQ_BODY(iseq)->param.keyword->table;
360 const int req_key_num = ISEQ_BODY(iseq)->param.keyword->required_num;
361 const int key_num = ISEQ_BODY(iseq)->param.keyword->num;
362 const VALUE * const default_values = ISEQ_BODY(iseq)->param.keyword->default_values;
363 VALUE missing = 0;
364 int i, di, found = 0;
365 int unspecified_bits = 0;
366 VALUE unspecified_bits_value = Qnil;
367
368 for (i=0; i<req_key_num; i++) {
369 ID key = acceptable_keywords[i];
370 if (args_setup_kw_parameters_lookup(key, &locals[i], passed_keywords, passed_values, passed_keyword_len)) {
371 found++;
372 }
373 else {
374 if (!missing) missing = rb_ary_hidden_new(1);
375 rb_ary_push(missing, ID2SYM(key));
376 }
377 }
378
379 if (missing) argument_kw_error(ec, iseq, cme, "missing", missing);
380
381 for (di=0; i<key_num; i++, di++) {
382 if (args_setup_kw_parameters_lookup(acceptable_keywords[i], &locals[i], passed_keywords, passed_values, passed_keyword_len)) {
383 found++;
384 }
385 else {
386 args_setup_kw_parameters_not_found(default_values, locals, i, di,
387 &unspecified_bits, &unspecified_bits_value);
388 }
389 }
390
391 if (ISEQ_BODY(iseq)->param.flags.has_kwrest) {
392 const int rest_hash_index = key_num + 1;
393 locals[rest_hash_index] = make_rest_kw_hash(passed_keywords, passed_keyword_len, passed_values);
394 }
395 else {
396 if (found != passed_keyword_len) {
397 VALUE keys = make_unknown_kw_hash(passed_keywords, passed_keyword_len, passed_values);
398 argument_kw_error(ec, iseq, cme, "unknown", keys);
399 }
400 }
401
402 if (NIL_P(unspecified_bits_value)) {
403 unspecified_bits_value = INT2FIX(unspecified_bits);
404 }
405 locals[key_num] = unspecified_bits_value;
406}
407
408static void
409args_setup_kw_parameters_from_kwsplat(rb_execution_context_t *const ec, const rb_iseq_t *const iseq, const rb_callable_method_entry_t *cme,
410 VALUE keyword_hash, VALUE *const locals, bool remove_hash_value)
411{
412 const ID *acceptable_keywords = ISEQ_BODY(iseq)->param.keyword->table;
413 const int req_key_num = ISEQ_BODY(iseq)->param.keyword->required_num;
414 const int key_num = ISEQ_BODY(iseq)->param.keyword->num;
415 const VALUE * const default_values = ISEQ_BODY(iseq)->param.keyword->default_values;
416 VALUE missing = 0;
417 int i, di;
418 int unspecified_bits = 0;
419 size_t keyword_size = RHASH_SIZE(keyword_hash);
420 VALUE unspecified_bits_value = Qnil;
421
422 for (i=0; i<req_key_num; i++) {
423 VALUE key = ID2SYM(acceptable_keywords[i]);
424 VALUE value;
425 if (remove_hash_value) {
426 value = rb_hash_delete_entry(keyword_hash, key);
427 }
428 else {
429 value = rb_hash_lookup2(keyword_hash, key, Qundef);
430 }
431
432 if (!UNDEF_P(value)) {
433 keyword_size--;
434 locals[i] = value;
435 }
436 else {
437 if (!missing) missing = rb_ary_hidden_new(1);
438 rb_ary_push(missing, key);
439 }
440 }
441
442 if (missing) argument_kw_error(ec, iseq, cme, "missing", missing);
443
444 for (di=0; i<key_num; i++, di++) {
445 VALUE key = ID2SYM(acceptable_keywords[i]);
446 VALUE value;
447 if (remove_hash_value) {
448 value = rb_hash_delete_entry(keyword_hash, key);
449 }
450 else {
451 value = rb_hash_lookup2(keyword_hash, key, Qundef);
452 }
453
454 if (!UNDEF_P(value)) {
455 keyword_size--;
456 locals[i] = value;
457 }
458 else {
459 args_setup_kw_parameters_not_found(default_values, locals, i, di,
460 &unspecified_bits, &unspecified_bits_value);
461 }
462 }
463
464 if (ISEQ_BODY(iseq)->param.flags.has_kwrest) {
465 const int rest_hash_index = key_num + 1;
466 locals[rest_hash_index] = keyword_hash;
467 }
468 else {
469 if (!remove_hash_value) {
470 if (keyword_size != 0) {
471 /* Recurse with duplicated keyword hash in remove mode.
472 * This is simpler than writing code to check which entries in the hash do not match.
473 * This will raise an exception, so the additional performance impact shouldn't be material.
474 */
475 args_setup_kw_parameters_from_kwsplat(ec, iseq, cme, rb_hash_dup(keyword_hash), locals, true);
476 }
477 }
478 else if (!RHASH_EMPTY_P(keyword_hash)) {
479 argument_kw_error(ec, iseq, cme, "unknown", rb_hash_keys(keyword_hash));
480 }
481 }
482
483 if (NIL_P(unspecified_bits_value)) {
484 unspecified_bits_value = INT2FIX(unspecified_bits);
485 }
486 locals[key_num] = unspecified_bits_value;
487}
488
489static inline void
490args_setup_kw_rest_parameter(VALUE keyword_hash, VALUE *locals, int kw_flag, bool anon_kwrest)
491{
492 if (NIL_P(keyword_hash)) {
493 if (!anon_kwrest) {
494 keyword_hash = rb_hash_new();
495 }
496 }
497 else if (!(kw_flag & VM_CALL_KW_SPLAT_MUT)) {
498 keyword_hash = rb_hash_dup(keyword_hash);
499 }
500 locals[0] = keyword_hash;
501}
502
503static inline void
504args_setup_block_parameter(const rb_execution_context_t *ec, struct rb_calling_info *calling, VALUE *locals)
505{
506 VALUE block_handler = calling->block_handler;
507 *locals = rb_vm_bh_to_procval(ec, block_handler);
508}
509
510static inline int
511ignore_keyword_hash_p(VALUE keyword_hash, const rb_iseq_t * const iseq, unsigned int * kw_flag, VALUE * converted_keyword_hash)
512{
513 if (keyword_hash == Qnil) {
514 goto ignore;
515 }
516 else if (!RB_TYPE_P(keyword_hash, T_HASH)) {
517 keyword_hash = rb_to_hash_type(keyword_hash);
518 }
519 else if (UNLIKELY(ISEQ_BODY(iseq)->param.flags.anon_kwrest)) {
520 if (!ISEQ_BODY(iseq)->param.flags.has_kw) {
521 *kw_flag |= VM_CALL_KW_SPLAT_MUT;
522 }
523 }
524
525 if (RHASH_EMPTY_P(keyword_hash) && !ISEQ_BODY(iseq)->param.flags.has_kwrest) {
526 goto ignore;
527 }
528
529 if (!(*kw_flag & VM_CALL_KW_SPLAT_MUT) &&
530 (ISEQ_BODY(iseq)->param.flags.has_kwrest ||
531 ISEQ_BODY(iseq)->param.flags.ruby2_keywords)) {
532 *kw_flag |= VM_CALL_KW_SPLAT_MUT;
533 keyword_hash = rb_hash_dup(keyword_hash);
534 }
535 *converted_keyword_hash = keyword_hash;
536
537 if (!(ISEQ_BODY(iseq)->param.flags.has_kw) &&
538 !(ISEQ_BODY(iseq)->param.flags.has_kwrest) &&
539 RHASH_EMPTY_P(keyword_hash)) {
540 ignore:
541 *kw_flag &= ~(VM_CALL_KW_SPLAT | VM_CALL_KW_SPLAT_MUT);
542 return 1;
543 }
544 else {
545 return 0;
546 }
547}
548
549static VALUE
550check_kwrestarg(VALUE keyword_hash, unsigned int *kw_flag)
551{
552 if (!(*kw_flag & VM_CALL_KW_SPLAT_MUT)) {
553 *kw_flag |= VM_CALL_KW_SPLAT_MUT;
554 return rb_hash_dup(keyword_hash);
555 }
556 else {
557 return keyword_hash;
558 }
559}
560
561static void
562flatten_rest_args(rb_execution_context_t * const ec, struct args_info *args, VALUE * const locals, unsigned int *ci_flag)
563{
564 const VALUE *argv = RARRAY_CONST_PTR(args->rest);
565 int j, i=args->argc, rest_len = RARRAY_LENINT(args->rest)-1;
566 args->argc += rest_len;
567 if (rest_len) {
568 CHECK_VM_STACK_OVERFLOW(ec->cfp, rest_len+1);
569 for (j=0; rest_len > 0; rest_len--, i++, j++) {
570 locals[i] = argv[j];
571 }
572 }
573 args->rest = Qfalse;
574 *ci_flag &= ~VM_CALL_ARGS_SPLAT;
575}
576
577static int
578setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * const iseq,
579 struct rb_calling_info *const calling,
580 const struct rb_callinfo *ci,
581 VALUE * const locals, const enum arg_setup_type arg_setup_type)
582{
583 const int min_argc = ISEQ_BODY(iseq)->param.lead_num + ISEQ_BODY(iseq)->param.post_num;
584 const int max_argc = (ISEQ_BODY(iseq)->param.flags.has_rest == FALSE) ? min_argc + ISEQ_BODY(iseq)->param.opt_num : UNLIMITED_ARGUMENTS;
585 int given_argc;
586 unsigned int ci_flag = vm_ci_flag(ci);
587 unsigned int kw_flag = ci_flag & (VM_CALL_KWARG | VM_CALL_KW_SPLAT | VM_CALL_KW_SPLAT_MUT);
588 int opt_pc = 0, allow_autosplat = !kw_flag;
589 struct args_info args_body, *args;
590 VALUE keyword_hash = Qnil;
591 VALUE * const orig_sp = ec->cfp->sp;
592 unsigned int i;
593 VALUE flag_keyword_hash = 0;
594 VALUE splat_flagged_keyword_hash = 0;
595 VALUE converted_keyword_hash = 0;
596 VALUE rest_last = 0;
597 const rb_callable_method_entry_t *cme = calling->cc ? vm_cc_cme(calling->cc) : NULL;
598
599 vm_check_canary(ec, orig_sp);
600 /*
601 * Extend SP for GC.
602 *
603 * [pushed values] [uninitialized values]
604 * <- ci->argc -->
605 * <- ISEQ_BODY(iseq)->param.size------------>
606 * ^ locals ^ sp
607 *
608 * =>
609 * [pushed values] [initialized values ]
610 * <- ci->argc -->
611 * <- ISEQ_BODY(iseq)->param.size------------>
612 * ^ locals ^ sp
613 */
614 if ((unsigned int)calling->argc < ISEQ_BODY(iseq)->param.size) {
615 /* Ensure the nil-fill below and the SP extension do not run into the
616 * control frame region, clobbering frames before the stack overflow
617 * check in vm_push_frame has a chance to raise SystemStackError. */
618 CHECK_VM_STACK_OVERFLOW0(ec->cfp, locals + calling->argc,
619 ISEQ_BODY(iseq)->param.size - calling->argc);
620 }
621 for (i=calling->argc; i<ISEQ_BODY(iseq)->param.size; i++) {
622 locals[i] = Qnil;
623 }
624 ec->cfp->sp = &locals[i];
625
626 /* setup args */
627 args = &args_body;
628 given_argc = args->argc = calling->argc;
629 args->argv = locals;
630 args->rest_dupped = ci_flag & VM_CALL_ARGS_SPLAT_MUT;
631
632 if (UNLIKELY(ISEQ_BODY(iseq)->param.flags.anon_rest)) {
633 if ((ci_flag & VM_CALL_ARGS_SPLAT) &&
634 given_argc == ISEQ_BODY(iseq)->param.lead_num + (kw_flag ? 2 : 1) &&
635 !ISEQ_BODY(iseq)->param.flags.has_opt &&
636 !ISEQ_BODY(iseq)->param.flags.has_post &&
637 !ISEQ_BODY(iseq)->param.flags.ruby2_keywords) {
638 if (kw_flag) {
639 if (ISEQ_BODY(iseq)->param.flags.has_kw ||
640 ISEQ_BODY(iseq)->param.flags.has_kwrest) {
641 args->rest_dupped = true;
642 }
643 else if (kw_flag & VM_CALL_KW_SPLAT) {
644 VALUE kw_hash = locals[args->argc - 1];
645 if (kw_hash == Qnil ||
646 (RB_TYPE_P(kw_hash, T_HASH) && RHASH_EMPTY_P(kw_hash))) {
647 args->rest_dupped = true;
648 }
649 }
650
651 }
652 else if (!ISEQ_BODY(iseq)->param.flags.has_kw &&
653 !ISEQ_BODY(iseq)->param.flags.has_kwrest &&
654 !ISEQ_BODY(iseq)->param.flags.accepts_no_kwarg) {
655 args->rest_dupped = true;
656 }
657 }
658 }
659
660 if (kw_flag & VM_CALL_KWARG) {
661 args->kw_arg = vm_ci_kwarg(ci);
662
663 if (ISEQ_BODY(iseq)->param.flags.has_kw) {
664 int kw_len = args->kw_arg->keyword_len;
665 /* copy kw_argv */
666 args->kw_argv = ALLOCA_N(VALUE, kw_len);
667 args->argc -= kw_len;
668 given_argc -= kw_len;
669 MEMCPY(args->kw_argv, locals + args->argc, VALUE, kw_len);
670 }
671 else {
672 args->kw_argv = NULL;
673 given_argc = args_kw_argv_to_hash(args);
674 kw_flag |= VM_CALL_KW_SPLAT | VM_CALL_KW_SPLAT_MUT;
675 }
676 }
677 else {
678 args->kw_arg = NULL;
679 args->kw_argv = NULL;
680 }
681
682 if ((ci_flag & VM_CALL_ARGS_SPLAT) && (ci_flag & VM_CALL_KW_SPLAT)) {
683 // f(*a, **kw)
684 args->rest_index = 0;
685 keyword_hash = locals[--args->argc];
686 args->rest = locals[--args->argc];
687
688 if (ignore_keyword_hash_p(keyword_hash, iseq, &kw_flag, &converted_keyword_hash)) {
689 keyword_hash = Qnil;
690 }
691 else if (UNLIKELY(ISEQ_BODY(iseq)->param.flags.ruby2_keywords)) {
692 converted_keyword_hash = check_kwrestarg(converted_keyword_hash, &kw_flag);
693 flag_keyword_hash = converted_keyword_hash;
694 arg_rest_dup(args);
695 rb_ary_push(args->rest, converted_keyword_hash);
696 keyword_hash = Qnil;
697 }
698 else if (!ISEQ_BODY(iseq)->param.flags.has_kwrest && !ISEQ_BODY(iseq)->param.flags.has_kw) {
699 converted_keyword_hash = check_kwrestarg(converted_keyword_hash, &kw_flag);
700 if (ISEQ_BODY(iseq)->param.flags.has_rest) {
701 arg_rest_dup(args);
702 rb_ary_push(args->rest, converted_keyword_hash);
703 keyword_hash = Qnil;
704 }
705 else {
706 // Avoid duping rest when not necessary
707 // Copy rest elements and converted keyword hash directly to VM stack
708 const VALUE *argv = RARRAY_CONST_PTR(args->rest);
709 int j, i=args->argc, rest_len = RARRAY_LENINT(args->rest);
710 if (rest_len) {
711 CHECK_VM_STACK_OVERFLOW(ec->cfp, rest_len+1);
712 given_argc += rest_len;
713 args->argc += rest_len;
714 for (j=0; rest_len > 0; rest_len--, i++, j++) {
715 locals[i] = argv[j];
716 }
717 }
718 locals[i] = converted_keyword_hash;
719 given_argc--;
720 args->argc++;
721 args->rest = Qfalse;
722 ci_flag &= ~(VM_CALL_ARGS_SPLAT|VM_CALL_KW_SPLAT);
723 keyword_hash = Qnil;
724 goto arg_splat_and_kw_splat_flattened;
725 }
726 }
727 else {
728 keyword_hash = converted_keyword_hash;
729 }
730
731 int len = RARRAY_LENINT(args->rest);
732 given_argc += len - 2;
733 }
734 else if (ci_flag & VM_CALL_ARGS_SPLAT) {
735 // f(*a)
736 args->rest_index = 0;
737 args->rest = locals[--args->argc];
738 int len = RARRAY_LENINT(args->rest);
739 given_argc += len - 1;
740
741 if (!kw_flag && len > 0) {
742 rest_last = RARRAY_AREF(args->rest, len - 1);
743 if (RB_TYPE_P(rest_last, T_HASH) && FL_TEST_RAW(rest_last, RHASH_PASS_AS_KEYWORDS)) {
744 // def f(**kw); a = [..., kw]; g(*a)
745 splat_flagged_keyword_hash = rest_last;
746 if (!(RHASH_EMPTY_P(rest_last) || ISEQ_BODY(iseq)->param.flags.has_kw) || (ISEQ_BODY(iseq)->param.flags.has_kwrest)) {
747 rest_last = rb_hash_dup(rest_last);
748 }
749 kw_flag |= VM_CALL_KW_SPLAT | VM_CALL_KW_SPLAT_MUT;
750
751 // Unset rest_dupped set by anon_rest as we may need to modify splat in this case
752 args->rest_dupped = false;
753
754 if (ignore_keyword_hash_p(rest_last, iseq, &kw_flag, &converted_keyword_hash)) {
755 if (ISEQ_BODY(iseq)->param.flags.has_rest) {
756 // Only duplicate/modify splat array if it will be used
757 arg_rest_dup(args);
758 rb_ary_pop(args->rest);
759 }
760 else if (arg_setup_type == arg_setup_block && !ISEQ_BODY(iseq)->param.flags.has_kwrest) {
761 // Avoid hash allocation for empty hashes
762 // Copy rest elements except empty keyword hash directly to VM stack
763 flatten_rest_args(ec, args, locals, &ci_flag);
764 keyword_hash = Qnil;
765 kw_flag = 0;
766 }
767 given_argc--;
768 }
769 else if (!ISEQ_BODY(iseq)->param.flags.has_rest) {
770 // Avoid duping rest when not necessary
771 // Copy rest elements and converted keyword hash directly to VM stack
772 flatten_rest_args(ec, args, locals, &ci_flag);
773
774 if (ISEQ_BODY(iseq)->param.flags.has_kw || ISEQ_BODY(iseq)->param.flags.has_kwrest) {
775 given_argc--;
776 keyword_hash = converted_keyword_hash;
777 }
778 else {
779 locals[args->argc] = converted_keyword_hash;
780 args->argc += 1;
781 keyword_hash = Qnil;
782 kw_flag = 0;
783 }
784 }
785 else {
786 if (rest_last != converted_keyword_hash) {
787 rest_last = converted_keyword_hash;
788 arg_rest_dup(args);
789 RARRAY_ASET(args->rest, len - 1, rest_last);
790 }
791
792 if (ISEQ_BODY(iseq)->param.flags.ruby2_keywords && rest_last) {
793 flag_keyword_hash = rest_last;
794 }
795 else if (ISEQ_BODY(iseq)->param.flags.has_kw || ISEQ_BODY(iseq)->param.flags.has_kwrest) {
796 arg_rest_dup(args);
797 rb_ary_pop(args->rest);
798 given_argc--;
799 keyword_hash = rest_last;
800 }
801 }
802 }
803 }
804 }
805 else {
806 args->rest = Qfalse;
807
808 if (args->argc > 0 && (kw_flag & VM_CALL_KW_SPLAT)) {
809 // f(**kw)
810 VALUE last_arg = args->argv[args->argc-1];
811 if (ignore_keyword_hash_p(last_arg, iseq, &kw_flag, &converted_keyword_hash)) {
812 args->argc--;
813 given_argc--;
814 }
815 else {
816 if (!(kw_flag & VM_CALL_KW_SPLAT_MUT) && !ISEQ_BODY(iseq)->param.flags.has_kw) {
817 converted_keyword_hash = rb_hash_dup(converted_keyword_hash);
818 kw_flag |= VM_CALL_KW_SPLAT_MUT;
819 }
820
821 if (last_arg != converted_keyword_hash) {
822 last_arg = converted_keyword_hash;
823 args->argv[args->argc-1] = last_arg;
824 }
825
826 if (ISEQ_BODY(iseq)->param.flags.ruby2_keywords) {
827 flag_keyword_hash = last_arg;
828 }
829 else if (ISEQ_BODY(iseq)->param.flags.has_kw || ISEQ_BODY(iseq)->param.flags.has_kwrest) {
830 args->argc--;
831 given_argc--;
832 keyword_hash = last_arg;
833 }
834 }
835 }
836 }
837
838 if (flag_keyword_hash) {
839 FL_SET_RAW(flag_keyword_hash, RHASH_PASS_AS_KEYWORDS);
840 }
841
842 arg_splat_and_kw_splat_flattened:
843 if (kw_flag && ISEQ_BODY(iseq)->param.flags.accepts_no_kwarg) {
844 rb_raise(rb_eArgError, "no keywords accepted");
845 }
846
847 switch (arg_setup_type) {
848 case arg_setup_method:
849 break; /* do nothing special */
850 case arg_setup_block:
851 if (given_argc == 1 &&
852 allow_autosplat &&
853 !splat_flagged_keyword_hash &&
854 (min_argc > 0 || ISEQ_BODY(iseq)->param.opt_num > 1) &&
855 !ISEQ_BODY(iseq)->param.flags.ambiguous_param0 &&
856 !((ISEQ_BODY(iseq)->param.flags.has_kw ||
857 ISEQ_BODY(iseq)->param.flags.has_kwrest)
858 && max_argc == 1) &&
859 args_check_block_arg0(args)) {
860 given_argc = RARRAY_LENINT(args->rest);
861 }
862 break;
863 }
864
865 /* argc check */
866 if (given_argc < min_argc) {
867 if (arg_setup_type == arg_setup_block) {
868 CHECK_VM_STACK_OVERFLOW(ec->cfp, min_argc);
869 given_argc = min_argc;
870 args_extend(args, min_argc);
871 }
872 else {
873 argument_arity_error(ec, iseq, cme, given_argc, min_argc, max_argc);
874 }
875 }
876
877 if (given_argc > max_argc && max_argc != UNLIMITED_ARGUMENTS) {
878 if (arg_setup_type == arg_setup_block) {
879 /* truncate */
880 args_reduce(args, given_argc - max_argc);
881 given_argc = max_argc;
882 }
883 else {
884 argument_arity_error(ec, iseq, cme, given_argc, min_argc, max_argc);
885 }
886 }
887
888 if (ISEQ_BODY(iseq)->param.flags.has_lead) {
889 args_setup_lead_parameters(args, ISEQ_BODY(iseq)->param.lead_num, locals + 0);
890 }
891
892 if (ISEQ_BODY(iseq)->param.flags.has_rest || ISEQ_BODY(iseq)->param.flags.has_post){
893 args_copy(args);
894 }
895
896 if (ISEQ_BODY(iseq)->param.flags.has_post) {
897 args_setup_post_parameters(args, ISEQ_BODY(iseq)->param.post_num, locals + ISEQ_BODY(iseq)->param.post_start);
898 }
899
900 if (ISEQ_BODY(iseq)->param.flags.has_opt) {
901 int opt = args_setup_opt_parameters(args, ISEQ_BODY(iseq)->param.opt_num, locals + ISEQ_BODY(iseq)->param.lead_num);
902 opt_pc = (int)ISEQ_BODY(iseq)->param.opt_table[opt];
903 }
904
905 if (ISEQ_BODY(iseq)->param.flags.has_rest) {
906 if (UNLIKELY(ISEQ_BODY(iseq)->param.flags.anon_rest && args->argc == 0 && !args->rest && !ISEQ_BODY(iseq)->param.flags.has_post)) {
907 *(locals + ISEQ_BODY(iseq)->param.rest_start) = args->rest = rb_cArray_empty_frozen;
908 args->rest_index = 0;
909 }
910 else {
911 args_setup_rest_parameter(args, locals + ISEQ_BODY(iseq)->param.rest_start);
912 VALUE ary = *(locals + ISEQ_BODY(iseq)->param.rest_start);
913 VALUE index = RARRAY_LEN(ary) - 1;
914 if (splat_flagged_keyword_hash &&
915 !ISEQ_BODY(iseq)->param.flags.ruby2_keywords &&
916 !ISEQ_BODY(iseq)->param.flags.has_kw &&
917 !ISEQ_BODY(iseq)->param.flags.has_kwrest &&
918 RARRAY_AREF(ary, index) == splat_flagged_keyword_hash) {
919 ((struct RHash *)rest_last)->basic.flags &= ~RHASH_PASS_AS_KEYWORDS;
920 RARRAY_ASET(ary, index, rest_last);
921 }
922 }
923 }
924
925 if (ISEQ_BODY(iseq)->param.flags.has_kw) {
926 VALUE * const klocals = locals + ISEQ_BODY(iseq)->param.keyword->bits_start - ISEQ_BODY(iseq)->param.keyword->num;
927
928 if (args->kw_argv != NULL) {
929 const struct rb_callinfo_kwarg *kw_arg = args->kw_arg;
930 args_setup_kw_parameters(ec, iseq, cme, args->kw_argv, kw_arg->keyword_len, kw_arg->keywords, klocals);
931 }
932 else if (!NIL_P(keyword_hash)) {
933 bool remove_hash_value = false;
934 if (ISEQ_BODY(iseq)->param.flags.has_kwrest) {
935 keyword_hash = check_kwrestarg(keyword_hash, &kw_flag);
936 remove_hash_value = true;
937 }
938 args_setup_kw_parameters_from_kwsplat(ec, iseq, cme, keyword_hash, klocals, remove_hash_value);
939 }
940 else {
941#if VM_CHECK_MODE > 0
942 if (args_argc(args) != 0) {
943 VM_ASSERT(ci_flag & VM_CALL_ARGS_SPLAT);
944 VM_ASSERT(!(ci_flag & (VM_CALL_KWARG | VM_CALL_KW_SPLAT | VM_CALL_KW_SPLAT_MUT)));
945 VM_ASSERT(!kw_flag);
946 VM_ASSERT(!ISEQ_BODY(iseq)->param.flags.has_rest);
947 VM_ASSERT(RARRAY_LENINT(args->rest) > 0);
948 VM_ASSERT(RB_TYPE_P(rest_last, T_HASH));
949 VM_ASSERT(FL_TEST_RAW(rest_last, RHASH_PASS_AS_KEYWORDS));
950 VM_ASSERT(args_argc(args) == 1);
951 }
952#endif
953 args_setup_kw_parameters(ec, iseq, cme, NULL, 0, NULL, klocals);
954 }
955 }
956 else if (ISEQ_BODY(iseq)->param.flags.has_kwrest) {
957 args_setup_kw_rest_parameter(keyword_hash, locals + ISEQ_BODY(iseq)->param.keyword->rest_start,
958 kw_flag, ISEQ_BODY(iseq)->param.flags.anon_kwrest);
959 }
960 else if (!NIL_P(keyword_hash) && RHASH_SIZE(keyword_hash) > 0 && arg_setup_type == arg_setup_method) {
961 argument_kw_error(ec, iseq, cme, "unknown", rb_hash_keys(keyword_hash));
962 }
963
964 if (ISEQ_BODY(iseq)->param.flags.accepts_no_block) {
965 VALUE given_block;
966 args_setup_block_parameter(ec, calling, &given_block);
967 if (!NIL_P(given_block)) {
968 VALUE exc = rb_exc_new_cstr(rb_eArgError, "no block accepted");
969 rb_exc_raise(set_error_backtrace(ec, iseq, cme, exc));
970 }
971 }
972 else if (ISEQ_BODY(iseq)->param.flags.has_block) {
973 if (ISEQ_BODY(iseq)->local_iseq == iseq) {
974 /* Do nothing */
975 }
976 else {
977 args_setup_block_parameter(ec, calling, locals + ISEQ_BODY(iseq)->param.block_start);
978 }
979 }
980
981#if 0
982 {
983 int i;
984 for (i=0; i<ISEQ_BODY(iseq)->param.size; i++) {
985 ruby_debug_printf("local[%d] = %p\n", i, (void *)locals[i]);
986 }
987 }
988#endif
989
990 ec->cfp->sp = orig_sp;
991 return opt_pc;
992}
993
994static VALUE
995set_error_backtrace(rb_execution_context_t *ec, const rb_iseq_t *iseq, const rb_callable_method_entry_t *cme, const VALUE exc)
996{
997 VALUE at;
998
999 if (iseq) {
1000 vm_push_frame(ec, iseq, VM_FRAME_MAGIC_DUMMY | VM_ENV_FLAG_LOCAL, Qnil /* self */,
1001 VM_BLOCK_HANDLER_NONE /* specval*/, (VALUE) cme /* me or cref */,
1002 ISEQ_BODY(iseq)->iseq_encoded,
1003 ec->cfp->sp, 0, 0 /* stack_max */);
1004 at = rb_ec_backtrace_object(ec);
1005 rb_vm_pop_frame(ec);
1006 }
1007 else {
1008 at = rb_ec_backtrace_object(ec);
1009 }
1010
1011 rb_ivar_set(exc, idBt_locations, at);
1012 rb_exc_set_backtrace(exc, at);
1013 return exc;
1014}
1015
1016static void
1017raise_argument_error(rb_execution_context_t *ec, const rb_iseq_t *iseq, const rb_callable_method_entry_t *cme, const VALUE exc)
1018{
1019 set_error_backtrace(ec, iseq, cme, exc);
1020 rb_exc_raise(exc);
1021}
1022
1023static void
1024argument_arity_error(rb_execution_context_t *ec, const rb_iseq_t *iseq, const rb_callable_method_entry_t *cme, const int miss_argc, const int min_argc, const int max_argc)
1025{
1026 VALUE exc = rb_arity_error_new(miss_argc, min_argc, max_argc);
1027 if (ISEQ_BODY(iseq)->param.flags.has_kw) {
1028 const struct rb_iseq_param_keyword *const kw = ISEQ_BODY(iseq)->param.keyword;
1029 const ID *keywords = kw->table;
1030 int req_key_num = kw->required_num;
1031 if (req_key_num > 0) {
1032 static const char required[] = "; required keywords";
1033 VALUE mesg = rb_attr_get(exc, idMesg);
1034 rb_str_resize(mesg, RSTRING_LEN(mesg)-1);
1035 rb_str_cat(mesg, required, sizeof(required) - 1 - (req_key_num == 1));
1036 rb_str_cat_cstr(mesg, ":");
1037 do {
1038 rb_str_cat_cstr(mesg, " ");
1039 rb_str_append(mesg, rb_id2str(*keywords++));
1040 rb_str_cat_cstr(mesg, ",");
1041 } while (--req_key_num);
1042 RSTRING_PTR(mesg)[RSTRING_LEN(mesg)-1] = ')';
1043 }
1044 }
1045 raise_argument_error(ec, iseq, cme, exc);
1046}
1047
1048static void
1049argument_kw_error(rb_execution_context_t *ec, const rb_iseq_t *iseq, const rb_callable_method_entry_t *cme, const char *error, const VALUE keys)
1050{
1051 raise_argument_error(ec, iseq, cme, rb_keyword_error_new(error, keys));
1052}
1053
1054static VALUE
1055vm_to_proc(VALUE proc)
1056{
1057 if (UNLIKELY(!rb_obj_is_proc(proc))) {
1058 VALUE b;
1059 const rb_callable_method_entry_t *me =
1060 rb_callable_method_entry_with_refinements(CLASS_OF(proc), idTo_proc, NULL);
1061
1062 if (me) {
1063 b = rb_vm_call0(GET_EC(), proc, idTo_proc, 0, NULL, me, RB_NO_KEYWORDS);
1064 }
1065 else {
1066 /* NOTE: calling method_missing */
1067 b = rb_check_convert_type_with_id(proc, T_DATA, "Proc", idTo_proc);
1068 }
1069
1070 if (NIL_P(b) || !rb_obj_is_proc(b)) {
1071 if (me) {
1072 rb_cant_convert_invalid_return(proc, "Proc", "to_proc", b);
1073 }
1074 else {
1075 rb_no_implicit_conversion(proc, "Proc");
1076 }
1077 }
1078 return b;
1079 }
1080 else {
1081 return proc;
1082 }
1083}
1084
1085static VALUE
1086refine_sym_proc_call(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg))
1087{
1088 VALUE obj;
1089 ID mid;
1090 const rb_callable_method_entry_t *me = 0; /* for hidden object case */
1092 const VALUE symbol = RARRAY_AREF(callback_arg, 0);
1093 const VALUE refinements = RARRAY_AREF(callback_arg, 1);
1094 int kw_splat = RB_PASS_CALLED_KEYWORDS;
1095 VALUE klass;
1096
1097 if (argc-- < 1) {
1098 rb_raise(rb_eArgError, "no receiver given");
1099 }
1100 obj = *argv++;
1101
1102 mid = SYM2ID(symbol);
1103 for (klass = CLASS_OF(obj); klass; klass = RCLASS_SUPER(klass)) {
1104 me = rb_callable_method_entry(klass, mid);
1105 if (me) {
1106 me = rb_resolve_refined_method_callable(refinements, me);
1107 if (me) break;
1108 }
1109 }
1110
1111 ec = GET_EC();
1112 if (!NIL_P(blockarg)) {
1113 vm_passed_block_handler_set(ec, blockarg);
1114 }
1115 if (!me) {
1116 return method_missing(ec, obj, mid, argc, argv, MISSING_NOENTRY, kw_splat);
1117 }
1118 return rb_vm_call0(ec, obj, mid, argc, argv, me, kw_splat);
1119}
1120
1121static VALUE
1122vm_caller_setup_arg_block(const rb_execution_context_t *ec, rb_control_frame_t *reg_cfp,
1123 const struct rb_callinfo *ci, const rb_iseq_t *blockiseq, const int is_super)
1124{
1125 if (vm_ci_flag(ci) & VM_CALL_ARGS_BLOCKARG) {
1126 VALUE block_code = *(--reg_cfp->sp);
1127
1128 if (NIL_P(block_code)) {
1129 return VM_BLOCK_HANDLER_NONE;
1130 }
1131 else if (block_code == rb_block_param_proxy) {
1132 return VM_CF_BLOCK_HANDLER(reg_cfp);
1133 }
1134 else if (SYMBOL_P(block_code) && rb_method_basic_definition_p(rb_cSymbol, idTo_proc)) {
1135 const rb_cref_t *cref = vm_env_cref(reg_cfp->ep);
1136 if (cref && !NIL_P(cref->refinements)) {
1137 VALUE ref = cref->refinements;
1138 VALUE func = rb_hash_lookup(ref, block_code);
1139 if (NIL_P(func)) {
1140 /* TODO: limit cached funcs */
1141 VALUE callback_arg = rb_ary_hidden_new(2);
1142 rb_ary_push(callback_arg, block_code);
1143 rb_ary_push(callback_arg, ref);
1144 OBJ_FREEZE(callback_arg);
1145 func = rb_func_lambda_new(refine_sym_proc_call, callback_arg, 1, UNLIMITED_ARGUMENTS);
1146 /* the table is frozen when it belongs to a Proc#refined memo; skip the cache then */
1147 if (!OBJ_FROZEN(ref)) {
1148 rb_hash_aset(ref, block_code, func);
1149 }
1150 }
1151 block_code = func;
1152 }
1153 return block_code;
1154 }
1155 else {
1156 return vm_to_proc(block_code);
1157 }
1158 }
1159 else if (blockiseq != NULL) { /* likely */
1160 struct rb_captured_block *captured = VM_CFP_TO_CAPTURED_BLOCK(reg_cfp);
1161 captured->code.iseq = blockiseq;
1162 return VM_BH_FROM_ISEQ_BLOCK(captured);
1163 }
1164 else {
1165 if (is_super) {
1166 return GET_BLOCK_HANDLER();
1167 }
1168 else {
1169 return VM_BLOCK_HANDLER_NONE;
1170 }
1171 }
1172}
1173
1174static void vm_adjust_stack_forwarding(const struct rb_execution_context_struct *ec, struct rb_control_frame_struct *cfp, int argc, VALUE splat);
1175
1176static VALUE
1177vm_caller_setup_fwd_args(const rb_execution_context_t *ec, rb_control_frame_t *reg_cfp,
1178 CALL_DATA cd, const rb_iseq_t *blockiseq, const int is_super,
1179 struct rb_forwarding_call_data *adjusted_cd, struct rb_callinfo *adjusted_ci)
1180{
1181 CALL_INFO site_ci = cd->ci;
1182 VALUE bh = Qundef;
1183
1184 RUBY_ASSERT(ISEQ_BODY(ISEQ_BODY(CFP_ISEQ(reg_cfp))->local_iseq)->param.flags.forwardable);
1185 CALL_INFO caller_ci = (CALL_INFO)TOPN(0);
1186
1187 unsigned int site_argc = vm_ci_argc(site_ci);
1188 unsigned int site_flag = vm_ci_flag(site_ci);
1189 ID site_mid = vm_ci_mid(site_ci);
1190
1191 unsigned int caller_argc = vm_ci_argc(caller_ci);
1192 unsigned int caller_flag = vm_ci_flag(caller_ci);
1193 const struct rb_callinfo_kwarg * kw = vm_ci_kwarg(caller_ci);
1194
1195 VALUE splat = Qfalse;
1196
1197 if (site_flag & VM_CALL_ARGS_SPLAT) {
1198 // If we're called with args_splat, the top 1 should be an array
1199 splat = TOPN(1);
1200 site_argc += (RARRAY_LEN(splat) - 1);
1201 }
1202
1203 // Need to setup the block in case of e.g. `super { :block }`
1204 if (is_super && blockiseq) {
1205 bh = vm_caller_setup_arg_block(ec, GET_CFP(), site_ci, blockiseq, is_super);
1206 }
1207 else {
1208 bh = VM_ENV_BLOCK_HANDLER(GET_LEP());
1209 }
1210
1211 vm_adjust_stack_forwarding(ec, GET_CFP(), caller_argc, splat);
1212
1213 *adjusted_ci = VM_CI_ON_STACK(
1214 site_mid,
1215 ((caller_flag & ~(VM_CALL_ARGS_SIMPLE | VM_CALL_FCALL)) |
1216 (site_flag & (VM_CALL_FCALL | VM_CALL_FORWARDING))),
1217 site_argc + caller_argc,
1218 kw
1219 );
1220
1221 adjusted_cd->cd.ci = adjusted_ci;
1222 adjusted_cd->cd.cc = cd->cc;
1223 adjusted_cd->caller_ci = caller_ci;
1224
1225 return bh;
1226}
#define RUBY_ASSERT(...)
Asserts that the given expression is truthy if and only if RUBY_DEBUG is truthy.
Definition assert.h:219
#define Qundef
Old name of RUBY_Qundef.
#define INT2FIX
Old name of RB_INT2FIX.
Definition long.h:48
#define OBJ_FROZEN
Old name of RB_OBJ_FROZEN.
Definition fl_type.h:133
#define ID2SYM
Old name of RB_ID2SYM.
Definition symbol.h:44
#define OBJ_FREEZE
Old name of RB_OBJ_FREEZE.
Definition fl_type.h:131
#define SYM2ID
Old name of RB_SYM2ID.
Definition symbol.h:45
#define T_DATA
Old name of RUBY_T_DATA.
Definition value_type.h:60
#define CLASS_OF
Old name of rb_class_of.
Definition globals.h:205
#define T_HASH
Old name of RUBY_T_HASH.
Definition value_type.h:65
#define FL_TEST_RAW
Old name of RB_FL_TEST_RAW.
Definition fl_type.h:128
#define Qnil
Old name of RUBY_Qnil.
#define Qfalse
Old name of RUBY_Qfalse.
#define NIL_P
Old name of RB_NIL_P.
#define FL_SET_RAW
Old name of RB_FL_SET_RAW.
Definition fl_type.h:126
#define SYMBOL_P
Old name of RB_SYMBOL_P.
Definition value_type.h:88
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
Definition eval.c:678
VALUE rb_cSymbol
Symbol class.
Definition string.c:86
VALUE rb_ary_dup(VALUE ary)
Duplicates an array.
VALUE rb_ary_resize(VALUE ary, rb_len_t len)
Expands or shrinks the passed array to the passed length.
VALUE rb_check_array_type(VALUE obj)
Try converting an object to its array representation using its to_ary method, if any.
VALUE rb_ary_new(void)
Allocates a new, empty array.
VALUE rb_ary_pop(VALUE ary)
Destructively deletes an element from the end of the passed array and returns what was deleted.
VALUE rb_ary_hidden_new(rb_len_t capa)
Allocates a hidden (no class) empty array.
VALUE rb_ary_push(VALUE ary, VALUE elem)
Special case of rb_ary_cat() that it adds only one element.
VALUE rb_ary_new_from_values(rb_len_t n, const VALUE *elts)
Identical to rb_ary_new_from_args(), except how objects are passed.
#define UNLIMITED_ARGUMENTS
This macro is used in conjunction with rb_check_arity().
Definition error.h:35
VALUE rb_obj_is_proc(VALUE recv)
Queries if the given object is a proc.
Definition proc.c:386
VALUE rb_str_append(VALUE dst, VALUE src)
Identical to rb_str_buf_append(), except it converts the right hand side before concatenating.
Definition string.c:3917
#define rb_exc_new_cstr(exc, str)
Identical to rb_exc_new(), except it assumes the passed pointer is a pointer to a C string.
Definition string.h:1695
VALUE rb_str_cat(VALUE dst, const char *src, rb_len_t srclen)
Destructively appends the passed contents to the string.
Definition string.c:3685
#define rb_str_cat_cstr(buf, str)
Identical to rb_str_cat(), except it assumes the passed pointer is a pointer to a C string.
Definition string.h:1681
VALUE rb_ivar_set(VALUE obj, ID name, VALUE val)
Identical to rb_iv_set(), except it accepts the name as an ID instead of a C string.
Definition variable.c:2141
int rb_method_basic_definition_p(VALUE klass, ID mid)
Well... Let us hesitate from describing what a "basic definition" is.
Definition vm_method.c:3574
int len
Length of the buffer.
Definition io.h:8
#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)
Shim for block function parameters.
Definition iterator.h:58
#define MEMCPY(p1, p2, type, n)
Handy macro to call memcpy.
Definition memory.h:372
#define ALLOCA_N(type, n)
Definition memory.h:292
#define RARRAY_LEN
Just another name of rb_array_len.
Definition rarray.h:50
static int RARRAY_LENINT(VALUE ary)
Identical to rb_array_len(), except it differs for the return type.
Definition rarray.h:280
#define RARRAY_AREF(a, i)
Definition rarray.h:402
static void RARRAY_ASET(VALUE ary, rb_len_t i, VALUE v)
Assigns an object in an array.
Definition rarray.h:385
#define RARRAY_CONST_PTR
Just another name of rb_array_const_ptr.
Definition rarray.h:51
#define RCLASS_SUPER
Just another name of rb_class_get_superclass.
Definition rclass.h:44
#define RHASH_SIZE(h)
Queries the size of the hash.
Definition rhash.h:57
#define RHASH_EMPTY_P(h)
Checks if the hash is empty.
Definition rhash.h:67
#define RB_PASS_CALLED_KEYWORDS
Pass keywords if current method is called with keywords, useful for argument delegation.
Definition scan_args.h:78
#define RB_NO_KEYWORDS
Do not pass keywords.
Definition scan_args.h:69
Definition hash.h:54
Definition method.h:63
CREF (Class REFerence)
Definition method.h:45
long rb_len_t
A signed integer type for lengths and indices of objects such as String and Array.
Definition value.h:131
uintptr_t ID
Type that represents a Ruby identifier such as a variable name.
Definition value.h:52
uintptr_t VALUE
Type that represents a Ruby object.
Definition value.h:40
static bool RB_TYPE_P(VALUE obj, enum ruby_value_type t)
Queries if the given object is of given type.
Definition value_type.h:376