Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

vm_args.c
Go to the documentation of this file.
1 /**********************************************************************
2
3 vm_args.c - process method call arguments.
4
5 $Author$
6
7 Copyright (C) 2014- Yukihiro Matsumoto
8
9 **********************************************************************/
10
11 NORETURN(static void raise_argument_error(rb_execution_context_t *ec, const rb_iseq_t *iseq, const VALUE exc));
12 NORETURN(static void argument_arity_error(rb_execution_context_t *ec, const rb_iseq_t *iseq, const int miss_argc, const int min_argc, const int max_argc));
13 NORETURN(static void argument_kw_error(rb_execution_context_t *ec, const rb_iseq_t *iseq, const char *error, const VALUE keys));
14 VALUE rb_keyword_error_new(const char *error, VALUE keys); /* class.c */
15 static VALUE method_missing(VALUE obj, ID id, int argc, const VALUE *argv,
16 enum method_missing_reason call_status, int kw_splat);
17 #if !defined(_MSC_VER) || !defined(MJIT_HEADER)
18 MJIT_FUNC_EXPORTED
19 #endif
20 const rb_callable_method_entry_t *rb_resolve_refined_method_callable(VALUE refinements, const rb_callable_method_entry_t *me);
21
22 struct args_info {
23 /* basic args info */
24 VALUE *argv;
25 int argc;
26
27 /* additional args info */
28 int rest_index;
29 int rest_dupped;
30 const struct rb_call_info_kw_arg *kw_arg;
31 VALUE *kw_argv;
32 VALUE rest;
33 };
34
35 enum arg_setup_type {
36 arg_setup_method,
37 arg_setup_block
38 };
39
40 static inline void
41 arg_rest_dup(struct args_info *args)
42 {
43 if (!args->rest_dupped) {
44 args->rest = rb_ary_dup(args->rest);
45 args->rest_dupped = TRUE;
46 }
47 }
48
49 static inline int
50 args_argc(struct args_info *args)
51 {
52 if (args->rest == Qfalse) {
53 return args->argc;
54 }
55 else {
56 return args->argc + RARRAY_LENINT(args->rest) - args->rest_index;
57 }
58 }
59
60 static inline void
61 args_extend(struct args_info *args, const int min_argc)
62 {
63 int i;
64
65 if (args->rest) {
66 arg_rest_dup(args);
67 VM_ASSERT(args->rest_index == 0);
68 for (i=args->argc + RARRAY_LENINT(args->rest); i<min_argc; i++) {
69 rb_ary_push(args->rest, Qnil);
70 }
71 }
72 else {
73 for (i=args->argc; i<min_argc; i++) {
74 args->argv[args->argc++] = Qnil;
75 }
76 }
77 }
78
79 static inline void
80 args_reduce(struct args_info *args, int over_argc)
81 {
82 if (args->rest) {
83 const long len = RARRAY_LEN(args->rest);
84
85 if (len > over_argc) {
86 arg_rest_dup(args);
87 rb_ary_resize(args->rest, len - over_argc);
88 return;
89 }
90 else {
91 args->rest = Qfalse;
92 over_argc -= len;
93 }
94 }
95
96 VM_ASSERT(args->argc >= over_argc);
97 args->argc -= over_argc;
98 }
99
100 static inline int
101 args_check_block_arg0(struct args_info *args)
102 {
103 VALUE ary = Qnil;
104
105 if (args->rest && RARRAY_LEN(args->rest) == 1) {
106 VALUE arg0 = RARRAY_AREF(args->rest, 0);
107 ary = rb_check_array_type(arg0);
108 }
109 else if (args->argc == 1) {
110 VALUE arg0 = args->argv[0];
111 ary = rb_check_array_type(arg0);
112 args->argv[0] = arg0; /* see: https://bugs.ruby-lang.org/issues/8484 */
113 }
114
115 if (!NIL_P(ary)) {
116 args->rest = ary;
117 args->rest_index = 0;
118 args->argc = 0;
119 return TRUE;
120 }
121
122 return FALSE;
123 }
124
125 static inline void
126 args_copy(struct args_info *args)
127 {
128 if (args->rest != Qfalse) {
129 int argc = args->argc;
130 args->argc = 0;
131 arg_rest_dup(args);
132
133 /*
134 * argv: [m0, m1, m2, m3]
135 * rest: [a0, a1, a2, a3, a4, a5]
136 * ^
137 * rest_index
138 *
139 * #=> first loop
140 *
141 * argv: [m0, m1]
142 * rest: [m2, m3, a2, a3, a4, a5]
143 * ^
144 * rest_index
145 *
146 * #=> 2nd loop
147 *
148 * argv: [] (argc == 0)
149 * rest: [m0, m1, m2, m3, a2, a3, a4, a5]
150 * ^
151 * rest_index
152 */
153 while (args->rest_index > 0 && argc > 0) {
154 RARRAY_ASET(args->rest, --args->rest_index, args->argv[--argc]);
155 }
156 while (argc > 0) {
157 rb_ary_unshift(args->rest, args->argv[--argc]);
158 }
159 }
160 else if (args->argc > 0) {
161 args->rest = rb_ary_new_from_values(args->argc, args->argv);
162 args->rest_index = 0;
163 args->rest_dupped = TRUE;
164 args->argc = 0;
165 }
166 }
167
168 static inline const VALUE *
169 args_rest_argv(struct args_info *args)
170 {
171 return RARRAY_CONST_PTR_TRANSIENT(args->rest) + args->rest_index;
172 }
173
174 static inline VALUE
175 args_rest_array(struct args_info *args)
176 {
177 VALUE ary;
178
179 if (args->rest) {
180 ary = rb_ary_behead(args->rest, args->rest_index);
181 args->rest_index = 0;
182 args->rest = 0;
183 }
184 else {
185 ary = rb_ary_new();
186 }
187 return ary;
188 }
189
190 #define KW_HASH_HAS_NO_KEYS 0
191 #define KW_HASH_HAS_SYMBOL_KEY 1
192 #define KW_HASH_HAS_OTHER_KEY 2
193 #define KW_HASH_HAS_BOTH_KEYS 3
194
195 static int
196 keyword_hash_symbol_other_iter(st_data_t key, st_data_t val, st_data_t arg)
197 {
198 *(int*)arg |= SYMBOL_P((VALUE)key) ? KW_HASH_HAS_SYMBOL_KEY : KW_HASH_HAS_OTHER_KEY;
199
200 if ((*(int*)arg & KW_HASH_HAS_BOTH_KEYS) == KW_HASH_HAS_BOTH_KEYS) {
201 return ST_STOP;
202 }
203
204 return ST_CONTINUE;
205 }
206
207 static int
208 keyword_hash_symbol_other(VALUE hash)
209 {
210 int symbol_other = KW_HASH_HAS_NO_KEYS;
211 rb_hash_stlike_foreach(hash, keyword_hash_symbol_other_iter, (st_data_t)(&symbol_other));
212 return symbol_other;
213 }
214
215 static int
216 keyword_hash_split_iter(st_data_t key, st_data_t val, st_data_t arg)
217 {
218 if (SYMBOL_P((VALUE)key)) {
219 rb_hash_aset((VALUE)arg, (VALUE)key, (VALUE)val);
220 return ST_DELETE;
221 }
222
223 return ST_CONTINUE;
224 }
225
226 static void
227 keyword_hash_split(VALUE *kw_hash_ptr, VALUE *rest_hash_ptr)
228 {
229 *kw_hash_ptr = rb_hash_new();
230 rb_hash_stlike_foreach(*rest_hash_ptr, keyword_hash_split_iter, (st_data_t)(*kw_hash_ptr));
231 }
232
233 static int
234 keyword_hash_p(VALUE *kw_hash_ptr, VALUE *rest_hash_ptr, int check_only_symbol)
235 {
236 *rest_hash_ptr = rb_check_hash_type(*kw_hash_ptr);
237
238 if (!NIL_P(*rest_hash_ptr)) {
239 if (check_only_symbol) {
240 switch (keyword_hash_symbol_other(*rest_hash_ptr)) {
241 case KW_HASH_HAS_NO_KEYS:
242 case KW_HASH_HAS_SYMBOL_KEY:
243 break;
244 case KW_HASH_HAS_OTHER_KEY:
245 *kw_hash_ptr = Qnil;
246 return FALSE;
247 case KW_HASH_HAS_BOTH_KEYS:
248 *rest_hash_ptr = rb_hash_dup(*rest_hash_ptr);
249 keyword_hash_split(kw_hash_ptr, rest_hash_ptr);
250 return TRUE;
251 }
252 }
253 *kw_hash_ptr = *rest_hash_ptr;
254 *rest_hash_ptr = Qfalse;
255 return TRUE;
256 }
257 else {
258 *kw_hash_ptr = Qnil;
259 return FALSE;
260 }
261 }
262
263 static VALUE
264 args_pop_keyword_hash(struct args_info *args, VALUE *kw_hash_ptr, int check_only_symbol)
265 {
266 VALUE rest_hash;
267
268 if (args->rest == Qfalse) {
269 from_argv:
270 VM_ASSERT(args->argc > 0);
271 *kw_hash_ptr = args->argv[args->argc-1];
272
273 if (keyword_hash_p(kw_hash_ptr, &rest_hash, check_only_symbol)) {
274 if (rest_hash) {
275 args->argv[args->argc-1] = rest_hash;
276 }
277 else {
278 args->argc--;
279 return TRUE;
280 }
281 }
282 }
283 else {
284 long len = RARRAY_LEN(args->rest);
285
286 if (len > 0) {
287 *kw_hash_ptr = RARRAY_AREF(args->rest, len - 1);
288
289 if (keyword_hash_p(kw_hash_ptr, &rest_hash, check_only_symbol)) {
290 if (rest_hash) {
291 RARRAY_ASET(args->rest, len - 1, rest_hash);
292 }
293 else {
294 arg_rest_dup(args);
295 rb_ary_pop(args->rest);
296 return TRUE;
297 }
298 }
299 }
300 else {
301 goto from_argv;
302 }
303 }
304
305 return FALSE;
306 }
307
308 static int
309 args_kw_argv_to_hash(struct args_info *args)
310 {
311 const struct rb_call_info_kw_arg *kw_arg = args->kw_arg;
312 const VALUE *const passed_keywords = kw_arg->keywords;
313 const int kw_len = kw_arg->keyword_len;
314 VALUE h = rb_hash_new_with_size(kw_len);
315 const int kw_start = args->argc - kw_len;
316 const VALUE * const kw_argv = args->argv + kw_start;
317 int i;
318
319 args->argc = kw_start + 1;
320 for (i=0; i<kw_len; i++) {
321 rb_hash_aset(h, passed_keywords[i], kw_argv[i]);
322 }
323
324 args->argv[args->argc - 1] = h;
325
326 return args->argc;
327 }
328
329 static void
330 args_stored_kw_argv_to_hash(struct args_info *args)
331 {
332 int i;
333 const struct rb_call_info_kw_arg *kw_arg = args->kw_arg;
334 const VALUE *const passed_keywords = kw_arg->keywords;
335 const int passed_keyword_len = kw_arg->keyword_len;
336 VALUE h = rb_hash_new_with_size(passed_keyword_len);
337
338 for (i=0; i<passed_keyword_len; i++) {
339 rb_hash_aset(h, passed_keywords[i], args->kw_argv[i]);
340 }
341 args->kw_argv = NULL;
342
343 if (args->rest) {
344 arg_rest_dup(args);
345 rb_ary_push(args->rest, h);
346 }
347 else {
348 args->argv[args->argc++] = h;
349 }
350 }
351
352 static inline void
353 args_setup_lead_parameters(struct args_info *args, int argc, VALUE *locals)
354 {
355 if (args->argc >= argc) {
356 /* do noting */
357 args->argc -= argc;
358 args->argv += argc;
359 }
360 else {
361 int i, j;
362 const VALUE *argv = args_rest_argv(args);
363
364 for (i=args->argc, j=0; i<argc; i++, j++) {
365 locals[i] = argv[j];
366 }
367 args->rest_index += argc - args->argc;
368 args->argc = 0;
369 }
370 }
371
372 static inline void
373 args_setup_post_parameters(struct args_info *args, int argc, VALUE *locals)
374 {
375 long len;
376 len = RARRAY_LEN(args->rest);
377 MEMCPY(locals, RARRAY_CONST_PTR_TRANSIENT(args->rest) + len - argc, VALUE, argc);
378 rb_ary_resize(args->rest, len - argc);
379 }
380
381 static inline int
382 args_setup_opt_parameters(struct args_info *args, int opt_max, VALUE *locals)
383 {
384 int i;
385
386 if (args->argc >= opt_max) {
387 args->argc -= opt_max;
388 args->argv += opt_max;
389 i = opt_max;
390 }
391 else {
392 int j;
393 i = args->argc;
394 args->argc = 0;
395
396 if (args->rest) {
397 int len = RARRAY_LENINT(args->rest);
398 const VALUE *argv = RARRAY_CONST_PTR_TRANSIENT(args->rest);
399
400 for (; i<opt_max && args->rest_index < len; i++, args->rest_index++) {
401 locals[i] = argv[args->rest_index];
402 }
403 }
404
405 /* initialize by nil */
406 for (j=i; j<opt_max; j++) {
407 locals[j] = Qnil;
408 }
409 }
410
411 return i;
412 }
413
414 static inline void
415 args_setup_rest_parameter(struct args_info *args, VALUE *locals)
416 {
417 *locals = args_rest_array(args);
418 }
419
420 static VALUE
421 make_unknown_kw_hash(const VALUE *passed_keywords, int passed_keyword_len, const VALUE *kw_argv)
422 {
423 int i;
424 VALUE obj = rb_ary_tmp_new(1);
425
426 for (i=0; i<passed_keyword_len; i++) {
427 if (kw_argv[i] != Qundef) {
428 rb_ary_push(obj, passed_keywords[i]);
429 }
430 }
431 return obj;
432 }
433
434 static VALUE
435 make_rest_kw_hash(const VALUE *passed_keywords, int passed_keyword_len, const VALUE *kw_argv)
436 {
437 int i;
438 VALUE obj = rb_hash_new_with_size(passed_keyword_len);
439
440 for (i=0; i<passed_keyword_len; i++) {
441 if (kw_argv[i] != Qundef) {
442 rb_hash_aset(obj, passed_keywords[i], kw_argv[i]);
443 }
444 }
445 return obj;
446 }
447
448 static inline int
449 args_setup_kw_parameters_lookup(const ID key, VALUE *ptr, const VALUE *const passed_keywords, VALUE *passed_values, const int passed_keyword_len)
450 {
451 int i;
452 const VALUE keyname = ID2SYM(key);
453
454 for (i=0; i<passed_keyword_len; i++) {
455 if (keyname == passed_keywords[i]) {
456 *ptr = passed_values[i];
457 passed_values[i] = Qundef;
458 return TRUE;
459 }
460 }
461
462 return FALSE;
463 }
464
465 #define KW_SPECIFIED_BITS_MAX (32-1) /* TODO: 32 -> Fixnum's max bits */
466
467 static void
468 args_setup_kw_parameters(rb_execution_context_t *const ec, const rb_iseq_t *const iseq,
469 VALUE *const passed_values, const int passed_keyword_len, const VALUE *const passed_keywords,
470 VALUE *const locals)
471 {
472 const ID *acceptable_keywords = iseq->body->param.keyword->table;
473 const int req_key_num = iseq->body->param.keyword->required_num;
474 const int key_num = iseq->body->param.keyword->num;
475 const VALUE * const default_values = iseq->body->param.keyword->default_values;
476 VALUE missing = 0;
477 int i, di, found = 0;
478 int unspecified_bits = 0;
479 VALUE unspecified_bits_value = Qnil;
480
481 for (i=0; i<req_key_num; i++) {
482 ID key = acceptable_keywords[i];
483 if (args_setup_kw_parameters_lookup(key, &locals[i], passed_keywords, passed_values, passed_keyword_len)) {
484 found++;
485 }
486 else {
487 if (!missing) missing = rb_ary_tmp_new(1);
488 rb_ary_push(missing, ID2SYM(key));
489 }
490 }
491
492 if (missing) argument_kw_error(ec, iseq, "missing", missing);
493
494 for (di=0; i<key_num; i++, di++) {
495 if (args_setup_kw_parameters_lookup(acceptable_keywords[i], &locals[i], passed_keywords, passed_values, passed_keyword_len)) {
496 found++;
497 }
498 else {
499 if (default_values[di] == Qundef) {
500 locals[i] = Qnil;
501
502 if (LIKELY(i < KW_SPECIFIED_BITS_MAX)) {
503 unspecified_bits |= 0x01 << di;
504 }
505 else {
506 if (NIL_P(unspecified_bits_value)) {
507 /* fixnum -> hash */
508 int j;
509 unspecified_bits_value = rb_hash_new();
510
511 for (j=0; j<KW_SPECIFIED_BITS_MAX; j++) {
512 if (unspecified_bits & (0x01 << j)) {
513 rb_hash_aset(unspecified_bits_value, INT2FIX(j), Qtrue);
514 }
515 }
516 }
517 rb_hash_aset(unspecified_bits_value, INT2FIX(di), Qtrue);
518 }
519 }
520 else {
521 locals[i] = default_values[di];
522 }
523 }
524 }
525
526 if (iseq->body->param.flags.has_kwrest) {
527 const int rest_hash_index = key_num + 1;
528 locals[rest_hash_index] = make_rest_kw_hash(passed_keywords, passed_keyword_len, passed_values);
529 }
530 else {
531 if (found != passed_keyword_len) {
532 VALUE keys = make_unknown_kw_hash(passed_keywords, passed_keyword_len, passed_values);
533 argument_kw_error(ec, iseq, "unknown", keys);
534 }
535 }
536
537 if (NIL_P(unspecified_bits_value)) {
538 unspecified_bits_value = INT2FIX(unspecified_bits);
539 }
540 locals[key_num] = unspecified_bits_value;
541 }
542
543 static inline void
544 args_setup_kw_rest_parameter(VALUE keyword_hash, VALUE *locals)
545 {
546 locals[0] = NIL_P(keyword_hash) ? rb_hash_new() : rb_hash_dup(keyword_hash);
547 }
548
549 static inline void
550 args_setup_block_parameter(const rb_execution_context_t *ec, struct rb_calling_info *calling, VALUE *locals)
551 {
552 VALUE block_handler = calling->block_handler;
553 *locals = rb_vm_bh_to_procval(ec, block_handler);
554 }
555
556 struct fill_values_arg {
557 VALUE *keys;
558 VALUE *vals;
559 int argc;
560 };
561
562 static int
563 fill_keys_values(st_data_t key, st_data_t val, st_data_t ptr)
564 {
565 struct fill_values_arg *arg = (struct fill_values_arg *)ptr;
566 int i = arg->argc++;
567 arg->keys[i] = (VALUE)key;
568 arg->vals[i] = (VALUE)val;
569 return ST_CONTINUE;
570 }
571
572 static inline int
573 ignore_keyword_hash_p(VALUE keyword_hash, const rb_iseq_t * const iseq)
574 {
575 if (!(iseq->body->param.flags.has_kw) &&
576 !(iseq->body->param.flags.has_kwrest)) {
577 keyword_hash = rb_check_hash_type(keyword_hash);
578
579 if (!NIL_P(keyword_hash) && RHASH_EMPTY_P(keyword_hash)) {
580 return 1;
581 }
582 }
583
584 return 0;
585 }
586
587 VALUE rb_iseq_location(const rb_iseq_t *iseq);
588
589 /* -- Remove In 3.0 -- */
590
591 /* This is a map from caller PC to a set of callee methods.
592 * When a warning about keyword argument change is printed,
593 * it keeps the pair of callee and caller.
594 */
595 static st_table *caller_to_callees = 0;
596
597 static VALUE
598 rb_warn_check(const rb_execution_context_t * const ec, const rb_iseq_t *const iseq)
599 {
600 if (!rb_warning_category_enabled_p(RB_WARN_CATEGORY_DEPRECATED)) return 1;
601
602 if (!iseq) return 0;
603
604 const st_data_t callee = (st_data_t)(iseq->body->iseq_unique_id * 2);
605
606 const rb_control_frame_t * const cfp = rb_vm_get_ruby_level_next_cfp(ec, ec->cfp);
607
608 if (!cfp) return 0;
609
610 const st_data_t caller = (st_data_t)cfp->pc;
611
612 if (!caller_to_callees) {
613 caller_to_callees = st_init_numtable();
614 }
615
616 st_data_t val;
617 if (st_lookup(caller_to_callees, caller, &val)) {
618 st_table *callees;
619
620 if (val & 1) {
621 val &= ~(st_data_t)1;
622 if (val == callee) return 1; /* already warned */
623
624 callees = st_init_numtable();
625 st_insert(callees, val, 1);
626 }
627 else {
628 callees = (st_table *) val;
629 if (st_is_member(callees, callee)) return 1; /* already warned */
630 }
631 st_insert(callees, callee, 1);
632 st_insert(caller_to_callees, caller, (st_data_t) callees);
633 }
634 else {
635 st_insert(caller_to_callees, caller, callee | 1);
636 }
637
638 return 0; /* not warned yet for the pair of caller and callee */
639 }
640
641 static inline void
642 rb_warn_keyword_to_last_hash(rb_execution_context_t * const ec, struct rb_calling_info *calling, const struct rb_call_info *ci, const rb_iseq_t * const iseq)
643 {
644 if (rb_warn_check(ec, iseq)) return;
645
646 VALUE name, loc;
647 if (calling->recv == Qundef) {
648 rb_warn("Passing the keyword argument as the last hash parameter is deprecated");
649 return;
650 }
651 name = rb_id2str(ci->mid);
652 loc = rb_iseq_location(iseq);
653 if (NIL_P(loc)) {
654 rb_warn("Passing the keyword argument for `%"PRIsVALUE"' as the last hash parameter is deprecated",
655 name);
656 }
657 else {
658 rb_warn("Passing the keyword argument as the last hash parameter is deprecated");
659 if (name) {
660 rb_compile_warn(RSTRING_PTR(RARRAY_AREF(loc, 0)), FIX2INT(RARRAY_AREF(loc, 1)),
661 "The called method `%"PRIsVALUE"' is defined here", name);
662 }
663 else {
664 rb_compile_warn(RSTRING_PTR(RARRAY_AREF(loc, 0)), FIX2INT(RARRAY_AREF(loc, 1)),
665 "The called method is defined here");
666 }
667 }
668 }
669
670 static inline void
671 rb_warn_split_last_hash_to_keyword(rb_execution_context_t * const ec, struct rb_calling_info *calling, const struct rb_call_info *ci, const rb_iseq_t * const iseq)
672 {
673 if (rb_warn_check(ec, iseq)) return;
674
675 VALUE name, loc;
676 name = rb_id2str(ci->mid);
677 loc = rb_iseq_location(iseq);
678 if (NIL_P(loc)) {
679 rb_warn("Splitting the last argument for `%"PRIsVALUE"' into positional and keyword parameters is deprecated",
680 name);
681 }
682 else {
683 rb_warn("Splitting the last argument into positional and keyword parameters is deprecated");
684 if (calling->recv != Qundef) {
685 rb_compile_warn(RSTRING_PTR(RARRAY_AREF(loc, 0)), FIX2INT(RARRAY_AREF(loc, 1)),
686 "The called method `%"PRIsVALUE"' is defined here", name);
687 }
688 else {
689 rb_compile_warn(RSTRING_PTR(RARRAY_AREF(loc, 0)), FIX2INT(RARRAY_AREF(loc, 1)),
690 "The called method is defined here");
691 }
692 }
693 }
694
695 static inline void
696 rb_warn_last_hash_to_keyword(rb_execution_context_t * const ec, struct rb_calling_info *calling, const struct rb_call_info *ci, const rb_iseq_t * const iseq)
697 {
698 if (rb_warn_check(ec, iseq)) return;
699
700 VALUE name, loc;
701 name = rb_id2str(ci->mid);
702 loc = rb_iseq_location(iseq);
703 if (NIL_P(loc)) {
704 rb_warn("Using the last argument for `%"PRIsVALUE"' as keyword parameters is deprecated; maybe ** should be added to the call",
705 name);
706 }
707 else {
708 rb_warn("Using the last argument as keyword parameters is deprecated; maybe ** should be added to the call");
709 if (calling->recv != Qundef) {
710 rb_compile_warn(RSTRING_PTR(RARRAY_AREF(loc, 0)), FIX2INT(RARRAY_AREF(loc, 1)),
711 "The called method `%"PRIsVALUE"' is defined here", name);
712 }
713 else {
714 rb_compile_warn(RSTRING_PTR(RARRAY_AREF(loc, 0)), FIX2INT(RARRAY_AREF(loc, 1)),
715 "The called method is defined here");
716 }
717 }
718 }
719
720 static int
721 setup_parameters_complex(rb_execution_context_t * const ec, const rb_iseq_t * const iseq,
722 struct rb_calling_info *const calling,
723 const struct rb_call_info *ci,
724 VALUE * const locals, const enum arg_setup_type arg_setup_type)
725 {
726 const int min_argc = iseq->body->param.lead_num + iseq->body->param.post_num;
727 const int max_argc = (iseq->body->param.flags.has_rest == FALSE) ? min_argc + iseq->body->param.opt_num : UNLIMITED_ARGUMENTS;
728 int opt_pc = 0;
729 int given_argc;
730 int kw_splat = FALSE;
731 unsigned int kw_flag = ci->flag & (VM_CALL_KWARG | VM_CALL_KW_SPLAT);
732 struct args_info args_body, *args;
733 VALUE keyword_hash = Qnil;
734 VALUE * const orig_sp = ec->cfp->sp;
735 unsigned int i;
736 int remove_empty_keyword_hash = 1;
737 VALUE flag_keyword_hash = 0;
738
739 vm_check_canary(ec, orig_sp);
740 /*
741 * Extend SP for GC.
742 *
743 * [pushed values] [uninitialized values]
744 * <- ci->argc -->
745 * <- iseq->body->param.size------------>
746 * ^ locals ^ sp
747 *
748 * =>
749 * [pushed values] [initialized values ]
750 * <- ci->argc -->
751 * <- iseq->body->param.size------------>
752 * ^ locals ^ sp
753 */
754 for (i=calling->argc; i<iseq->body->param.size; i++) {
755 locals[i] = Qnil;
756 }
757 ec->cfp->sp = &locals[i];
758
759 /* setup args */
760 args = &args_body;
761 given_argc = args->argc = calling->argc;
762 args->argv = locals;
763 args->rest_dupped = FALSE;
764
765 if (kw_flag & VM_CALL_KWARG) {
766 args->kw_arg = ((struct rb_call_info_with_kwarg *)ci)->kw_arg;
767
768 if (iseq->body->param.flags.has_kw) {
769 int kw_len = args->kw_arg->keyword_len;
770 /* copy kw_argv */
771 args->kw_argv = ALLOCA_N(VALUE, kw_len);
772 args->argc -= kw_len;
773 given_argc -= kw_len;
774 MEMCPY(args->kw_argv, locals + args->argc, VALUE, kw_len);
775 }
776 else {
777 args->kw_argv = NULL;
778 given_argc = args_kw_argv_to_hash(args);
779 kw_flag |= VM_CALL_KW_SPLAT;
780 }
781 }
782 else {
783 args->kw_arg = NULL;
784 args->kw_argv = NULL;
785 }
786
787 if (kw_flag && iseq->body->param.flags.ruby2_keywords) {
788 remove_empty_keyword_hash = 0;
789 }
790
791 if (ci->flag & VM_CALL_ARGS_SPLAT) {
792 VALUE rest_last = 0;
793 int len;
794 args->rest = locals[--args->argc];
795 args->rest_index = 0;
796 len = RARRAY_LENINT(args->rest);
797 given_argc += len - 1;
798 rest_last = RARRAY_AREF(args->rest, len - 1);
799
800 if (!kw_flag && len > 0) {
801 if (RB_TYPE_P(rest_last, T_HASH) &&
802 (((struct RHash *)rest_last)->basic.flags & RHASH_PASS_AS_KEYWORDS)) {
803 rest_last = rb_hash_dup(rest_last);
804 kw_flag |= VM_CALL_KW_SPLAT;
805 if (iseq->body->param.flags.ruby2_keywords) {
806 remove_empty_keyword_hash = 0;
807 }
808 }
809 else {
810 rest_last = 0;
811 }
812 }
813
814 if (kw_flag & VM_CALL_KW_SPLAT) {
815 if (len > 0 && ignore_keyword_hash_p(rest_last, iseq)) {
816 if (given_argc != min_argc) {
817 if (remove_empty_keyword_hash) {
818 arg_rest_dup(args);
819 rb_ary_pop(args->rest);
820 given_argc--;
821 kw_flag &= ~VM_CALL_KW_SPLAT;
822 }
823 else {
824 flag_keyword_hash = rest_last;
825 }
826 }
827 else {
828 rb_warn_keyword_to_last_hash(ec, calling, ci, iseq);
829 }
830 }
831 else if (!remove_empty_keyword_hash && rest_last) {
832 flag_keyword_hash = rest_last;
833 }
834 }
835 }
836 else {
837 if (kw_flag & VM_CALL_KW_SPLAT) {
838 VALUE last_arg = args->argv[args->argc-1];
839 if (ignore_keyword_hash_p(last_arg, iseq)) {
840 if (given_argc != min_argc) {
841 if (remove_empty_keyword_hash) {
842 args->argc--;
843 given_argc--;
844 kw_flag &= ~VM_CALL_KW_SPLAT;
845 }
846 else {
847 flag_keyword_hash = last_arg;
848 }
849 }
850 else {
851 rb_warn_keyword_to_last_hash(ec, calling, ci, iseq);
852 }
853 }
854 else if (!remove_empty_keyword_hash) {
855 flag_keyword_hash = args->argv[args->argc-1];
856 }
857 }
858 args->rest = Qfalse;
859 }
860
861 if (flag_keyword_hash && RB_TYPE_P(flag_keyword_hash, T_HASH)) {
862 ((struct RHash *)flag_keyword_hash)->basic.flags |= RHASH_PASS_AS_KEYWORDS;
863 }
864
865 if (kw_flag && iseq->body->param.flags.accepts_no_kwarg) {
866 rb_raise(rb_eArgError, "no keywords accepted");
867 }
868
869 switch (arg_setup_type) {
870 case arg_setup_method:
871 break; /* do nothing special */
872 case arg_setup_block:
873 if (given_argc == 1 &&
874 (min_argc > 0 || iseq->body->param.opt_num > 1 ||
875 iseq->body->param.flags.has_kw || iseq->body->param.flags.has_kwrest) &&
876 !iseq->body->param.flags.ambiguous_param0 &&
877 args_check_block_arg0(args)) {
878 given_argc = RARRAY_LENINT(args->rest);
879 }
880 break;
881 }
882
883 /* argc check */
884 if (given_argc < min_argc) {
885 if (given_argc == min_argc - 1 && args->kw_argv) {
886 args_stored_kw_argv_to_hash(args);
887 given_argc = args_argc(args);
888 }
889 else {
890 if (arg_setup_type == arg_setup_block) {
891 CHECK_VM_STACK_OVERFLOW(ec->cfp, min_argc);
892 given_argc = min_argc;
893 args_extend(args, min_argc);
894 }
895 else {
896 argument_arity_error(ec, iseq, given_argc, min_argc, max_argc);
897 }
898 }
899 }
900
901 if (kw_flag & VM_CALL_KW_SPLAT) {
902 kw_splat = !iseq->body->param.flags.has_rest;
903 }
904 if ((iseq->body->param.flags.has_kw || iseq->body->param.flags.has_kwrest ||
905 (kw_splat && given_argc > max_argc)) &&
906 args->kw_argv == NULL) {
907 if (given_argc > min_argc) {
908 if (kw_flag) {
909 int check_only_symbol = (kw_flag & VM_CALL_KW_SPLAT) &&
910 iseq->body->param.flags.has_kw &&
911 !iseq->body->param.flags.has_kwrest;
912
913 if (args_pop_keyword_hash(args, &keyword_hash, check_only_symbol)) {
914 given_argc--;
915 }
916 else if (check_only_symbol) {
917 if (keyword_hash != Qnil) {
918 rb_warn_split_last_hash_to_keyword(ec, calling, ci, iseq);
919 }
920 else {
921 rb_warn_keyword_to_last_hash(ec, calling, ci, iseq);
922 }
923 }
924 }
925 else if (args_pop_keyword_hash(args, &keyword_hash, 1)) {
926 /* Warn the following:
927 * def foo(k:1) p [k]; end
928 * foo({k:42}) #=> 42
929 */
930 rb_warn_last_hash_to_keyword(ec, calling, ci, iseq);
931 given_argc--;
932 }
933 else if (keyword_hash != Qnil) {
934 rb_warn_split_last_hash_to_keyword(ec, calling, ci, iseq);
935 }
936 }
937 else if (given_argc == min_argc && kw_flag) {
938 rb_warn_keyword_to_last_hash(ec, calling, ci, iseq);
939 }
940 }
941
942 if (given_argc > max_argc && max_argc != UNLIMITED_ARGUMENTS) {
943 if (arg_setup_type == arg_setup_block) {
944 /* truncate */
945 args_reduce(args, given_argc - max_argc);
946 given_argc = max_argc;
947 }
948 else {
949 argument_arity_error(ec, iseq, given_argc, min_argc, max_argc);
950 }
951 }
952
953 if (iseq->body->param.flags.has_lead) {
954 args_setup_lead_parameters(args, iseq->body->param.lead_num, locals + 0);
955 }
956
957 if (iseq->body->param.flags.has_rest || iseq->body->param.flags.has_post){
958 args_copy(args);
959 }
960
961 if (iseq->body->param.flags.has_post) {
962 args_setup_post_parameters(args, iseq->body->param.post_num, locals + iseq->body->param.post_start);
963 }
964
965 if (iseq->body->param.flags.has_opt) {
966 int opt = args_setup_opt_parameters(args, iseq->body->param.opt_num, locals + iseq->body->param.lead_num);
967 opt_pc = (int)iseq->body->param.opt_table[opt];
968 }
969
970 if (iseq->body->param.flags.has_rest) {
971 args_setup_rest_parameter(args, locals + iseq->body->param.rest_start);
972 }
973
974 if (iseq->body->param.flags.has_kw) {
975 VALUE * const klocals = locals + iseq->body->param.keyword->bits_start - iseq->body->param.keyword->num;
976
977 if (args->kw_argv != NULL) {
978 const struct rb_call_info_kw_arg *kw_arg = args->kw_arg;
979 args_setup_kw_parameters(ec, iseq, args->kw_argv, kw_arg->keyword_len, kw_arg->keywords, klocals);
980 }
981 else if (!NIL_P(keyword_hash)) {
982 int kw_len = rb_long2int(RHASH_SIZE(keyword_hash));
983 struct fill_values_arg arg;
984 /* copy kw_argv */
985 arg.keys = args->kw_argv = ALLOCA_N(VALUE, kw_len * 2);
986 arg.vals = arg.keys + kw_len;
987 arg.argc = 0;
988 rb_hash_foreach(keyword_hash, fill_keys_values, (VALUE)&arg);
989 VM_ASSERT(arg.argc == kw_len);
990 args_setup_kw_parameters(ec, iseq, arg.vals, kw_len, arg.keys, klocals);
991 }
992 else {
993 VM_ASSERT(args_argc(args) == 0);
994 args_setup_kw_parameters(ec, iseq, NULL, 0, NULL, klocals);
995 }
996 }
997 else if (iseq->body->param.flags.has_kwrest) {
998 args_setup_kw_rest_parameter(keyword_hash, locals + iseq->body->param.keyword->rest_start);
999 }
1000 else if (!NIL_P(keyword_hash) && RHASH_SIZE(keyword_hash) > 0 && arg_setup_type == arg_setup_method) {
1001 argument_kw_error(ec, iseq, "unknown", rb_hash_keys(keyword_hash));
1002 }
1003
1004 if (iseq->body->param.flags.has_block) {
1005 if (iseq->body->local_iseq == iseq) {
1006 /* Do nothing */
1007 }
1008 else {
1009 args_setup_block_parameter(ec, calling, locals + iseq->body->param.block_start);
1010 }
1011 }
1012
1013 #if 0
1014 {
1015 int i;
1016 for (i=0; i<iseq->body->param.size; i++) {
1017 fprintf(stderr, "local[%d] = %p\n", i, (void *)locals[i]);
1018 }
1019 }
1020 #endif
1021
1022 ec->cfp->sp = orig_sp;
1023 return opt_pc;
1024 }
1025
1026 void rb_backtrace_use_iseq_first_lineno_for_last_location(VALUE self); /* vm_backtrace.c */
1027
1028 static void
1029 raise_argument_error(rb_execution_context_t *ec, const rb_iseq_t *iseq, const VALUE exc)
1030 {
1031 VALUE at;
1032
1033 if (iseq) {
1034 vm_push_frame(ec, iseq, VM_FRAME_MAGIC_DUMMY | VM_ENV_FLAG_LOCAL, Qnil /* self */,
1035 VM_BLOCK_HANDLER_NONE /* specval*/, Qfalse /* me or cref */,
1036 iseq->body->iseq_encoded,
1037 ec->cfp->sp, 0, 0 /* stack_max */);
1038 at = rb_ec_backtrace_object(ec);
1039 rb_backtrace_use_iseq_first_lineno_for_last_location(at);
1040 rb_vm_pop_frame(ec);
1041 }
1042 else {
1043 at = rb_ec_backtrace_object(ec);
1044 }
1045
1046 rb_ivar_set(exc, idBt_locations, at);
1047 rb_exc_set_backtrace(exc, at);
1048 rb_exc_raise(exc);
1049 }
1050
1051 static void
1052 argument_arity_error(rb_execution_context_t *ec, const rb_iseq_t *iseq, const int miss_argc, const int min_argc, const int max_argc)
1053 {
1054 VALUE exc = rb_arity_error_new(miss_argc, min_argc, max_argc);
1055 if (iseq->body->param.flags.has_kw) {
1056 const struct rb_iseq_param_keyword *const kw = iseq->body->param.keyword;
1057 const ID *keywords = kw->table;
1058 int req_key_num = kw->required_num;
1059 if (req_key_num > 0) {
1060 static const char required[] = "; required keywords";
1061 VALUE mesg = rb_attr_get(exc, idMesg);
1062 rb_str_resize(mesg, RSTRING_LEN(mesg)-1);
1063 rb_str_cat(mesg, required, sizeof(required) - 1 - (req_key_num == 1));
1064 rb_str_cat_cstr(mesg, ":");
1065 do {
1066 rb_str_cat_cstr(mesg, " ");
1067 rb_str_append(mesg, rb_id2str(*keywords++));
1068 rb_str_cat_cstr(mesg, ",");
1069 } while (--req_key_num);
1070 RSTRING_PTR(mesg)[RSTRING_LEN(mesg)-1] = ')';
1071 }
1072 }
1073 raise_argument_error(ec, iseq, exc);
1074 }
1075
1076 static void
1077 argument_kw_error(rb_execution_context_t *ec, const rb_iseq_t *iseq, const char *error, const VALUE keys)
1078 {
1079 raise_argument_error(ec, iseq, rb_keyword_error_new(error, keys));
1080 }
1081
1082 static inline void
1083 vm_caller_setup_arg_splat(rb_control_frame_t *cfp, struct rb_calling_info *calling)
1084 {
1085 int argc = calling->argc;
1086 VALUE *argv = cfp->sp - argc;
1087 VALUE ary = argv[argc-1];
1088
1089 vm_check_canary(GET_EC(), cfp->sp);
1090 cfp->sp--;
1091
1092 if (!NIL_P(ary)) {
1093 const VALUE *ptr = RARRAY_CONST_PTR_TRANSIENT(ary);
1094 long len = RARRAY_LEN(ary), i;
1095
1096 CHECK_VM_STACK_OVERFLOW(cfp, len);
1097
1098 for (i = 0; i < len; i++) {
1099 *cfp->sp++ = ptr[i];
1100 }
1101 calling->argc += i - 1;
1102 }
1103 }
1104
1105 static inline void
1106 vm_caller_setup_arg_kw(rb_control_frame_t *cfp, struct rb_calling_info *calling, const struct rb_call_info *ci)
1107 {
1108 struct rb_call_info_with_kwarg *ci_kw = (struct rb_call_info_with_kwarg *)ci;
1109 const VALUE *const passed_keywords = ci_kw->kw_arg->keywords;
1110 const int kw_len = ci_kw->kw_arg->keyword_len;
1111 const VALUE h = rb_hash_new_with_size(kw_len);
1112 VALUE *sp = cfp->sp;
1113 int i;
1114
1115 for (i=0; i<kw_len; i++) {
1116 rb_hash_aset(h, passed_keywords[i], (sp - kw_len)[i]);
1117 }
1118 (sp-kw_len)[0] = h;
1119
1120 cfp->sp -= kw_len - 1;
1121 calling->argc -= kw_len - 1;
1122 calling->kw_splat = 1;
1123 }
1124
1125 static VALUE
1126 vm_to_proc(VALUE proc)
1127 {
1128 if (UNLIKELY(!rb_obj_is_proc(proc))) {
1129 VALUE b;
1130 const rb_callable_method_entry_t *me =
1131 rb_callable_method_entry_with_refinements(CLASS_OF(proc), idTo_proc, NULL);
1132
1133 if (me) {
1134 b = rb_vm_call0(GET_EC(), proc, idTo_proc, 0, NULL, me, RB_NO_KEYWORDS);
1135 }
1136 else {
1137 /* NOTE: calling method_missing */
1138 b = rb_check_convert_type_with_id(proc, T_DATA, "Proc", idTo_proc);
1139 }
1140
1141 if (NIL_P(b) || !rb_obj_is_proc(b)) {
1142 rb_raise(rb_eTypeError,
1143 "wrong argument type %s (expected Proc)",
1144 rb_obj_classname(proc));
1145 }
1146 return b;
1147 }
1148 else {
1149 return proc;
1150 }
1151 }
1152
1153 static VALUE
1154 refine_sym_proc_call(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg))
1155 {
1156 VALUE obj;
1157 ID mid;
1158 const rb_callable_method_entry_t *me;
1159 rb_execution_context_t *ec;
1160 const VALUE symbol = RARRAY_AREF(callback_arg, 0);
1161 const VALUE refinements = RARRAY_AREF(callback_arg, 1);
1162 int kw_splat = RB_PASS_CALLED_KEYWORDS;
1163 VALUE v;
1164 VALUE ret;
1165 VALUE klass;
1166
1167 if (argc-- < 1) {
1168 rb_raise(rb_eArgError, "no receiver given");
1169 }
1170 obj = *argv++;
1171
1172 mid = SYM2ID(symbol);
1173 for (klass = CLASS_OF(obj); klass; klass = RCLASS_SUPER(klass)) {
1174 me = rb_callable_method_entry(klass, mid);
1175 if (me) {
1176 me = rb_resolve_refined_method_callable(refinements, me);
1177 if (me) break;
1178 }
1179 }
1180
1181 ec = GET_EC();
1182 if (!NIL_P(blockarg)) {
1183 vm_passed_block_handler_set(ec, blockarg);
1184 }
1185 v = rb_adjust_argv_kw_splat(&argc, &argv, &kw_splat);
1186 if (!me) {
1187 ret = method_missing(obj, mid, argc, argv, MISSING_NOENTRY, kw_splat);
1188 }
1189 else {
1190 ret = rb_vm_call0(ec, obj, mid, argc, argv, me, kw_splat);
1191 }
1192 rb_free_tmp_buffer(&v);
1193 return ret;
1194 }
1195
1196 static VALUE
1197 vm_caller_setup_arg_block(const rb_execution_context_t *ec, rb_control_frame_t *reg_cfp,
1198 const struct rb_call_info *ci, const rb_iseq_t *blockiseq, const int is_super)
1199 {
1200 if (ci->flag & VM_CALL_ARGS_BLOCKARG) {
1201 VALUE block_code = *(--reg_cfp->sp);
1202
1203 if (NIL_P(block_code)) {
1204 return VM_BLOCK_HANDLER_NONE;
1205 }
1206 else if (block_code == rb_block_param_proxy) {
1207 VM_ASSERT(!VM_CFP_IN_HEAP_P(GET_EC(), reg_cfp));
1208 VALUE handler = VM_CF_BLOCK_HANDLER(reg_cfp);
1209 reg_cfp->block_code = (const void *) handler;
1210 return handler;
1211 }
1212 else if (SYMBOL_P(block_code) && rb_method_basic_definition_p(rb_cSymbol, idTo_proc)) {
1213 const rb_cref_t *cref = vm_env_cref(reg_cfp->ep);
1214 if (cref && !NIL_P(cref->refinements)) {
1215 VALUE ref = cref->refinements;
1216 VALUE func = rb_hash_lookup(ref, block_code);
1217 if (NIL_P(func)) {
1218 /* TODO: limit cached funcs */
1219 VALUE callback_arg = rb_ary_tmp_new(2);
1220 rb_ary_push(callback_arg, block_code);
1221 rb_ary_push(callback_arg, ref);
1222 OBJ_FREEZE_RAW(callback_arg);
1223 func = rb_func_proc_new(refine_sym_proc_call, callback_arg);
1224 rb_hash_aset(ref, block_code, func);
1225 }
1226 block_code = func;
1227 }
1228 return block_code;
1229 }
1230 else {
1231 return vm_to_proc(block_code);
1232 }
1233 }
1234 else if (blockiseq != NULL) { /* likely */
1235 struct rb_captured_block *captured = VM_CFP_TO_CAPTURED_BLOCK(reg_cfp);
1236 captured->code.iseq = blockiseq;
1237 return VM_BH_FROM_ISEQ_BLOCK(captured);
1238 }
1239 else {
1240 if (is_super) {
1241 return GET_BLOCK_HANDLER();
1242 }
1243 else {
1244 return VM_BLOCK_HANDLER_NONE;
1245 }
1246 }
1247 }
UNLIKELY
#define UNLIKELY(x)
Definition: ffi_common.h:126
ID
unsigned long ID
Definition: ruby.h:103
rb_method_basic_definition_p
#define rb_method_basic_definition_p(klass, mid)
Definition: rb_mjit_min_header-2.7.0.h:7900
TRUE
#define TRUE
Definition: nkf.h:175
rb_check_convert_type_with_id
VALUE rb_check_convert_type_with_id(VALUE, int, const char *, ID)
Definition: object.c:2957
rb_callable_method_entry_with_refinements
const rb_callable_method_entry_t * rb_callable_method_entry_with_refinements(VALUE klass, ID id, VALUE *defined_class)
Definition: vm_method.c:917
reg_cfp
rb_control_frame_t * reg_cfp
Definition: rb_mjit_min_header-2.7.0.h:15146
RB_PASS_CALLED_KEYWORDS
#define RB_PASS_CALLED_KEYWORDS
Definition: ruby.h:1980
FIX2INT
#define FIX2INT(x)
Definition: ruby.h:717
rb_iseq_struct
Definition: vm_core.h:456
rb_hash_new
VALUE rb_hash_new(void)
Definition: hash.c:1501
rb_warn
void rb_warn(const char *fmt,...)
Definition: error.c:313
ST_STOP
@ ST_STOP
Definition: st.h:99
INT2FIX
#define INT2FIX(i)
Definition: ruby.h:263
rb_call_info_kw_arg::keywords
VALUE keywords[1]
Definition: vm_core.h:242
st_is_member
#define st_is_member(table, key)
Definition: st.h:97
rb_warning_category_enabled_p
MJIT_FUNC_EXPORTED bool rb_warning_category_enabled_p(rb_warning_category_t category)
Definition: error.c:164
RSTRING_PTR
#define RSTRING_PTR(str)
Definition: ruby.h:1009
rb_attr_get
VALUE rb_attr_get(VALUE, ID)
Definition: variable.c:1084
rb_iseq_constant_body::rest_start
int rest_start
Definition: vm_core.h:369
st_init_numtable
st_table * st_init_numtable(void)
Definition: st.c:653
rb_ary_unshift
VALUE rb_ary_unshift(VALUE ary, VALUE item)
Definition: array.c:1494
VALUE
unsigned long VALUE
Definition: ruby.h:102
rb_ary_behead
MJIT_FUNC_EXPORTED VALUE rb_ary_behead(VALUE ary, long n)
Definition: array.c:1369
rb_eArgError
VALUE rb_eArgError
Definition: error.c:923
RB_TYPE_P
#define RB_TYPE_P(obj, type)
Definition: ruby.h:560
KW_HASH_HAS_NO_KEYS
#define KW_HASH_HAS_NO_KEYS
Definition: vm_args.c:190
rb_callable_method_entry_struct
Definition: method.h:59
NORETURN
NORETURN(static void raise_argument_error(rb_execution_context_t *ec, const rb_iseq_t *iseq, const VALUE exc))
int
__inline__ int
Definition: rb_mjit_min_header-2.7.0.h:2839
rb_iseq_constant_body::keyword
const struct rb_iseq_constant_body::@178::rb_iseq_param_keyword * keyword
rb_iseq_constant_body::local_iseq
struct rb_iseq_struct * local_iseq
Definition: vm_core.h:418
fill_values_arg::keys
VALUE * keys
Definition: vm_args.c:557
vm_check_canary
#define vm_check_canary(ec, sp)
Definition: vm_insnhelper.c:257
ci
rb_control_frame_t struct rb_calling_info const struct rb_call_info * ci
Definition: rb_mjit_min_header-2.7.0.h:15146
Qundef
#define Qundef
Definition: ruby.h:470
rb_vm_bh_to_procval
MJIT_STATIC VALUE rb_vm_bh_to_procval(const rb_execution_context_t *ec, VALUE block_handler)
Definition: rb_mjit_min_header-2.7.0.h:12353
GET_EC
#define GET_EC()
Definition: vm_core.h:1766
rb_long2int
#define rb_long2int(n)
Definition: ruby.h:350
rb_hash_keys
MJIT_FUNC_EXPORTED VALUE rb_hash_keys(VALUE hash)
Definition: hash.c:3334
rb_calling_info
Definition: vm_core.h:250
ptr
struct RIMemo * ptr
Definition: debug.c:74
T_DATA
#define T_DATA
Definition: ruby.h:538
rb_call_info_kw_arg::keyword_len
int keyword_len
Definition: vm_core.h:241
Qfalse
#define Qfalse
Definition: ruby.h:467
rb_hash_dup
VALUE rb_hash_dup(VALUE hash)
Definition: hash.c:1537
RARRAY_ASET
#define RARRAY_ASET(a, i, v)
Definition: ruby.h:1102
rb_id2str
#define rb_id2str(id)
Definition: vm_backtrace.c:30
VM_CALL_KWARG
#define VM_CALL_KWARG
Definition: vm_core.h:1107
NULL
#define NULL
Definition: _sdbm.c:101
ST_DELETE
@ ST_DELETE
Definition: st.h:99
PRIsVALUE
#define PRIsVALUE
Definition: ruby.h:166
rb_callable_method_entry
const RUBY_SYMBOL_EXPORT_END rb_callable_method_entry_t * rb_callable_method_entry(VALUE klass, ID id)
Definition: vm_method.c:878
miss_argc
const rb_iseq_t const int miss_argc
Definition: rb_mjit_min_header-2.7.0.h:13505
st_insert
int st_insert(st_table *tab, st_data_t key, st_data_t value)
Definition: st.c:1171
ID2SYM
#define ID2SYM(x)
Definition: ruby.h:414
error
const rb_iseq_t const char * error
Definition: rb_mjit_min_header-2.7.0.h:13506
rb_free_tmp_buffer
void rb_free_tmp_buffer(volatile VALUE *store)
Definition: gc.c:10257
rb_ary_pop
VALUE rb_ary_pop(VALUE ary)
Definition: array.c:1241
VM_ASSERT
#define VM_ASSERT(expr)
Definition: vm_core.h:56
rb_iseq_constant_body::opt_table
const VALUE * opt_table
Definition: vm_core.h:374
block_handler
rb_control_frame_t struct rb_calling_info const struct rb_call_info VALUE block_handler
Definition: rb_mjit_min_header-2.7.0.h:15146
RB_BLOCK_CALL_FUNC_ARGLIST
#define RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg)
Definition: ruby.h:1964
rb_hash_new_with_size
MJIT_FUNC_EXPORTED VALUE rb_hash_new_with_size(st_index_t size)
Definition: hash.c:1507
VM_BLOCK_HANDLER_NONE
#define VM_BLOCK_HANDLER_NONE
Definition: vm_core.h:1291
RARRAY_LENINT
#define RARRAY_LENINT(ary)
Definition: ruby.h:1071
v
int VALUE v
Definition: rb_mjit_min_header-2.7.0.h:12332
args_info
Definition: vm_args.c:22
rb_str_resize
VALUE rb_str_resize(VALUE, long)
Definition: string.c:2709
GET_BLOCK_HANDLER
#define GET_BLOCK_HANDLER()
Definition: vm_insnhelper.h:138
rb_control_frame_struct::sp
VALUE * sp
Definition: vm_core.h:762
UNLIMITED_ARGUMENTS
#define UNLIMITED_ARGUMENTS
Definition: intern.h:57
rb_call_info_kw_arg
Definition: vm_core.h:240
idMesg
@ idMesg
Definition: rb_mjit_min_header-2.7.0.h:8728
rb_raise
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:2669
rb_execution_context_struct::cfp
rb_control_frame_t * cfp
Definition: vm_core.h:847
if
if((ID)(DISPID) nameid !=nameid)
Definition: win32ole.c:357
obj
const VALUE VALUE obj
Definition: rb_mjit_min_header-2.7.0.h:5742
fill_values_arg::argc
int argc
Definition: vm_args.c:559
rb_obj_is_proc
VALUE rb_obj_is_proc(VALUE)
Definition: proc.c:152
rb_iseq_constant_body::param
struct rb_iseq_constant_body::@178 param
parameter information
opt_pc
rb_control_frame_t struct rb_calling_info const rb_callable_method_entry_t int opt_pc
Definition: rb_mjit_min_header-2.7.0.h:14544
rb_iseq_constant_body::lead_num
int lead_num
Definition: vm_core.h:367
fprintf
int fprintf(FILE *__restrict, const char *__restrict,...) __attribute__((__format__(__printf__
args_info::rest_dupped
int rest_dupped
Definition: vm_args.c:29
LIKELY
#define LIKELY(x)
Definition: ffi_common.h:125
RHASH_SIZE
#define RHASH_SIZE(hsh)
Definition: fbuffer.h:8
VM_CALL_KW_SPLAT
#define VM_CALL_KW_SPLAT
Definition: vm_core.h:1108
arg_setup_type
arg_setup_type
Definition: vm_args.c:35
rb_block_param_proxy
VALUE rb_block_param_proxy
Definition: vm.c:368
rb_ary_tmp_new
VALUE rb_ary_tmp_new(long capa)
Definition: array.c:768
i
uint32_t i
Definition: rb_mjit_min_header-2.7.0.h:5464
rb_cSymbol
RUBY_EXTERN VALUE rb_cSymbol
Definition: ruby.h:2046
RHASH_EMPTY_P
#define RHASH_EMPTY_P(h)
Definition: ruby.h:1131
KW_HASH_HAS_SYMBOL_KEY
#define KW_HASH_HAS_SYMBOL_KEY
Definition: vm_args.c:191
st_data_t
RUBY_SYMBOL_EXPORT_BEGIN typedef unsigned long st_data_t
Definition: st.h:22
rb_iseq_constant_body::size
unsigned int size
Definition: vm_core.h:365
rb_cref_struct
CREF (Class REFerence)
Definition: method.h:41
rb_hash_lookup
VALUE rb_hash_lookup(VALUE hash, VALUE key)
Definition: hash.c:1990
rb_resolve_refined_method_callable
const MJIT_FUNC_EXPORTED rb_callable_method_entry_t * rb_resolve_refined_method_callable(VALUE refinements, const rb_callable_method_entry_t *me)
Definition: vm_method.c:979
rb_call_info_with_kwarg::kw_arg
struct rb_call_info_kw_arg * kw_arg
Definition: vm_core.h:247
rb_ary_push
VALUE rb_ary_push(VALUE ary, VALUE item)
Definition: array.c:1195
VM_ENV_FLAG_LOCAL
@ VM_ENV_FLAG_LOCAL
Definition: vm_core.h:1186
stderr
#define stderr
Definition: rb_mjit_min_header-2.7.0.h:1485
min_argc
const rb_iseq_t const int const int min_argc
Definition: rb_mjit_min_header-2.7.0.h:13505
rb_eTypeError
VALUE rb_eTypeError
Definition: error.c:922
RHASH_PASS_AS_KEYWORDS
@ RHASH_PASS_AS_KEYWORDS
Definition: internal.h:818
ALLOCA_N
#define ALLOCA_N(type, n)
Definition: ruby.h:1684
RARRAY_AREF
#define RARRAY_AREF(a, i)
Definition: ruby.h:1101
rb_control_frame_struct
Definition: vm_core.h:760
rb_iseq_constant_body::block_start
int block_start
Definition: vm_core.h:372
FALSE
#define FALSE
Definition: nkf.h:174
rb_ary_resize
VALUE rb_ary_resize(VALUE ary, long len)
expands or shrinks ary to len elements.
Definition: array.c:1955
RCLASS_SUPER
#define RCLASS_SUPER(c)
Definition: classext.h:16
KW_HASH_HAS_BOTH_KEYS
#define KW_HASH_HAS_BOTH_KEYS
Definition: vm_args.c:193
rb_iseq_constant_body::flags
struct rb_iseq_constant_body::@178::@180 flags
rb_hash_foreach
void rb_hash_foreach(VALUE hash, rb_foreach_func *func, VALUE farg)
Definition: hash.c:1461
args_info::kw_arg
const struct rb_call_info_kw_arg * kw_arg
Definition: vm_args.c:30
args_info::rest_index
int rest_index
Definition: vm_args.c:28
arg_setup_method
@ arg_setup_method
Definition: vm_args.c:36
calling
rb_control_frame_t struct rb_calling_info * calling
Definition: rb_mjit_min_header-2.7.0.h:14544
VM_CALL_ARGS_BLOCKARG
#define VM_CALL_ARGS_BLOCKARG
Definition: vm_core.h:1102
me
const rb_callable_method_entry_t * me
Definition: rb_mjit_min_header-2.7.0.h:13226
call_status
int const VALUE VALUE int call_status
Definition: rb_mjit_min_header-2.7.0.h:15420
rb_check_array_type
VALUE rb_check_array_type(VALUE ary)
Definition: array.c:909
key
key
Definition: openssl_missing.h:181
T_HASH
#define T_HASH
Definition: ruby.h:531
args_info::argv
VALUE * argv
Definition: vm_args.c:24
RHash
Definition: internal.h:887
CLASS_OF
#define CLASS_OF(v)
Definition: ruby.h:484
args_info::argc
int argc
Definition: vm_args.c:25
rb_iseq_constant_body::iseq_unique_id
uintptr_t iseq_unique_id
Definition: vm_core.h:451
RARRAY_LEN
#define RARRAY_LEN(a)
Definition: ruby.h:1070
rb_check_hash_type
VALUE rb_check_hash_type(VALUE hash)
Definition: hash.c:1825
rb_str_cat_cstr
#define rb_str_cat_cstr(str, ptr)
Definition: rb_mjit_min_header-2.7.0.h:6126
rb_func_proc_new
VALUE rb_func_proc_new(rb_block_call_func_t func, VALUE val)
Definition: proc.c:728
rb_exc_raise
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
Definition: eval.c:667
rb_str_append
VALUE rb_str_append(VALUE, VALUE)
Definition: string.c:2965
VM_FRAME_MAGIC_DUMMY
@ VM_FRAME_MAGIC_DUMMY
Definition: vm_core.h:1171
rb_ary_new_from_values
VALUE rb_ary_new_from_values(long n, const VALUE *elts)
Definition: array.c:762
arg
VALUE arg
Definition: rb_mjit_min_header-2.7.0.h:5601
argv
char ** argv
Definition: ruby.c:223
rb_control_frame_struct::block_code
const void * block_code
Definition: vm_core.h:766
ST_CONTINUE
@ ST_CONTINUE
Definition: st.h:99
rb_iseq_constant_body::iseq_encoded
VALUE * iseq_encoded
Definition: vm_core.h:325
rb_vm_get_ruby_level_next_cfp
MJIT_FUNC_EXPORTED rb_control_frame_t * rb_vm_get_ruby_level_next_cfp(const rb_execution_context_t *ec, const rb_control_frame_t *cfp)
Definition: vm.c:553
klass
VALUE klass
Definition: rb_mjit_min_header-2.7.0.h:13254
st_data_t
unsigned long st_data_t
Definition: rb_mjit_min_header-2.7.0.h:5363
rb_captured_block::iseq
const rb_iseq_t * iseq
Definition: vm_core.h:731
rb_iseq_constant_body::opt_num
int opt_num
Definition: vm_core.h:368
rb_captured_block::code
union rb_captured_block::@186 code
rb_captured_block
Definition: vm_core.h:727
keys
const rb_iseq_t const char const VALUE keys
Definition: rb_mjit_min_header-2.7.0.h:13506
MEMCPY
#define MEMCPY(p1, p2, type, n)
Definition: ruby.h:1753
args_info::kw_argv
VALUE * kw_argv
Definition: vm_args.c:31
rb_hash_aset
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
Definition: hash.c:2779
idBt_locations
@ idBt_locations
Definition: rb_mjit_min_header-2.7.0.h:8726
rb_iseq_constant_body::post_num
int post_num
Definition: vm_core.h:371
NIL_P
#define NIL_P(v)
Definition: ruby.h:482
OBJ_FREEZE_RAW
#define OBJ_FREEZE_RAW(x)
Definition: ruby.h:1376
rb_cref_struct::refinements
VALUE refinements
Definition: method.h:43
idTo_proc
@ idTo_proc
Definition: rb_mjit_min_header-2.7.0.h:8718
rb_iseq_constant_body::post_start
int post_start
Definition: vm_core.h:370
argc
int argc
Definition: ruby.c:222
rb_obj_classname
const char * rb_obj_classname(VALUE)
Definition: variable.c:289
VM_CALL_ARGS_SPLAT
#define VM_CALL_ARGS_SPLAT
Definition: vm_core.h:1101
RB_NO_KEYWORDS
#define RB_NO_KEYWORDS
Definition: ruby.h:1977
rb_adjust_argv_kw_splat
VALUE rb_adjust_argv_kw_splat(int *, const VALUE **, int *)
Definition: vm_eval.c:237
rb_ec_backtrace_object
VALUE rb_ec_backtrace_object(const rb_execution_context_t *ec)
Definition: vm_backtrace.c:557
rb_vm_pop_frame
MJIT_STATIC void rb_vm_pop_frame(rb_execution_context_t *ec)
Definition: rb_mjit_min_header-2.7.0.h:12308
MISSING_NOENTRY
@ MISSING_NOENTRY
Definition: internal.h:2330
MJIT_FUNC_EXPORTED
#define MJIT_FUNC_EXPORTED
Definition: defines.h:396
rb_compile_warn
void rb_compile_warn(const char *file, int line, const char *fmt,...)
Definition: error.c:270
Qtrue
#define Qtrue
Definition: ruby.h:468
rb_control_frame_struct::ep
const VALUE * ep
Definition: vm_core.h:765
len
uint8_t len
Definition: escape.c:17
SYMBOL_P
#define SYMBOL_P(x)
Definition: ruby.h:413
rb_iseq_struct::body
struct rb_iseq_constant_body * body
Definition: vm_core.h:460
rb_control_frame_struct::pc
const VALUE * pc
Definition: vm_core.h:761
rb_ary_dup
VALUE rb_ary_dup(VALUE ary)
Definition: array.c:2238
fill_values_arg::vals
VALUE * vals
Definition: vm_args.c:558
rb_ivar_set
VALUE rb_ivar_set(VALUE, ID, VALUE)
Definition: variable.c:1300
args_info::rest
VALUE rest
Definition: vm_args.c:32
iseq
const rb_iseq_t * iseq
Definition: rb_mjit_min_header-2.7.0.h:13504
rb_backtrace_use_iseq_first_lineno_for_last_location
void rb_backtrace_use_iseq_first_lineno_for_last_location(VALUE self)
Definition: vm_backtrace.c:632
rb_hash_stlike_foreach
int rb_hash_stlike_foreach(VALUE hash, st_foreach_callback_func *func, st_data_t arg)
Definition: hash.c:1420
rb_call_info
Definition: internal.h:2387
RARRAY_CONST_PTR_TRANSIENT
#define RARRAY_CONST_PTR_TRANSIENT(a)
Definition: ruby.h:1073
rb_ary_new
VALUE rb_ary_new(void)
Definition: array.c:723
RB_WARN_CATEGORY_DEPRECATED
@ RB_WARN_CATEGORY_DEPRECATED
Definition: internal.h:1560
Qnil
#define Qnil
Definition: ruby.h:469
method_missing_reason
method_missing_reason
Definition: internal.h:2329
exc
const rb_iseq_t const VALUE exc
Definition: rb_mjit_min_header-2.7.0.h:13504
h
size_t st_index_t h
Definition: rb_mjit_min_header-2.7.0.h:5462
st_lookup
int st_lookup(st_table *tab, st_data_t key, st_data_t *value)
Definition: st.c:1101
rb_keyword_error_new
VALUE rb_keyword_error_new(const char *error, VALUE keys)
Definition: class.c:1819
arg_setup_block
@ arg_setup_block
Definition: vm_args.c:37
callee
my_ffi_struct callee(struct my_ffi_struct a1, struct my_ffi_struct a2)
Definition: problem1.c:16
RSTRING_LEN
#define RSTRING_LEN(str)
Definition: ruby.h:1005
KW_HASH_HAS_OTHER_KEY
#define KW_HASH_HAS_OTHER_KEY
Definition: vm_args.c:192
st_table
Definition: st.h:79
rb_call_info_with_kwarg
Definition: vm_core.h:245
fill_values_arg
Definition: vm_args.c:556
rb_str_cat
VALUE rb_str_cat(VALUE, const char *, long)
Definition: string.c:2812
KW_SPECIFIED_BITS_MAX
#define KW_SPECIFIED_BITS_MAX
Definition: vm_args.c:465
rb_vm_call0
MJIT_FUNC_EXPORTED VALUE rb_vm_call0(rb_execution_context_t *ec, VALUE recv, ID id, int argc, const VALUE *argv, const rb_callable_method_entry_t *me, int kw_splat)
Definition: vm_eval.c:46
max_argc
const rb_iseq_t const int const int const int max_argc
Definition: rb_mjit_min_header-2.7.0.h:13505
SYM2ID
#define SYM2ID(x)
Definition: ruby.h:415
rb_exc_set_backtrace
MJIT_FUNC_EXPORTED VALUE rb_exc_set_backtrace(VALUE exc, VALUE bt)
Definition: error.c:1310
CHECK_VM_STACK_OVERFLOW
#define CHECK_VM_STACK_OVERFLOW(cfp, margin)
Definition: vm_core.h:1746
rb_iseq_location
VALUE rb_iseq_location(const rb_iseq_t *iseq)
Definition: proc.c:1242
cfp
rb_control_frame_t * cfp
Definition: rb_mjit_min_header-2.7.0.h:14544
name
const char * name
Definition: nkf.c:208
rb_execution_context_struct
Definition: vm_core.h:843