Ruby  2.4.2p198(2017-09-14revision59899)
vm_eval.c
Go to the documentation of this file.
1 /**********************************************************************
2 
3  vm_eval.c -
4 
5  $Author: nagachika $
6  created at: Sat May 24 16:02:32 JST 2008
7 
8  Copyright (C) 1993-2007 Yukihiro Matsumoto
9  Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
10  Copyright (C) 2000 Information-technology Promotion Agency, Japan
11 
12 **********************************************************************/
13 
16 };
17 
18 static inline VALUE method_missing(VALUE obj, ID id, int argc, const VALUE *argv, enum method_missing_reason call_status);
19 static inline VALUE vm_yield_with_cref(rb_thread_t *th, int argc, const VALUE *argv, const rb_cref_t *cref, int is_lambda);
20 static inline VALUE vm_yield(rb_thread_t *th, int argc, const VALUE *argv);
21 static inline VALUE vm_yield_with_block(rb_thread_t *th, int argc, const VALUE *argv, VALUE block_handler);
22 static inline VALUE vm_yield_lambda_splattable(rb_thread_t *th, VALUE args);
23 static VALUE vm_exec(rb_thread_t *th);
24 static void vm_set_eval_stack(rb_thread_t * th, const rb_iseq_t *iseq, const rb_cref_t *cref, const struct rb_block *base_block);
25 static int vm_collect_local_variables_in_heap(rb_thread_t *th, const VALUE *dfp, const struct local_var_list *vars);
26 
29 #define id_mesg idMesg
30 
31 /* vm_backtrace.c */
32 VALUE rb_vm_backtrace_str_ary(rb_thread_t *th, int lev, int n);
33 
34 typedef enum call_type {
39 } call_type;
40 
41 static VALUE send_internal(int argc, const VALUE *argv, VALUE recv, call_type scope);
42 
43 static VALUE vm_call0_body(rb_thread_t* th, struct rb_calling_info *calling, const struct rb_call_info *ci, struct rb_call_cache *cc, const VALUE *argv);
44 
45 static VALUE
46 vm_call0(rb_thread_t* th, VALUE recv, ID id, int argc, const VALUE *argv, const rb_callable_method_entry_t *me)
47 {
48  struct rb_calling_info calling_entry, *calling;
49  struct rb_call_info ci_entry;
50  struct rb_call_cache cc_entry;
51 
52  calling = &calling_entry;
53 
54  ci_entry.flag = 0;
55  ci_entry.mid = id;
56 
57  cc_entry.me = me;
58 
59  calling->recv = recv;
60  calling->argc = argc;
61 
62  return vm_call0_body(th, calling, &ci_entry, &cc_entry, argv);
63 }
64 
65 #if OPT_CALL_CFUNC_WITHOUT_FRAME
66 static VALUE
67 vm_call0_cfunc(rb_thread_t* th, struct rb_calling_info *calling, const struct rb_call_info *ci, struct rb_call_cache *cc, const VALUE *argv)
68 {
69  VALUE val;
70 
72  EXEC_EVENT_HOOK(th, RUBY_EVENT_C_CALL, calling->recv, ci->mid, ci->mid, cc->me->owner, Qnil);
73  {
74  rb_control_frame_t *reg_cfp = th->cfp;
75  const rb_callable_method_entry_t *me = cc->me;
76  const rb_method_cfunc_t *cfunc = &me->def->body.cfunc;
77  int len = cfunc->argc;
78  VALUE recv = calling->recv;
79  int argc = calling->argc;
80 
81  if (len >= 0) rb_check_arity(argc, len, len);
82 
83  th->passed_ci = ci;
84  cc->aux.inc_sp = 0;
85  VM_PROFILE_UP(C2C_CALL);
86  val = (*cfunc->invoker)(cfunc->func, recv, argc, argv);
87 
88  if (reg_cfp == th->cfp) {
89  if (UNLIKELY(th->passed_ci != ci)) {
90  rb_bug("vm_call0_cfunc: passed_ci error (ci: %p, passed_ci: %p)", ci, th->passed_ci);
91  }
92  th->passed_ci = 0;
93  }
94  else {
95  if (reg_cfp != th->cfp + 1) {
96  rb_bug("vm_call0_cfunc: cfp consistency error");
97  }
98  VM_PROFILE_UP(C2C_POPF);
99  rb_vm_pop_frame(th);
100  }
101  }
102  EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, calling->recv, ci->mid, ci->mid, callnig->cc->me->owner, val);
104 
105  return val;
106 }
107 #else
108 static VALUE
109 vm_call0_cfunc_with_frame(rb_thread_t* th, struct rb_calling_info *calling, const struct rb_call_info *ci, struct rb_call_cache *cc, const VALUE *argv)
110 {
111  VALUE val;
112  const rb_callable_method_entry_t *me = cc->me;
113  const rb_method_cfunc_t *cfunc = &me->def->body.cfunc;
114  int len = cfunc->argc;
115  VALUE recv = calling->recv;
116  int argc = calling->argc;
117  ID mid = ci->mid;
118  VALUE block_handler = calling->block_handler;
119 
121  EXEC_EVENT_HOOK(th, RUBY_EVENT_C_CALL, recv, me->def->original_id, mid, me->owner, Qnil);
122  {
123  rb_control_frame_t *reg_cfp = th->cfp;
124 
126  block_handler, (VALUE)me,
127  0, reg_cfp->sp, 0, 0);
128 
129  if (len >= 0) rb_check_arity(argc, len, len);
130 
131  VM_PROFILE_UP(C2C_CALL);
132  val = (*cfunc->invoker)(cfunc->func, recv, argc, argv);
133 
134  if (UNLIKELY(reg_cfp != th->cfp + 1)) {
135  rb_bug("vm_call0_cfunc_with_frame: cfp consistency error");
136  }
137  VM_PROFILE_UP(C2C_POPF);
138  rb_vm_pop_frame(th);
139  }
140  EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, recv, me->def->original_id, mid, me->owner, val);
142 
143  return val;
144 }
145 
146 static VALUE
147 vm_call0_cfunc(rb_thread_t* th, struct rb_calling_info *calling, const struct rb_call_info *ci, struct rb_call_cache *cc, const VALUE *argv)
148 {
149  return vm_call0_cfunc_with_frame(th, calling, ci, cc, argv);
150 }
151 #endif
152 
153 /* `ci' should point temporal value (on stack value) */
154 static VALUE
155 vm_call0_body(rb_thread_t* th, struct rb_calling_info *calling, const struct rb_call_info *ci, struct rb_call_cache *cc, const VALUE *argv)
156 {
157  VALUE ret;
158 
159  calling->block_handler = vm_passed_block_handler(th);
160 
161  again:
162  switch (cc->me->def->type) {
163  case VM_METHOD_TYPE_ISEQ:
164  {
165  rb_control_frame_t *reg_cfp = th->cfp;
166  int i;
167 
168  CHECK_VM_STACK_OVERFLOW(reg_cfp, calling->argc + 1);
169 
170  *reg_cfp->sp++ = calling->recv;
171  for (i = 0; i < calling->argc; i++) {
172  *reg_cfp->sp++ = argv[i];
173  }
174 
175  vm_call_iseq_setup(th, reg_cfp, calling, ci, cc);
177  return vm_exec(th); /* CHECK_INTS in this function */
178  }
181  ret = vm_call0_cfunc(th, calling, ci, cc, argv);
182  goto success;
184  rb_check_arity(calling->argc, 1, 1);
185  ret = rb_ivar_set(calling->recv, cc->me->def->body.attr.id, argv[0]);
186  goto success;
187  case VM_METHOD_TYPE_IVAR:
188  rb_check_arity(calling->argc, 0, 0);
189  ret = rb_attr_get(calling->recv, cc->me->def->body.attr.id);
190  goto success;
192  ret = vm_call_bmethod_body(th, calling, ci, cc, argv);
193  goto success;
196  {
197  const rb_method_type_t type = cc->me->def->type;
198  VALUE super_class = cc->me->defined_class;
199 
200  if (type == VM_METHOD_TYPE_ZSUPER) {
201  super_class = RCLASS_ORIGIN(super_class);
202  }
203  else if (cc->me->def->body.refined.orig_me) {
205  goto again;
206  }
207 
208  super_class = RCLASS_SUPER(super_class);
209 
210  if (!super_class || !(cc->me = rb_callable_method_entry(super_class, ci->mid))) {
212  ret = method_missing(calling->recv, ci->mid, calling->argc, argv, ex);
213  goto success;
214  }
215  RUBY_VM_CHECK_INTS(th);
216  goto again;
217  }
220  goto again;
222  {
224  return method_missing(calling->recv, ci->mid, calling->argc,
225  argv, MISSING_NOENTRY);
226  }
228  switch (cc->me->def->body.optimize_type) {
229  case OPTIMIZED_METHOD_TYPE_SEND:
230  ret = send_internal(calling->argc, argv, calling->recv, CALL_FCALL);
231  goto success;
232  case OPTIMIZED_METHOD_TYPE_CALL:
233  {
234  rb_proc_t *proc;
235  GetProcPtr(calling->recv, proc);
236  ret = rb_vm_invoke_proc(th, proc, calling->argc, argv, calling->block_handler);
237  goto success;
238  }
239  default:
240  rb_bug("vm_call0: unsupported optimized method type (%d)", cc->me->def->body.optimize_type);
241  }
242  break;
244  break;
245  }
246  rb_bug("vm_call0: unsupported method type (%d)", cc->me->def->type);
247  return Qundef;
248 
249  success:
250  RUBY_VM_CHECK_INTS(th);
251  return ret;
252 }
253 
254 VALUE
256 {
257  return vm_call0(th, recv, id, argc, argv, me);
258 }
259 
260 static inline VALUE
262 {
263  VALUE recv = th->cfp->self;
264  VALUE klass;
265  ID id;
266  rb_control_frame_t *cfp = th->cfp;
268 
269  if (VM_FRAME_RUBYFRAME_P(cfp)) {
270  rb_bug("vm_call_super: should not be reached");
271  }
272 
273  klass = RCLASS_ORIGIN(me->defined_class);
274  klass = RCLASS_SUPER(klass);
275  id = me->def->original_id;
276  me = rb_callable_method_entry(klass, id);
277 
278  if (!me) {
279  return method_missing(recv, id, argc, argv, MISSING_SUPER);
280  }
281  else {
282  return vm_call0(th, recv, id, argc, argv, me);
283  }
284 }
285 
286 VALUE
288 {
289  rb_thread_t *th = GET_THREAD();
291  return vm_call_super(th, argc, argv);
292 }
293 
294 VALUE
296 {
297  rb_thread_t *th = GET_THREAD();
298  rb_control_frame_t *cfp;
299  if (!th || !(cfp = th->cfp))
300  rb_raise(rb_eRuntimeError, "no self, no life");
301  return cfp->self;
302 }
303 
304 static inline void
306 {
310  }
311 }
312 
313 static inline const rb_callable_method_entry_t *rb_search_method_entry(VALUE recv, ID mid);
315 
331 static inline VALUE
332 rb_call0(VALUE recv, ID mid, int argc, const VALUE *argv,
333  call_type scope, VALUE self)
334 {
335  const rb_callable_method_entry_t *me = rb_search_method_entry(recv, mid);
336  rb_thread_t *th = GET_THREAD();
337  enum method_missing_reason call_status = rb_method_call_status(th, me, scope, self);
338 
339  if (call_status != MISSING_NONE) {
340  return method_missing(recv, mid, argc, argv, call_status);
341  }
342  stack_check(th);
343  return vm_call0(th, recv, mid, argc, argv, me);
344 }
345 
352  unsigned int respond: 1;
353  unsigned int respond_to_missing: 1;
354  int argc;
355  const VALUE *argv;
356 };
357 
358 static VALUE
360 {
361  return call_method_entry(args->th, args->defined_class,
362  args->recv, idMethodMissing,
363  args->me, args->argc, args->argv);
364 }
365 
366 #define PRIV Qfalse /* TODO: for rubyspec now, should be Qtrue */
367 
368 static VALUE
370 {
371  int ret = args->respond;
372  if (!ret) {
373  switch (rb_method_boundp(args->defined_class, args->mid,
375  case 2:
376  ret = TRUE;
377  break;
378  case 0:
379  ret = args->respond_to_missing;
380  break;
381  default:
382  ret = FALSE;
383  break;
384  }
385  }
386  if (ret) {
387  rb_exc_raise(e);
388  }
389  return Qundef;
390 }
391 
392 static int
394 {
395  return vm_respond_to(th, klass, recv, mid, TRUE);
396 }
397 
398 static int
400 {
401  return rb_method_call_status(th, me, CALL_FCALL, th->cfp->self) == MISSING_NONE;
402 }
403 
404 static VALUE
405 check_funcall_missing(rb_thread_t *th, VALUE klass, VALUE recv, ID mid, int argc, const VALUE *argv, int respond, VALUE def)
406 {
407  struct rescue_funcall_args args;
408  const rb_method_entry_t *me;
409  VALUE ret = Qundef;
410 
411  ret = basic_obj_respond_to_missing(th, klass, recv,
412  ID2SYM(mid), PRIV);
413  if (!RTEST(ret)) return def;
414  args.respond = respond > 0;
415  args.respond_to_missing = (ret != Qundef);
416  ret = def;
417  me = method_entry_get(klass, idMethodMissing, &args.defined_class);
418  if (me && !METHOD_ENTRY_BASIC(me)) {
419  VALUE argbuf, *new_args = ALLOCV_N(VALUE, argbuf, argc+1);
420 
421  new_args[0] = ID2SYM(mid);
422  MEMCPY(new_args+1, argv, VALUE, argc);
424  args.th = th;
425  args.recv = recv;
426  args.me = me;
427  args.mid = mid;
428  args.argc = argc + 1;
429  args.argv = new_args;
430  ret = rb_rescue2(check_funcall_exec, (VALUE)&args,
431  check_funcall_failed, (VALUE)&args,
433  ALLOCV_END(argbuf);
434  }
435  return ret;
436 }
437 
438 VALUE
440 {
441  return rb_check_funcall_default(recv, mid, argc, argv, Qundef);
442 }
443 
444 VALUE
446 {
447  VALUE klass = CLASS_OF(recv);
449  rb_thread_t *th = GET_THREAD();
450  int respond = check_funcall_respond_to(th, klass, recv, mid);
451 
452  if (!respond)
453  return def;
454 
455  me = rb_search_method_entry(recv, mid);
456  if (!check_funcall_callable(th, me)) {
457  return check_funcall_missing(th, klass, recv, mid, argc, argv,
458  respond, def);
459  }
460  stack_check(th);
461  return vm_call0(th, recv, mid, argc, argv, me);
462 }
463 
464 VALUE
466  rb_check_funcall_hook *hook, VALUE arg)
467 {
468  VALUE klass = CLASS_OF(recv);
470  rb_thread_t *th = GET_THREAD();
471  int respond = check_funcall_respond_to(th, klass, recv, mid);
472 
473  if (!respond) {
474  (*hook)(FALSE, recv, mid, argc, argv, arg);
475  return Qundef;
476  }
477 
478  me = rb_search_method_entry(recv, mid);
479  if (!check_funcall_callable(th, me)) {
480  VALUE ret = check_funcall_missing(th, klass, recv, mid, argc, argv,
481  respond, Qundef);
482  (*hook)(ret != Qundef, recv, mid, argc, argv, arg);
483  return ret;
484  }
485  stack_check(th);
486  (*hook)(TRUE, recv, mid, argc, argv, arg);
487  return vm_call0(th, recv, mid, argc, argv, me);
488 }
489 
490 static const char *
492 {
493 #define type_case(t) case t: return #t;
494  switch (type) {
521  default: return NULL;
522  }
523 #undef type_case
524 }
525 
526 static inline const rb_callable_method_entry_t *
528 {
529  VALUE klass = CLASS_OF(recv);
530 
531  if (!klass) {
532  VALUE flags;
533  if (SPECIAL_CONST_P(recv)) {
535  "method `%"PRIsVALUE"' called on unexpected immediate object (%p)",
536  rb_id2str(mid), (void *)recv);
537  }
538  flags = RBASIC(recv)->flags;
539  if (flags == 0) {
541  "method `%"PRIsVALUE"' called on terminated object"
542  " (%p flags=0x%"PRIxVALUE")",
543  rb_id2str(mid), (void *)recv, flags);
544  }
545  else {
546  int type = BUILTIN_TYPE(recv);
547  const char *typestr = rb_type_str(type);
548  if (typestr && T_OBJECT <= type && type < T_NIL)
550  "method `%"PRIsVALUE"' called on hidden %s object"
551  " (%p flags=0x%"PRIxVALUE")",
552  rb_id2str(mid), typestr, (void *)recv, flags);
553  if (typestr)
555  "method `%"PRIsVALUE"' called on unexpected %s object"
556  " (%p flags=0x%"PRIxVALUE")",
557  rb_id2str(mid), typestr, (void *)recv, flags);
558  else
560  "method `%"PRIsVALUE"' called on broken T_???" "(0x%02x) object"
561  " (%p flags=0x%"PRIxVALUE")",
562  rb_id2str(mid), type, (void *)recv, flags);
563  }
564  }
565  return rb_callable_method_entry(klass, mid);
566 }
567 
568 static inline enum method_missing_reason
570 {
571  VALUE klass;
572  ID oid;
574 
575  if (UNDEFINED_METHOD_ENTRY_P(me)) {
576  undefined:
577  return scope == CALL_VCALL ? MISSING_VCALL : MISSING_NOENTRY;
578  }
579  if (me->def->type == VM_METHOD_TYPE_REFINED) {
581  if (UNDEFINED_METHOD_ENTRY_P(me)) goto undefined;
582  }
583 
584  klass = me->owner;
585  oid = me->def->original_id;
586  visi = METHOD_ENTRY_VISI(me);
587 
588  if (oid != idMethodMissing) {
589  /* receiver specified form for private method */
590  if (UNLIKELY(visi != METHOD_VISI_PUBLIC)) {
591  if (visi == METHOD_VISI_PRIVATE && scope == CALL_PUBLIC) {
592  return MISSING_PRIVATE;
593  }
594 
595  /* self must be kind of a specified form for protected method */
596  if (visi == METHOD_VISI_PROTECTED && scope == CALL_PUBLIC) {
597  VALUE defined_class = klass;
598 
599  if (RB_TYPE_P(defined_class, T_ICLASS)) {
600  defined_class = RBASIC(defined_class)->klass;
601  }
602 
603  if (self == Qundef || !rb_obj_is_kind_of(self, defined_class)) {
604  return MISSING_PROTECTED;
605  }
606  }
607  }
608  }
609 
610  return MISSING_NONE;
611 }
612 
613 
625 static inline VALUE
626 rb_call(VALUE recv, ID mid, int argc, const VALUE *argv, call_type scope)
627 {
628  rb_thread_t *th = GET_THREAD();
629  return rb_call0(recv, mid, argc, argv, scope, th->cfp->self);
630 }
631 
632 NORETURN(static void raise_method_missing(rb_thread_t *th, int argc, const VALUE *argv,
633  VALUE obj, enum method_missing_reason call_status));
634 
635 /*
636  * call-seq:
637  * obj.method_missing(symbol [, *args] ) -> result
638  *
639  * Invoked by Ruby when <i>obj</i> is sent a message it cannot handle.
640  * <i>symbol</i> is the symbol for the method called, and <i>args</i>
641  * are any arguments that were passed to it. By default, the interpreter
642  * raises an error when this method is called. However, it is possible
643  * to override the method to provide more dynamic behavior.
644  * If it is decided that a particular method should not be handled, then
645  * <i>super</i> should be called, so that ancestors can pick up the
646  * missing method.
647  * The example below creates
648  * a class <code>Roman</code>, which responds to methods with names
649  * consisting of roman numerals, returning the corresponding integer
650  * values.
651  *
652  * class Roman
653  * def roman_to_int(str)
654  * # ...
655  * end
656  * def method_missing(methId)
657  * str = methId.id2name
658  * roman_to_int(str)
659  * end
660  * end
661  *
662  * r = Roman.new
663  * r.iv #=> 4
664  * r.xxiii #=> 23
665  * r.mm #=> 2000
666  */
667 
668 static VALUE
670 {
671  rb_thread_t *th = GET_THREAD();
672  raise_method_missing(th, argc, argv, obj, th->method_missing_reason);
673  UNREACHABLE;
674 }
675 
676 static VALUE
678  int argc, const VALUE *argv, int priv)
679 {
680  int n = 0;
681  enum {
682  arg_mesg,
683  arg_name,
684  arg_args,
685  arg_priv,
686  args_size
687  };
688  VALUE args[args_size];
689 
690  if (!format) {
691  format = rb_fstring_cstr("undefined method `%s' for %s%s%s");
692  }
693  args[n++] = rb_name_err_mesg_new(format, obj, argv[0]);
694  args[n++] = argv[0];
695  if (exc == rb_eNoMethodError) {
696  args[n++] = rb_ary_new4(argc - 1, argv + 1);
697  args[n++] = priv ? Qtrue : Qfalse;
698  }
699  return rb_class_new_instance(n, args, exc);
700 }
701 
702 static void
704  enum method_missing_reason last_call_status)
705 {
706  VALUE exc = rb_eNoMethodError;
707  VALUE format = 0;
708 
709  if (UNLIKELY(argc == 0)) {
710  rb_raise(rb_eArgError, "no method name given");
711  }
712  else if (UNLIKELY(!SYMBOL_P(argv[0]))) {
713  const VALUE e = rb_eArgError; /* TODO: TypeError? */
714  rb_raise(e, "method name must be a Symbol but %"PRIsVALUE" is given",
715  rb_obj_class(argv[0]));
716  }
717 
718  stack_check(th);
719 
720  if (last_call_status & MISSING_PRIVATE) {
721  format = rb_fstring_cstr("private method `%s' called for %s%s%s");
722  }
723  else if (last_call_status & MISSING_PROTECTED) {
724  format = rb_fstring_cstr("protected method `%s' called for %s%s%s");
725  }
726  else if (last_call_status & MISSING_VCALL) {
727  format = rb_fstring_cstr("undefined local variable or method `%s' for %s%s%s");
728  exc = rb_eNameError;
729  }
730  else if (last_call_status & MISSING_SUPER) {
731  format = rb_fstring_cstr("super: no superclass method `%s' for %s%s%s");
732  }
733 
734  {
735  exc = make_no_method_exception(exc, format, obj, argc, argv,
736  last_call_status & (MISSING_FCALL|MISSING_VCALL));
737  if (!(last_call_status & MISSING_MISSING)) {
739  }
740  rb_exc_raise(exc);
741  }
742 }
743 
744 static inline VALUE
745 method_missing(VALUE obj, ID id, int argc, const VALUE *argv, enum method_missing_reason call_status)
746 {
747  VALUE *nargv, result, work, klass;
748  rb_thread_t *th = GET_THREAD();
749  VALUE block_handler = vm_passed_block_handler(th);
751 
752  th->method_missing_reason = call_status;
753 
754  if (id == idMethodMissing) {
755  missing:
756  raise_method_missing(th, argc, argv, obj, call_status | MISSING_MISSING);
757  }
758 
759  nargv = ALLOCV_N(VALUE, work, argc + 1);
760  nargv[0] = ID2SYM(id);
761  MEMCPY(nargv + 1, argv, VALUE, argc);
762  ++argc;
763  argv = nargv;
764 
765  klass = CLASS_OF(obj);
766  if (!klass) goto missing;
767  me = rb_callable_method_entry(klass, idMethodMissing);
768  if (!me || METHOD_ENTRY_BASIC(me)) goto missing;
769  vm_passed_block_handler_set(th, block_handler);
770  result = vm_call0(th, obj, idMethodMissing, argc, argv, me);
771  if (work) ALLOCV_END(work);
772  return result;
773 }
774 
775 void
777  VALUE obj, int call_status)
778 {
780  raise_method_missing(th, argc, argv, obj, call_status | MISSING_MISSING);
781 }
782 
791 VALUE
793 {
794  int argc;
795  VALUE *argv, ret;
796 
797  argc = RARRAY_LENINT(args);
798  if (argc >= 0x100) {
799  args = rb_ary_subseq(args, 0, argc);
800  RBASIC_CLEAR_CLASS(args);
801  OBJ_FREEZE(args);
802  ret = rb_call(recv, mid, argc, RARRAY_CONST_PTR(args), CALL_FCALL);
803  RB_GC_GUARD(args);
804  return ret;
805  }
806  argv = ALLOCA_N(VALUE, argc);
807  MEMCPY(argv, RARRAY_CONST_PTR(args), VALUE, argc);
808  return rb_call(recv, mid, argc, argv, CALL_FCALL);
809 }
810 
820 VALUE
821 rb_funcall(VALUE recv, ID mid, int n, ...)
822 {
823  VALUE *argv;
824  va_list ar;
825 
826  if (n > 0) {
827  long i;
828 
829  va_init_list(ar, n);
830 
831  argv = ALLOCA_N(VALUE, n);
832 
833  for (i = 0; i < n; i++) {
834  argv[i] = va_arg(ar, VALUE);
835  }
836  va_end(ar);
837  }
838  else {
839  argv = 0;
840  }
841  return rb_call(recv, mid, n, argv, CALL_FCALL);
842 }
843 
851 VALUE
853 {
854  return rb_call(recv, mid, argc, argv, CALL_FCALL);
855 }
856 
866 VALUE
868 {
869  return rb_call(recv, mid, argc, argv, CALL_PUBLIC);
870 }
871 
872 VALUE
874 {
876  return rb_call(recv, mid, argc, argv, CALL_PUBLIC);
877 }
878 
879 VALUE
880 rb_funcall_with_block(VALUE recv, ID mid, int argc, const VALUE *argv, VALUE passed_procval)
881 {
882  if (!NIL_P(passed_procval)) {
883  rb_thread_t *th = GET_THREAD();
884  vm_passed_block_handler_set(th, passed_procval);
885  }
886 
887  return rb_call(recv, mid, argc, argv, CALL_PUBLIC);
888 }
889 
890 static VALUE *
892 {
894  if (RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, prev_cfp)) return NULL;
895  if (prev_cfp->sp + 1 != argv) return NULL;
896  return prev_cfp->sp + 1;
897 }
898 
899 static VALUE
901 {
902  ID id;
903  VALUE vid;
904  VALUE self;
905  VALUE ret, vargv = 0;
906  rb_thread_t *th = GET_THREAD();
907 
908  if (scope == CALL_PUBLIC) {
909  self = Qundef;
910  }
911  else {
912  self = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp)->self;
913  }
914 
915  if (argc == 0) {
916  rb_raise(rb_eArgError, "no method name given");
917  }
918 
919  vid = *argv;
920 
921  id = rb_check_id(&vid);
922  if (!id) {
923  if (rb_method_basic_definition_p(CLASS_OF(recv), idMethodMissing)) {
925  recv, argc, argv,
926  scope != CALL_PUBLIC);
927  rb_exc_raise(exc);
928  }
929  if (!SYMBOL_P(*argv)) {
930  VALUE *tmp_argv = current_vm_stack_arg(th, argv);
931  vid = rb_str_intern(vid);
932  if (tmp_argv) {
933  tmp_argv[0] = vid;
934  }
935  else if (argc > 1) {
936  tmp_argv = ALLOCV_N(VALUE, vargv, argc);
937  tmp_argv[0] = vid;
938  MEMCPY(tmp_argv+1, argv+1, VALUE, argc-1);
939  argv = tmp_argv;
940  }
941  else {
942  argv = &vid;
943  }
944  }
945  id = idMethodMissing;
947  }
948  else {
949  argv++; argc--;
950  }
952  ret = rb_call0(recv, id, argc, argv, scope, self);
953  ALLOCV_END(vargv);
954  return ret;
955 }
956 
957 /*
958  * call-seq:
959  * foo.send(symbol [, args...]) -> obj
960  * foo.__send__(symbol [, args...]) -> obj
961  * foo.send(string [, args...]) -> obj
962  * foo.__send__(string [, args...]) -> obj
963  *
964  * Invokes the method identified by _symbol_, passing it any
965  * arguments specified. You can use <code>__send__</code> if the name
966  * +send+ clashes with an existing method in _obj_.
967  * When the method is identified by a string, the string is converted
968  * to a symbol.
969  *
970  * class Klass
971  * def hello(*args)
972  * "Hello " + args.join(' ')
973  * end
974  * end
975  * k = Klass.new
976  * k.send :hello, "gentle", "readers" #=> "Hello gentle readers"
977  */
978 
979 VALUE
981 {
982  return send_internal(argc, argv, recv, CALL_FCALL);
983 }
984 
985 /*
986  * call-seq:
987  * obj.public_send(symbol [, args...]) -> obj
988  * obj.public_send(string [, args...]) -> obj
989  *
990  * Invokes the method identified by _symbol_, passing it any
991  * arguments specified. Unlike send, public_send calls public
992  * methods only.
993  * When the method is identified by a string, the string is converted
994  * to a symbol.
995  *
996  * 1.public_send(:puts, "hello") # causes NoMethodError
997  */
998 
999 VALUE
1001 {
1002  return send_internal(argc, argv, recv, CALL_PUBLIC);
1003 }
1004 
1005 /* yield */
1006 
1007 static inline VALUE
1008 rb_yield_0(int argc, const VALUE * argv)
1009 {
1010  return vm_yield(GET_THREAD(), argc, argv);
1011 }
1012 
1013 VALUE
1015 {
1016  return rb_yield_0(1, &val);
1017 }
1018 
1019 VALUE
1021 {
1022  if (val == Qundef) {
1023  return rb_yield_0(0, 0);
1024  }
1025  else {
1026  return rb_yield_1(val);
1027  }
1028 }
1029 
1030 VALUE
1031 rb_yield_values(int n, ...)
1032 {
1033  if (n == 0) {
1034  return rb_yield_0(0, 0);
1035  }
1036  else {
1037  int i;
1038  VALUE *argv;
1039  va_list args;
1040  argv = ALLOCA_N(VALUE, n);
1041 
1042  va_init_list(args, n);
1043  for (i=0; i<n; i++) {
1044  argv[i] = va_arg(args, VALUE);
1045  }
1046  va_end(args);
1047 
1048  return rb_yield_0(n, argv);
1049  }
1050 }
1051 
1052 VALUE
1054 {
1055  return rb_yield_0(argc, argv);
1056 }
1057 
1058 VALUE
1060 {
1061  VALUE tmp = rb_check_array_type(values);
1062  VALUE v;
1063  if (NIL_P(tmp)) {
1064  rb_raise(rb_eArgError, "not an array");
1065  }
1066  v = rb_yield_0(RARRAY_LENINT(tmp), RARRAY_CONST_PTR(tmp));
1067  RB_GC_GUARD(tmp);
1068  return v;
1069 }
1070 
1071 VALUE
1073 {
1074  return vm_yield_lambda_splattable(GET_THREAD(), values);
1075 }
1076 
1077 VALUE
1078 rb_yield_block(VALUE val, VALUE arg, int argc, const VALUE *argv, VALUE blockarg)
1079 {
1080  return vm_yield_with_block(GET_THREAD(), argc, argv,
1081  NIL_P(blockarg) ? VM_BLOCK_HANDLER_NONE : blockarg);
1082 }
1083 
1084 static VALUE
1085 loop_i(void)
1086 {
1087  for (;;) {
1088  rb_yield_0(0, 0);
1089  }
1090  return Qnil;
1091 }
1092 
1093 static VALUE
1094 loop_stop(VALUE dummy, VALUE exc)
1095 {
1096  return rb_attr_get(exc, id_result);
1097 }
1098 
1099 static VALUE
1100 rb_f_loop_size(VALUE self, VALUE args, VALUE eobj)
1101 {
1102  return DBL2NUM(INFINITY);
1103 }
1104 
1105 /*
1106  * call-seq:
1107  * loop { block }
1108  * loop -> an_enumerator
1109  *
1110  * Repeatedly executes the block.
1111  *
1112  * If no block is given, an enumerator is returned instead.
1113  *
1114  * loop do
1115  * print "Input: "
1116  * line = gets
1117  * break if !line or line =~ /^qQ/
1118  * # ...
1119  * end
1120  *
1121  * StopIteration raised in the block breaks the loop. In this case,
1122  * loop returns the "result" value stored in the exception.
1123  *
1124  * enum = Enumerator.new { |y|
1125  * y << "one"
1126  * y << "two"
1127  * :ok
1128  * }
1129  *
1130  * result = loop {
1131  * puts enum.next
1132  * } #=> :ok
1133  */
1134 
1135 static VALUE
1137 {
1140 }
1141 
1142 #if VMDEBUG
1143 static const char *
1144 vm_frametype_name(const rb_control_frame_t *cfp);
1145 #endif
1146 
1147 static VALUE
1148 rb_iterate0(VALUE (* it_proc) (VALUE), VALUE data1,
1149  const struct vm_ifunc *const ifunc,
1150  rb_thread_t *const th)
1151 {
1152  int state;
1153  volatile VALUE retval = Qnil;
1154  rb_control_frame_t *const cfp = th->cfp;
1155 
1156  TH_PUSH_TAG(th);
1157  state = TH_EXEC_TAG();
1158  if (state == 0) {
1159  iter_retry:
1160  {
1161  VALUE block_handler;
1162 
1163  if (ifunc) {
1164  struct rb_captured_block *captured = VM_CFP_TO_CAPTURED_BLOCK(cfp);
1165  captured->code.ifunc = ifunc;
1166  block_handler = VM_BH_FROM_IFUNC_BLOCK(captured);
1167  }
1168  else {
1169  block_handler = VM_CF_BLOCK_HANDLER(cfp);
1170  }
1171  vm_passed_block_handler_set(th, block_handler);
1172  }
1173  retval = (*it_proc) (data1);
1174  }
1175  else if (state == TAG_BREAK || state == TAG_RETRY) {
1176  const struct vm_throw_data *const err = (struct vm_throw_data *)th->errinfo;
1177  const rb_control_frame_t *const escape_cfp = THROW_DATA_CATCH_FRAME(err);
1178 
1179  if (cfp == escape_cfp) {
1180  rb_vm_rewind_cfp(th, cfp);
1181 
1182  state = 0;
1183  th->state = 0;
1184  th->errinfo = Qnil;
1185 
1186  if (state == TAG_RETRY) goto iter_retry;
1187  retval = THROW_DATA_VAL(err);
1188  }
1189  else if (0) {
1190  SDR(); fprintf(stderr, "%p, %p\n", cfp, escape_cfp);
1191  }
1192  }
1193  TH_POP_TAG();
1194 
1195  if (state) {
1196  TH_JUMP_TAG(th, state);
1197  }
1198  return retval;
1199 }
1200 
1201 VALUE
1202 rb_iterate(VALUE (* it_proc)(VALUE), VALUE data1,
1203  VALUE (* bl_proc)(ANYARGS), VALUE data2)
1204 {
1205  return rb_iterate0(it_proc, data1,
1206  bl_proc ? rb_vm_ifunc_proc_new(bl_proc, (void *)data2) : 0,
1207  GET_THREAD());
1208 }
1209 
1213  int argc;
1214  const VALUE *argv;
1215 };
1216 
1217 static VALUE
1219 {
1220  const struct iter_method_arg * arg =
1221  (struct iter_method_arg *) obj;
1222 
1223  return rb_call(arg->obj, arg->mid, arg->argc, arg->argv, CALL_FCALL);
1224 }
1225 
1226 VALUE
1228  VALUE (*bl_proc) (ANYARGS), VALUE data2)
1229 {
1230  struct iter_method_arg arg;
1231 
1232  arg.obj = obj;
1233  arg.mid = mid;
1234  arg.argc = argc;
1235  arg.argv = argv;
1236  return rb_iterate(iterate_method, (VALUE)&arg, bl_proc, data2);
1237 }
1238 
1239 VALUE
1240 rb_lambda_call(VALUE obj, ID mid, int argc, const VALUE *argv,
1241  rb_block_call_func_t bl_proc, int min_argc, int max_argc,
1242  VALUE data2)
1243 {
1244  struct iter_method_arg arg;
1245  struct vm_ifunc *block;
1246 
1247  if (!bl_proc) rb_raise(rb_eArgError, "NULL lambda function");
1248  arg.obj = obj;
1249  arg.mid = mid;
1250  arg.argc = argc;
1251  arg.argv = argv;
1252  block = rb_vm_ifunc_new(bl_proc, (void *)data2, min_argc, max_argc);
1253  return rb_iterate0(iterate_method, (VALUE)&arg, block, GET_THREAD());
1254 }
1255 
1256 static VALUE
1258 {
1259  const struct iter_method_arg * arg =
1260  (struct iter_method_arg *) obj;
1261 
1262  return rb_check_funcall(arg->obj, arg->mid, arg->argc, arg->argv);
1263 }
1264 
1265 VALUE
1266 rb_check_block_call(VALUE obj, ID mid, int argc, const VALUE *argv,
1267  VALUE (*bl_proc) (ANYARGS), VALUE data2)
1268 {
1269  struct iter_method_arg arg;
1270 
1271  arg.obj = obj;
1272  arg.mid = mid;
1273  arg.argc = argc;
1274  arg.argv = argv;
1275  return rb_iterate(iterate_check_method, (VALUE)&arg, bl_proc, data2);
1276 }
1277 
1278 VALUE
1280 {
1281  return rb_call(obj, idEach, 0, 0, CALL_FCALL);
1282 }
1283 
1284 static VALUE
1286 {
1287  VALUE errat = rb_get_backtrace(errinfo);
1288  VALUE mesg = rb_attr_get(errinfo, id_mesg);
1289  if (RB_TYPE_P(errat, T_ARRAY)) {
1290  VALUE bt2 = rb_vm_backtrace_str_ary(th, 0, 0);
1291  if (RARRAY_LEN(bt2) > 0) {
1292  if (RB_TYPE_P(mesg, T_STRING) && !RSTRING_LEN(mesg)) {
1293  rb_ivar_set(errinfo, id_mesg, RARRAY_AREF(errat, 0));
1294  }
1295  RARRAY_ASET(errat, 0, RARRAY_AREF(bt2, 0));
1296  }
1297  }
1298  return errinfo;
1299 }
1300 
1301 static VALUE
1302 eval_string_with_cref(VALUE self, VALUE src, VALUE scope, rb_cref_t *const cref_arg,
1303  VALUE filename, int lineno)
1304 {
1305  int state;
1306  VALUE result = Qundef;
1307  rb_thread_t *volatile th = GET_THREAD();
1308  struct rb_block block;
1309  const struct rb_block *base_block;
1310  volatile VALUE file;
1311  volatile int line;
1312 
1313  file = filename ? filename : rb_source_location(&lineno);
1314  line = lineno;
1315 
1316  {
1317  rb_cref_t *cref = cref_arg;
1318  rb_binding_t *bind = 0;
1319  const rb_iseq_t *iseq;
1320  VALUE absolute_path = Qnil;
1321  VALUE fname;
1322 
1323  if (file != Qundef) {
1324  absolute_path = file;
1325  }
1326 
1327  if (!NIL_P(scope)) {
1328  bind = Check_TypedStruct(scope, &ruby_binding_data_type);
1329 
1330  if (NIL_P(absolute_path) && !NIL_P(bind->path)) {
1331  file = bind->path;
1332  line = bind->first_lineno;
1333  absolute_path = rb_current_realfilepath();
1334  }
1335  base_block = &bind->block;
1336  }
1337  else {
1339 
1340  if (cfp != 0) {
1341  block.as.captured = *VM_CFP_TO_CAPTURED_BLOCK(cfp);
1342  block.as.captured.self = self;
1343  block.as.captured.code.iseq = cfp->iseq;
1344  block.type = block_type_iseq;
1345  base_block = &block;
1346  }
1347  else {
1348  rb_raise(rb_eRuntimeError, "Can't eval on top of Fiber or Thread");
1349  }
1350  }
1351 
1352  if ((fname = file) == Qundef) {
1353  fname = rb_usascii_str_new_cstr("(eval)");
1354  }
1355 
1356  if (RTEST(fname))
1357  fname = rb_fstring(fname);
1358  if (RTEST(absolute_path))
1359  absolute_path = rb_fstring(absolute_path);
1360 
1361  /* make eval iseq */
1362  iseq = rb_iseq_compile_with_option(src, fname, absolute_path, INT2FIX(line), base_block, Qnil);
1363 
1364  if (!iseq) {
1366  }
1367 
1368  /* TODO: what the code checking? */
1369  if (!cref && base_block->as.captured.code.val) {
1370  if (NIL_P(scope)) {
1371  rb_cref_t *orig_cref = rb_vm_get_cref(vm_block_ep(base_block));
1372  cref = vm_cref_dup(orig_cref);
1373  }
1374  else {
1375  cref = NULL; /* use stacked CREF */
1376  }
1377  }
1378  vm_set_eval_stack(th, iseq, cref, base_block);
1379 
1380  if (0) { /* for debug */
1381  VALUE disasm = rb_iseq_disasm(iseq);
1382  printf("%s\n", StringValuePtr(disasm));
1383  }
1384 
1385  /* save new env */
1386  if (bind && iseq->body->local_table_size > 0) {
1387  vm_bind_update_env(bind, vm_make_env_object(th, th->cfp));
1388  }
1389  }
1390 
1391  if (file != Qundef) {
1392  /* kick */
1393  return vm_exec(th);
1394  }
1395 
1396  TH_PUSH_TAG(th);
1397  if ((state = TH_EXEC_TAG()) == 0) {
1398  result = vm_exec(th);
1399  }
1400  TH_POP_TAG();
1401 
1402  if (state) {
1403  if (state == TAG_RAISE) {
1405  }
1406  TH_JUMP_TAG(th, state);
1407  }
1408  return result;
1409 }
1410 
1411 static VALUE
1412 eval_string(VALUE self, VALUE src, VALUE scope, VALUE file, int line)
1413 {
1414  return eval_string_with_cref(self, src, scope, 0, file, line);
1415 }
1416 
1417 /*
1418  * call-seq:
1419  * eval(string [, binding [, filename [,lineno]]]) -> obj
1420  *
1421  * Evaluates the Ruby expression(s) in <em>string</em>. If
1422  * <em>binding</em> is given, which must be a <code>Binding</code>
1423  * object, the evaluation is performed in its context. If the
1424  * optional <em>filename</em> and <em>lineno</em> parameters are
1425  * present, they will be used when reporting syntax errors.
1426  *
1427  * def get_binding(str)
1428  * return binding
1429  * end
1430  * str = "hello"
1431  * eval "str + ' Fred'" #=> "hello Fred"
1432  * eval "str + ' Fred'", get_binding("bye") #=> "bye Fred"
1433  */
1434 
1435 VALUE
1436 rb_f_eval(int argc, const VALUE *argv, VALUE self)
1437 {
1438  VALUE src, scope, vfile, vline;
1439  VALUE file = Qundef;
1440  int line = 1;
1441 
1442  rb_scan_args(argc, argv, "13", &src, &scope, &vfile, &vline);
1443  SafeStringValue(src);
1444  if (argc >= 3) {
1445  StringValue(vfile);
1446  }
1447  if (argc >= 4) {
1448  line = NUM2INT(vline);
1449  }
1450 
1451  if (!NIL_P(vfile))
1452  file = vfile;
1453  return eval_string(self, src, scope, file, line);
1454 }
1455 
1457 VALUE
1458 ruby_eval_string_from_file(const char *str, const char *filename)
1459 {
1460  VALUE file = filename ? rb_str_new_cstr(filename) : 0;
1461  return eval_string(rb_vm_top_self(), rb_str_new2(str), Qnil, file, 1);
1462 }
1463 
1467 };
1468 
1469 static VALUE
1471 {
1472  const struct eval_string_from_file_arg *const arg = (struct eval_string_from_file_arg*)data;
1473  return eval_string(rb_vm_top_self(), arg->str, Qnil, arg->filename, 1);
1474 }
1475 
1476 VALUE
1477 ruby_eval_string_from_file_protect(const char *str, const char *filename, int *state)
1478 {
1479  struct eval_string_from_file_arg arg;
1480  arg.str = rb_str_new_cstr(str);
1481  arg.filename = filename ? rb_str_new_cstr(filename) : 0;
1482  return rb_protect(eval_string_from_file_helper, (VALUE)&arg, state);
1483 }
1484 
1497 VALUE
1498 rb_eval_string(const char *str)
1499 {
1500  return ruby_eval_string_from_file(str, "eval");
1501 }
1502 
1513 VALUE
1514 rb_eval_string_protect(const char *str, int *state)
1515 {
1516  return rb_protect((VALUE (*)(VALUE))rb_eval_string, (VALUE)str, state);
1517 }
1518 
1530 VALUE
1531 rb_eval_string_wrap(const char *str, int *state)
1532 {
1533  int status;
1534  rb_thread_t *th = GET_THREAD();
1535  VALUE self = th->top_self;
1536  VALUE wrapper = th->top_wrapper;
1537  VALUE val;
1538 
1539  th->top_wrapper = rb_module_new();
1542 
1543  val = rb_eval_string_protect(str, &status);
1544 
1545  th->top_self = self;
1546  th->top_wrapper = wrapper;
1547 
1548  if (state) {
1549  *state = status;
1550  }
1551  else if (status) {
1552  TH_JUMP_TAG(th, status);
1553  }
1554  return val;
1555 }
1556 
1557 VALUE
1559 {
1560  int state;
1561  volatile VALUE val = Qnil; /* OK */
1562  const int VAR_NOCLOBBERED(safe) = rb_safe_level();
1563  rb_thread_t *const VAR_NOCLOBBERED(th) = GET_THREAD();
1564 
1565  if (OBJ_TAINTED(cmd)) {
1566  level = RUBY_SAFE_LEVEL_MAX;
1567  }
1568 
1569  TH_PUSH_TAG(th);
1570  rb_set_safe_level_force(level);
1571  if ((state = TH_EXEC_TAG()) == 0) {
1572  if (!RB_TYPE_P(cmd, T_STRING)) {
1573  val = rb_funcallv(cmd, idCall, RARRAY_LENINT(arg),
1574  RARRAY_CONST_PTR(arg));
1575  }
1576  else {
1577  val = eval_string(rb_vm_top_self(), cmd, Qnil, 0, 0);
1578  }
1579  }
1580  TH_POP_TAG();
1581 
1583  if (state) TH_JUMP_TAG(th, state);
1584  return val;
1585 }
1586 
1587 /* block eval under the class/module context */
1588 
1589 static VALUE
1590 yield_under(VALUE under, VALUE self, int argc, const VALUE *argv)
1591 {
1592  rb_thread_t *th = GET_THREAD();
1593  rb_control_frame_t *cfp = th->cfp;
1594  VALUE block_handler = VM_CF_BLOCK_HANDLER(cfp);
1595  VALUE new_block_handler = 0;
1596  const struct rb_captured_block *captured = NULL;
1597  struct rb_captured_block new_captured;
1598  const VALUE *ep = NULL;
1599  rb_cref_t *cref;
1600  int is_lambda = FALSE;
1601 
1602  if (block_handler != VM_BLOCK_HANDLER_NONE) {
1603  again:
1604  switch (vm_block_handler_type(block_handler)) {
1606  captured = VM_BH_TO_CAPT_BLOCK(block_handler);
1607  new_captured = *captured;
1608  new_block_handler = VM_BH_FROM_ISEQ_BLOCK(&new_captured);
1609  break;
1611  captured = VM_BH_TO_CAPT_BLOCK(block_handler);
1612  new_captured = *captured;
1613  new_block_handler = VM_BH_FROM_IFUNC_BLOCK(&new_captured);
1614  break;
1616  is_lambda = rb_proc_lambda_p(block_handler) != Qfalse;
1617  block_handler = vm_proc_to_block_handler(VM_BH_TO_PROC(block_handler));
1618  goto again;
1620  return rb_sym_proc_call(SYM2ID(VM_BH_TO_SYMBOL(block_handler)),
1621  argc, argv, VM_BLOCK_HANDLER_NONE);
1622  }
1623 
1624  new_captured.self = self;
1625  ep = captured->ep;
1626 
1628  }
1629 
1630  cref = vm_cref_push(th, under, ep, TRUE);
1631  return vm_yield_with_cref(th, argc, argv, cref, is_lambda);
1632 }
1633 
1634 VALUE
1635 rb_yield_refine_block(VALUE refinement, VALUE refinements)
1636 {
1637  rb_thread_t *th = GET_THREAD();
1638  VALUE block_handler = VM_CF_BLOCK_HANDLER(th->cfp);
1639 
1640  if (vm_block_handler_type(block_handler) != block_handler_type_iseq) {
1641  rb_bug("rb_yield_refine_block: an iseq block is required");
1642  }
1643  else {
1644  const struct rb_captured_block *captured = VM_BH_TO_ISEQ_BLOCK(block_handler);
1645  struct rb_captured_block new_captured = *captured;
1646  VALUE new_block_handler = VM_BH_FROM_ISEQ_BLOCK(&new_captured);
1647  const VALUE *ep = captured->ep;
1648  rb_cref_t *cref = vm_cref_push(th, refinement, ep, TRUE);
1649  CREF_REFINEMENTS_SET(cref, refinements);
1651  new_captured.self = refinement;
1652  return vm_yield_with_cref(th, 0, NULL, cref, FALSE);
1653  }
1654 }
1655 
1656 /* string eval under the class/module context */
1657 static VALUE
1658 eval_under(VALUE under, VALUE self, VALUE src, VALUE file, int line)
1659 {
1660  rb_cref_t *cref = vm_cref_push(GET_THREAD(), under, NULL, SPECIAL_CONST_P(self) && !NIL_P(under));
1661  SafeStringValue(src);
1662  return eval_string_with_cref(self, src, Qnil, cref, file, line);
1663 }
1664 
1665 static VALUE
1666 specific_eval(int argc, const VALUE *argv, VALUE klass, VALUE self)
1667 {
1668  if (rb_block_given_p()) {
1669  rb_check_arity(argc, 0, 0);
1670  return yield_under(klass, self, 1, &self);
1671  }
1672  else {
1673  VALUE file = Qundef;
1674  int line = 1;
1675  VALUE code;
1676 
1677  rb_check_arity(argc, 1, 3);
1678  code = argv[0];
1679  SafeStringValue(code);
1680  if (argc > 2)
1681  line = NUM2INT(argv[2]);
1682  if (argc > 1) {
1683  file = argv[1];
1684  if (!NIL_P(file)) StringValue(file);
1685  }
1686  return eval_under(klass, self, code, file, line);
1687  }
1688 }
1689 
1690 static VALUE
1692 {
1693  if (SPECIAL_CONST_P(self)) {
1694  return rb_special_singleton_class(self);
1695  }
1696  switch (BUILTIN_TYPE(self)) {
1697  case T_FLOAT: case T_BIGNUM: case T_SYMBOL:
1698  return Qnil;
1699  case T_STRING:
1700  if (FL_TEST_RAW(self, RSTRING_FSTR)) return Qnil;
1701  default:
1702  return rb_singleton_class(self);
1703  }
1704 }
1705 
1706 /*
1707  * call-seq:
1708  * obj.instance_eval(string [, filename [, lineno]] ) -> obj
1709  * obj.instance_eval {|obj| block } -> obj
1710  *
1711  * Evaluates a string containing Ruby source code, or the given block,
1712  * within the context of the receiver (_obj_). In order to set the
1713  * context, the variable +self+ is set to _obj_ while
1714  * the code is executing, giving the code access to _obj_'s
1715  * instance variables and private methods.
1716  *
1717  * When <code>instance_eval</code> is given a block, _obj_ is also
1718  * passed in as the block's only argument.
1719  *
1720  * When <code>instance_eval</code> is given a +String+, the optional
1721  * second and third parameters supply a filename and starting line number
1722  * that are used when reporting compilation errors.
1723  *
1724  * class KlassWithSecret
1725  * def initialize
1726  * @secret = 99
1727  * end
1728  * private
1729  * def the_secret
1730  * "Ssssh! The secret is #{@secret}."
1731  * end
1732  * end
1733  * k = KlassWithSecret.new
1734  * k.instance_eval { @secret } #=> 99
1735  * k.instance_eval { the_secret } #=> "Ssssh! The secret is 99."
1736  * k.instance_eval {|obj| obj == self } #=> true
1737  */
1738 
1739 VALUE
1740 rb_obj_instance_eval(int argc, const VALUE *argv, VALUE self)
1741 {
1742  VALUE klass = singleton_class_for_eval(self);
1743  return specific_eval(argc, argv, klass, self);
1744 }
1745 
1746 /*
1747  * call-seq:
1748  * obj.instance_exec(arg...) {|var...| block } -> obj
1749  *
1750  * Executes the given block within the context of the receiver
1751  * (_obj_). In order to set the context, the variable +self+ is set
1752  * to _obj_ while the code is executing, giving the code access to
1753  * _obj_'s instance variables. Arguments are passed as block parameters.
1754  *
1755  * class KlassWithSecret
1756  * def initialize
1757  * @secret = 99
1758  * end
1759  * end
1760  * k = KlassWithSecret.new
1761  * k.instance_exec(5) {|x| @secret+x } #=> 104
1762  */
1763 
1764 VALUE
1765 rb_obj_instance_exec(int argc, const VALUE *argv, VALUE self)
1766 {
1767  VALUE klass = singleton_class_for_eval(self);
1768  return yield_under(klass, self, argc, argv);
1769 }
1770 
1771 /*
1772  * call-seq:
1773  * mod.class_eval(string [, filename [, lineno]]) -> obj
1774  * mod.class_eval {|mod| block } -> obj
1775  * mod.module_eval(string [, filename [, lineno]]) -> obj
1776  * mod.module_eval {|mod| block } -> obj
1777  *
1778  * Evaluates the string or block in the context of _mod_, except that when
1779  * a block is given, constant/class variable lookup is not affected. This
1780  * can be used to add methods to a class. <code>module_eval</code> returns
1781  * the result of evaluating its argument. The optional _filename_ and
1782  * _lineno_ parameters set the text for error messages.
1783  *
1784  * class Thing
1785  * end
1786  * a = %q{def hello() "Hello there!" end}
1787  * Thing.module_eval(a)
1788  * puts Thing.new.hello()
1789  * Thing.module_eval("invalid code", "dummy", 123)
1790  *
1791  * <em>produces:</em>
1792  *
1793  * Hello there!
1794  * dummy:123:in `module_eval': undefined local variable
1795  * or method `code' for Thing:Class
1796  */
1797 
1798 VALUE
1799 rb_mod_module_eval(int argc, const VALUE *argv, VALUE mod)
1800 {
1801  return specific_eval(argc, argv, mod, mod);
1802 }
1803 
1804 /*
1805  * call-seq:
1806  * mod.module_exec(arg...) {|var...| block } -> obj
1807  * mod.class_exec(arg...) {|var...| block } -> obj
1808  *
1809  * Evaluates the given block in the context of the class/module.
1810  * The method defined in the block will belong to the receiver.
1811  * Any arguments passed to the method will be passed to the block.
1812  * This can be used if the block needs to access instance variables.
1813  *
1814  * class Thing
1815  * end
1816  * Thing.class_exec{
1817  * def hello() "Hello there!" end
1818  * }
1819  * puts Thing.new.hello()
1820  *
1821  * <em>produces:</em>
1822  *
1823  * Hello there!
1824  */
1825 
1826 VALUE
1827 rb_mod_module_exec(int argc, const VALUE *argv, VALUE mod)
1828 {
1829  return yield_under(mod, mod, argc, argv);
1830 }
1831 
1832 /*
1833  * Document-class: UncaughtThrowError
1834  *
1835  * Raised when +throw+ is called with a _tag_ which does not have
1836  * corresponding +catch+ block.
1837  *
1838  * throw "foo", "bar"
1839  *
1840  * <em>raises the exception:</em>
1841  *
1842  * UncaughtThrowError: uncaught throw "foo"
1843  */
1844 
1845 static VALUE
1846 uncaught_throw_init(int argc, const VALUE *argv, VALUE exc)
1847 {
1849  rb_call_super(argc - 2, argv + 2);
1850  rb_ivar_set(exc, id_tag, argv[0]);
1851  rb_ivar_set(exc, id_value, argv[1]);
1852  return exc;
1853 }
1854 
1855 /*
1856  * call-seq:
1857  * uncaught_throw.tag -> obj
1858  *
1859  * Return the tag object which was called for.
1860  */
1861 
1862 static VALUE
1864 {
1865  return rb_ivar_get(exc, id_tag);
1866 }
1867 
1868 /*
1869  * call-seq:
1870  * uncaught_throw.value -> obj
1871  *
1872  * Return the return value which was called for.
1873  */
1874 
1875 static VALUE
1877 {
1878  return rb_ivar_get(exc, id_value);
1879 }
1880 
1881 /*
1882  * call-seq:
1883  * uncaught_throw.to_s -> string
1884  *
1885  * Returns formatted message with the inspected tag.
1886  */
1887 
1888 static VALUE
1890 {
1891  VALUE mesg = rb_attr_get(exc, id_mesg);
1892  VALUE tag = uncaught_throw_tag(exc);
1893  return rb_str_format(1, &tag, mesg);
1894 }
1895 
1896 /*
1897  * call-seq:
1898  * throw(tag [, obj])
1899  *
1900  * Transfers control to the end of the active +catch+ block
1901  * waiting for _tag_. Raises +UncaughtThrowError+ if there
1902  * is no +catch+ block for the _tag_. The optional second
1903  * parameter supplies a return value for the +catch+ block,
1904  * which otherwise defaults to +nil+. For examples, see
1905  * <code>Kernel::catch</code>.
1906  */
1907 
1908 static VALUE
1909 rb_f_throw(int argc, VALUE *argv)
1910 {
1911  VALUE tag, value;
1912 
1913  rb_scan_args(argc, argv, "11", &tag, &value);
1914  rb_throw_obj(tag, value);
1915  UNREACHABLE;
1916 }
1917 
1918 void
1920 {
1921  rb_thread_t *th = GET_THREAD();
1922  struct rb_vm_tag *tt = th->tag;
1923 
1924  while (tt) {
1925  if (tt->tag == tag) {
1926  tt->retval = value;
1927  break;
1928  }
1929  tt = tt->prev;
1930  }
1931  if (!tt) {
1932  VALUE desc[3];
1933  desc[0] = tag;
1934  desc[1] = value;
1935  desc[2] = rb_str_new_cstr("uncaught throw %p");
1937  }
1938 
1939  th->errinfo = (VALUE)THROW_DATA_NEW(tag, NULL, TAG_THROW);
1940  TH_JUMP_TAG(th, TAG_THROW);
1941 }
1942 
1943 void
1944 rb_throw(const char *tag, VALUE val)
1945 {
1947 }
1948 
1949 static VALUE
1951 {
1952  return rb_yield_0(1, &tag);
1953 }
1954 
1955 /*
1956  * call-seq:
1957  * catch([tag]) {|tag| block } -> obj
1958  *
1959  * +catch+ executes its block. If +throw+ is not called, the block executes
1960  * normally, and +catch+ returns the value of the last expression evaluated.
1961  *
1962  * catch(1) { 123 } # => 123
1963  *
1964  * If <code>throw(tag2, val)</code> is called, Ruby searches up its stack for
1965  * a +catch+ block whose +tag+ has the same +object_id+ as _tag2_. When found,
1966  * the block stops executing and returns _val_ (or +nil+ if no second argument
1967  * was given to +throw+).
1968  *
1969  * catch(1) { throw(1, 456) } # => 456
1970  * catch(1) { throw(1) } # => nil
1971  *
1972  * When +tag+ is passed as the first argument, +catch+ yields it as the
1973  * parameter of the block.
1974  *
1975  * catch(1) {|x| x + 2 } # => 3
1976  *
1977  * When no +tag+ is given, +catch+ yields a new unique object (as from
1978  * +Object.new+) as the block parameter. This object can then be used as the
1979  * argument to +throw+, and will match the correct +catch+ block.
1980  *
1981  * catch do |obj_A|
1982  * catch do |obj_B|
1983  * throw(obj_B, 123)
1984  * puts "This puts is not reached"
1985  * end
1986  *
1987  * puts "This puts is displayed"
1988  * 456
1989  * end
1990  *
1991  * # => 456
1992  *
1993  * catch do |obj_A|
1994  * catch do |obj_B|
1995  * throw(obj_A, 123)
1996  * puts "This puts is still not reached"
1997  * end
1998  *
1999  * puts "Now this puts is also not reached"
2000  * 456
2001  * end
2002  *
2003  * # => 123
2004  */
2005 
2006 static VALUE
2007 rb_f_catch(int argc, VALUE *argv)
2008 {
2009  VALUE tag;
2010 
2011  if (argc == 0) {
2012  tag = rb_obj_alloc(rb_cObject);
2013  }
2014  else {
2015  rb_scan_args(argc, argv, "01", &tag);
2016  }
2017  return rb_catch_obj(tag, catch_i, 0);
2018 }
2019 
2020 VALUE
2021 rb_catch(const char *tag, VALUE (*func)(), VALUE data)
2022 {
2024  return rb_catch_obj(vtag, func, data);
2025 }
2026 
2027 static VALUE vm_catch_protect(VALUE, rb_block_call_func *, VALUE, int *, rb_thread_t *volatile);
2028 
2029 VALUE
2031 {
2032  int state;
2033  rb_thread_t *th = GET_THREAD();
2034  VALUE val = vm_catch_protect(t, (rb_block_call_func *)func, data, &state, th);
2035  if (state)
2036  TH_JUMP_TAG(th, state);
2037  return val;
2038 }
2039 
2040 VALUE
2042 {
2043  return vm_catch_protect(t, func, data, stateptr, GET_THREAD());
2044 }
2045 
2046 static VALUE
2048  int *stateptr, rb_thread_t *volatile th)
2049 {
2050  int state;
2051  VALUE val = Qnil; /* OK */
2052  rb_control_frame_t *volatile saved_cfp = th->cfp;
2053 
2054  TH_PUSH_TAG(th);
2055 
2056  _tag.tag = tag;
2057 
2058  if ((state = TH_EXEC_TAG()) == 0) {
2059  /* call with argc=1, argv = [tag], block = Qnil to insure compatibility */
2060  val = (*func)(tag, data, 1, (const VALUE *)&tag, Qnil);
2061  }
2062  else if (state == TAG_THROW && THROW_DATA_VAL((struct vm_throw_data *)th->errinfo) == tag) {
2063  rb_vm_rewind_cfp(th, saved_cfp);
2064  val = th->tag->retval;
2065  th->errinfo = Qnil;
2066  state = 0;
2067  }
2068  TH_POP_TAG();
2069  if (stateptr)
2070  *stateptr = state;
2071 
2072  return val;
2073 }
2074 
2075 static void
2077 {
2078  vars->tbl = rb_hash_new();
2079  RHASH(vars->tbl)->ntbl = st_init_numtable(); /* compare_by_identity */
2080  RBASIC_CLEAR_CLASS(vars->tbl);
2081 }
2082 
2083 static VALUE
2085 {
2086  /* TODO: not to depend on the order of st_table */
2087  VALUE ary = rb_hash_keys(vars->tbl);
2088  rb_hash_clear(vars->tbl);
2089  vars->tbl = 0;
2090  return ary;
2091 }
2092 
2093 static int
2095 {
2096  if (existing) return ST_STOP;
2097  *value = (st_data_t)Qtrue; /* INT2FIX(arg) */
2098  return ST_CONTINUE;
2099 }
2100 
2101 static void
2102 local_var_list_add(const struct local_var_list *vars, ID lid)
2103 {
2104  if (lid && rb_is_local_id(lid)) {
2105  /* should skip temporary variable */
2106  st_table *tbl = RHASH_TBL_RAW(vars->tbl);
2107  st_data_t idx = 0; /* tbl->num_entries */
2108  st_update(tbl, ID2SYM(lid), local_var_list_update, idx);
2109  }
2110 }
2111 
2112 /*
2113  * call-seq:
2114  * local_variables -> array
2115  *
2116  * Returns the names of the current local variables.
2117  *
2118  * fred = 1
2119  * for i in 1..10
2120  * # ...
2121  * end
2122  * local_variables #=> [:fred, :i]
2123  */
2124 
2125 static VALUE
2127 {
2128  struct local_var_list vars;
2129  rb_thread_t *th = GET_THREAD();
2130  rb_control_frame_t *cfp =
2132  unsigned int i;
2133 
2134  local_var_list_init(&vars);
2135  while (cfp) {
2136  if (cfp->iseq) {
2137  for (i = 0; i < cfp->iseq->body->local_table_size; i++) {
2138  local_var_list_add(&vars, cfp->iseq->body->local_table[i]);
2139  }
2140  }
2141  if (!VM_ENV_LOCAL_P(cfp->ep)) {
2142  /* block */
2143  const VALUE *ep = VM_CF_PREV_EP(cfp);
2144 
2145  if (vm_collect_local_variables_in_heap(th, ep, &vars)) {
2146  break;
2147  }
2148  else {
2149  while (cfp->ep != ep) {
2150  cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
2151  }
2152  }
2153  }
2154  else {
2155  break;
2156  }
2157  }
2158  return local_var_list_finish(&vars);
2159 }
2160 
2161 /*
2162  * call-seq:
2163  * block_given? -> true or false
2164  * iterator? -> true or false
2165  *
2166  * Returns <code>true</code> if <code>yield</code> would execute a
2167  * block in the current context. The <code>iterator?</code> form
2168  * is mildly deprecated.
2169  *
2170  * def try
2171  * if block_given?
2172  * yield
2173  * else
2174  * "no block"
2175  * end
2176  * end
2177  * try #=> "no block"
2178  * try { "hello" } #=> "hello"
2179  * try do "hello" end #=> "hello"
2180  */
2181 
2182 
2183 VALUE
2185 {
2186  rb_thread_t *th = GET_THREAD();
2187  rb_control_frame_t *cfp = th->cfp;
2189 
2190  if (cfp != NULL && VM_CF_BLOCK_HANDLER(cfp) != VM_BLOCK_HANDLER_NONE) {
2191  return Qtrue;
2192  }
2193  else {
2194  return Qfalse;
2195  }
2196 }
2197 
2198 VALUE
2200 {
2201  rb_thread_t *th = GET_THREAD();
2202  rb_control_frame_t *cfp = th->cfp;
2204  if (cfp != 0) return cfp->iseq->body->location.absolute_path;
2205  return Qnil;
2206 }
2207 
2208 void
2210 {
2211  rb_define_global_function("eval", rb_f_eval, -1);
2212  rb_define_global_function("local_variables", rb_f_local_variables, 0);
2214  rb_define_global_function("block_given?", rb_f_block_given_p, 0);
2215 
2216  rb_define_global_function("catch", rb_f_catch, -1);
2217  rb_define_global_function("throw", rb_f_throw, -1);
2218 
2220 
2221  rb_define_method(rb_cBasicObject, "instance_eval", rb_obj_instance_eval, -1);
2222  rb_define_method(rb_cBasicObject, "instance_exec", rb_obj_instance_exec, -1);
2224 
2225 #if 1
2227  VM_METHOD_TYPE_OPTIMIZED, (void *)OPTIMIZED_METHOD_TYPE_SEND, METHOD_VISI_PUBLIC);
2229  VM_METHOD_TYPE_OPTIMIZED, (void *)OPTIMIZED_METHOD_TYPE_SEND, METHOD_VISI_PUBLIC);
2230 #else
2231  rb_define_method(rb_cBasicObject, "__send__", rb_f_send, -1);
2232  rb_define_method(rb_mKernel, "send", rb_f_send, -1);
2233 #endif
2234  rb_define_method(rb_mKernel, "public_send", rb_f_public_send, -1);
2235 
2236  rb_define_method(rb_cModule, "module_exec", rb_mod_module_exec, -1);
2237  rb_define_method(rb_cModule, "class_exec", rb_mod_module_exec, -1);
2238  rb_define_method(rb_cModule, "module_eval", rb_mod_module_eval, -1);
2239  rb_define_method(rb_cModule, "class_eval", rb_mod_module_eval, -1);
2240 
2241  rb_eUncaughtThrow = rb_define_class("UncaughtThrowError", rb_eArgError);
2246 
2247  id_result = rb_intern_const("result");
2248  id_tag = rb_intern_const("tag");
2249  id_value = rb_intern_const("value");
2250 }
VALUE rb_f_public_send(int argc, VALUE *argv, VALUE recv)
Definition: vm_eval.c:1000
#define RBASIC_CLEAR_CLASS(obj)
Definition: internal.h:1312
rb_control_frame_t * cfp
Definition: vm_core.h:708
static VALUE basic_obj_respond_to_missing(rb_thread_t *th, VALUE klass, VALUE obj, VALUE mid, VALUE priv)
Definition: vm_method.c:1901
#define T_SYMBOL
Definition: ruby.h:508
#define T_OBJECT
Definition: ruby.h:491
static VALUE vm_call_bmethod_body(rb_thread_t *th, struct rb_calling_info *calling, const struct rb_call_info *ci, struct rb_call_cache *cc, const VALUE *argv)
rb_control_frame_t * rb_vm_get_ruby_level_next_cfp(const rb_thread_t *th, const rb_control_frame_t *cfp)
Definition: vm.c:489
static VALUE loop_stop(VALUE dummy, VALUE exc)
Definition: vm_eval.c:1094
static const VALUE * VM_CF_LEP(const rb_control_frame_t *const cfp)
Definition: vm.c:62
#define UNDEFINED_METHOD_ENTRY_P(me)
Definition: method.h:171
ID rb_check_id(volatile VALUE *)
Returns ID for the given name if it is interned already, or 0.
Definition: symbol.c:923
static VALUE * current_vm_stack_arg(rb_thread_t *th, const VALUE *argv)
Definition: vm_eval.c:891
#define RUBY_VM_CHECK_INTS(th)
Definition: vm_core.h:1569
static int check_funcall_respond_to(rb_thread_t *th, VALUE klass, VALUE recv, ID mid)
Definition: vm_eval.c:393
const VALUE * ep
Definition: vm_core.h:636
static void vm_passed_block_handler_set(rb_thread_t *th, VALUE block_handler)
Definition: eval_intern.h:8
static VALUE vm_call0_cfunc_with_frame(rb_thread_t *th, struct rb_calling_info *calling, const struct rb_call_info *ci, struct rb_call_cache *cc, const VALUE *argv)
Definition: vm_eval.c:109
#define RARRAY_LEN(a)
Definition: ruby.h:1026
#define RUBY_EVENT_C_RETURN
Definition: ruby.h:2065
void rb_bug(const char *fmt,...)
Definition: error.c:482
rb_method_type_t type
Definition: method.h:148
#define FALSE
Definition: nkf.h:174
static VALUE make_no_method_exception(VALUE exc, VALUE format, VALUE obj, int argc, const VALUE *argv, int priv)
Definition: vm_eval.c:677
rb_method_attr_t attr
Definition: method.h:155
VALUE(* rb_block_call_func_t)(ANYARGS)
Definition: ruby.h:1837
static VALUE iterate_method(VALUE obj)
Definition: vm_eval.c:1218
#define va_init_list(a, b)
Definition: win32ole.h:34
static VALUE rb_call0(VALUE recv, ID mid, int argc, const VALUE *argv, call_type scope, VALUE self)
Definition: vm_eval.c:332
VALUE rb_current_realfilepath(void)
Definition: vm_eval.c:2199
#define T_FIXNUM
Definition: ruby.h:503
Definition: st.h:79
Definition: st.h:99
VALUE rb_yield_values(int n,...)
Definition: vm_eval.c:1031
const rb_callable_method_entry_t * me
Definition: vm_core.h:246
#define T_MATCH
Definition: ruby.h:507
static rb_cref_t * rb_vm_get_cref(const VALUE *ep)
#define NUM2INT(x)
Definition: ruby.h:684
VALUE rb_obj_instance_exec(int argc, const VALUE *argv, VALUE self)
Definition: vm_eval.c:1765
const VALUE owner
Definition: method.h:63
static VALUE send_internal(int argc, const VALUE *argv, VALUE recv, call_type scope)
Definition: vm_eval.c:900
#define id_mesg
Definition: vm_eval.c:29
#define VAR_NOCLOBBERED(var)
Definition: eval_intern.h:156
void rb_throw(const char *tag, VALUE val)
Definition: vm_eval.c:1944
#define RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)
Definition: vm_core.h:1172
#define GetProcPtr(obj, ptr)
Definition: vm_core.h:863
VALUE rb_eval_string_protect(const char *str, int *state)
Evaluates the given string in an isolated binding.
Definition: vm_eval.c:1514
VALUE rb_yield_splat(VALUE values)
Definition: vm_eval.c:1059
VALUE rb_check_funcall_with_hook(VALUE recv, ID mid, int argc, const VALUE *argv, rb_check_funcall_hook *hook, VALUE arg)
Definition: vm_eval.c:465
VALUE rb_ary_subseq(VALUE ary, long beg, long len)
Definition: array.c:1212
#define CLASS_OF(v)
Definition: ruby.h:453
static VALUE method_missing(VALUE obj, ID id, int argc, const VALUE *argv, enum method_missing_reason call_status)
Definition: vm_eval.c:745
VALUE rb_fstring_cstr(const char *str)
Definition: string.c:387
VALUE rb_yield_lambda(VALUE values)
Definition: vm_eval.c:1072
#define T_MODULE
Definition: ruby.h:494
static VALUE singleton_class_for_eval(VALUE self)
Definition: vm_eval.c:1691
VALUE rb_call_super(int argc, const VALUE *argv)
Definition: vm_eval.c:287
struct vm_ifunc * rb_vm_ifunc_new(VALUE(*func)(ANYARGS), const void *data, int min_argc, int max_argc)
Definition: proc.c:647
enum method_missing_reason method_missing_reason
Definition: vm_core.h:812
#define Qtrue
Definition: ruby.h:437
VALUE rb_vm_call(rb_thread_t *th, VALUE recv, VALUE id, int argc, const VALUE *argv, const rb_callable_method_entry_t *me)
Definition: vm_eval.c:255
struct rb_method_definition_struct *const def
Definition: method.h:61
static VALUE uncaught_throw_init(int argc, const VALUE *argv, VALUE exc)
Definition: vm_eval.c:1846
#define rb_id2str(id)
Definition: vm_backtrace.c:29
Definition: st.h:99
const int id
Definition: nkf.c:209
const rb_callable_method_entry_t * rb_vm_frame_method_entry(const rb_control_frame_t *cfp)
#define new_args(f, o, r, p, t)
Definition: ripper.c:513
VALUE rb_mod_module_eval(int argc, const VALUE *argv, VALUE mod)
Definition: vm_eval.c:1799
void rb_define_private_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1527
#define sysstack_error
Definition: vm_core.h:1486
#define TH_JUMP_TAG(th, st)
Definition: eval_intern.h:186
#define T_RATIONAL
Definition: ruby.h:509
#define rb_check_arity
Definition: intern.h:303
VALUE rb_vm_invoke_proc(rb_thread_t *th, rb_proc_t *proc, int argc, const VALUE *argv, VALUE passed_block_handler)
Definition: vm.c:1150
#define UNREACHABLE
Definition: ruby.h:46
static VALUE check_funcall_failed(struct rescue_funcall_args *args, VALUE e)
Definition: vm_eval.c:369
const ID * local_table
Definition: vm_core.h:363
#define VM_BLOCK_HANDLER_NONE
Definition: vm_core.h:1070
static const rb_callable_method_entry_t * aliased_callable_method_entry(const rb_callable_method_entry_t *me)
VALUE rb_check_funcall_default(VALUE recv, ID mid, int argc, const VALUE *argv, VALUE def)
Definition: vm_eval.c:445
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:54
#define SYM2ID(x)
Definition: ruby.h:384
static VALUE VM_BH_TO_SYMBOL(VALUE block_handler)
Definition: vm_core.h:1377
struct rb_iseq_constant_body * body
Definition: vm_core.h:395
VALUE rb_each(VALUE obj)
Definition: vm_eval.c:1279
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *state)
Definition: eval.c:891
#define PRIV
Definition: vm_eval.c:366
#define PRIxVALUE
Definition: ruby.h:133
static VALUE vm_yield_with_cref(rb_thread_t *th, int argc, const VALUE *argv, const rb_cref_t *cref, int is_lambda)
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:2207
static VALUE rb_yield_0(int argc, const VALUE *argv)
Definition: vm_eval.c:1008
VALUE rb_ivar_get(VALUE, ID)
Definition: variable.c:1260
VALUE rb_check_funcall(VALUE recv, ID mid, int argc, const VALUE *argv)
Definition: vm_eval.c:439
unsigned int flag
Definition: vm_core.h:217
#define TH_EXEC_TAG()
Definition: eval_intern.h:180
#define RB_GC_GUARD(v)
Definition: ruby.h:552
VALUE rb_obj_is_kind_of(VALUE, VALUE)
Definition: object.c:690
#define T_HASH
Definition: ruby.h:499
#define VM_PROFILE_UP(x)
void Init_vm_eval(void)
Definition: vm_eval.c:2209
#define SDR()
Definition: vm_core.h:1414
static VALUE vm_yield(rb_thread_t *th, int argc, const VALUE *argv)
VALUE rb_catch(const char *tag, VALUE(*func)(), VALUE data)
Definition: vm_eval.c:2021
static VALUE catch_i(VALUE tag, VALUE data)
Definition: vm_eval.c:1950
#define RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp)
Definition: vm_core.h:1178
#define T_ARRAY
Definition: ruby.h:498
static VALUE eval_string_from_file_helper(VALUE data)
Definition: vm_eval.c:1470
int st_update(st_table *table, st_data_t key, st_update_callback_func *func, st_data_t arg)
Definition: st.c:1371
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
Definition: class.c:1745
static int VM_ENV_LOCAL_P(const VALUE *ep)
Definition: vm_core.h:1073
unsigned int respond
Definition: vm_eval.c:352
static int VM_FRAME_RUBYFRAME_P(const rb_control_frame_t *cfp)
Definition: vm_core.h:1061
VALUE rb_eval_string_wrap(const char *str, int *state)
Evaluates the given string under a module binding in an isolated binding.
Definition: vm_eval.c:1531
VALUE ruby_eval_string_from_file(const char *str, const char *filename)
Definition: vm_eval.c:1458
#define T_UNDEF
Definition: ruby.h:512
int ruby_stack_check(void)
Definition: gc.c:3976
#define OBJ_TAINTED(x)
Definition: ruby.h:1298
VALUE rb_catch_obj(VALUE t, VALUE(*func)(), VALUE data)
Definition: vm_eval.c:2030
#define RUBY_DTRACE_CMETHOD_ENTRY_HOOK(th, klass, id)
Definition: probes_helper.h:37
union rb_block::@203 as
static rb_control_frame_t * vm_push_frame(rb_thread_t *th, const rb_iseq_t *iseq, VALUE type, VALUE self, VALUE specval, VALUE cref_or_me, const VALUE *pc, VALUE *sp, int local_size, int stack_max)
const VALUE * ep
Definition: vm_core.h:600
VALUE rb_obj_instance_eval(int argc, const VALUE *argv, VALUE self)
Definition: vm_eval.c:1740
#define GET_THREAD()
Definition: vm_core.h:1513
VALUE rb_hash_keys(VALUE hash)
Definition: hash.c:2017
RUBY_SYMBOL_EXPORT_BEGIN typedef unsigned long st_data_t
Definition: st.h:22
const VALUE * argv
Definition: vm_eval.c:355
void rb_exc_raise(VALUE mesg)
Definition: eval.c:620
static const struct rb_captured_block * VM_BH_TO_CAPT_BLOCK(VALUE block_handler)
Definition: vm_core.h:1246
#define RHASH(obj)
Definition: internal.h:562
VALUE rb_singleton_class(VALUE obj)
Returns the singleton class of obj.
Definition: class.c:1689
#define RB_TYPE_P(obj, type)
Definition: ruby.h:527
VALUE rb_eNameError
Definition: error.c:767
VALUE rb_check_block_call(VALUE obj, ID mid, int argc, const VALUE *argv, VALUE(*bl_proc)(ANYARGS), VALUE data2)
Definition: vm_eval.c:1266
#define TH_POP_TAG()
Definition: eval_intern.h:137
struct rb_block block
Definition: vm_core.h:887
rb_method_cfunc_t cfunc
Definition: method.h:154
VALUE rb_block_call_func(RB_BLOCK_CALL_FUNC_ARGLIST(yielded_arg, callback_arg))
Definition: ruby.h:1832
const rb_iseq_t * iseq
Definition: vm_core.h:634
unsigned short first_lineno
Definition: vm_core.h:889
static VALUE check_funcall_missing(rb_thread_t *th, VALUE klass, VALUE recv, ID mid, int argc, const VALUE *argv, int respond, VALUE def)
Definition: vm_eval.c:405
static VALUE rb_f_local_variables(void)
Definition: vm_eval.c:2126
static VALUE vm_proc_to_block_handler(VALUE procval)
static VALUE adjust_backtrace_in_eval(rb_thread_t *th, VALUE errinfo)
Definition: vm_eval.c:1285
#define RUBY_SAFE_LEVEL_MAX
Definition: ruby.h:599
int rb_block_given_p(void)
Definition: eval.c:797
static VALUE rb_f_catch(int argc, VALUE *argv)
Definition: vm_eval.c:2007
unsigned int local_table_size
Definition: vm_core.h:382
static rb_control_frame_t * vm_get_ruby_level_caller_cfp(const rb_thread_t *th, const rb_control_frame_t *cfp)
Definition: vm.c:501
#define val
#define PASS_PASSED_BLOCK_HANDLER_TH(th)
Definition: eval_intern.h:23
RUBY_EXTERN VALUE rb_cObject
Definition: ruby.h:1872
static VALUE vm_call0(rb_thread_t *th, VALUE recv, ID id, int argc, const VALUE *argv, const rb_callable_method_entry_t *me)
Definition: vm_eval.c:46
VALUE rb_eRuntimeError
Definition: error.c:761
VALUE rb_special_singleton_class(VALUE obj)
Definition: class.c:1579
#define T_NIL
Definition: ruby.h:490
RUBY_EXTERN VALUE rb_cBasicObject
Definition: ruby.h:1871
VALUE rb_funcall(VALUE recv, ID mid, int n,...)
Calls a method.
Definition: vm_eval.c:821
VALUE rb_sym_proc_call(ID mid, int argc, const VALUE *argv, VALUE passed_proc)
Definition: string.c:9716
#define T_TRUE
Definition: ruby.h:504
union rb_call_cache::@195 aux
RUBY_EXTERN VALUE rb_mKernel
Definition: ruby.h:1860
static const rb_control_frame_t * THROW_DATA_CATCH_FRAME(const struct vm_throw_data *obj)
VALUE rb_funcall_with_block(VALUE recv, ID mid, int argc, const VALUE *argv, VALUE passed_procval)
Definition: vm_eval.c:880
#define RCLASS_ORIGIN(c)
Definition: internal.h:693
void rb_check_funcall_hook(int, VALUE, ID, int, const VALUE *, VALUE)
Definition: internal.h:1605
#define NIL_P(v)
Definition: ruby.h:451
VALUE rb_define_class(const char *name, VALUE super)
Defines a top-level class.
Definition: class.c:646
static VALUE iterate_check_method(VALUE obj)
Definition: vm_eval.c:1257
VALUE rb_eNoMethodError
Definition: error.c:770
rb_method_visibility_t
Definition: method.h:26
static void local_var_list_init(struct local_var_list *vars)
Definition: vm_eval.c:2076
static void vm_set_eval_stack(rb_thread_t *th, const rb_iseq_t *iseq, const rb_cref_t *cref, const struct rb_block *base_block)
VALUE rb_f_eval(int argc, const VALUE *argv, VALUE self)
Definition: vm_eval.c:1436
static VALUE vm_make_env_object(rb_thread_t *th, rb_control_frame_t *cfp)
Definition: vm.c:717
VALUE tag
Definition: vm_core.h:663
#define BOUND_RESPONDS
Definition: vm_method.c:1066
static const struct rb_captured_block * VM_BH_TO_ISEQ_BLOCK(VALUE block_handler)
Definition: vm_core.h:1206
static const char * rb_type_str(enum ruby_value_type type)
Definition: vm_eval.c:491
VALUE top_self
Definition: vm_core.h:726
#define T_FLOAT
Definition: ruby.h:495
int argc
Definition: ruby.c:183
#define Qfalse
Definition: ruby.h:436
const rb_data_type_t ruby_binding_data_type
Definition: proc.c:297
#define undefined
Definition: vm_method.c:36
#define ALLOCV_N(type, v, n)
Definition: ruby.h:1657
#define ALLOCA_N(type, n)
Definition: ruby.h:1593
const VALUE defined_class
Definition: method.h:60
#define RUBY_DTRACE_CMETHOD_RETURN_HOOK(th, klass, id)
Definition: probes_helper.h:40
Definition: method.h:50
RUBY_EXTERN VALUE rb_cModule
Definition: ruby.h:1895
#define T_BIGNUM
Definition: ruby.h:501
Definition: method.h:58
static VALUE eval_under(VALUE under, VALUE self, VALUE src, VALUE file, int line)
Definition: vm_eval.c:1658
static VALUE rb_iterate0(VALUE(*it_proc)(VALUE), VALUE data1, const struct vm_ifunc *const ifunc, rb_thread_t *const th)
Definition: vm_eval.c:1148
#define MEMCPY(p1, p2, type, n)
Definition: ruby.h:1661
#define T_NODE
Definition: ruby.h:513
#define rb_ary_new4
Definition: intern.h:92
#define rb_str_new2
Definition: intern.h:857
VALUE rb_obj_alloc(VALUE)
Definition: object.c:1845
int err
Definition: win32.c:135
#define RUBY_EVENT_C_CALL
Definition: ruby.h:2064
static VALUE vm_yield_with_block(rb_thread_t *th, int argc, const VALUE *argv, VALUE block_handler)
#define OBJ_FREEZE(x)
Definition: ruby.h:1308
static VALUE rb_f_loop(VALUE self)
Definition: vm_eval.c:1136
#define T_COMPLEX
Definition: ruby.h:510
void rb_throw_obj(VALUE tag, VALUE value)
Definition: vm_eval.c:1919
#define ALLOCV_END(v)
Definition: ruby.h:1658
const VALUE * argv
Definition: vm_eval.c:1214
VALUE rb_class_new_instance(int, const VALUE *, VALUE)
Definition: object.c:1891
const rb_callable_method_entry_t * rb_resolve_refined_method_callable(VALUE refinements, const rb_callable_method_entry_t *me)
Definition: vm_method.c:947
VALUE rb_funcallv(VALUE recv, ID mid, int argc, const VALUE *argv)
Calls a method.
Definition: vm_eval.c:852
#define VM_ENV_DATA_INDEX_SPECVAL
Definition: vm_core.h:991
#define numberof(array)
Definition: etc.c:616
rb_method_type_t
Definition: method.h:100
rb_thread_t * th
Definition: vm_eval.c:347
static rb_cref_t * vm_cref_push(rb_thread_t *th, VALUE klass, const VALUE *ep, int pushed_by_eval)
VALUE rb_lambda_call(VALUE obj, ID mid, int argc, const VALUE *argv, rb_block_call_func_t bl_proc, int min_argc, int max_argc, VALUE data2)
Definition: vm_eval.c:1240
static const VALUE * VM_CF_PREV_EP(const rb_control_frame_t *const cfp)
Definition: vm.c:68
void rb_vm_pop_frame(rb_thread_t *th)
#define RSTRING_LEN(str)
Definition: ruby.h:978
#define RARRAY_CONST_PTR(a)
Definition: ruby.h:1028
VALUE tbl
Definition: vm_eval.c:15
VALUE(* invoker)(VALUE(*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv)
Definition: method.h:129
union rb_method_definition_struct::@144 body
#define TRUE
Definition: nkf.h:175
#define T_DATA
Definition: ruby.h:506
static VALUE vm_exec(rb_thread_t *th)
VALUE rb_str_format(int, const VALUE *, VALUE)
Definition: sprintf.c:461
const rb_callable_method_entry_t * rb_callable_method_entry(VALUE klass, ID id)
Definition: vm_method.c:834
NORETURN(static void raise_method_missing(rb_thread_t *th, int argc, const VALUE *argv, VALUE obj, enum method_missing_reason call_status))
void rb_raise_method_missing(rb_thread_t *th, int argc, const VALUE *argv, VALUE obj, int call_status)
Definition: vm_eval.c:776
static enum rb_block_handler_type vm_block_handler_type(VALUE block_handler)
Definition: vm_core.h:1254
VALUE(* func)(ANYARGS)
Definition: method.h:128
VALUE rb_eval_string(const char *str)
Evaluates the given string in an isolated binding.
Definition: vm_eval.c:1498
VALUE rb_hash_new(void)
Definition: hash.c:441
VALUE rb_vm_backtrace_str_ary(rb_thread_t *th, int lev, int n)
static VALUE yield_under(VALUE under, VALUE self, int argc, const VALUE *argv)
Definition: vm_eval.c:1590
static void raise_method_missing(rb_thread_t *th, int argc, const VALUE *argv, VALUE obj, enum method_missing_reason last_call_status)
Definition: vm_eval.c:703
VALUE rb_iterate(VALUE(*it_proc)(VALUE), VALUE data1, VALUE(*bl_proc)(ANYARGS), VALUE data2)
Definition: vm_eval.c:1202
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:1919
#define rb_thread_raised_set(th, f)
Definition: eval_intern.h:267
VALUE rb_ivar_set(VALUE, ID, VALUE)
Definition: variable.c:1364
VALUE rb_f_send(int argc, VALUE *argv, VALUE recv)
Definition: vm_eval.c:980
void rb_vm_pop_cfunc_frame(void)
Definition: vm.c:523
#define T_IMEMO
Definition: ruby.h:511
#define PRIsVALUE
Definition: ruby.h:135
unsigned long ID
Definition: ruby.h:86
static const VALUE * vm_block_ep(const struct rb_block *block)
Definition: vm_core.h:1348
#define T_STRUCT
Definition: ruby.h:500
#define Qnil
Definition: ruby.h:438
VALUE rb_eStopIteration
Definition: enumerator.c:109
#define FL_TEST_RAW(x, f)
Definition: ruby.h:1283
#define METHOD_ENTRY_VISI(me)
Definition: method.h:66
#define BUILTIN_TYPE(x)
Definition: ruby.h:518
static VALUE uncaught_throw_to_s(VALUE exc)
Definition: vm_eval.c:1889
unsigned long VALUE
Definition: ruby.h:85
VALUE rb_vm_top_self(void)
Definition: vm.c:3151
static VALUE uncaught_throw_tag(VALUE exc)
Definition: vm_eval.c:1863
method_missing_reason
Definition: vm_core.h:203
static VALUE result
Definition: nkf.c:40
#define EXEC_EVENT_HOOK(th_, flag_, self_, id_, called_id_, klass_, data_)
Definition: vm_core.h:1628
static ID id_tag
Definition: vm_eval.c:28
static VALUE rb_f_throw(int argc, VALUE *argv)
Definition: vm_eval.c:1909
VALUE rb_hash_clear(VALUE hash)
Definition: hash.c:1506
#define RETURN_SIZED_ENUMERATOR(obj, argc, argv, size_fn)
Definition: intern.h:236
#define RBASIC(obj)
Definition: ruby.h:1204
void rb_extend_object(VALUE obj, VALUE module)
Definition: eval.c:1429
static VALUE vm_call_super(rb_thread_t *th, int argc, const VALUE *argv)
Definition: vm_eval.c:261
static VALUE VM_BH_FROM_IFUNC_BLOCK(const struct rb_captured_block *captured)
Definition: vm_core.h:1230
VALUE rb_rescue2(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*r_proc)(ANYARGS), VALUE data2,...)
Definition: eval.c:825
static struct vm_ifunc * rb_vm_ifunc_proc_new(VALUE(*func)(ANYARGS), const void *data)
Definition: internal.h:811
#define TH_PUSH_TAG(th)
Definition: eval_intern.h:131
#define INFINITY
Definition: missing.h:149
const struct vm_ifunc * ifunc
Definition: vm_core.h:603
VALUE rb_str_new_cstr(const char *)
Definition: string.c:770
VALUE rb_proc_lambda_p(VALUE)
Definition: proc.c:255
#define RARRAY_LENINT(ary)
Definition: ruby.h:1027
const rb_method_entry_t * me
Definition: vm_eval.c:351
VALUE rb_fstring(VALUE)
Definition: string.c:305
call_type
Definition: vm_eval.c:34
static const rb_callable_method_entry_t * rb_search_method_entry(VALUE recv, ID mid)
Definition: vm_eval.c:527
static rb_method_entry_t * method_entry_get(VALUE klass, ID id, VALUE *defined_class_ptr)
Definition: vm_method.c:776
ruby_value_type
Definition: ruby.h:455
VALUE rb_sym_intern_ascii_cstr(const char *ptr)
Definition: symbol.c:1050
struct rb_captured_block captured
Definition: vm_core.h:624
VALUE rb_yield_refine_block(VALUE refinement, VALUE refinements)
Definition: vm_eval.c:1635
register unsigned int len
Definition: zonetab.h:51
void rb_set_safe_level_force(int)
Definition: safe.c:41
static VALUE rb_f_loop_size(VALUE self, VALUE args, VALUE eobj)
Definition: vm_eval.c:1100
static VALUE specific_eval(int argc, const VALUE *argv, VALUE klass, VALUE self)
Definition: vm_eval.c:1666
static VALUE eval_string_with_cref(VALUE self, VALUE src, VALUE scope, rb_cref_t *const cref_arg, VALUE filename, int lineno)
Definition: vm_eval.c:1302
static VALUE vm_catch_protect(VALUE, rb_block_call_func *, VALUE, int *, rb_thread_t *volatile)
Definition: vm_eval.c:2047
VALUE rb_mod_module_exec(int argc, const VALUE *argv, VALUE mod)
Definition: vm_eval.c:1827
static VALUE loop_i(void)
Definition: vm_eval.c:1085
static VALUE call_method_entry(rb_thread_t *th, VALUE defined_class, VALUE obj, ID id, const rb_method_entry_t *me, int argc, const VALUE *argv)
Definition: vm_method.c:1889
static VALUE VM_BH_TO_PROC(VALUE block_handler)
Definition: vm_core.h:1391
#define RARRAY_ASET(a, i, v)
Definition: ruby.h:1041
VALUE rb_iseq_disasm(const rb_iseq_t *iseq)
Definition: iseq.c:1487
static VALUE THROW_DATA_VAL(const struct vm_throw_data *obj)
static VALUE vm_call0_body(rb_thread_t *th, struct rb_calling_info *calling, const struct rb_call_info *ci, struct rb_call_cache *cc, const VALUE *argv)
Definition: vm_eval.c:155
#define TAG_RETRY
Definition: vm_core.h:166
#define INT2FIX(i)
Definition: ruby.h:232
VALUE top_wrapper
Definition: vm_core.h:727
#define UNLIMITED_ARGUMENTS
Definition: intern.h:44
static int local_var_list_update(st_data_t *key, st_data_t *value, st_data_t arg, int existing)
Definition: vm_eval.c:2094
#define TAG_THROW
Definition: vm_core.h:169
#define RCLASS_SUPER(c)
Definition: classext.h:16
int rb_safe_level(void)
Definition: safe.c:35
VALUE rb_module_new(void)
Definition: class.c:749
#define RARRAY_AREF(a, i)
Definition: ruby.h:1040
static const rb_callable_method_entry_t * refined_method_callable_without_refinement(const rb_callable_method_entry_t *me)
#define METHOD_ENTRY_BASIC(me)
Definition: method.h:67
static int check_funcall_callable(rb_thread_t *th, const rb_callable_method_entry_t *me)
Definition: vm_eval.c:399
#define st_init_numtable
Definition: regint.h:178
unsigned int respond_to_missing
Definition: vm_eval.c:353
#define ANYARGS
Definition: defines.h:173
static int vm_collect_local_variables_in_heap(rb_thread_t *th, const VALUE *dfp, const struct local_var_list *vars)
VALUE rb_check_array_type(VALUE ary)
Definition: array.c:635
static ID id_result
Definition: vm_eval.c:28
VALUE block_handler
Definition: vm_core.h:232
static rb_cref_t * vm_cref_dup(const rb_cref_t *cref)
Definition: vm.c:223
VALUE rb_catch_protect(VALUE t, rb_block_call_func *func, VALUE data, int *stateptr)
Definition: vm_eval.c:2041
static ID id_value
Definition: vm_eval.c:28
#define RHASH_TBL_RAW(h)
Definition: internal.h:1118
VALUE ruby_eval_string_from_file_protect(const char *str, const char *filename, int *state)
Definition: vm_eval.c:1477
static void local_var_list_add(const struct local_var_list *vars, ID lid)
Definition: vm_eval.c:2102
#define RTEST(v)
Definition: ruby.h:450
#define T_STRING
Definition: ruby.h:496
rb_method_entry_t * rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *option, rb_method_visibility_t visi)
Definition: vm_method.c:631
int rb_method_basic_definition_p(VALUE, ID)
Definition: vm_method.c:1880
#define T_FALSE
Definition: ruby.h:505
#define T_FILE
Definition: ruby.h:502
VALUE rb_apply(VALUE recv, ID mid, VALUE args)
Calls a method.
Definition: vm_eval.c:792
static void VM_FORCE_WRITE_SPECIAL_CONST(const VALUE *ptr, VALUE special_const_value)
Definition: vm_core.h:1154
static VALUE rb_call(VALUE recv, ID mid, int argc, const VALUE *argv, call_type scope)
Definition: vm_eval.c:626
VALUE rb_yield_values2(int argc, const VALUE *argv)
Definition: vm_eval.c:1053
VALUE rb_funcall_passing_block(VALUE recv, ID mid, int argc, const VALUE *argv)
Definition: vm_eval.c:873
#define UNLIKELY(x)
Definition: ffi_common.h:126
int rb_is_local_id(ID id)
Definition: symbol.c:858
static void vm_bind_update_env(rb_binding_t *bind, VALUE envval)
Definition: vm.c:270
#define rb_thread_raised_p(th, f)
Definition: eval_intern.h:269
const rb_iseq_t * iseq
Definition: vm_core.h:602
#define SafeStringValue(v)
Definition: ruby.h:574
VALUE rb_eNotImpError
Definition: error.c:772
VALUE rb_funcallv_public(VALUE recv, ID mid, int argc, const VALUE *argv)
Calls a method.
Definition: vm_eval.c:867
VALUE rb_f_block_given_p(void)
Definition: vm_eval.c:2184
#define T_CLASS
Definition: ruby.h:492
static int vm_respond_to(rb_thread_t *th, VALUE klass, VALUE obj, ID id, int priv)
Definition: vm_method.c:1934
static VALUE VM_BH_FROM_ISEQ_BLOCK(const struct rb_captured_block *captured)
Definition: vm_core.h:1198
static VALUE vm_passed_block_handler(rb_thread_t *th)
Definition: vm.c:169
#define ID2SYM(x)
Definition: ruby.h:383
VALUE rb_yield(VALUE val)
Definition: vm_eval.c:1020
VALUE rb_name_err_mesg_new(VALUE mesg, VALUE recv, VALUE method)
Definition: error.c:1354
#define StringValuePtr(v)
Definition: ruby.h:570
static void stack_check(rb_thread_t *th)
Definition: vm_eval.c:305
rb_iseq_t * rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE absolute_path, VALUE line, const struct rb_block *base_block, VALUE opt)
Definition: iseq.c:610
enum rb_block_type type
Definition: vm_core.h:628
static enum method_missing_reason rb_method_call_status(rb_thread_t *th, const rb_callable_method_entry_t *me, call_type scope, VALUE self)
Definition: vm_eval.c:569
struct rb_vm_tag * tag
Definition: vm_core.h:769
VALUE rb_source_location(int *pline)
Definition: vm.c:1275
VALUE rb_get_backtrace(VALUE exc)
Definition: error.c:965
struct rb_vm_tag * prev
Definition: vm_core.h:666
static struct rb_captured_block * VM_CFP_TO_CAPTURED_BLOCK(const rb_control_frame_t *cfp)
Definition: vm.c:146
void rb_vm_rewind_cfp(rb_thread_t *th, rb_control_frame_t *cfp)
Definition: vm.c:535
static VALUE rb_method_missing(int argc, const VALUE *argv, VALUE obj)
Definition: vm_eval.c:669
VALUE retval
Definition: vm_core.h:664
VALUE rb_str_intern(VALUE)
Definition: symbol.c:661
#define rb_intern_const(str)
Definition: ruby.h:1756
enum rb_method_definition_struct::@144::method_optimized_type optimize_type
#define TAG_BREAK
Definition: vm_core.h:164
#define SPECIAL_CONST_P(x)
Definition: ruby.h:1249
#define CHECK_VM_STACK_OVERFLOW(cfp, margin)
Definition: vm_core.h:1497
static VALUE VM_CF_BLOCK_HANDLER(const rb_control_frame_t *const cfp)
Definition: vm.c:75
#define rb_intern(str)
int rb_method_boundp(VALUE, ID, int)
Definition: vm_method.c:1069
static void CREF_REFINEMENTS_SET(rb_cref_t *cref, VALUE refs)
Definition: eval_intern.h:222
#define T_ZOMBIE
Definition: ruby.h:514
#define SYMBOL_P(x)
Definition: ruby.h:382
#define mod(x, y)
Definition: date_strftime.c:28
#define T_NONE
Definition: ruby.h:489
const struct rb_method_entry_struct *const orig_me
Definition: method.h:143
VALUE path
Definition: vm_core.h:888
#define TAG_RAISE
Definition: vm_core.h:168
VALUE rb_yield_1(VALUE val)
Definition: vm_eval.c:1014
static VALUE eval_string(VALUE self, VALUE src, VALUE scope, VALUE file, int line)
Definition: vm_eval.c:1412
VALUE rb_eval_cmd(VALUE cmd, VALUE arg, int level)
Definition: vm_eval.c:1558
#define NULL
Definition: _sdbm.c:102
#define BOUND_PRIVATE
Definition: vm_method.c:1065
rb_method_refined_t refined
Definition: method.h:157
#define Qundef
Definition: ruby.h:439
#define T_ICLASS
Definition: ruby.h:493
static VALUE local_var_list_finish(struct local_var_list *vars)
Definition: vm_eval.c:2084
VALUE rb_block_call(VALUE obj, ID mid, int argc, const VALUE *argv, VALUE(*bl_proc)(ANYARGS), VALUE data2)
Definition: vm_eval.c:1227
static VALUE vm_call0_cfunc(rb_thread_t *th, struct rb_calling_info *calling, const struct rb_call_info *ci, struct rb_call_cache *cc, const VALUE *argv)
Definition: vm_eval.c:147
static VALUE vm_call_iseq_setup(rb_thread_t *th, rb_control_frame_t *cfp, struct rb_calling_info *calling, const struct rb_call_info *ci, struct rb_call_cache *cc)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1515
static VALUE vm_yield_lambda_splattable(rb_thread_t *th, VALUE args)
VALUE rb_yield_block(VALUE val, VALUE arg, int argc, const VALUE *argv, VALUE blockarg)
Definition: vm_eval.c:1078
#define Check_TypedStruct(v, t)
Definition: ruby.h:1138
static void VM_ENV_FLAGS_SET(const VALUE *ep, VALUE flag)
Definition: vm_core.h:1001
static VALUE uncaught_throw_value(VALUE exc)
Definition: vm_eval.c:1876
static VALUE rb_eUncaughtThrow
Definition: vm_eval.c:27
VALUE rb_eArgError
Definition: error.c:763
union rb_captured_block::@202 code
#define T_REGEXP
Definition: ruby.h:497
VALUE rb_obj_clone(VALUE)
Definition: object.c:388
static VALUE check_funcall_exec(struct rescue_funcall_args *args)
Definition: vm_eval.c:359
VALUE rb_attr_get(VALUE, ID)
Definition: variable.c:1273
VALUE rb_usascii_str_new_cstr(const char *)
Definition: string.c:777
#define type_case(t)
char ** argv
Definition: ruby.c:184
#define DBL2NUM(dbl)
Definition: ruby.h:941
#define StringValue(v)
Definition: ruby.h:569
rb_iseq_location_t location
Definition: vm_core.h:358
#define PASS_PASSED_BLOCK_HANDLER()
Definition: eval_intern.h:24
VALUE rb_current_receiver(void)
Definition: vm_eval.c:295
VALUE rb_obj_class(VALUE)
Definition: object.c:229
static struct vm_throw_data * THROW_DATA_NEW(VALUE val, const rb_control_frame_t *cf, VALUE st)