Ruby  2.0.0p594(2014-10-27revision48167)
vm_eval.c
Go to the documentation of this file.
1 /**********************************************************************
2 
3  vm_eval.c -
4 
5  $Author: usa $
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 
14 static inline VALUE method_missing(VALUE obj, ID id, int argc, const VALUE *argv, int call_status);
15 static inline VALUE vm_yield_with_cref(rb_thread_t *th, int argc, const VALUE *argv, const NODE *cref);
16 static inline VALUE vm_yield(rb_thread_t *th, int argc, const VALUE *argv);
17 static NODE *vm_cref_push(rb_thread_t *th, VALUE klass, int noex, rb_block_t *blockptr);
18 static VALUE vm_exec(rb_thread_t *th);
19 static void vm_set_eval_stack(rb_thread_t * th, VALUE iseqval, const NODE *cref, rb_block_t *base_block);
21 
22 /* vm_backtrace.c */
23 VALUE vm_backtrace_str_ary(rb_thread_t *th, int lev, int n);
24 
25 typedef enum call_type {
30 } call_type;
31 
32 static VALUE send_internal(int argc, const VALUE *argv, VALUE recv, call_type scope);
33 
35 
36 static VALUE
37 vm_call0(rb_thread_t* th, VALUE recv, ID id, int argc, const VALUE *argv,
38  const rb_method_entry_t *me, VALUE defined_class)
39 {
40  rb_call_info_t ci_entry, *ci = &ci_entry;
41 
42  ci->flag = 0;
43  ci->mid = id;
44  ci->recv = recv;
45  ci->defined_class = defined_class;
46  ci->argc = argc;
47  ci->me = me;
48 
49  return vm_call0_body(th, ci, argv);
50 }
51 
52 #if OPT_CALL_CFUNC_WITHOUT_FRAME
53 static VALUE
55 {
56  VALUE val;
57 
60  {
61  rb_control_frame_t *reg_cfp = th->cfp;
62  const rb_method_entry_t *me = ci->me;
63  const rb_method_cfunc_t *cfunc = &me->def->body.cfunc;
64  int len = cfunc->argc;
65 
66  if (len >= 0) rb_check_arity(ci->argc, len, len);
67 
68  th->passed_ci = ci;
69  ci->aux.inc_sp = 0;
70  VM_PROFILE_UP(2);
71  val = (*cfunc->invoker)(cfunc->func, ci, argv);
72 
73  if (reg_cfp == th->cfp) {
74  if (UNLIKELY(th->passed_ci != ci)) {
75  rb_bug("vm_call0_cfunc: passed_ci error (ci: %p, passed_ci: %p)", ci, th->passed_ci);
76  }
77  th->passed_ci = 0;
78  }
79  else {
80  if (reg_cfp != th->cfp + 1) {
81  rb_bug("vm_call0_cfunc: cfp consistency error");
82  }
83  VM_PROFILE_UP(3);
84  vm_pop_frame(th);
85  }
86  }
87  EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, ci->recv, ci->mid, ci->defined_class, val);
89 
90  return val;
91 }
92 #else
93 static VALUE
95 {
96  VALUE val;
97  const rb_method_entry_t *me = ci->me;
98  const rb_method_cfunc_t *cfunc = &me->def->body.cfunc;
99  int len = cfunc->argc;
100  VALUE recv = ci->recv;
101  VALUE defined_class = ci->defined_class;
102  int argc = ci->argc;
103  ID mid = ci->mid;
104  rb_block_t *blockptr = ci->blockptr;
105 
106  RUBY_DTRACE_CMETHOD_ENTRY_HOOK(th, defined_class, mid);
107  EXEC_EVENT_HOOK(th, RUBY_EVENT_C_CALL, recv, mid, defined_class, Qnil);
108  {
109  rb_control_frame_t *reg_cfp = th->cfp;
110 
111  vm_push_frame(th, 0, VM_FRAME_MAGIC_CFUNC, recv, defined_class,
112  VM_ENVVAL_BLOCK_PTR(blockptr), 0, reg_cfp->sp, 1, me);
113 
114  if (len >= 0) rb_check_arity(argc, len, len);
115 
116  VM_PROFILE_UP(2);
117  val = (*cfunc->invoker)(cfunc->func, recv, argc, argv);
118 
119  if (UNLIKELY(reg_cfp != th->cfp + 1)) {
120  rb_bug("vm_call0_cfunc_with_frame: cfp consistency error");
121  }
122  VM_PROFILE_UP(3);
123  vm_pop_frame(th);
124  }
125  EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, recv, mid, defined_class, val);
126  RUBY_DTRACE_CMETHOD_RETURN_HOOK(th, defined_class, mid);
127 
128  return val;
129 }
130 
131 static VALUE
133 {
134  return vm_call0_cfunc_with_frame(th, ci, argv);
135 }
136 #endif
137 
138 /* `ci' should point temporal value (on stack value) */
139 static VALUE
141 {
142  VALUE ret;
143 
144  if (!ci->me->def) return Qnil;
145 
146  if (th->passed_block) {
147  ci->blockptr = (rb_block_t *)th->passed_block;
148  th->passed_block = 0;
149  }
150  else {
151  ci->blockptr = 0;
152  }
153 
154  again:
155  switch (ci->me->def->type) {
156  case VM_METHOD_TYPE_ISEQ:
157  {
158  rb_control_frame_t *reg_cfp = th->cfp;
159  int i;
160 
161  CHECK_VM_STACK_OVERFLOW(reg_cfp, ci->argc + 1);
162 
163  *reg_cfp->sp++ = ci->recv;
164  for (i = 0; i < ci->argc; i++) {
165  *reg_cfp->sp++ = argv[i];
166  }
167 
168  vm_call_iseq_setup(th, reg_cfp, ci);
169  th->cfp->flag |= VM_FRAME_FLAG_FINISH;
170  return vm_exec(th); /* CHECK_INTS in this function */
171  }
174  ret = vm_call0_cfunc(th, ci, argv);
175  goto success;
177  rb_check_arity(ci->argc, 1, 1);
178  ret = rb_ivar_set(ci->recv, ci->me->def->body.attr.id, argv[0]);
179  goto success;
180  case VM_METHOD_TYPE_IVAR:
181  rb_check_arity(ci->argc, 0, 0);
182  ret = rb_attr_get(ci->recv, ci->me->def->body.attr.id);
183  goto success;
185  ret = vm_call_bmethod_body(th, ci, argv);
186  goto success;
189  {
190  if (ci->me->def->type == VM_METHOD_TYPE_REFINED &&
191  ci->me->def->body.orig_me) {
192  ci->me = ci->me->def->body.orig_me;
193  goto again;
194  }
195 
197 
198  if (!ci->defined_class || !(ci->me = rb_method_entry(ci->defined_class, ci->mid, &ci->defined_class))) {
199  ret = method_missing(ci->recv, ci->mid, ci->argc, argv, NOEX_SUPER);
200  goto success;
201  }
202  RUBY_VM_CHECK_INTS(th);
203  if (!ci->me->def) return Qnil;
204  goto again;
205  }
207  {
208  VALUE new_args = rb_ary_new4(ci->argc, argv);
209 
210  RB_GC_GUARD(new_args);
211  rb_ary_unshift(new_args, ID2SYM(ci->mid));
212  th->passed_block = ci->blockptr;
213  return rb_funcall2(ci->recv, idMethodMissing, ci->argc+1, RARRAY_PTR(new_args));
214  }
216  switch (ci->me->def->body.optimize_type) {
217  case OPTIMIZED_METHOD_TYPE_SEND:
218  ret = send_internal(ci->argc, argv, ci->recv, CALL_FCALL);
219  goto success;
220  case OPTIMIZED_METHOD_TYPE_CALL:
221  {
222  rb_proc_t *proc;
223  GetProcPtr(ci->recv, proc);
224  ret = rb_vm_invoke_proc(th, proc, ci->argc, argv, ci->blockptr);
225  goto success;
226  }
227  default:
228  rb_bug("vm_call0: unsupported optimized method type (%d)", ci->me->def->body.optimize_type);
229  }
230  break;
232  break;
233  }
234  rb_bug("vm_call0: unsupported method type (%d)", ci->me->def->type);
235  return Qundef;
236 
237  success:
238  RUBY_VM_CHECK_INTS(th);
239  return ret;
240 }
241 
242 VALUE
243 rb_vm_call(rb_thread_t *th, VALUE recv, VALUE id, int argc, const VALUE *argv,
244  const rb_method_entry_t *me, VALUE defined_class)
245 {
246  return vm_call0(th, recv, id, argc, argv, me, defined_class);
247 }
248 
249 static inline VALUE
250 vm_call_super(rb_thread_t *th, int argc, const VALUE *argv)
251 {
252  VALUE recv = th->cfp->self;
253  VALUE klass;
254  ID id;
255  rb_method_entry_t *me;
256  rb_control_frame_t *cfp = th->cfp;
257 
258  if (cfp->iseq || NIL_P(cfp->klass)) {
259  rb_bug("vm_call_super: should not be reached");
260  }
261 
262  klass = RCLASS_SUPER(cfp->klass);
263  id = cfp->me->def->original_id;
264  me = rb_method_entry(klass, id, &klass);
265  if (!me) {
266  return method_missing(recv, id, argc, argv, NOEX_SUPER);
267  }
268 
269  return vm_call0(th, recv, id, argc, argv, me, klass);
270 }
271 
272 VALUE
273 rb_call_super(int argc, const VALUE *argv)
274 {
276  return vm_call_super(GET_THREAD(), argc, argv);
277 }
278 
279 static inline void
281 {
282  rb_thread_t *th = GET_THREAD();
283 
287  }
288 }
289 
290 static inline rb_method_entry_t *
291  rb_search_method_entry(VALUE recv, ID mid, VALUE *defined_class_ptr);
292 static inline int rb_method_call_status(rb_thread_t *th, const rb_method_entry_t *me, call_type scope, VALUE self);
293 #define NOEX_OK NOEX_NOSUPER
294 
310 static inline VALUE
311 rb_call0(VALUE recv, ID mid, int argc, const VALUE *argv,
312  call_type scope, VALUE self)
313 {
314  VALUE defined_class;
315  rb_method_entry_t *me =
316  rb_search_method_entry(recv, mid, &defined_class);
317  rb_thread_t *th = GET_THREAD();
318  int call_status = rb_method_call_status(th, me, scope, self);
319 
320  if (call_status != NOEX_OK) {
321  return method_missing(recv, mid, argc, argv, call_status);
322  }
323  stack_check();
324  return vm_call0(th, recv, mid, argc, argv, me, defined_class);
325 }
326 
330  int argc;
332 };
333 
334 static VALUE
336 {
337  VALUE new_args = rb_ary_new4(args->argc, args->argv);
338 
339  RB_GC_GUARD(new_args);
340  rb_ary_unshift(new_args, args->sym);
341  return rb_funcall2(args->recv, idMethodMissing,
342  args->argc+1, RARRAY_PTR(new_args));
343 }
344 
345 static VALUE
347 {
348  if (rb_respond_to(args->recv, SYM2ID(args->sym))) {
349  rb_exc_raise(e);
350  }
351  return Qundef;
352 }
353 
354 static int
356 {
357  VALUE defined_class;
358  const rb_method_entry_t *me = rb_method_entry(klass, idRespond_to, &defined_class);
359 
360  if (me && !(me->flag & NOEX_BASIC)) {
361  const rb_block_t *passed_block = th->passed_block;
362  VALUE args[2], result;
363  int arity = rb_method_entry_arity(me);
364 
365  if (arity > 2)
366  rb_raise(rb_eArgError, "respond_to? must accept 1 or 2 arguments (requires %d)", arity);
367 
368  if (arity < 1) arity = 2;
369 
370  args[0] = ID2SYM(mid);
371  args[1] = Qtrue;
372  result = vm_call0(th, recv, idRespond_to, arity, args, me, defined_class);
373  th->passed_block = passed_block;
374  if (!RTEST(result)) {
375  return FALSE;
376  }
377  }
378  return TRUE;
379 }
380 
381 static int
383 {
384  return rb_method_call_status(th, me, CALL_FCALL, th->cfp->self) == NOEX_OK;
385 }
386 
387 static VALUE
389 {
390  if (rb_method_basic_definition_p(klass, idMethodMissing)) {
391  return Qundef;
392  }
393  else {
394  struct rescue_funcall_args args;
395 
396  th->method_missing_reason = 0;
397  args.recv = recv;
398  args.sym = ID2SYM(mid);
399  args.argc = argc;
400  args.argv = argv;
401  return rb_rescue2(check_funcall_exec, (VALUE)&args,
402  check_funcall_failed, (VALUE)&args,
404  }
405 }
406 
407 VALUE
409 {
410  VALUE klass = CLASS_OF(recv);
411  const rb_method_entry_t *me;
412  rb_thread_t *th = GET_THREAD();
413  VALUE defined_class;
414 
415  if (!check_funcall_respond_to(th, klass, recv, mid))
416  return Qundef;
417 
418  me = rb_search_method_entry(recv, mid, &defined_class);
419  if (check_funcall_callable(th, me) != NOEX_OK) {
420  return check_funcall_missing(th, klass, recv, mid, argc, argv);
421  }
422  stack_check();
423  return vm_call0(th, recv, mid, argc, argv, me, defined_class);
424 }
425 
426 VALUE
429 {
430  VALUE klass = CLASS_OF(recv);
431  const rb_method_entry_t *me;
432  rb_thread_t *th = GET_THREAD();
433  VALUE defined_class;
434 
435  if (!check_funcall_respond_to(th, klass, recv, mid))
436  return Qundef;
437 
438  me = rb_search_method_entry(recv, mid, &defined_class);
439  if (check_funcall_callable(th, me) != NOEX_OK) {
440  (*hook)(FALSE, recv, mid, argc, argv, arg);
441  return check_funcall_missing(th, klass, recv, mid, argc, argv);
442  }
443  stack_check();
444  (*hook)(TRUE, recv, mid, argc, argv, arg);
445  return vm_call0(th, recv, mid, argc, argv, me, defined_class);
446 }
447 
448 static const char *
450 {
451 #define type_case(t) case t: return #t;
452  switch (type) {
478  default: return NULL;
479  }
480 #undef type_case
481 }
482 
483 static inline rb_method_entry_t *
484 rb_search_method_entry(VALUE recv, ID mid, VALUE *defined_class_ptr)
485 {
486  VALUE klass = CLASS_OF(recv);
487 
488  if (!klass) {
489  VALUE flags;
490  if (SPECIAL_CONST_P(recv)) {
492  "method `%"PRIsVALUE"' called on unexpected immediate object (%p)",
493  rb_id2str(mid), (void *)recv);
494  }
495  flags = RBASIC(recv)->flags;
496  if (flags == 0) {
498  "method `%"PRIsVALUE"' called on terminated object"
499  " (%p flags=0x%"PRIxVALUE")",
500  rb_id2str(mid), (void *)recv, flags);
501  }
502  else {
503  int type = BUILTIN_TYPE(recv);
504  const char *typestr = rb_type_str(type);
505  if (typestr && T_OBJECT <= type && type < T_NIL)
507  "method `%"PRIsVALUE"' called on hidden %s object"
508  " (%p flags=0x%"PRIxVALUE")",
509  rb_id2str(mid), typestr, (void *)recv, flags);
510  if (typestr)
512  "method `%"PRIsVALUE"' called on unexpected %s object"
513  " (%p flags=0x%"PRIxVALUE")",
514  rb_id2str(mid), typestr, (void *)recv, flags);
515  else
517  "method `%"PRIsVALUE"' called on broken T_???" "(0x%02x) object"
518  " (%p flags=0x%"PRIxVALUE")",
519  rb_id2str(mid), type, (void *)recv, flags);
520  }
521  }
522  return rb_method_entry(klass, mid, defined_class_ptr);
523 }
524 
525 static inline int
527 {
528  VALUE klass;
529  ID oid;
530  int noex;
531 
532  if (UNDEFINED_METHOD_ENTRY_P(me)) {
533  return scope == CALL_VCALL ? NOEX_VCALL : 0;
534  }
535  klass = me->klass;
536  oid = me->def->original_id;
537  noex = me->flag;
538 
539  if (oid != idMethodMissing) {
540  /* receiver specified form for private method */
541  if (UNLIKELY(noex)) {
542  if (((noex & NOEX_MASK) & NOEX_PRIVATE) && scope == CALL_PUBLIC) {
543  return NOEX_PRIVATE;
544  }
545 
546  /* self must be kind of a specified form for protected method */
547  if (((noex & NOEX_MASK) & NOEX_PROTECTED) && scope == CALL_PUBLIC) {
548  VALUE defined_class = klass;
549 
550  if (RB_TYPE_P(defined_class, T_ICLASS)) {
551  defined_class = RBASIC(defined_class)->klass;
552  }
553 
554  if (self == Qundef || !rb_obj_is_kind_of(self, defined_class)) {
555  return NOEX_PROTECTED;
556  }
557  }
558 
559  if (NOEX_SAFE(noex) > th->safe_level) {
560  rb_raise(rb_eSecurityError, "calling insecure method: %s",
561  rb_id2name(me->called_id));
562  }
563  }
564  }
565  return NOEX_OK;
566 }
567 
568 
580 static inline VALUE
581 rb_call(VALUE recv, ID mid, int argc, const VALUE *argv, call_type scope)
582 {
583  rb_thread_t *th = GET_THREAD();
584  return rb_call0(recv, mid, argc, argv, scope, th->cfp->self);
585 }
586 
587 NORETURN(static void raise_method_missing(rb_thread_t *th, int argc, const VALUE *argv,
588  VALUE obj, int call_status));
589 
590 /*
591  * call-seq:
592  * obj.method_missing(symbol [, *args] ) -> result
593  *
594  * Invoked by Ruby when <i>obj</i> is sent a message it cannot handle.
595  * <i>symbol</i> is the symbol for the method called, and <i>args</i>
596  * are any arguments that were passed to it. By default, the interpreter
597  * raises an error when this method is called. However, it is possible
598  * to override the method to provide more dynamic behavior.
599  * If it is decided that a particular method should not be handled, then
600  * <i>super</i> should be called, so that ancestors can pick up the
601  * missing method.
602  * The example below creates
603  * a class <code>Roman</code>, which responds to methods with names
604  * consisting of roman numerals, returning the corresponding integer
605  * values.
606  *
607  * class Roman
608  * def roman_to_int(str)
609  * # ...
610  * end
611  * def method_missing(methId)
612  * str = methId.id2name
613  * roman_to_int(str)
614  * end
615  * end
616  *
617  * r = Roman.new
618  * r.iv #=> 4
619  * r.xxiii #=> 23
620  * r.mm #=> 2000
621  */
622 
623 static VALUE
625 {
626  rb_thread_t *th = GET_THREAD();
627  raise_method_missing(th, argc, argv, obj, th->method_missing_reason);
628  UNREACHABLE;
629 }
630 
631 #define NOEX_MISSING 0x80
632 
633 static VALUE
634 make_no_method_exception(VALUE exc, const char *format, VALUE obj, int argc, const VALUE *argv)
635 {
636  int n = 0;
637  VALUE mesg;
638  VALUE args[3];
639 
640  if (!format) {
641  format = "undefined method `%s' for %s";
642  }
643  mesg = rb_const_get(exc, rb_intern("message"));
644  if (rb_method_basic_definition_p(CLASS_OF(mesg), '!')) {
645  args[n++] = rb_name_err_mesg_new(mesg, rb_str_new2(format), obj, argv[0]);
646  }
647  else {
648  args[n++] = rb_funcall(mesg, '!', 3, rb_str_new2(format), obj, argv[0]);
649  }
650  args[n++] = argv[0];
651  if (exc == rb_eNoMethodError) {
652  args[n++] = rb_ary_new4(argc - 1, argv + 1);
653  }
654  return rb_class_new_instance(n, args, exc);
655 }
656 
657 static void
659  int last_call_status)
660 {
662  const char *format = 0;
663 
664  if (argc == 0 || !SYMBOL_P(argv[0])) {
665  rb_raise(rb_eArgError, "no id given");
666  }
667 
668  stack_check();
669 
670  if (last_call_status & NOEX_PRIVATE) {
671  format = "private method `%s' called for %s";
672  }
673  else if (last_call_status & NOEX_PROTECTED) {
674  format = "protected method `%s' called for %s";
675  }
676  else if (last_call_status & NOEX_VCALL) {
677  format = "undefined local variable or method `%s' for %s";
678  exc = rb_eNameError;
679  }
680  else if (last_call_status & NOEX_SUPER) {
681  format = "super: no superclass method `%s' for %s";
682  }
683 
684  {
685  exc = make_no_method_exception(exc, format, obj, argc, argv);
686  if (!(last_call_status & NOEX_MISSING)) {
688  }
689  rb_exc_raise(exc);
690  }
691 }
692 
693 static inline VALUE
694 method_missing(VALUE obj, ID id, int argc, const VALUE *argv, int call_status)
695 {
696  VALUE *nargv, result, argv_ary = 0;
697  rb_thread_t *th = GET_THREAD();
698  const rb_block_t *blockptr = th->passed_block;
699 
700  th->method_missing_reason = call_status;
701  th->passed_block = 0;
702 
703  if (id == idMethodMissing) {
704  raise_method_missing(th, argc, argv, obj, call_status | NOEX_MISSING);
705  }
706 
707  if (argc < 0x100) {
708  nargv = ALLOCA_N(VALUE, argc + 1);
709  }
710  else {
711  argv_ary = rb_ary_tmp_new(argc + 1);
712  nargv = RARRAY_PTR(argv_ary);
713  }
714  nargv[0] = ID2SYM(id);
715  MEMCPY(nargv + 1, argv, VALUE, argc);
716  if (argv_ary) rb_ary_set_len(argv_ary, argc + 1);
717 
718  if (rb_method_basic_definition_p(CLASS_OF(obj) , idMethodMissing)) {
719  raise_method_missing(th, argc+1, nargv, obj, call_status | NOEX_MISSING);
720  }
721  th->passed_block = blockptr;
722  result = rb_funcall2(obj, idMethodMissing, argc + 1, nargv);
723  if (argv_ary) rb_ary_clear(argv_ary);
724  return result;
725 }
726 
727 void
729  VALUE obj, int call_status)
730 {
731  th->passed_block = 0;
732  raise_method_missing(th, argc, argv, obj, call_status | NOEX_MISSING);
733 }
734 
743 VALUE
745 {
746  int argc;
747  VALUE *argv, ret;
748 
749  argc = RARRAY_LENINT(args);
750  if (argc >= 0x100) {
751  args = rb_ary_subseq(args, 0, argc);
752  RBASIC(args)->klass = 0;
753  OBJ_FREEZE(args);
754  ret = rb_call(recv, mid, argc, RARRAY_PTR(args), CALL_FCALL);
755  RB_GC_GUARD(args);
756  return ret;
757  }
758  argv = ALLOCA_N(VALUE, argc);
759  MEMCPY(argv, RARRAY_PTR(args), VALUE, argc);
760  return rb_call(recv, mid, argc, argv, CALL_FCALL);
761 }
762 
772 VALUE
773 rb_funcall(VALUE recv, ID mid, int n, ...)
774 {
775  VALUE *argv;
776  va_list ar;
777 
778  if (n > 0) {
779  long i;
780 
781  va_init_list(ar, n);
782 
783  argv = ALLOCA_N(VALUE, n);
784 
785  for (i = 0; i < n; i++) {
786  argv[i] = va_arg(ar, VALUE);
787  }
788  va_end(ar);
789  }
790  else {
791  argv = 0;
792  }
793  return rb_call(recv, mid, n, argv, CALL_FCALL);
794 }
795 
803 VALUE
804 rb_funcall2(VALUE recv, ID mid, int argc, const VALUE *argv)
805 {
806  return rb_call(recv, mid, argc, argv, CALL_FCALL);
807 }
808 
818 VALUE
819 rb_funcall3(VALUE recv, ID mid, int argc, const VALUE *argv)
820 {
821  return rb_call(recv, mid, argc, argv, CALL_PUBLIC);
822 }
823 
824 VALUE
826 {
828 
829  return rb_call(recv, mid, argc, argv, CALL_PUBLIC);
830 }
831 
832 VALUE
833 rb_funcall_with_block(VALUE recv, ID mid, int argc, const VALUE *argv, VALUE pass_procval)
834 {
835  if (!NIL_P(pass_procval)) {
836  rb_thread_t *th = GET_THREAD();
837  rb_block_t *block = 0;
838 
839  rb_proc_t *pass_proc;
840  GetProcPtr(pass_procval, pass_proc);
841  block = &pass_proc->block;
842 
843  th->passed_block = block;
844  }
845 
846  return rb_call(recv, mid, argc, argv, CALL_PUBLIC);
847 }
848 
849 static VALUE
850 send_internal(int argc, const VALUE *argv, VALUE recv, call_type scope)
851 {
852  ID id;
853  VALUE vid;
854  VALUE self;
855  rb_thread_t *th = GET_THREAD();
856 
857  if (scope == CALL_PUBLIC) {
858  self = Qundef;
859  }
860  else {
861  self = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp)->self;
862  }
863 
864  if (argc == 0) {
865  rb_raise(rb_eArgError, "no method name given");
866  }
867 
868  vid = *argv++; argc--;
869 
870  id = rb_check_id(&vid);
871  if (!id) {
872  if (rb_method_basic_definition_p(CLASS_OF(recv), idMethodMissing)) {
874  recv, ++argc, --argv);
875  rb_exc_raise(exc);
876  }
877  id = rb_to_id(vid);
878  }
880  return rb_call0(recv, id, argc, argv, scope, self);
881 }
882 
883 /*
884  * call-seq:
885  * foo.send(symbol [, args...]) -> obj
886  * foo.__send__(symbol [, args...]) -> obj
887  *
888  * Invokes the method identified by _symbol_, passing it any
889  * arguments specified. You can use <code>__send__</code> if the name
890  * +send+ clashes with an existing method in _obj_.
891  *
892  * class Klass
893  * def hello(*args)
894  * "Hello " + args.join(' ')
895  * end
896  * end
897  * k = Klass.new
898  * k.send :hello, "gentle", "readers" #=> "Hello gentle readers"
899  */
900 
901 VALUE
903 {
904  return send_internal(argc, argv, recv, CALL_FCALL);
905 }
906 
907 /*
908  * call-seq:
909  * obj.public_send(symbol [, args...]) -> obj
910  *
911  * Invokes the method identified by _symbol_, passing it any
912  * arguments specified. Unlike send, public_send calls public
913  * methods only.
914  *
915  * 1.public_send(:puts, "hello") # causes NoMethodError
916  */
917 
918 VALUE
920 {
921  return send_internal(argc, argv, recv, CALL_PUBLIC);
922 }
923 
924 /* yield */
925 
926 static inline VALUE
927 rb_yield_0(int argc, const VALUE * argv)
928 {
929  return vm_yield(GET_THREAD(), argc, argv);
930 }
931 
932 VALUE
934 {
935  if (val == Qundef) {
936  return rb_yield_0(0, 0);
937  }
938  else {
939  return rb_yield_0(1, &val);
940  }
941 }
942 
943 VALUE
945 {
946  if (n == 0) {
947  return rb_yield_0(0, 0);
948  }
949  else {
950  int i;
951  VALUE *argv;
952  va_list args;
953  argv = ALLOCA_N(VALUE, n);
954 
955  va_init_list(args, n);
956  for (i=0; i<n; i++) {
957  argv[i] = va_arg(args, VALUE);
958  }
959  va_end(args);
960 
961  return rb_yield_0(n, argv);
962  }
963 }
964 
965 VALUE
966 rb_yield_values2(int argc, const VALUE *argv)
967 {
968  return rb_yield_0(argc, argv);
969 }
970 
971 VALUE
973 {
974  VALUE tmp = rb_check_array_type(values);
975  volatile VALUE v;
976  if (NIL_P(tmp)) {
977  rb_raise(rb_eArgError, "not an array");
978  }
979  v = rb_yield_0(RARRAY_LENINT(tmp), RARRAY_PTR(tmp));
980  return v;
981 }
982 
983 static VALUE
984 loop_i(void)
985 {
986  for (;;) {
987  rb_yield_0(0, 0);
988  }
989  return Qnil;
990 }
991 
992 static VALUE
994 {
995  return DBL2NUM(INFINITY);
996 }
997 
998 /*
999  * call-seq:
1000  * loop { block }
1001  * loop -> an_enumerator
1002  *
1003  * Repeatedly executes the block.
1004  *
1005  * If no block is given, an enumerator is returned instead.
1006  *
1007  * loop do
1008  * print "Input: "
1009  * line = gets
1010  * break if !line or line =~ /^qQ/
1011  * # ...
1012  * end
1013  *
1014  * StopIteration raised in the block breaks the loop.
1015  */
1016 
1017 static VALUE
1019 {
1021  rb_rescue2(loop_i, (VALUE)0, 0, 0, rb_eStopIteration, (VALUE)0);
1022  return Qnil; /* dummy */
1023 }
1024 
1025 #if VMDEBUG
1026 static const char *
1027 vm_frametype_name(const rb_control_frame_t *cfp);
1028 #endif
1029 
1030 VALUE
1031 rb_iterate(VALUE (* it_proc) (VALUE), VALUE data1,
1032  VALUE (* bl_proc) (ANYARGS), VALUE data2)
1033 {
1034  int state;
1035  volatile VALUE retval = Qnil;
1036  NODE *node = NEW_IFUNC(bl_proc, data2);
1037  rb_thread_t *th = GET_THREAD();
1038  rb_control_frame_t *volatile cfp = th->cfp;
1039 
1040  node->nd_aid = rb_frame_this_func();
1041  TH_PUSH_TAG(th);
1042  state = TH_EXEC_TAG();
1043  if (state == 0) {
1044  iter_retry:
1045  {
1046  rb_block_t *blockptr;
1047  if (bl_proc) {
1048  blockptr = RUBY_VM_GET_BLOCK_PTR_IN_CFP(th->cfp);
1049  blockptr->iseq = (void *)node;
1050  blockptr->proc = 0;
1051  }
1052  else {
1053  blockptr = VM_CF_BLOCK_PTR(th->cfp);
1054  }
1055  th->passed_block = blockptr;
1056  }
1057  retval = (*it_proc) (data1);
1058  }
1059  else {
1060  VALUE err = th->errinfo;
1061  if (state == TAG_BREAK) {
1062  VALUE *escape_ep = GET_THROWOBJ_CATCH_POINT(err);
1063  VALUE *cep = cfp->ep;
1064 
1065  if (cep == escape_ep) {
1066  state = 0;
1067  th->state = 0;
1068  th->errinfo = Qnil;
1069  retval = GET_THROWOBJ_VAL(err);
1070 
1071  rb_vm_rewind_cfp(th, cfp);
1072  }
1073  else{
1074  /* SDR(); printf("%p, %p\n", cdfp, escape_dfp); */
1075  }
1076  }
1077  else if (state == TAG_RETRY) {
1078  VALUE *escape_ep = GET_THROWOBJ_CATCH_POINT(err);
1079  VALUE *cep = cfp->ep;
1080 
1081  if (cep == escape_ep) {
1082  rb_vm_rewind_cfp(th, cfp);
1083 
1084  state = 0;
1085  th->state = 0;
1086  th->errinfo = Qnil;
1087  goto iter_retry;
1088  }
1089  }
1090  }
1091  TH_POP_TAG();
1092 
1093  switch (state) {
1094  case 0:
1095  break;
1096  default:
1097  TH_JUMP_TAG(th, state);
1098  }
1099  return retval;
1100 }
1101 
1105  int argc;
1107 };
1108 
1109 static VALUE
1111 {
1112  const struct iter_method_arg * arg =
1113  (struct iter_method_arg *) obj;
1114 
1115  return rb_call(arg->obj, arg->mid, arg->argc, arg->argv, CALL_FCALL);
1116 }
1117 
1118 VALUE
1120  VALUE (*bl_proc) (ANYARGS), VALUE data2)
1121 {
1122  struct iter_method_arg arg;
1123 
1124  arg.obj = obj;
1125  arg.mid = mid;
1126  arg.argc = argc;
1127  arg.argv = argv;
1128  return rb_iterate(iterate_method, (VALUE)&arg, bl_proc, data2);
1129 }
1130 
1131 static VALUE
1133 {
1134  const struct iter_method_arg * arg =
1135  (struct iter_method_arg *) obj;
1136 
1137  return rb_check_funcall(arg->obj, arg->mid, arg->argc, arg->argv);
1138 }
1139 
1140 VALUE
1141 rb_check_block_call(VALUE obj, ID mid, int argc, VALUE * argv,
1142  VALUE (*bl_proc) (ANYARGS), VALUE data2)
1143 {
1144  struct iter_method_arg arg;
1145 
1146  arg.obj = obj;
1147  arg.mid = mid;
1148  arg.argc = argc;
1149  arg.argv = argv;
1150  return rb_iterate(iterate_check_method, (VALUE)&arg, bl_proc, data2);
1151 }
1152 
1153 VALUE
1155 {
1156  return rb_call(obj, idEach, 0, 0, CALL_FCALL);
1157 }
1158 
1159 static VALUE
1160 eval_string_with_cref(VALUE self, VALUE src, VALUE scope, NODE *cref, volatile VALUE file, volatile int line)
1161 {
1162  int state;
1163  VALUE result = Qundef;
1164  VALUE envval;
1165  rb_thread_t *th = GET_THREAD();
1166  rb_env_t *env = NULL;
1167  rb_block_t block, *base_block;
1168  volatile int parse_in_eval;
1169  volatile int mild_compile_error;
1170 
1171  if (file == 0) {
1172  file = rb_sourcefilename();
1173  line = rb_sourceline();
1174  }
1175 
1176  parse_in_eval = th->parse_in_eval;
1177  mild_compile_error = th->mild_compile_error;
1178  TH_PUSH_TAG(th);
1179  if ((state = TH_EXEC_TAG()) == 0) {
1180  rb_binding_t *bind = 0;
1181  rb_iseq_t *iseq;
1182  volatile VALUE iseqval;
1183  VALUE absolute_path = Qnil;
1184  VALUE fname;
1185 
1186  if (file != Qundef) {
1187  absolute_path = file;
1188  }
1189 
1190  if (!NIL_P(scope)) {
1191  if (rb_obj_is_kind_of(scope, rb_cBinding)) {
1192  GetBindingPtr(scope, bind);
1193  envval = bind->env;
1194  if (NIL_P(absolute_path) && !NIL_P(bind->path)) {
1195  file = bind->path;
1196  line = bind->first_lineno;
1197  absolute_path = rb_current_realfilepath();
1198  }
1199  }
1200  else {
1202  "wrong argument type %s (expected Binding)",
1203  rb_obj_classname(scope));
1204  }
1205  GetEnvPtr(envval, env);
1206  base_block = &env->block;
1207  }
1208  else {
1210 
1211  if (cfp != 0) {
1212  block = *RUBY_VM_GET_BLOCK_PTR_IN_CFP(cfp);
1213  base_block = &block;
1214  base_block->self = self;
1215  base_block->iseq = cfp->iseq; /* TODO */
1216  }
1217  else {
1218  rb_raise(rb_eRuntimeError, "Can't eval on top of Fiber or Thread");
1219  }
1220  }
1221 
1222  if ((fname = file) == Qundef) {
1223  fname = rb_usascii_str_new_cstr("(eval)");
1224  }
1225 
1226  /* make eval iseq */
1227  th->parse_in_eval++;
1228  th->mild_compile_error++;
1229  iseqval = rb_iseq_compile_with_option(src, fname, absolute_path, INT2FIX(line), base_block, Qnil);
1230  th->mild_compile_error--;
1231  th->parse_in_eval--;
1232 
1233  vm_set_eval_stack(th, iseqval, cref, base_block);
1234  th->cfp->klass = CLASS_OF(base_block->self);
1235 
1236  if (0) { /* for debug */
1237  VALUE disasm = rb_iseq_disasm(iseqval);
1238  printf("%s\n", StringValuePtr(disasm));
1239  }
1240 
1241  /* save new env */
1242  GetISeqPtr(iseqval, iseq);
1243  if (bind && iseq->local_table_size > 0) {
1244  bind->env = rb_vm_make_env_object(th, th->cfp);
1245  }
1246 
1247  /* kick */
1249  result = vm_exec(th);
1250  }
1251  TH_POP_TAG();
1252  th->mild_compile_error = mild_compile_error;
1253  th->parse_in_eval = parse_in_eval;
1254 
1255  if (state) {
1256  if (state == TAG_RAISE) {
1257  VALUE errinfo = th->errinfo;
1258  if (file == Qundef) {
1259  VALUE mesg, errat, bt2;
1260  ID id_mesg;
1261 
1262  CONST_ID(id_mesg, "mesg");
1263  errat = rb_get_backtrace(errinfo);
1264  mesg = rb_attr_get(errinfo, id_mesg);
1265  if (!NIL_P(errat) && RB_TYPE_P(errat, T_ARRAY) &&
1266  (bt2 = vm_backtrace_str_ary(th, 0, 0), RARRAY_LEN(bt2) > 0)) {
1267  if (!NIL_P(mesg) && RB_TYPE_P(mesg, T_STRING) && !RSTRING_LEN(mesg)) {
1268  if (OBJ_FROZEN(mesg)) {
1269  VALUE m = rb_str_cat(rb_str_dup(RARRAY_PTR(errat)[0]), ": ", 2);
1270  rb_ivar_set(errinfo, id_mesg, rb_str_append(m, mesg));
1271  }
1272  else {
1273  rb_str_update(mesg, 0, 0, rb_str_new2(": "));
1274  rb_str_update(mesg, 0, 0, RARRAY_PTR(errat)[0]);
1275  }
1276  }
1277  RARRAY_PTR(errat)[0] = RARRAY_PTR(bt2)[0];
1278  }
1279  }
1280  rb_exc_raise(errinfo);
1281  }
1282  JUMP_TAG(state);
1283  }
1284  return result;
1285 }
1286 
1287 static VALUE
1288 eval_string(VALUE self, VALUE src, VALUE scope, VALUE file, int line)
1289 {
1290  return eval_string_with_cref(self, src, scope, 0, file, line);
1291 }
1292 
1293 /*
1294  * call-seq:
1295  * eval(string [, binding [, filename [,lineno]]]) -> obj
1296  *
1297  * Evaluates the Ruby expression(s) in <em>string</em>. If
1298  * <em>binding</em> is given, which must be a <code>Binding</code>
1299  * object, the evaluation is performed in its context. If the
1300  * optional <em>filename</em> and <em>lineno</em> parameters are
1301  * present, they will be used when reporting syntax errors.
1302  *
1303  * def get_binding(str)
1304  * return binding
1305  * end
1306  * str = "hello"
1307  * eval "str + ' Fred'" #=> "hello Fred"
1308  * eval "str + ' Fred'", get_binding("bye") #=> "bye Fred"
1309  */
1310 
1311 VALUE
1312 rb_f_eval(int argc, VALUE *argv, VALUE self)
1313 {
1314  VALUE src, scope, vfile, vline;
1315  VALUE file = Qundef;
1316  int line = 1;
1317 
1318  rb_scan_args(argc, argv, "13", &src, &scope, &vfile, &vline);
1319  if (rb_safe_level() >= 4) {
1320  StringValue(src);
1321  if (!NIL_P(scope) && !OBJ_TAINTED(scope)) {
1323  "Insecure: can't modify trusted binding");
1324  }
1325  }
1326  else {
1327  SafeStringValue(src);
1328  }
1329  if (argc >= 3) {
1330  StringValue(vfile);
1331  }
1332  if (argc >= 4) {
1333  line = NUM2INT(vline);
1334  }
1335 
1336  if (!NIL_P(vfile))
1337  file = vfile;
1338  return eval_string(self, src, scope, file, line);
1339 }
1340 
1342 VALUE
1343 ruby_eval_string_from_file(const char *str, const char *filename)
1344 {
1345  VALUE file = filename ? rb_str_new_cstr(filename) : 0;
1346  return eval_string(rb_vm_top_self(), rb_str_new2(str), Qnil, file, 1);
1347 }
1348 
1352 };
1353 
1354 static VALUE
1356 {
1357  const struct eval_string_from_file_arg *const arg = (struct eval_string_from_file_arg*)data;
1358  return eval_string(rb_vm_top_self(), arg->str, Qnil, arg->filename, 1);
1359 }
1360 
1361 VALUE
1362 ruby_eval_string_from_file_protect(const char *str, const char *filename, int *state)
1363 {
1364  struct eval_string_from_file_arg arg;
1365  arg.str = rb_str_new_cstr(str);
1366  arg.filename = filename ? rb_str_new_cstr(filename) : 0;
1367  return rb_protect((VALUE (*)(VALUE))eval_string_from_file_helper, (VALUE)&arg, state);
1368 }
1369 
1382 VALUE
1383 rb_eval_string(const char *str)
1384 {
1385  return ruby_eval_string_from_file(str, "eval");
1386 }
1387 
1398 VALUE
1400 {
1401  return rb_protect((VALUE (*)(VALUE))rb_eval_string, (VALUE)str, state);
1402 }
1403 
1415 VALUE
1416 rb_eval_string_wrap(const char *str, int *state)
1417 {
1418  int status;
1419  rb_thread_t *th = GET_THREAD();
1420  VALUE self = th->top_self;
1421  VALUE wrapper = th->top_wrapper;
1422  VALUE val;
1423 
1424  th->top_wrapper = rb_module_new();
1427 
1428  val = rb_eval_string_protect(str, &status);
1429 
1430  th->top_self = self;
1431  th->top_wrapper = wrapper;
1432 
1433  if (state) {
1434  *state = status;
1435  }
1436  else if (status) {
1437  JUMP_TAG(status);
1438  }
1439  return val;
1440 }
1441 
1442 VALUE
1444 {
1445  int state;
1446  VALUE val = Qnil; /* OK */
1447  volatile int safe = rb_safe_level();
1448 
1449  if (OBJ_TAINTED(cmd)) {
1450  level = 4;
1451  }
1452 
1453  if (!RB_TYPE_P(cmd, T_STRING)) {
1454  PUSH_TAG();
1455  rb_set_safe_level_force(level);
1456  if ((state = EXEC_TAG()) == 0) {
1457  val = rb_funcall2(cmd, rb_intern("call"), RARRAY_LENINT(arg),
1458  RARRAY_PTR(arg));
1459  }
1460  POP_TAG();
1461 
1463 
1464  if (state)
1465  JUMP_TAG(state);
1466  return val;
1467  }
1468 
1469  PUSH_TAG();
1470  if ((state = EXEC_TAG()) == 0) {
1471  val = eval_string(rb_vm_top_self(), cmd, Qnil, 0, 0);
1472  }
1473  POP_TAG();
1474 
1476  if (state) JUMP_TAG(state);
1477  return val;
1478 }
1479 
1480 /* block eval under the class/module context */
1481 
1482 static VALUE
1483 yield_under(VALUE under, VALUE self, VALUE values)
1484 {
1485  rb_thread_t *th = GET_THREAD();
1486  rb_block_t block, *blockptr;
1487  NODE *cref;
1488 
1489  if ((blockptr = VM_CF_BLOCK_PTR(th->cfp)) != 0) {
1490  block = *blockptr;
1491  block.self = self;
1492  VM_CF_LEP(th->cfp)[0] = VM_ENVVAL_BLOCK_PTR(&block);
1493  }
1494  cref = vm_cref_push(th, under, NOEX_PUBLIC, blockptr);
1496 
1497  if (values == Qundef) {
1498  return vm_yield_with_cref(th, 1, &self, cref);
1499  }
1500  else {
1501  return vm_yield_with_cref(th, RARRAY_LENINT(values), RARRAY_PTR(values), cref);
1502  }
1503 }
1504 
1505 VALUE
1506 rb_yield_refine_block(VALUE refinement, VALUE refinements)
1507 {
1508  rb_thread_t *th = GET_THREAD();
1509  rb_block_t block, *blockptr;
1510  NODE *cref;
1511 
1512  if ((blockptr = VM_CF_BLOCK_PTR(th->cfp)) != 0) {
1513  block = *blockptr;
1514  block.self = refinement;
1515  VM_CF_LEP(th->cfp)[0] = VM_ENVVAL_BLOCK_PTR(&block);
1516  }
1517  cref = vm_cref_push(th, refinement, NOEX_PUBLIC, blockptr);
1519  cref->nd_refinements = refinements;
1520 
1521  return vm_yield_with_cref(th, 0, NULL, cref);
1522 }
1523 
1524 /* string eval under the class/module context */
1525 static VALUE
1526 eval_under(VALUE under, VALUE self, VALUE src, VALUE file, int line)
1527 {
1528  NODE *cref = vm_cref_push(GET_THREAD(), under, NOEX_PUBLIC, NULL);
1529 
1530  if (SPECIAL_CONST_P(self) && !NIL_P(under)) {
1532  }
1533  if (rb_safe_level() >= 4) {
1534  StringValue(src);
1535  }
1536  else {
1537  SafeStringValue(src);
1538  }
1539 
1540  return eval_string_with_cref(self, src, Qnil, cref, file, line);
1541 }
1542 
1543 static VALUE
1544 specific_eval(int argc, VALUE *argv, VALUE klass, VALUE self)
1545 {
1546  if (rb_block_given_p()) {
1547  rb_check_arity(argc, 0, 0);
1548  return yield_under(klass, self, Qundef);
1549  }
1550  else {
1551  VALUE file = Qundef;
1552  int line = 1;
1553 
1554  rb_check_arity(argc, 1, 3);
1555  if (rb_safe_level() >= 4) {
1556  StringValue(argv[0]);
1557  }
1558  else {
1559  SafeStringValue(argv[0]);
1560  }
1561  if (argc > 2)
1562  line = NUM2INT(argv[2]);
1563  if (argc > 1) {
1564  file = argv[1];
1565  if (!NIL_P(file)) StringValue(file);
1566  }
1567  return eval_under(klass, self, argv[0], file, line);
1568  }
1569 }
1570 
1571 /*
1572  * call-seq:
1573  * obj.instance_eval(string [, filename [, lineno]] ) -> obj
1574  * obj.instance_eval {| | block } -> obj
1575  *
1576  * Evaluates a string containing Ruby source code, or the given block,
1577  * within the context of the receiver (_obj_). In order to set the
1578  * context, the variable +self+ is set to _obj_ while
1579  * the code is executing, giving the code access to _obj_'s
1580  * instance variables. In the version of <code>instance_eval</code>
1581  * that takes a +String+, the optional second and third
1582  * parameters supply a filename and starting line number that are used
1583  * when reporting compilation errors.
1584  *
1585  * class KlassWithSecret
1586  * def initialize
1587  * @secret = 99
1588  * end
1589  * end
1590  * k = KlassWithSecret.new
1591  * k.instance_eval { @secret } #=> 99
1592  */
1593 
1594 VALUE
1595 rb_obj_instance_eval(int argc, VALUE *argv, VALUE self)
1596 {
1597  VALUE klass;
1598 
1599  if (SPECIAL_CONST_P(self)) {
1600  klass = rb_special_singleton_class(self);
1601  }
1602  else {
1603  klass = rb_singleton_class(self);
1604  }
1605  return specific_eval(argc, argv, klass, self);
1606 }
1607 
1608 /*
1609  * call-seq:
1610  * obj.instance_exec(arg...) {|var...| block } -> obj
1611  *
1612  * Executes the given block within the context of the receiver
1613  * (_obj_). In order to set the context, the variable +self+ is set
1614  * to _obj_ while the code is executing, giving the code access to
1615  * _obj_'s instance variables. Arguments are passed as block parameters.
1616  *
1617  * class KlassWithSecret
1618  * def initialize
1619  * @secret = 99
1620  * end
1621  * end
1622  * k = KlassWithSecret.new
1623  * k.instance_exec(5) {|x| @secret+x } #=> 104
1624  */
1625 
1626 VALUE
1627 rb_obj_instance_exec(int argc, VALUE *argv, VALUE self)
1628 {
1629  VALUE klass;
1630 
1631  if (SPECIAL_CONST_P(self)) {
1632  klass = rb_special_singleton_class(self);
1633  }
1634  else {
1635  klass = rb_singleton_class(self);
1636  }
1637  return yield_under(klass, self, rb_ary_new4(argc, argv));
1638 }
1639 
1640 /*
1641  * call-seq:
1642  * mod.class_eval(string [, filename [, lineno]]) -> obj
1643  * mod.module_eval {|| block } -> obj
1644  *
1645  * Evaluates the string or block in the context of _mod_, except that when
1646  * a block is given, constant/class variable lookup is not affected. This
1647  * can be used to add methods to a class. <code>module_eval</code> returns
1648  * the result of evaluating its argument. The optional _filename_ and
1649  * _lineno_ parameters set the text for error messages.
1650  *
1651  * class Thing
1652  * end
1653  * a = %q{def hello() "Hello there!" end}
1654  * Thing.module_eval(a)
1655  * puts Thing.new.hello()
1656  * Thing.module_eval("invalid code", "dummy", 123)
1657  *
1658  * <em>produces:</em>
1659  *
1660  * Hello there!
1661  * dummy:123:in `module_eval': undefined local variable
1662  * or method `code' for Thing:Class
1663  */
1664 
1665 VALUE
1667 {
1668  return specific_eval(argc, argv, mod, mod);
1669 }
1670 
1671 /*
1672  * call-seq:
1673  * mod.module_exec(arg...) {|var...| block } -> obj
1674  * mod.class_exec(arg...) {|var...| block } -> obj
1675  *
1676  * Evaluates the given block in the context of the class/module.
1677  * The method defined in the block will belong to the receiver.
1678  *
1679  * class Thing
1680  * end
1681  * Thing.class_exec{
1682  * def hello() "Hello there!" end
1683  * }
1684  * puts Thing.new.hello()
1685  *
1686  * <em>produces:</em>
1687  *
1688  * Hello there!
1689  */
1690 
1691 VALUE
1693 {
1694  return yield_under(mod, mod, rb_ary_new4(argc, argv));
1695 }
1696 
1697 /*
1698  * call-seq:
1699  * throw(tag [, obj])
1700  *
1701  * Transfers control to the end of the active +catch+ block
1702  * waiting for _tag_. Raises +ArgumentError+ if there
1703  * is no +catch+ block for the _tag_. The optional second
1704  * parameter supplies a return value for the +catch+ block,
1705  * which otherwise defaults to +nil+. For examples, see
1706  * <code>Kernel::catch</code>.
1707  */
1708 
1709 static VALUE
1710 rb_f_throw(int argc, VALUE *argv)
1711 {
1712  VALUE tag, value;
1713 
1714  rb_scan_args(argc, argv, "11", &tag, &value);
1715  rb_throw_obj(tag, value);
1716  UNREACHABLE;
1717 }
1718 
1719 void
1721 {
1722  rb_thread_t *th = GET_THREAD();
1723  struct rb_vm_tag *tt = th->tag;
1724 
1725  while (tt) {
1726  if (tt->tag == tag) {
1727  tt->retval = value;
1728  break;
1729  }
1730  tt = tt->prev;
1731  }
1732  if (!tt) {
1733  VALUE desc = rb_inspect(tag);
1734  RB_GC_GUARD(desc);
1735  rb_raise(rb_eArgError, "uncaught throw %s", RSTRING_PTR(desc));
1736  }
1737  th->errinfo = NEW_THROW_OBJECT(tag, 0, TAG_THROW);
1738 
1740 }
1741 
1742 void
1743 rb_throw(const char *tag, VALUE val)
1744 {
1745  rb_throw_obj(ID2SYM(rb_intern(tag)), val);
1746 }
1747 
1748 static VALUE
1750 {
1751  return rb_yield_0(1, &tag);
1752 }
1753 
1754 /*
1755  * call-seq:
1756  * catch([arg]) {|tag| block } -> obj
1757  *
1758  * +catch+ executes its block. If a +throw+ is
1759  * executed, Ruby searches up its stack for a +catch+ block
1760  * with a tag corresponding to the +throw+'s
1761  * _tag_. If found, that block is terminated, and
1762  * +catch+ returns the value given to +throw+. If
1763  * +throw+ is not called, the block terminates normally, and
1764  * the value of +catch+ is the value of the last expression
1765  * evaluated. +catch+ expressions may be nested, and the
1766  * +throw+ call need not be in lexical scope.
1767  *
1768  * def routine(n)
1769  * puts n
1770  * throw :done if n <= 0
1771  * routine(n-1)
1772  * end
1773  *
1774  *
1775  * catch(:done) { routine(3) }
1776  *
1777  * <em>produces:</em>
1778  *
1779  * 3
1780  * 2
1781  * 1
1782  * 0
1783  *
1784  * when _arg_ is given, +catch+ yields it as is, or when no
1785  * _arg_ is given, +catch+ assigns a new unique object to
1786  * +throw+. this is useful for nested +catch+. _arg_ can
1787  * be an arbitrary object, not only Symbol.
1788  *
1789  */
1790 
1791 static VALUE
1792 rb_f_catch(int argc, VALUE *argv)
1793 {
1794  VALUE tag;
1795 
1796  if (argc == 0) {
1797  tag = rb_obj_alloc(rb_cObject);
1798  }
1799  else {
1800  rb_scan_args(argc, argv, "01", &tag);
1801  }
1802  return rb_catch_obj(tag, catch_i, 0);
1803 }
1804 
1805 VALUE
1806 rb_catch(const char *tag, VALUE (*func)(), VALUE data)
1807 {
1808  VALUE vtag = tag ? ID2SYM(rb_intern(tag)) : rb_obj_alloc(rb_cObject);
1809  return rb_catch_obj(vtag, func, data);
1810 }
1811 
1812 VALUE
1814 {
1815  int state;
1816  volatile VALUE val = Qnil; /* OK */
1817  rb_thread_t *th = GET_THREAD();
1818  rb_control_frame_t *saved_cfp = th->cfp;
1819 
1820  TH_PUSH_TAG(th);
1821 
1822  th->tag->tag = tag;
1823 
1824  if ((state = TH_EXEC_TAG()) == 0) {
1825  /* call with argc=1, argv = [tag], block = Qnil to insure compatibility */
1826  val = (*func)(tag, data, 1, &tag, Qnil);
1827  }
1828  else if (state == TAG_THROW && RNODE(th->errinfo)->u1.value == tag) {
1829  rb_vm_rewind_cfp(th, saved_cfp);
1830  val = th->tag->retval;
1831  th->errinfo = Qnil;
1832  state = 0;
1833  }
1834  TH_POP_TAG();
1835  if (state)
1836  JUMP_TAG(state);
1837 
1838  return val;
1839 }
1840 
1841 /*
1842  * call-seq:
1843  * local_variables -> array
1844  *
1845  * Returns the names of the current local variables.
1846  *
1847  * fred = 1
1848  * for i in 1..10
1849  * # ...
1850  * end
1851  * local_variables #=> [:fred, :i]
1852  */
1853 
1854 static VALUE
1856 {
1857  VALUE ary = rb_ary_new();
1858  rb_thread_t *th = GET_THREAD();
1859  rb_control_frame_t *cfp =
1861  int i;
1862 
1863  while (cfp) {
1864  if (cfp->iseq) {
1865  for (i = 0; i < cfp->iseq->local_table_size; i++) {
1866  ID lid = cfp->iseq->local_table[i];
1867  if (lid) {
1868  const char *vname = rb_id2name(lid);
1869  /* should skip temporary variable */
1870  if (vname) {
1871  rb_ary_push(ary, ID2SYM(lid));
1872  }
1873  }
1874  }
1875  }
1876  if (!VM_EP_LEP_P(cfp->ep)) {
1877  /* block */
1878  VALUE *ep = VM_CF_PREV_EP(cfp);
1879 
1880  if (vm_collect_local_variables_in_heap(th, ep, ary)) {
1881  break;
1882  }
1883  else {
1884  while (cfp->ep != ep) {
1885  cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
1886  }
1887  }
1888  }
1889  else {
1890  break;
1891  }
1892  }
1893  return ary;
1894 }
1895 
1896 /*
1897  * call-seq:
1898  * block_given? -> true or false
1899  * iterator? -> true or false
1900  *
1901  * Returns <code>true</code> if <code>yield</code> would execute a
1902  * block in the current context. The <code>iterator?</code> form
1903  * is mildly deprecated.
1904  *
1905  * def try
1906  * if block_given?
1907  * yield
1908  * else
1909  * "no block"
1910  * end
1911  * end
1912  * try #=> "no block"
1913  * try { "hello" } #=> "hello"
1914  * try do "hello" end #=> "hello"
1915  */
1916 
1917 
1918 VALUE
1920 {
1921  rb_thread_t *th = GET_THREAD();
1922  rb_control_frame_t *cfp = th->cfp;
1924 
1925  if (cfp != 0 && VM_CF_BLOCK_PTR(cfp)) {
1926  return Qtrue;
1927  }
1928  else {
1929  return Qfalse;
1930  }
1931 }
1932 
1933 VALUE
1935 {
1936  rb_thread_t *th = GET_THREAD();
1937  rb_control_frame_t *cfp = th->cfp;
1939  if (cfp != 0) return cfp->iseq->location.absolute_path;
1940  return Qnil;
1941 }
1942 
1943 void
1945 {
1946  rb_define_global_function("eval", rb_f_eval, -1);
1947  rb_define_global_function("local_variables", rb_f_local_variables, 0);
1949  rb_define_global_function("block_given?", rb_f_block_given_p, 0);
1950 
1951  rb_define_global_function("catch", rb_f_catch, -1);
1952  rb_define_global_function("throw", rb_f_throw, -1);
1953 
1955 
1956  rb_define_method(rb_cBasicObject, "instance_eval", rb_obj_instance_eval, -1);
1957  rb_define_method(rb_cBasicObject, "instance_exec", rb_obj_instance_exec, -1);
1959 
1960 #if 1
1962  VM_METHOD_TYPE_OPTIMIZED, (void *)OPTIMIZED_METHOD_TYPE_SEND, 0);
1964  VM_METHOD_TYPE_OPTIMIZED, (void *)OPTIMIZED_METHOD_TYPE_SEND, 0);
1965 #else
1966  rb_define_method(rb_cBasicObject, "__send__", rb_f_send, -1);
1967  rb_define_method(rb_mKernel, "send", rb_f_send, -1);
1968 #endif
1969  rb_define_method(rb_mKernel, "public_send", rb_f_public_send, -1);
1970 
1971  rb_define_method(rb_cModule, "module_exec", rb_mod_module_exec, -1);
1972  rb_define_method(rb_cModule, "class_exec", rb_mod_module_exec, -1);
1973  rb_define_method(rb_cModule, "module_eval", rb_mod_module_eval, -1);
1974  rb_define_method(rb_cModule, "class_eval", rb_mod_module_eval, -1);
1975 }
VALUE data
Definition: tcltklib.c:3367
VALUE rb_f_public_send(int argc, VALUE *argv, VALUE recv)
Definition: vm_eval.c:919
const rb_block_t * passed_block
Definition: vm_core.h:511
#define RB_TYPE_P(obj, type)
RARRAY_PTR(q->result)[0]
rb_control_frame_t * cfp
Definition: vm_core.h:500
struct rb_block_struct * blockptr
Definition: vm_core.h:163
volatile VALUE tmp
Definition: tcltklib.c:10208
VALUE rb_ary_unshift(VALUE ary, VALUE item)
Definition: array.c:1071
#define UNDEFINED_METHOD_ENTRY_P(me)
Definition: method.h:108
#define RUBY_VM_CHECK_INTS(th)
Definition: vm_core.h:953
static int check_funcall_respond_to(rb_thread_t *th, VALUE klass, VALUE recv, ID mid)
Definition: vm_eval.c:355
ssize_t n
Definition: bigdecimal.c:5676
int register char * block
Definition: crypt.c:949
volatile VALUE ary
Definition: tcltklib.c:9712
RUBY_EXTERN VALUE rb_cBasicObject
Definition: ripper.y:1425
VALUE rb_ary_new4(long n, const VALUE *elts)
Definition: array.c:451
static int vm_collect_local_variables_in_heap(rb_thread_t *th, VALUE *dfp, VALUE ary)
void rb_bug(const char *fmt,...)
Definition: error.c:295
rb_method_type_t type
Definition: method.h:77
VALUE rb_obj_instance_exec(int, VALUE *, VALUE)
Definition: vm_eval.c:1627
VALUE * argv
Definition: vm_eval.c:1106
#define FALSE
Definition: nkf.h:174
#define T_STRUCT
static NODE * vm_cref_push(rb_thread_t *th, VALUE klass, int noex, rb_block_t *blockptr)
rb_method_attr_t attr
Definition: method.h:82
RUBY_EXTERN VALUE rb_cModule
Definition: ripper.y:1445
static VALUE iterate_method(VALUE obj)
Definition: vm_eval.c:1110
static VALUE VALUE th
Definition: tcltklib.c:2947
static VALUE rb_call0(VALUE recv, ID mid, int argc, const VALUE *argv, call_type scope, VALUE self)
Definition: vm_eval.c:311
static rb_control_frame_t * vm_get_ruby_level_caller_cfp(rb_thread_t *th, rb_control_frame_t *cfp)
Definition: vm.c:213
VALUE rb_class_new_instance(int, VALUE *, VALUE)
Definition: object.c:1794
#define T_MATCH
#define VM_FRAME_FLAG_FINISH
Definition: vm_core.h:742
const char * rb_obj_classname(VALUE)
Definition: variable.c:396
VALUE rb_id2str(ID id)
Definition: ripper.c:16940
VALUE rb_mod_module_eval(int, VALUE *, VALUE)
Definition: vm_eval.c:1666
static void stack_check(void)
Definition: vm_eval.c:280
VALUE rb_eval_cmd(VALUE, VALUE, int)
Definition: vm_eval.c:1443
static VALUE * VM_CF_PREV_EP(rb_control_frame_t *cfp)
Definition: vm.c:48
#define TAG_THROW
Definition: eval_intern.h:169
#define VM_FRAME_MAGIC_CFUNC
Definition: vm_core.h:729
static VALUE send_internal(int argc, const VALUE *argv, VALUE recv, call_type scope)
Definition: vm_eval.c:850
void rb_throw(const char *tag, VALUE val)
Definition: vm_eval.c:1743
#define RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)
Definition: vm_core.h:789
#define GetProcPtr(obj, ptr)
Definition: vm_core.h:665
rb_method_flag_t flag
Definition: method.h:96
VALUE rb_ary_subseq(VALUE ary, long beg, long len)
Definition: array.c:1097
rb_block_t block
Definition: vm_core.h:686
#define T_ICLASS
VALUE proc
Definition: tcltklib.c:2958
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:108
VALUE rb_eval_string_wrap(const char *, int *)
Evaluates the given string under a module binding in an isolated binding.
Definition: vm_eval.c:1416
VALUE rb_const_get(VALUE, ID)
Definition: variable.c:1876
ssize_t i
Definition: bigdecimal.c:5676
rb_iseq_t * iseq
Definition: vm_core.h:446
#define TAG_BREAK
Definition: eval_intern.h:164
static void vm_set_eval_stack(rb_thread_t *th, VALUE iseqval, const NODE *cref, rb_block_t *base_block)
#define T_NODE
#define RUBY_EVENT_C_RETURN
#define GET_THROWOBJ_CATCH_POINT(obj)
Definition: eval_intern.h:181
void rb_check_funcall_hook(int, VALUE, ID, int, VALUE *, VALUE)
Definition: ripper.y:335
struct rb_method_entry_struct * orig_me
Definition: method.h:90
RUBY_EXTERN VALUE rb_cBinding
Definition: ripper.y:1429
VALUE rb_str_new_cstr(const char *)
Definition: string.c:447
#define new_args(f, o, r, p, t)
Definition: ripper.c:469
static void raise_method_missing(rb_thread_t *th, int argc, const VALUE *argv, VALUE obj, int last_call_status)
Definition: vm_eval.c:658
int ret
Definition: tcltklib.c:280
void rb_define_private_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1360
ID rb_frame_this_func(void)
Definition: eval.c:902
int status
Definition: tcltklib.c:2196
#define sysstack_error
Definition: vm_core.h:866
VALUE rb_eTypeError
Definition: error.c:516
VALUE rb_name_err_mesg_new(VALUE obj, VALUE mesg, VALUE recv, VALUE method)
Definition: error.c:1032
#define OBJ_FREEZE(x)
#define TH_JUMP_TAG(th, st)
Definition: eval_intern.h:144
#define OBJ_TAINTED(x)
#define UNREACHABLE
Definition: ruby.h:40
VALUE exc
Definition: tcltklib.c:3095
static VALUE check_funcall_failed(struct rescue_funcall_args *args, VALUE e)
Definition: vm_eval.c:346
VALUE rb_ary_push(VALUE ary, VALUE item)
Definition: array.c:822
VALUE rb_yield_values2(int n, const VALUE *argv)
Definition: vm_eval.c:966
VALUE rb_yield_values(int n,...)
Definition: vm_eval.c:944
VALUE rb_ary_tmp_new(long capa)
Definition: array.c:465
VALUE rb_iseq_compile_with_option(VALUE src, VALUE file, VALUE absolute_path, VALUE line, rb_block_t *base_block, VALUE opt)
Definition: iseq.c:585
#define RSTRING_PTR(str)
#define CLASS_OF(v)
NIL_P(eventloop_thread)
Definition: tcltklib.c:4067
#define T_ARRAY
void rb_vm_pop_cfunc_frame(void)
Definition: vm.c:235
#define RUBY_VM_GET_BLOCK_PTR_IN_CFP(cfp)
Definition: vm_core.h:802
#define VM_ENVVAL_BLOCK_PTR(v)
Definition: vm_core.h:777
int local_table_size
Definition: vm_core.h:226
int safe
Definition: tcltklib.c:6403
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *state)
Definition: eval.c:771
static VALUE vm_call0_cfunc_with_frame(rb_thread_t *th, rb_call_info_t *ci, const VALUE *argv)
Definition: vm_eval.c:94
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
Definition: vm_eval.c:773
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:1788
VALUE rb_funcall_with_block(VALUE, ID, int, const VALUE *, VALUE)
Definition: vm_eval.c:833
static VALUE rb_yield_0(int argc, const VALUE *argv)
Definition: vm_eval.c:927
#define T_HASH
return Qtrue
Definition: tcltklib.c:9609
VALUE rb_ary_clear(VALUE ary)
Definition: array.c:3208
ID called_id
Definition: method.h:99
#define TH_EXEC_TAG()
Definition: eval_intern.h:139
#define T_FILE
#define VM_PROFILE_UP(x)
#define SafeStringValue(v)
union rb_method_definition_struct::@112 body
size_t stack_max
Definition: vm_core.h:278
VALUE rb_eSecurityError
Definition: error.c:525
#define T_NIL
static VALUE vm_yield(rb_thread_t *th, int argc, const VALUE *argv)
static VALUE catch_i(VALUE tag, VALUE data)
Definition: vm_eval.c:1749
#define TAG_RAISE
Definition: eval_intern.h:168
#define GetEnvPtr(obj, ptr)
Definition: vm_core.h:678
#define PUSH_TAG()
Definition: eval_intern.h:136
#define rb_str_new2
VALUE rb_catch_obj(VALUE, VALUE(*)(ANYARGS), VALUE)
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
Definition: class.c:1530
VALUE rb_funcall_passing_block(VALUE, ID, int, const VALUE *)
Definition: vm_eval.c:825
VALUE rb_vm_invoke_proc(rb_thread_t *th, rb_proc_t *proc, int argc, const VALUE *argv, const rb_block_t *blockptr)
Definition: vm.c:780
static VALUE * VM_CF_LEP(rb_control_frame_t *cfp)
Definition: vm.c:42
int state
Definition: tcltklib.c:1461
ruby_value_type
Definition: ripper.y:450
VALUE env
Definition: vm_core.h:693
ID rb_check_id(volatile VALUE *namep)
Returns ID for the given name if it is interned already, or 0.
Definition: ripper.c:17100
#define NOEX_OK
Definition: vm_eval.c:293
#define ID2SYM(x)
VALUE rb_catch(const char *, VALUE(*)(ANYARGS), VALUE)
VALUE ruby_eval_string_from_file(const char *str, const char *filename)
Definition: vm_eval.c:1343
#define T_FLOAT
VALUE rb_iterate(VALUE(*)(VALUE), VALUE, VALUE(*)(ANYARGS), VALUE)
Definition: vm_eval.c:1031
VALUE VALUE args
Definition: tcltklib.c:2560
#define T_OBJECT
static int check_funcall_callable(rb_thread_t *th, const rb_method_entry_t *me)
Definition: vm_eval.c:382
VALUE rb_str_append(VALUE, VALUE)
Definition: string.c:2125
int ruby_stack_check(void)
Definition: gc.c:2309
#define RUBY_DTRACE_CMETHOD_ENTRY_HOOK(th, klass, id)
Definition: probes_helper.h:61
static VALUE check_funcall_missing(rb_thread_t *th, VALUE klass, VALUE recv, ID mid, int argc, VALUE *argv)
Definition: vm_eval.c:388
VALUE rb_vm_call(rb_thread_t *th, VALUE recv, VALUE id, int argc, const VALUE *argv, const rb_method_entry_t *me, VALUE defined_class)
Definition: vm_eval.c:243
Definition: ripper.y:240
#define NORETURN(x)
Definition: ruby.h:31
#define T_COMPLEX
void rb_exc_raise(VALUE mesg)
Definition: eval.c:527
static VALUE vm_call0_cfunc(rb_thread_t *th, rb_call_info_t *ci, const VALUE *argv)
Definition: vm_eval.c:132
VALUE rb_singleton_class(VALUE obj)
Returns the singleton class of obj.
Definition: class.c:1474
VALUE rb_obj_instance_eval(int, VALUE *, VALUE)
Definition: vm_eval.c:1595
VALUE rb_eNameError
Definition: error.c:521
#define TH_POP_TAG()
Definition: eval_intern.h:129
void rb_str_update(VALUE, long, long, VALUE)
Definition: string.c:3455
rb_method_cfunc_t cfunc
Definition: method.h:81
unsigned short first_lineno
Definition: vm_core.h:696
BDIGIT m
Definition: bigdecimal.c:5106
static VALUE make_no_method_exception(VALUE exc, const char *format, VALUE obj, int argc, const VALUE *argv)
Definition: vm_eval.c:634
VALUE rb_check_funcall_with_hook(VALUE recv, ID mid, int argc, VALUE *argv, rb_check_funcall_hook *hook, VALUE arg)
Definition: vm_eval.c:427
static VALUE rb_f_local_variables(void)
Definition: vm_eval.c:1855
return Qfalse
Definition: tcltklib.c:6778
int rb_block_given_p(void)
Definition: eval.c:672
#define EXEC_TAG()
Definition: eval_intern.h:141
static VALUE rb_f_catch(int argc, VALUE *argv)
Definition: vm_eval.c:1792
#define RARRAY_LEN(a)
#define NEW_IFUNC(f, c)
#define Qnil
Definition: tcltklib.c:1895
#define StringValuePtr(v)
rb_control_frame_t * rb_vm_get_ruby_level_next_cfp(rb_thread_t *th, const rb_control_frame_t *cfp)
Definition: vm.c:201
#define val
Definition: tcltklib.c:1948
VALUE rb_yield_splat(VALUE)
Definition: vm_eval.c:972
void rb_raise_method_missing(rb_thread_t *th, int argc, VALUE *argv, VALUE obj, int call_status)
Definition: vm_eval.c:728
VALUE rb_eRuntimeError
Definition: error.c:515
VALUE rb_special_singleton_class(VALUE obj)
Definition: class.c:1395
VALUE rb_eval_string_protect(const char *, int *)
Evaluates the given string in an isolated binding.
Definition: vm_eval.c:1399
RUBY_EXTERN VALUE rb_mKernel
Definition: ripper.y:1414
static VALUE char * str
Definition: tcltklib.c:3546
#define GetBindingPtr(obj, ptr)
Definition: vm_core.h:689
VALUE rb_yield_refine_block(VALUE refinement, VALUE refinements)
Definition: vm_eval.c:1506
VALUE rb_ary_new(void)
Definition: array.c:424
static int rb_method_call_status(rb_thread_t *th, const rb_method_entry_t *me, call_type scope, VALUE self)
Definition: vm_eval.c:526
int flags
Definition: tcltklib.c:3022
unsigned long ID
Definition: ripper.y:105
va_end(args)
#define NOEX_MISSING
Definition: vm_eval.c:631
#define T_RATIONAL
#define RCLASS_SUPER(c)
#define JUMP_TAG(st)
Definition: eval_intern.h:148
rb_iseq_t * iseq
Definition: vm_core.h:428
#define PASS_PASSED_BLOCK()
Definition: eval_intern.h:12
#define UNLIKELY(x)
Definition: vm_core.h:115
#define PRIxVALUE
static VALUE iterate_check_method(VALUE obj)
Definition: vm_eval.c:1132
VALUE rb_eNoMethodError
Definition: error.c:524
static VALUE VALUE obj
Definition: tcltklib.c:3157
#define RSTRING_LEN(str)
VALUE rb_get_backtrace(VALUE info)
Definition: eval_error.c:54
#define INT2FIX(i)
VALUE tag
Definition: vm_core.h:469
#define ANYARGS
#define T_STRING
static const char * rb_type_str(enum ruby_value_type type)
Definition: vm_eval.c:449
VALUE top_self
Definition: vm_core.h:520
int rb_method_entry_arity(const rb_method_entry_t *me)
Definition: proc.c:1743
VALUE rb_call_super(int, const VALUE *)
Definition: vm_eval.c:273
#define RUBY_DTRACE_CMETHOD_RETURN_HOOK(th, klass, id)
Definition: probes_helper.h:64
Definition: method.h:95
static VALUE eval_under(VALUE under, VALUE self, VALUE src, VALUE file, int line)
Definition: vm_eval.c:1526
int err
Definition: win32.c:87
VALUE rb_vm_make_env_object(rb_thread_t *th, rb_control_frame_t *cfp)
Definition: vm.c:530
static VALUE rb_f_loop(VALUE self)
Definition: vm_eval.c:1018
#define POP_TAG()
Definition: eval_intern.h:137
#define DBL2NUM(dbl)
#define ALLOCA_N(type, n)
enum rb_method_definition_struct::@112::method_optimized_type optimize_type
void rb_throw_obj(VALUE tag, VALUE value)
Definition: vm_eval.c:1720
VALUE rb_check_funcall(VALUE, ID, int, VALUE *)
Definition: vm_eval.c:408
ID * local_table
Definition: vm_core.h:225
static rb_control_frame_t * vm_push_frame(rb_thread_t *th, const rb_iseq_t *iseq, VALUE type, VALUE self, VALUE klass, VALUE specval, const VALUE *pc, VALUE *sp, int local_size, const rb_method_entry_t *me)
Definition: vm_insnhelper.c:34
rb_method_entry_t * rb_method_entry(VALUE klass, ID id, VALUE *define_class_ptr)
Definition: vm_method.c:572
VALUE rb_vm_top_self()
Definition: vm.c:2494
VALUE(* func)(ANYARGS)
Definition: method.h:64
VALUE klass
Definition: method.h:100
VALUE rb_eval_string(const char *)
Evaluates the given string in an isolated binding.
Definition: vm_eval.c:1383
VALUE rb_str_dup(VALUE)
Definition: string.c:946
VALUE vm_backtrace_str_ary(rb_thread_t *th, long lev, long n)
Definition: vm_backtrace.c:649
gz level
Definition: zlib.c:2262
VALUE * argv
Definition: tcltklib.c:1970
VALUE rb_yield(VALUE)
Definition: vm_eval.c:933
#define RTEST(v)
const int id
Definition: nkf.c:209
VALUE rb_obj_clone(VALUE)
Definition: object.c:305
static rb_block_t * VM_CF_BLOCK_PTR(rb_control_frame_t *cfp)
Definition: vm.c:54
#define TRUE
Definition: nkf.h:175
q result
Definition: tcltklib.c:7069
static VALUE vm_exec(rb_thread_t *th)
volatile VALUE value
Definition: tcltklib.c:9441
#define StringValue(v)
#define T_REGEXP
rb_method_entry_t * rb_add_method(VALUE klass, ID mid, rb_method_type_t type, void *option, rb_method_flag_t noex)
Definition: vm_method.c:405
#define CONST_ID(var, str)
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:1574
#define rb_thread_raised_set(th, f)
Definition: eval_intern.h:198
VALUE rb_block_call(VALUE, ID, int, VALUE *, VALUE(*)(ANYARGS), VALUE)
Definition: vm_eval.c:1119
VALUE retval
Definition: tcltklib.c:7829
VALUE rb_f_send(int argc, VALUE *argv, VALUE recv)
Definition: vm_eval.c:902
VALUE rb_eStopIteration
Definition: enumerator.c:111
#define OBJ_FROZEN(x)
#define RB_GC_GUARD(v)
int type
Definition: tcltklib.c:111
#define T_FIXNUM
int argc
Definition: tcltklib.c:1969
static VALUE rb_f_throw(int argc, VALUE *argv)
Definition: vm_eval.c:1710
static void vm_pop_frame(rb_thread_t *th)
Definition: vm_insnhelper.c:99
void rb_set_safe_level_force(int)
Definition: safe.c:34
void rb_extend_object(VALUE obj, VALUE module)
Definition: eval.c:1227
static VALUE vm_yield_with_cref(rb_thread_t *th, int argc, const VALUE *argv, const NODE *cref)
VALUE rb_check_block_call(VALUE, ID, int, VALUE *, VALUE(*)(ANYARGS), VALUE)
Definition: vm_eval.c:1141
static VALUE vm_call_super(rb_thread_t *th, int argc, const VALUE *argv)
Definition: vm_eval.c:250
VALUE rb_rescue2(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*r_proc)(ANYARGS), VALUE data2,...)
Definition: eval.c:701
rb_iseq_location_t location
Definition: vm_core.h:213
#define TH_PUSH_TAG(th)
Definition: eval_intern.h:122
VALUE rb_attr_get(VALUE, ID)
Definition: variable.c:1122
#define INFINITY
Definition: missing.h:138
const char * cmd
Definition: tcltklib.c:278
static VALUE vm_call_bmethod_body(rb_thread_t *th, rb_call_info_t *ci, const VALUE *argv)
VALUE(* invoker)(VALUE(*func)(ANYARGS), VALUE recv, int argc, const VALUE *argv)
Definition: method.h:65
int rb_sourceline(void)
Definition: vm.c:884
VALUE flags
Definition: ripper.y:241
call_type
Definition: vm_eval.c:25
VALUE rb_each(VALUE)
Definition: vm_eval.c:1154
static VALUE vm_call0(rb_thread_t *th, VALUE recv, ID id, int argc, const VALUE *argv, const rb_method_entry_t *me, VALUE defined_class)
Definition: vm_eval.c:37
#define NEW_THROW_OBJECT(val, pt, st)
Definition: eval_intern.h:173
#define T_BIGNUM
#define MEMCPY(p1, p2, type, n)
#define T_TRUE
ID rb_to_id(VALUE)
Definition: string.c:8169
#define va_init_list(a, b)
Definition: tcltklib.c:61
static VALUE loop_i(void)
Definition: vm_eval.c:984
VALUE rb_ivar_set(VALUE, ID, VALUE)
Definition: variable.c:1128
arg
Definition: ripper.y:1317
VALUE src
Definition: tcltklib.c:7952
#define T_SYMBOL
VALUE rb_str_cat(VALUE, const char *, long)
Definition: string.c:1967
#define RETURN_SIZED_ENUMERATOR(obj, argc, argv, size_fn)
static VALUE eval_string_from_file_helper(void *data)
Definition: vm_eval.c:1355
VALUE top_wrapper
Definition: vm_core.h:521
#define SYMBOL_P(x)
rb_block_t block
Definition: vm_core.h:669
VALUE rb_module_new(void)
Definition: class.c:600
#define Qundef
VALUE rb_obj_is_kind_of(VALUE, VALUE)
Definition: object.c:593
int rb_method_basic_definition_p(VALUE, ID)
Definition: vm_method.c:1525
int mild_compile_error
Thread-local state of compiling context.
Definition: vm_core.h:576
#define T_CLASS
rb_method_definition_t * def
Definition: method.h:98
VALUE rb_funcall3(VALUE, ID, int, const VALUE *)
Calls a method.
Definition: vm_eval.c:819
const rb_method_entry_t * me
Definition: vm_core.h:435
VALUE rb_check_array_type(VALUE ary)
Definition: array.c:557
static VALUE yield_under(VALUE under, VALUE self, VALUE values)
Definition: vm_eval.c:1483
RUBY_EXTERN VALUE rb_cObject
Definition: ripper.y:1426
VALUE ruby_eval_string_from_file_protect(const char *str, const char *filename, int *state)
Definition: vm_eval.c:1362
#define RBASIC(obj)
#define RARRAY_LENINT(ary)
klass
Definition: tcltklib.c:3503
int rb_respond_to(VALUE, ID)
Definition: vm_method.c:1591
static VALUE vm_call_iseq_setup(rb_thread_t *th, rb_control_frame_t *cfp, rb_call_info_t *ci)
static VALUE rb_call(VALUE recv, ID mid, int argc, const VALUE *argv, call_type scope)
Definition: vm_eval.c:581
VALUE rb_apply(VALUE, ID, VALUE)
Calls a method.
Definition: vm_eval.c:744
#define NOEX_SAFE(n)
Definition: method.h:39
static VALUE specific_eval(int argc, VALUE *argv, VALUE klass, VALUE self)
Definition: vm_eval.c:1544
#define rb_thread_raised_p(th, f)
Definition: eval_intern.h:200
VALUE rb_eNotImpError
Definition: error.c:526
VALUE rb_f_block_given_p(void)
Definition: vm_eval.c:1919
#define rb_safe_level()
Definition: tcltklib.c:94
#define T_MODULE
rb_call_info_t * passed_ci
Definition: vm_core.h:517
#define EXEC_EVENT_HOOK(th_, flag_, self_, id_, klass_, data_)
Definition: vm_core.h:998
VALUE rb_f_eval(int argc, VALUE *argv, VALUE self)
Definition: vm_eval.c:1312
#define GetISeqPtr(obj, ptr)
Definition: vm_core.h:183
#define NUM2INT(x)
#define T_UNDEF
VALUE rb_obj_alloc(VALUE)
Definition: object.c:1740
const char * rb_id2name(ID id)
Definition: ripper.c:17006
static VALUE rb_f_loop_size(VALUE self, VALUE args)
Definition: vm_eval.c:993
#define rb_check_arity(argc, min, max)
#define BUILTIN_TYPE(x)
#define PRIsVALUE
struct rb_vm_tag * tag
Definition: vm_core.h:561
BDIGIT e
Definition: bigdecimal.c:5106
static rb_method_entry_t * rb_search_method_entry(VALUE recv, ID mid, VALUE *defined_class_ptr)
Definition: vm_eval.c:484
struct rb_vm_tag * prev
Definition: vm_core.h:472
VALUE rb_funcall2(VALUE, ID, int, const VALUE *)
Calls a method.
Definition: vm_eval.c:804
unsigned long VALUE
Definition: ripper.y:104
#define PASS_PASSED_BLOCK_TH(th)
Definition: eval_intern.h:7
void rb_vm_rewind_cfp(rb_thread_t *th, rb_control_frame_t *cfp)
Definition: vm.c:245
static VALUE rb_method_missing(int argc, const VALUE *argv, VALUE obj)
Definition: vm_eval.c:624
VALUE retval
Definition: vm_core.h:470
VALUE rb_current_realfilepath(void)
Definition: vm_eval.c:1934
static VALUE eval_string_with_cref(VALUE self, VALUE src, VALUE scope, NODE *cref, volatile VALUE file, volatile int line)
Definition: vm_eval.c:1160
void Init_vm_eval(void)
Definition: vm_eval.c:1944
#define CHECK_VM_STACK_OVERFLOW(cfp, margin)
Definition: vm_core.h:868
#define SPECIAL_CONST_P(x)
#define rb_intern(str)
BDIGIT v
Definition: bigdecimal.c:5677
#define NODE_FL_CREF_PUSHED_BY_EVAL
#define mod(x, y)
Definition: date_strftime.c:28
VALUE path
Definition: vm_core.h:694
#define env
static VALUE eval_string(VALUE self, VALUE src, VALUE scope, VALUE file, int line)
Definition: vm_eval.c:1288
#define NULL
Definition: _sdbm.c:103
#define T_DATA
int method_missing_reason
Definition: vm_core.h:612
#define RNODE(obj)
union rb_call_info_struct::@151 aux
#define VM_EP_LEP_P(ep)
Definition: vm_core.h:784
static rb_thread_t * GET_THREAD(void)
Definition: vm_core.h:888
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1348
#define RUBY_EVENT_C_CALL
VALUE rb_iseq_disasm(VALUE self)
Definition: iseq.c:1358
static VALUE method_missing(VALUE obj, ID id, int argc, const VALUE *argv, int call_status)
Definition: vm_eval.c:694
#define GET_THROWOBJ_VAL(obj)
Definition: eval_intern.h:180
#define SYM2ID(x)
VALUE rb_eArgError
Definition: error.c:517
#define T_NONE
VALUE rb_usascii_str_new_cstr(const char *)
static VALUE check_funcall_exec(struct rescue_funcall_args *args)
Definition: vm_eval.c:335
#define T_FALSE
static VALUE vm_call0_body(rb_thread_t *th, rb_call_info_t *ci, const VALUE *argv)
Definition: vm_eval.c:140
#define type_case(t)
VALUE rb_mod_module_exec(int, VALUE *, VALUE)
Definition: vm_eval.c:1692
const rb_method_entry_t * me
Definition: vm_core.h:158
#define TAG_RETRY
Definition: eval_intern.h:166
int parse_in_eval
Thread-local state of evaluation context.
Definition: vm_core.h:570
#define T_ZOMBIE
VALUE rb_inspect(VALUE)
Definition: object.c:411
void rb_ary_set_len(VALUE ary, long len)
Definition: array.c:1478
VALUE rb_sourcefilename(void)
Definition: vm.c:856
size_t len
Definition: tcltklib.c:3567