Ruby  2.7.1p83(2020-03-31revisiona0c7c23c9cec0d0ffcba012279cd652d28ad5bf3)
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)
19 #endif
21 
22 struct args_info {
23  /* basic args info */
25  int argc;
26 
27  /* additional args info */
30  const struct rb_call_info_kw_arg *kw_arg;
33 };
34 
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 {
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:
243  break;
245  *kw_hash_ptr = Qnil;
246  return FALSE;
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 
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 
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 {
601 
602  if (!iseq) return 0;
603 
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) {
661  "The called method `%"PRIsVALUE"' is defined here", name);
662  }
663  else {
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) {
686  "The called method `%"PRIsVALUE"' is defined here", name);
687  }
688  else {
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) {
711  "The called method `%"PRIsVALUE"' is defined here", name);
712  }
713  else {
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 given_argc;
729  int kw_splat = FALSE;
730  unsigned int kw_flag = ci->flag & (VM_CALL_KWARG | VM_CALL_KW_SPLAT);
731  int opt_pc = 0, allow_autosplat = !kw_flag;
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  if (RB_TYPE_P(rest_last, T_HASH) && rb_obj_frozen_p(rest_last)) {
825  rest_last = rb_hash_new();
826  RARRAY_ASET(args->rest, len - 1, rest_last);
827  }
828  flag_keyword_hash = rest_last;
829  }
830  }
831  else {
832  rb_warn_keyword_to_last_hash(ec, calling, ci, iseq);
833  }
834  }
835  else if (!remove_empty_keyword_hash && rest_last) {
836  flag_keyword_hash = rest_last;
837  }
838  }
839  }
840  else {
841  if (kw_flag & VM_CALL_KW_SPLAT) {
842  VALUE last_arg = args->argv[args->argc-1];
843  if (ignore_keyword_hash_p(last_arg, iseq)) {
844  if (given_argc != min_argc) {
845  if (remove_empty_keyword_hash) {
846  args->argc--;
847  given_argc--;
848  kw_flag &= ~VM_CALL_KW_SPLAT;
849  }
850  else {
851  if (RB_TYPE_P(last_arg, T_HASH) && rb_obj_frozen_p(last_arg)) {
852  last_arg = rb_hash_new();
853  args->argv[args->argc-1] = last_arg;
854  }
855  flag_keyword_hash = last_arg;
856  }
857  }
858  else {
859  rb_warn_keyword_to_last_hash(ec, calling, ci, iseq);
860  }
861  }
862  else if (!remove_empty_keyword_hash) {
863  flag_keyword_hash = args->argv[args->argc-1];
864  }
865  }
866  args->rest = Qfalse;
867  }
868 
869  if (flag_keyword_hash && RB_TYPE_P(flag_keyword_hash, T_HASH)) {
870  ((struct RHash *)flag_keyword_hash)->basic.flags |= RHASH_PASS_AS_KEYWORDS;
871  }
872 
873  if (kw_flag && iseq->body->param.flags.accepts_no_kwarg) {
874  rb_raise(rb_eArgError, "no keywords accepted");
875  }
876 
877  switch (arg_setup_type) {
878  case arg_setup_method:
879  break; /* do nothing special */
880  case arg_setup_block:
881  if (given_argc == 1 &&
882  allow_autosplat &&
883  (min_argc > 0 || iseq->body->param.opt_num > 1 ||
884  iseq->body->param.flags.has_kw || iseq->body->param.flags.has_kwrest) &&
885  !iseq->body->param.flags.ambiguous_param0 &&
886  args_check_block_arg0(args)) {
887  given_argc = RARRAY_LENINT(args->rest);
888  }
889  break;
890  }
891 
892  /* argc check */
893  if (given_argc < min_argc) {
894  if (given_argc == min_argc - 1 && args->kw_argv) {
895  args_stored_kw_argv_to_hash(args);
896  given_argc = args_argc(args);
897  }
898  else {
901  given_argc = min_argc;
902  args_extend(args, min_argc);
903  }
904  else {
905  argument_arity_error(ec, iseq, given_argc, min_argc, max_argc);
906  }
907  }
908  }
909 
910  if (kw_flag & VM_CALL_KW_SPLAT) {
911  kw_splat = !iseq->body->param.flags.has_rest;
912  }
913  if ((iseq->body->param.flags.has_kw || iseq->body->param.flags.has_kwrest ||
914  (kw_splat && given_argc > max_argc)) &&
915  args->kw_argv == NULL) {
916  if (given_argc > min_argc) {
917  if (kw_flag) {
918  int check_only_symbol = (kw_flag & VM_CALL_KW_SPLAT) &&
919  iseq->body->param.flags.has_kw &&
920  !iseq->body->param.flags.has_kwrest;
921 
922  if (args_pop_keyword_hash(args, &keyword_hash, check_only_symbol)) {
923  given_argc--;
924  }
925  else if (check_only_symbol) {
926  if (keyword_hash != Qnil) {
927  rb_warn_split_last_hash_to_keyword(ec, calling, ci, iseq);
928  }
929  else {
930  rb_warn_keyword_to_last_hash(ec, calling, ci, iseq);
931  }
932  }
933  }
934  else if (args_pop_keyword_hash(args, &keyword_hash, 1)) {
935  /* Warn the following:
936  * def foo(k:1) p [k]; end
937  * foo({k:42}) #=> 42
938  */
939  rb_warn_last_hash_to_keyword(ec, calling, ci, iseq);
940  given_argc--;
941  }
942  else if (keyword_hash != Qnil) {
943  rb_warn_split_last_hash_to_keyword(ec, calling, ci, iseq);
944  }
945  }
946  else if (given_argc == min_argc && kw_flag) {
947  rb_warn_keyword_to_last_hash(ec, calling, ci, iseq);
948  }
949  }
950 
951  if (given_argc > max_argc && max_argc != UNLIMITED_ARGUMENTS) {
953  /* truncate */
954  args_reduce(args, given_argc - max_argc);
955  given_argc = max_argc;
956  }
957  else {
958  argument_arity_error(ec, iseq, given_argc, min_argc, max_argc);
959  }
960  }
961 
962  if (iseq->body->param.flags.has_lead) {
963  args_setup_lead_parameters(args, iseq->body->param.lead_num, locals + 0);
964  }
965 
966  if (iseq->body->param.flags.has_rest || iseq->body->param.flags.has_post){
967  args_copy(args);
968  }
969 
970  if (iseq->body->param.flags.has_post) {
971  args_setup_post_parameters(args, iseq->body->param.post_num, locals + iseq->body->param.post_start);
972  }
973 
974  if (iseq->body->param.flags.has_opt) {
975  int opt = args_setup_opt_parameters(args, iseq->body->param.opt_num, locals + iseq->body->param.lead_num);
976  opt_pc = (int)iseq->body->param.opt_table[opt];
977  }
978 
979  if (iseq->body->param.flags.has_rest) {
980  args_setup_rest_parameter(args, locals + iseq->body->param.rest_start);
981  }
982 
983  if (iseq->body->param.flags.has_kw) {
984  VALUE * const klocals = locals + iseq->body->param.keyword->bits_start - iseq->body->param.keyword->num;
985 
986  if (args->kw_argv != NULL) {
987  const struct rb_call_info_kw_arg *kw_arg = args->kw_arg;
988  args_setup_kw_parameters(ec, iseq, args->kw_argv, kw_arg->keyword_len, kw_arg->keywords, klocals);
989  }
990  else if (!NIL_P(keyword_hash)) {
991  int kw_len = rb_long2int(RHASH_SIZE(keyword_hash));
992  struct fill_values_arg arg;
993  /* copy kw_argv */
994  arg.keys = args->kw_argv = ALLOCA_N(VALUE, kw_len * 2);
995  arg.vals = arg.keys + kw_len;
996  arg.argc = 0;
997  rb_hash_foreach(keyword_hash, fill_keys_values, (VALUE)&arg);
998  VM_ASSERT(arg.argc == kw_len);
999  args_setup_kw_parameters(ec, iseq, arg.vals, kw_len, arg.keys, klocals);
1000  }
1001  else {
1002  VM_ASSERT(args_argc(args) == 0);
1003  args_setup_kw_parameters(ec, iseq, NULL, 0, NULL, klocals);
1004  }
1005  }
1006  else if (iseq->body->param.flags.has_kwrest) {
1007  args_setup_kw_rest_parameter(keyword_hash, locals + iseq->body->param.keyword->rest_start);
1008  }
1009  else if (!NIL_P(keyword_hash) && RHASH_SIZE(keyword_hash) > 0 && arg_setup_type == arg_setup_method) {
1010  argument_kw_error(ec, iseq, "unknown", rb_hash_keys(keyword_hash));
1011  }
1012 
1013  if (iseq->body->param.flags.has_block) {
1014  if (iseq->body->local_iseq == iseq) {
1015  /* Do nothing */
1016  }
1017  else {
1018  args_setup_block_parameter(ec, calling, locals + iseq->body->param.block_start);
1019  }
1020  }
1021 
1022 #if 0
1023  {
1024  int i;
1025  for (i=0; i<iseq->body->param.size; i++) {
1026  fprintf(stderr, "local[%d] = %p\n", i, (void *)locals[i]);
1027  }
1028  }
1029 #endif
1030 
1031  ec->cfp->sp = orig_sp;
1032  return opt_pc;
1033 }
1034 
1035 void rb_backtrace_use_iseq_first_lineno_for_last_location(VALUE self); /* vm_backtrace.c */
1036 
1037 static void
1038 raise_argument_error(rb_execution_context_t *ec, const rb_iseq_t *iseq, const VALUE exc)
1039 {
1040  VALUE at;
1041 
1042  if (iseq) {
1043  vm_push_frame(ec, iseq, VM_FRAME_MAGIC_DUMMY | VM_ENV_FLAG_LOCAL, Qnil /* self */,
1044  VM_BLOCK_HANDLER_NONE /* specval*/, Qfalse /* me or cref */,
1046  ec->cfp->sp, 0, 0 /* stack_max */);
1047  at = rb_ec_backtrace_object(ec);
1049  rb_vm_pop_frame(ec);
1050  }
1051  else {
1052  at = rb_ec_backtrace_object(ec);
1053  }
1054 
1057  rb_exc_raise(exc);
1058 }
1059 
1060 static void
1061 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)
1062 {
1063  VALUE exc = rb_arity_error_new(miss_argc, min_argc, max_argc);
1064  if (iseq->body->param.flags.has_kw) {
1065  const struct rb_iseq_param_keyword *const kw = iseq->body->param.keyword;
1066  const ID *keywords = kw->table;
1067  int req_key_num = kw->required_num;
1068  if (req_key_num > 0) {
1069  static const char required[] = "; required keywords";
1070  VALUE mesg = rb_attr_get(exc, idMesg);
1071  rb_str_resize(mesg, RSTRING_LEN(mesg)-1);
1072  rb_str_cat(mesg, required, sizeof(required) - 1 - (req_key_num == 1));
1073  rb_str_cat_cstr(mesg, ":");
1074  do {
1075  rb_str_cat_cstr(mesg, " ");
1076  rb_str_append(mesg, rb_id2str(*keywords++));
1077  rb_str_cat_cstr(mesg, ",");
1078  } while (--req_key_num);
1079  RSTRING_PTR(mesg)[RSTRING_LEN(mesg)-1] = ')';
1080  }
1081  }
1082  raise_argument_error(ec, iseq, exc);
1083 }
1084 
1085 static void
1086 argument_kw_error(rb_execution_context_t *ec, const rb_iseq_t *iseq, const char *error, const VALUE keys)
1087 {
1088  raise_argument_error(ec, iseq, rb_keyword_error_new(error, keys));
1089 }
1090 
1091 static inline void
1092 vm_caller_setup_arg_splat(rb_control_frame_t *cfp, struct rb_calling_info *calling)
1093 {
1094  int argc = calling->argc;
1095  VALUE *argv = cfp->sp - argc;
1096  VALUE ary = argv[argc-1];
1097 
1099  cfp->sp--;
1100 
1101  if (!NIL_P(ary)) {
1102  const VALUE *ptr = RARRAY_CONST_PTR_TRANSIENT(ary);
1103  long len = RARRAY_LEN(ary), i;
1104 
1106 
1107  for (i = 0; i < len; i++) {
1108  *cfp->sp++ = ptr[i];
1109  }
1110  calling->argc += i - 1;
1111  }
1112 }
1113 
1114 static inline void
1115 vm_caller_setup_arg_kw(rb_control_frame_t *cfp, struct rb_calling_info *calling, const struct rb_call_info *ci)
1116 {
1117  struct rb_call_info_with_kwarg *ci_kw = (struct rb_call_info_with_kwarg *)ci;
1118  const VALUE *const passed_keywords = ci_kw->kw_arg->keywords;
1119  const int kw_len = ci_kw->kw_arg->keyword_len;
1120  const VALUE h = rb_hash_new_with_size(kw_len);
1121  VALUE *sp = cfp->sp;
1122  int i;
1123 
1124  for (i=0; i<kw_len; i++) {
1125  rb_hash_aset(h, passed_keywords[i], (sp - kw_len)[i]);
1126  }
1127  (sp-kw_len)[0] = h;
1128 
1129  cfp->sp -= kw_len - 1;
1130  calling->argc -= kw_len - 1;
1131  calling->kw_splat = 1;
1132 }
1133 
1134 static VALUE
1135 vm_to_proc(VALUE proc)
1136 {
1137  if (UNLIKELY(!rb_obj_is_proc(proc))) {
1138  VALUE b;
1141 
1142  if (me) {
1143  b = rb_vm_call0(GET_EC(), proc, idTo_proc, 0, NULL, me, RB_NO_KEYWORDS);
1144  }
1145  else {
1146  /* NOTE: calling method_missing */
1147  b = rb_check_convert_type_with_id(proc, T_DATA, "Proc", idTo_proc);
1148  }
1149 
1150  if (NIL_P(b) || !rb_obj_is_proc(b)) {
1152  "wrong argument type %s (expected Proc)",
1153  rb_obj_classname(proc));
1154  }
1155  return b;
1156  }
1157  else {
1158  return proc;
1159  }
1160 }
1161 
1162 static VALUE
1163 refine_sym_proc_call(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg))
1164 {
1165  VALUE obj;
1166  ID mid;
1169  const VALUE symbol = RARRAY_AREF(callback_arg, 0);
1170  const VALUE refinements = RARRAY_AREF(callback_arg, 1);
1171  int kw_splat = RB_PASS_CALLED_KEYWORDS;
1172  VALUE v;
1173  VALUE ret;
1174  VALUE klass;
1175 
1176  if (argc-- < 1) {
1177  rb_raise(rb_eArgError, "no receiver given");
1178  }
1179  obj = *argv++;
1180 
1181  mid = SYM2ID(symbol);
1182  for (klass = CLASS_OF(obj); klass; klass = RCLASS_SUPER(klass)) {
1184  if (me) {
1185  me = rb_resolve_refined_method_callable(refinements, me);
1186  if (me) break;
1187  }
1188  }
1189 
1190  ec = GET_EC();
1191  if (!NIL_P(blockarg)) {
1192  vm_passed_block_handler_set(ec, blockarg);
1193  }
1194  v = rb_adjust_argv_kw_splat(&argc, &argv, &kw_splat);
1195  if (!me) {
1196  ret = method_missing(obj, mid, argc, argv, MISSING_NOENTRY, kw_splat);
1197  }
1198  else {
1199  ret = rb_vm_call0(ec, obj, mid, argc, argv, me, kw_splat);
1200  }
1202  return ret;
1203 }
1204 
1205 static VALUE
1206 vm_caller_setup_arg_block(const rb_execution_context_t *ec, rb_control_frame_t *reg_cfp,
1207  const struct rb_call_info *ci, const rb_iseq_t *blockiseq, const int is_super)
1208 {
1209  if (ci->flag & VM_CALL_ARGS_BLOCKARG) {
1210  VALUE block_code = *(--reg_cfp->sp);
1211 
1212  if (NIL_P(block_code)) {
1213  return VM_BLOCK_HANDLER_NONE;
1214  }
1215  else if (block_code == rb_block_param_proxy) {
1216  VM_ASSERT(!VM_CFP_IN_HEAP_P(GET_EC(), reg_cfp));
1217  VALUE handler = VM_CF_BLOCK_HANDLER(reg_cfp);
1218  reg_cfp->block_code = (const void *) handler;
1219  return handler;
1220  }
1221  else if (SYMBOL_P(block_code) && rb_method_basic_definition_p(rb_cSymbol, idTo_proc)) {
1222  const rb_cref_t *cref = vm_env_cref(reg_cfp->ep);
1223  if (cref && !NIL_P(cref->refinements)) {
1224  VALUE ref = cref->refinements;
1225  VALUE func = rb_hash_lookup(ref, block_code);
1226  if (NIL_P(func)) {
1227  /* TODO: limit cached funcs */
1228  VALUE callback_arg = rb_ary_tmp_new(2);
1229  rb_ary_push(callback_arg, block_code);
1230  rb_ary_push(callback_arg, ref);
1231  OBJ_FREEZE_RAW(callback_arg);
1232  func = rb_func_proc_new(refine_sym_proc_call, callback_arg);
1233  rb_hash_aset(ref, block_code, func);
1234  }
1235  block_code = func;
1236  }
1237  return block_code;
1238  }
1239  else {
1240  return vm_to_proc(block_code);
1241  }
1242  }
1243  else if (blockiseq != NULL) { /* likely */
1244  struct rb_captured_block *captured = VM_CFP_TO_CAPTURED_BLOCK(reg_cfp);
1245  captured->code.iseq = blockiseq;
1246  return VM_BH_FROM_ISEQ_BLOCK(captured);
1247  }
1248  else {
1249  if (is_super) {
1250  return GET_BLOCK_HANDLER();
1251  }
1252  else {
1253  return VM_BLOCK_HANDLER_NONE;
1254  }
1255  }
1256 }
i
uint32_t i
Definition: rb_mjit_min_header-2.7.1.h:5464
UNLIKELY
#define UNLIKELY(x)
Definition: ffi_common.h:126
ID
unsigned long ID
Definition: ruby.h:103
rb_str_cat_cstr
#define rb_str_cat_cstr(str, ptr)
Definition: rb_mjit_min_header-2.7.1.h:6126
obj
const VALUE VALUE obj
Definition: rb_mjit_min_header-2.7.1.h:5742
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
klass
VALUE klass
Definition: rb_mjit_min_header-2.7.1.h:13259
st_data_t
unsigned long st_data_t
Definition: rb_mjit_min_header-2.7.1.h:5363
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:1523
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
idBt_locations
@ idBt_locations
Definition: rb_mjit_min_header-2.7.1.h:8731
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))
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
arg
VALUE arg
Definition: rb_mjit_min_header-2.7.1.h:5601
fill_values_arg::keys
VALUE * keys
Definition: vm_args.c:557
iseq
const rb_iseq_t * iseq
Definition: rb_mjit_min_header-2.7.1.h:13509
vm_check_canary
#define vm_check_canary(ec, sp)
Definition: vm_insnhelper.c:257
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.1.h:12358
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:3403
rb_calling_info
Definition: vm_core.h:250
ptr
struct RIMemo * ptr
Definition: debug.c:74
me
const rb_callable_method_entry_t * me
Definition: rb_mjit_min_header-2.7.1.h:13231
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:1559
RARRAY_ASET
#define RARRAY_ASET(a, i, v)
Definition: ruby.h:1102
rb_id2str
#define rb_id2str(id)
Definition: vm_backtrace.c:30
keys
const rb_iseq_t const char const VALUE keys
Definition: rb_mjit_min_header-2.7.1.h:13511
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
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
idMesg
@ idMesg
Definition: rb_mjit_min_header-2.7.1.h:8733
rb_free_tmp_buffer
void rb_free_tmp_buffer(volatile VALUE *store)
Definition: gc.c:10276
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
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:1529
VM_BLOCK_HANDLER_NONE
#define VM_BLOCK_HANDLER_NONE
Definition: vm_core.h:1291
RARRAY_LENINT
#define RARRAY_LENINT(ary)
Definition: ruby.h:1071
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
exc
const rb_iseq_t const VALUE exc
Definition: rb_mjit_min_header-2.7.1.h:13509
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
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
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
rb_iseq_constant_body::lead_num
int lead_num
Definition: vm_core.h:367
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
cfp
rb_control_frame_t * cfp
Definition: rb_mjit_min_header-2.7.1.h:14564
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
h
size_t st_index_t h
Definition: rb_mjit_min_header-2.7.1.h:5462
rb_cSymbol
RUBY_EXTERN VALUE rb_cSymbol
Definition: ruby.h:2046
RHASH_EMPTY_P
#define RHASH_EMPTY_P(h)
Definition: ruby.h:1131
rb_method_basic_definition_p
#define rb_method_basic_definition_p(klass, mid)
Definition: rb_mjit_min_header-2.7.1.h:7905
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:2058
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
max_argc
const rb_iseq_t const int const int const int max_argc
Definition: rb_mjit_min_header-2.7.1.h:13510
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
rb_eTypeError
VALUE rb_eTypeError
Definition: error.c:922
RHASH_PASS_AS_KEYWORDS
@ RHASH_PASS_AS_KEYWORDS
Definition: internal.h:818
rb_obj_frozen_p
VALUE rb_obj_frozen_p(VALUE obj)
Determines if the object is frozen.
Definition: object.c:1099
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:1483
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
reg_cfp
rb_control_frame_t * reg_cfp
Definition: rb_mjit_min_header-2.7.1.h:15166
VM_CALL_ARGS_BLOCKARG
#define VM_CALL_ARGS_BLOCKARG
Definition: vm_core.h:1102
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
idTo_proc
@ idTo_proc
Definition: rb_mjit_min_header-2.7.1.h:8723
RARRAY_LEN
#define RARRAY_LEN(a)
Definition: ruby.h:1070
rb_check_hash_type
VALUE rb_check_hash_type(VALUE hash)
Definition: hash.c:1847
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:668
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
error
const rb_iseq_t const char * error
Definition: rb_mjit_min_header-2.7.1.h:13511
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
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.1.h:15166
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
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
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:2847
int
__inline__ int
Definition: rb_mjit_min_header-2.7.1.h:2839
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
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
ci
rb_control_frame_t struct rb_calling_info const struct rb_call_info * ci
Definition: rb_mjit_min_header-2.7.1.h:15166
rb_ec_backtrace_object
VALUE rb_ec_backtrace_object(const rb_execution_context_t *ec)
Definition: vm_backtrace.c:557
v
int VALUE v
Definition: rb_mjit_min_header-2.7.1.h:12337
rb_vm_pop_frame
MJIT_STATIC void rb_vm_pop_frame(rb_execution_context_t *ec)
Definition: rb_mjit_min_header-2.7.1.h:12313
MISSING_NOENTRY
@ MISSING_NOENTRY
Definition: internal.h:2335
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
miss_argc
const rb_iseq_t const int miss_argc
Definition: rb_mjit_min_header-2.7.1.h:13510
args_info::rest
VALUE rest
Definition: vm_args.c:32
stderr
#define stderr
Definition: rb_mjit_min_header-2.7.1.h:1485
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:1442
rb_call_info
Definition: internal.h:2392
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:1562
Qnil
#define Qnil
Definition: ruby.h:469
method_missing_reason
method_missing_reason
Definition: internal.h:2334
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
calling
rb_control_frame_t struct rb_calling_info * calling
Definition: rb_mjit_min_header-2.7.1.h:14564
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
fprintf
int fprintf(FILE *__restrict, const char *__restrict,...) __attribute__((__format__(__printf__
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.1.h:14564
SYM2ID
#define SYM2ID(x)
Definition: ruby.h:415
call_status
int const VALUE VALUE int call_status
Definition: rb_mjit_min_header-2.7.1.h:15440
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
min_argc
const rb_iseq_t const int const int min_argc
Definition: rb_mjit_min_header-2.7.1.h:13510
name
const char * name
Definition: nkf.c:208
rb_execution_context_struct
Definition: vm_core.h:843