Ruby  1.9.3p448(2013-06-27revision41675)
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 rb_vm_set_finish_env(rb_thread_t * th);
16 static inline VALUE vm_yield_with_cref(rb_thread_t *th, int argc, const VALUE *argv, const NODE *cref);
17 static inline VALUE vm_yield(rb_thread_t *th, int argc, const VALUE *argv);
18 static inline VALUE vm_backtrace(rb_thread_t *th, int lev);
19 static int vm_backtrace_each(rb_thread_t *th, int lev, void (*init)(void *), rb_backtrace_iter_func *iter, void *arg);
20 static NODE *vm_cref_push(rb_thread_t *th, VALUE klass, int noex, rb_block_t *blockptr);
21 static VALUE vm_exec(rb_thread_t *th);
22 static void vm_set_eval_stack(rb_thread_t * th, VALUE iseqval, const NODE *cref);
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 
34 static inline VALUE
35 vm_call0(rb_thread_t* th, VALUE recv, VALUE id, int argc, const VALUE *argv,
36  const rb_method_entry_t *me)
37 {
38  const rb_method_definition_t *def = me->def;
39  VALUE val;
40  VALUE klass = me->klass;
41  const rb_block_t *blockptr = 0;
42 
43  if (!def) return Qnil;
44  if (th->passed_block) {
45  blockptr = th->passed_block;
46  th->passed_block = 0;
47  }
48 
49  again:
50  switch (def->type) {
51  case VM_METHOD_TYPE_ISEQ: {
52  rb_control_frame_t *reg_cfp;
53  int i;
54 
56  reg_cfp = th->cfp;
57 
58  CHECK_STACK_OVERFLOW(reg_cfp, argc + 1);
59 
60  *reg_cfp->sp++ = recv;
61  for (i = 0; i < argc; i++) {
62  *reg_cfp->sp++ = argv[i];
63  }
64 
65  vm_setup_method(th, reg_cfp, recv, argc, blockptr, 0 /* flag */, me);
66  val = vm_exec(th);
67  break;
68  }
70  case VM_METHOD_TYPE_CFUNC: {
71  EXEC_EVENT_HOOK(th, RUBY_EVENT_C_CALL, recv, id, klass);
72  {
73  rb_control_frame_t *reg_cfp = th->cfp;
74  rb_control_frame_t *cfp =
76  recv, (VALUE)blockptr, 0, reg_cfp->sp, 0, 1);
77 
78  cfp->me = me;
79  val = call_cfunc(def->body.cfunc.func, recv, def->body.cfunc.argc, argc, argv);
80 
81  if (reg_cfp != th->cfp + 1) {
82  rb_bug("cfp consistency error - call0");
83  }
84  vm_pop_frame(th);
85  }
86  EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, recv, id, klass);
87  break;
88  }
90  if (argc != 1) {
91  rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)", argc);
92  }
93  val = rb_ivar_set(recv, def->body.attr.id, argv[0]);
94  break;
95  }
96  case VM_METHOD_TYPE_IVAR: {
97  if (argc != 0) {
98  rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
99  }
100  val = rb_attr_get(recv, def->body.attr.id);
101  break;
102  }
103  case VM_METHOD_TYPE_BMETHOD: {
104  val = vm_call_bmethod(th, recv, argc, argv, blockptr, me);
105  break;
106  }
107  case VM_METHOD_TYPE_ZSUPER: {
108  klass = RCLASS_SUPER(klass);
109  if (!klass || !(me = rb_method_entry(klass, id))) {
110  return method_missing(recv, id, argc, argv, NOEX_SUPER);
111  }
113  if (!(def = me->def)) return Qnil;
114  goto again;
115  }
116  case VM_METHOD_TYPE_MISSING: {
117  VALUE new_args = rb_ary_new4(argc, argv);
118 
119  RB_GC_GUARD(new_args);
120  rb_ary_unshift(new_args, ID2SYM(id));
121  th->passed_block = blockptr;
122  return rb_funcall2(recv, idMethodMissing,
123  argc+1, RARRAY_PTR(new_args));
124  }
126  switch (def->body.optimize_type) {
127  case OPTIMIZED_METHOD_TYPE_SEND:
128  val = send_internal(argc, argv, recv, CALL_FCALL);
129  break;
130  case OPTIMIZED_METHOD_TYPE_CALL: {
131  rb_proc_t *proc;
132  GetProcPtr(recv, proc);
133  val = rb_vm_invoke_proc(th, proc, proc->block.self, argc, argv, blockptr);
134  break;
135  }
136  default:
137  rb_bug("vm_call0: unsupported optimized method type (%d)", def->body.optimize_type);
138  val = Qundef;
139  break;
140  }
141  break;
142  }
143  default:
144  rb_bug("vm_call0: unsupported method type (%d)", def->type);
145  val = Qundef;
146  }
148  return val;
149 }
150 
151 VALUE
152 rb_vm_call(rb_thread_t *th, VALUE recv, VALUE id, int argc, const VALUE *argv,
153  const rb_method_entry_t *me)
154 {
155  return vm_call0(th, recv, id, argc, argv, me);
156 }
157 
158 static inline VALUE
160 {
161  VALUE recv = th->cfp->self;
162  VALUE klass;
163  ID id;
164  rb_method_entry_t *me;
165  rb_control_frame_t *cfp = th->cfp;
166 
167  if (!cfp->iseq) {
168  klass = cfp->me->klass;
169  klass = RCLASS_SUPER(klass);
170 
171  if (klass == 0) {
172  klass = vm_search_normal_superclass(cfp->me->klass, recv);
173  }
174  id = cfp->me->def->original_id;
175  }
176  else {
177  rb_bug("vm_call_super: should not be reached");
178  }
179 
180  me = rb_method_entry(klass, id);
181  if (!me) {
182  return method_missing(recv, id, argc, argv, NOEX_SUPER);
183  }
184 
185  return vm_call0(th, recv, id, argc, argv, me);
186 }
187 
188 VALUE
190 {
192  return vm_call_super(GET_THREAD(), argc, argv);
193 }
194 
195 static inline void
197 {
198  rb_thread_t *th = GET_THREAD();
199 
203  }
204 }
205 
206 static inline rb_method_entry_t *rb_search_method_entry(VALUE recv, ID mid);
207 static inline int rb_method_call_status(rb_thread_t *th, const rb_method_entry_t *me, call_type scope, VALUE self);
208 #define NOEX_OK NOEX_NOSUPER
209 
224 static inline VALUE
225 rb_call0(VALUE recv, ID mid, int argc, const VALUE *argv,
226  call_type scope, VALUE self)
227 {
228  rb_method_entry_t *me = rb_search_method_entry(recv, mid);
229  rb_thread_t *th = GET_THREAD();
230  int call_status = rb_method_call_status(th, me, scope, self);
231 
232  if (call_status != NOEX_OK) {
233  return method_missing(recv, mid, argc, argv, call_status);
234  }
235  stack_check();
236  return vm_call0(th, recv, mid, argc, argv, me);
237 }
238 
242  int argc;
244 };
245 
246 static VALUE
248 {
249  VALUE new_args = rb_ary_new4(args->argc, args->argv);
250 
251  RB_GC_GUARD(new_args);
252  rb_ary_unshift(new_args, args->sym);
253  return rb_funcall2(args->recv, idMethodMissing,
254  args->argc+1, RARRAY_PTR(new_args));
255 }
256 
257 static VALUE
259 {
260  if (rb_respond_to(args->recv, SYM2ID(args->sym))) {
261  rb_exc_raise(e);
262  }
263  return Qundef;
264 }
265 
266 static VALUE
267 check_funcall(VALUE recv, ID mid, int argc, VALUE *argv)
268 {
269  VALUE klass = CLASS_OF(recv);
270  const rb_method_entry_t *me;
271  rb_thread_t *th = GET_THREAD();
272  int call_status;
273 
274  me = rb_method_entry(klass, idRespond_to);
275  if (me && !(me->flag & NOEX_BASIC)) {
276  VALUE args[2];
277  int arity = rb_method_entry_arity(me);
278 
279  if (arity < 1 || arity > 3) arity = 2;
280 
281  args[0] = ID2SYM(mid);
282  args[1] = Qtrue;
283  if (!RTEST(vm_call0(th, recv, idRespond_to, arity, args, me))) {
284  return Qundef;
285  }
286  }
287 
288  me = rb_search_method_entry(recv, mid);
289  call_status = rb_method_call_status(th, me, CALL_FCALL, Qundef);
290  if (call_status != NOEX_OK) {
291  if (rb_method_basic_definition_p(klass, idMethodMissing)) {
292  return Qundef;
293  }
294  else {
295  struct rescue_funcall_args args;
296 
297  th->method_missing_reason = 0;
298  args.recv = recv;
299  args.sym = ID2SYM(mid);
300  args.argc = argc;
301  args.argv = argv;
302  return rb_rescue2(check_funcall_exec, (VALUE)&args,
303  check_funcall_failed, (VALUE)&args,
305  }
306  }
307  stack_check();
308  return vm_call0(th, recv, mid, argc, argv, me);
309 }
310 
311 VALUE
313 {
314  return check_funcall(recv, mid, argc, argv);
315 }
316 
317 static const char *
319 {
320 #define type_case(t) case t: return #t;
321  switch (type) {
347  default: return NULL;
348  }
349 #undef type_case
350 }
351 
352 static inline rb_method_entry_t *
354 {
355  VALUE klass = CLASS_OF(recv);
356 
357  if (!klass) {
358  VALUE flags, klass;
359  if (IMMEDIATE_P(recv)) {
361  "method `%s' called on unexpected immediate object (%p)",
362  rb_id2name(mid), (void *)recv);
363  }
364  flags = RBASIC(recv)->flags;
365  klass = RBASIC(recv)->klass;
366  if (flags == 0) {
368  "method `%s' called on terminated object"
369  " (%p flags=0x%"PRIxVALUE" klass=0x%"PRIxVALUE")",
370  rb_id2name(mid), (void *)recv, flags, klass);
371  }
372  else {
373  int type = BUILTIN_TYPE(recv);
374  const char *typestr = rb_type_str(type);
375  if (typestr && T_OBJECT <= type && type < T_NIL)
377  "method `%s' called on hidden %s object"
378  " (%p flags=0x%"PRIxVALUE" klass=0x%"PRIxVALUE")",
379  rb_id2name(mid), typestr, (void *)recv, flags, klass);
380  if (typestr)
382  "method `%s' called on unexpected %s object"
383  " (%p flags=0x%"PRIxVALUE" klass=0x%"PRIxVALUE")",
384  rb_id2name(mid), typestr, (void *)recv, flags, klass);
385  else
387  "method `%s' called on broken T_???" "(0x%02x) object"
388  " (%p flags=0x%"PRIxVALUE" klass=0x%"PRIxVALUE")",
389  rb_id2name(mid), type, (void *)recv, flags, klass);
390  }
391  }
392  return rb_method_entry(klass, mid);
393 }
394 
395 static inline int
397 {
398  VALUE klass;
399  ID oid;
400  int noex;
401 
402  if (UNDEFINED_METHOD_ENTRY_P(me)) {
403  return scope == CALL_VCALL ? NOEX_VCALL : 0;
404  }
405  klass = me->klass;
406  oid = me->def->original_id;
407  noex = me->flag;
408 
409  if (oid != idMethodMissing) {
410  /* receiver specified form for private method */
411  if (UNLIKELY(noex)) {
412  if (((noex & NOEX_MASK) & NOEX_PRIVATE) && scope == CALL_PUBLIC) {
413  return NOEX_PRIVATE;
414  }
415 
416  /* self must be kind of a specified form for protected method */
417  if (((noex & NOEX_MASK) & NOEX_PROTECTED) && scope == CALL_PUBLIC) {
418  VALUE defined_class = klass;
419 
420  if (TYPE(defined_class) == T_ICLASS) {
421  defined_class = RBASIC(defined_class)->klass;
422  }
423 
424  if (self == Qundef) {
425  self = th->cfp->self;
426  }
427  if (!rb_obj_is_kind_of(self, defined_class)) {
428  return NOEX_PROTECTED;
429  }
430  }
431 
432  if (NOEX_SAFE(noex) > th->safe_level) {
433  rb_raise(rb_eSecurityError, "calling insecure method: %s",
434  rb_id2name(me->called_id));
435  }
436  }
437  }
438  return NOEX_OK;
439 }
440 
441 
453 static inline VALUE
454 rb_call(VALUE recv, ID mid, int argc, const VALUE *argv, call_type scope)
455 {
456  return rb_call0(recv, mid, argc, argv, scope, Qundef);
457 }
458 
459 NORETURN(static void raise_method_missing(rb_thread_t *th, int argc, const VALUE *argv,
460  VALUE obj, int call_status));
461 
462 /*
463  * call-seq:
464  * obj.method_missing(symbol [, *args] ) -> result
465  *
466  * Invoked by Ruby when <i>obj</i> is sent a message it cannot handle.
467  * <i>symbol</i> is the symbol for the method called, and <i>args</i>
468  * are any arguments that were passed to it. By default, the interpreter
469  * raises an error when this method is called. However, it is possible
470  * to override the method to provide more dynamic behavior.
471  * If it is decided that a particular method should not be handled, then
472  * <i>super</i> should be called, so that ancestors can pick up the
473  * missing method.
474  * The example below creates
475  * a class <code>Roman</code>, which responds to methods with names
476  * consisting of roman numerals, returning the corresponding integer
477  * values.
478  *
479  * class Roman
480  * def roman_to_int(str)
481  * # ...
482  * end
483  * def method_missing(methId)
484  * str = methId.id2name
485  * roman_to_int(str)
486  * end
487  * end
488  *
489  * r = Roman.new
490  * r.iv #=> 4
491  * r.xxiii #=> 23
492  * r.mm #=> 2000
493  */
494 
495 static VALUE
497 {
498  rb_thread_t *th = GET_THREAD();
499  raise_method_missing(th, argc, argv, obj, th->method_missing_reason);
500  return Qnil; /* not reached */
501 }
502 
503 #define NOEX_MISSING 0x80
504 
505 static void
507  int last_call_status)
508 {
509  ID id;
510  VALUE exc = rb_eNoMethodError;
511  const char *format = 0;
512 
513  if (argc == 0 || !SYMBOL_P(argv[0])) {
514  rb_raise(rb_eArgError, "no id given");
515  }
516 
517  stack_check();
518 
519  id = SYM2ID(argv[0]);
520 
521  if (last_call_status & NOEX_PRIVATE) {
522  format = "private method `%s' called for %s";
523  }
524  else if (last_call_status & NOEX_PROTECTED) {
525  format = "protected method `%s' called for %s";
526  }
527  else if (last_call_status & NOEX_VCALL) {
528  format = "undefined local variable or method `%s' for %s";
529  exc = rb_eNameError;
530  }
531  else if (last_call_status & NOEX_SUPER) {
532  format = "super: no superclass method `%s' for %s";
533  }
534  if (!format) {
535  format = "undefined method `%s' for %s";
536  }
537 
538  {
539  int n = 0;
540  VALUE mesg;
541  VALUE args[3];
542 
543  mesg = rb_const_get(exc, rb_intern("message"));
544  if (rb_method_basic_definition_p(CLASS_OF(mesg), '!')) {
545  args[n++] = rb_name_err_mesg_new(mesg, rb_str_new2(format), obj, argv[0]);
546  }
547  else {
548  args[n++] = rb_funcall(mesg, '!', 3, rb_str_new2(format), obj, argv[0]);
549  }
550  args[n++] = argv[0];
551  if (exc == rb_eNoMethodError) {
552  args[n++] = rb_ary_new4(argc - 1, argv + 1);
553  }
554  exc = rb_class_new_instance(n, args, exc);
555 
556  if (!(last_call_status & NOEX_MISSING)) {
558  }
559  rb_exc_raise(exc);
560  }
561 }
562 
563 static inline VALUE
564 method_missing(VALUE obj, ID id, int argc, const VALUE *argv, int call_status)
565 {
566  VALUE *nargv, result, argv_ary = 0;
567  rb_thread_t *th = GET_THREAD();
568  const rb_block_t *blockptr = th->passed_block;
569 
570  th->method_missing_reason = call_status;
571  th->passed_block = 0;
572 
573  if (id == idMethodMissing) {
574  raise_method_missing(th, argc, argv, obj, call_status | NOEX_MISSING);
575  }
576  else if (id == ID_ALLOCATOR) {
577  rb_raise(rb_eTypeError, "allocator undefined for %s",
578  rb_class2name(obj));
579  }
580 
581  if (argc < 0x100) {
582  nargv = ALLOCA_N(VALUE, argc + 1);
583  }
584  else {
585  argv_ary = rb_ary_tmp_new(argc + 1);
586  nargv = RARRAY_PTR(argv_ary);
587  }
588  nargv[0] = ID2SYM(id);
589  MEMCPY(nargv + 1, argv, VALUE, argc);
590 
591  if (rb_method_basic_definition_p(CLASS_OF(obj) , idMethodMissing)) {
592  raise_method_missing(th, argc+1, nargv, obj, call_status | NOEX_MISSING);
593  }
594  th->passed_block = blockptr;
595  result = rb_funcall2(obj, idMethodMissing, argc + 1, nargv);
596  if (argv_ary) rb_ary_clear(argv_ary);
597  return result;
598 }
599 
600 void
602  VALUE obj, int call_status)
603 {
604  th->passed_block = 0;
605  raise_method_missing(th, argc, argv, obj, call_status | NOEX_MISSING);
606 }
607 
616 VALUE
618 {
619  int argc;
620  VALUE *argv;
621 
622  argc = RARRAY_LENINT(args);
623  argv = ALLOCA_N(VALUE, argc);
624  MEMCPY(argv, RARRAY_PTR(args), VALUE, argc);
625  return rb_call(recv, mid, argc, argv, CALL_FCALL);
626 }
627 
637 VALUE
638 rb_funcall(VALUE recv, ID mid, int n, ...)
639 {
640  VALUE *argv;
641  va_list ar;
642 
643  if (n > 0) {
644  long i;
645 
646  va_init_list(ar, n);
647 
648  argv = ALLOCA_N(VALUE, n);
649 
650  for (i = 0; i < n; i++) {
651  argv[i] = va_arg(ar, VALUE);
652  }
653  va_end(ar);
654  }
655  else {
656  argv = 0;
657  }
658  return rb_call(recv, mid, n, argv, CALL_FCALL);
659 }
660 
668 VALUE
669 rb_funcall2(VALUE recv, ID mid, int argc, const VALUE *argv)
670 {
671  return rb_call(recv, mid, argc, argv, CALL_FCALL);
672 }
673 
683 VALUE
684 rb_funcall3(VALUE recv, ID mid, int argc, const VALUE *argv)
685 {
686  return rb_call(recv, mid, argc, argv, CALL_PUBLIC);
687 }
688 
689 VALUE
691 {
693 
694  return rb_call(recv, mid, argc, argv, CALL_PUBLIC);
695 }
696 
697 VALUE
698 rb_funcall_with_block(VALUE recv, ID mid, int argc, const VALUE *argv, VALUE pass_procval)
699 {
700  if (!NIL_P(pass_procval)) {
701  rb_thread_t *th = GET_THREAD();
702  rb_block_t *block = 0;
703 
704  rb_proc_t *pass_proc;
705  GetProcPtr(pass_procval, pass_proc);
706  block = &pass_proc->block;
707 
708  th->passed_block = block;
709  }
710 
711  return rb_call(recv, mid, argc, argv, CALL_PUBLIC);
712 }
713 
714 static VALUE
716 {
717  VALUE vid;
718  VALUE self = RUBY_VM_PREVIOUS_CONTROL_FRAME(GET_THREAD()->cfp)->self;
719  rb_thread_t *th = GET_THREAD();
720 
721  if (argc == 0) {
722  rb_raise(rb_eArgError, "no method name given");
723  }
724 
725  vid = *argv++; argc--;
727 
728  return rb_call0(recv, rb_to_id(vid), argc, argv, scope, self);
729 }
730 
731 /*
732  * call-seq:
733  * obj.send(symbol [, args...]) -> obj
734  * obj.__send__(symbol [, args...]) -> obj
735  *
736  * Invokes the method identified by _symbol_, passing it any
737  * arguments specified. You can use <code>__send__</code> if the name
738  * +send+ clashes with an existing method in _obj_.
739  *
740  * class Klass
741  * def hello(*args)
742  * "Hello " + args.join(' ')
743  * end
744  * end
745  * k = Klass.new
746  * k.send :hello, "gentle", "readers" #=> "Hello gentle readers"
747  */
748 
749 VALUE
751 {
752  return send_internal(argc, argv, recv, CALL_FCALL);
753 }
754 
755 /*
756  * call-seq:
757  * obj.public_send(symbol [, args...]) -> obj
758  *
759  * Invokes the method identified by _symbol_, passing it any
760  * arguments specified. Unlike send, public_send calls public
761  * methods only.
762  *
763  * 1.public_send(:puts, "hello") # causes NoMethodError
764  */
765 
766 VALUE
768 {
769  return send_internal(argc, argv, recv, CALL_PUBLIC);
770 }
771 
772 /* yield */
773 
774 static inline VALUE
775 rb_yield_0(int argc, const VALUE * argv)
776 {
777  return vm_yield(GET_THREAD(), argc, argv);
778 }
779 
780 VALUE
782 {
783  if (val == Qundef) {
784  return rb_yield_0(0, 0);
785  }
786  else {
787  return rb_yield_0(1, &val);
788  }
789 }
790 
791 VALUE
792 rb_yield_values(int n, ...)
793 {
794  if (n == 0) {
795  return rb_yield_0(0, 0);
796  }
797  else {
798  int i;
799  VALUE *argv;
800  va_list args;
801  argv = ALLOCA_N(VALUE, n);
802 
803  va_init_list(args, n);
804  for (i=0; i<n; i++) {
805  argv[i] = va_arg(args, VALUE);
806  }
807  va_end(args);
808 
809  return rb_yield_0(n, argv);
810  }
811 }
812 
813 VALUE
815 {
816  return rb_yield_0(argc, argv);
817 }
818 
819 VALUE
821 {
822  VALUE tmp = rb_check_array_type(values);
823  volatile VALUE v;
824  if (NIL_P(tmp)) {
825  rb_raise(rb_eArgError, "not an array");
826  }
827  v = rb_yield_0(RARRAY_LENINT(tmp), RARRAY_PTR(tmp));
828  return v;
829 }
830 
831 static VALUE
832 loop_i(void)
833 {
834  for (;;) {
835  rb_yield_0(0, 0);
836  }
837  return Qnil;
838 }
839 
840 /*
841  * call-seq:
842  * loop { block }
843  * loop -> an_enumerator
844  *
845  * Repeatedly executes the block.
846  *
847  * If no block is given, an enumerator is returned instead.
848  *
849  * loop do
850  * print "Input: "
851  * line = gets
852  * break if !line or line =~ /^qQ/
853  * # ...
854  * end
855  *
856  * StopIteration raised in the block breaks the loop.
857  */
858 
859 static VALUE
861 {
862  RETURN_ENUMERATOR(self, 0, 0);
864  return Qnil; /* dummy */
865 }
866 
867 #if VMDEBUG
868 static const char *
869 vm_frametype_name(const rb_control_frame_t *cfp);
870 #endif
871 
872 VALUE
873 rb_iterate(VALUE (* it_proc) (VALUE), VALUE data1,
874  VALUE (* bl_proc) (ANYARGS), VALUE data2)
875 {
876  int state;
877  volatile VALUE retval = Qnil;
878  NODE *node = NEW_IFUNC(bl_proc, data2);
879  rb_thread_t *th = GET_THREAD();
880  rb_control_frame_t *volatile cfp = th->cfp;
881 
882  node->nd_aid = rb_frame_this_func();
883  TH_PUSH_TAG(th);
884  state = TH_EXEC_TAG();
885  if (state == 0) {
886  iter_retry:
887  {
888  rb_block_t *blockptr;
889  if (bl_proc) {
890  blockptr = RUBY_VM_GET_BLOCK_PTR_IN_CFP(th->cfp);
891  blockptr->iseq = (void *)node;
892  blockptr->proc = 0;
893  }
894  else {
895  blockptr = GC_GUARDED_PTR_REF(th->cfp->lfp[0]);
896  }
897  th->passed_block = blockptr;
898  }
899  retval = (*it_proc) (data1);
900  }
901  else {
902  VALUE err = th->errinfo;
903  if (state == TAG_BREAK) {
904  VALUE *escape_dfp = GET_THROWOBJ_CATCH_POINT(err);
905  VALUE *cdfp = cfp->dfp;
906 
907  if (cdfp == escape_dfp) {
908  state = 0;
909  th->state = 0;
910  th->errinfo = Qnil;
911 
912  /* check skipped frame */
913  while (th->cfp != cfp) {
914 #if VMDEBUG
915  printf("skipped frame: %s\n", vm_frametype_name(th->cfp));
916 #endif
918  const rb_method_entry_t *me = th->cfp->me;
920  }
921 
923  }
924  }
925  else{
926  /* SDR(); printf("%p, %p\n", cdfp, escape_dfp); */
927  }
928  }
929  else if (state == TAG_RETRY) {
930  VALUE *escape_dfp = GET_THROWOBJ_CATCH_POINT(err);
931  VALUE *cdfp = cfp->dfp;
932 
933  if (cdfp == escape_dfp) {
934  state = 0;
935  th->state = 0;
936  th->errinfo = Qnil;
937  th->cfp = cfp;
938  goto iter_retry;
939  }
940  }
941  }
942  TH_POP_TAG();
943 
944  switch (state) {
945  case 0:
946  break;
947  default:
948  TH_JUMP_TAG(th, state);
949  }
950  return retval;
951 }
952 
956  int argc;
958 };
959 
960 static VALUE
962 {
963  const struct iter_method_arg * arg =
964  (struct iter_method_arg *) obj;
965 
966  return rb_call(arg->obj, arg->mid, arg->argc, arg->argv, CALL_FCALL);
967 }
968 
969 VALUE
971  VALUE (*bl_proc) (ANYARGS), VALUE data2)
972 {
973  struct iter_method_arg arg;
974 
975  arg.obj = obj;
976  arg.mid = mid;
977  arg.argc = argc;
978  arg.argv = argv;
979  return rb_iterate(iterate_method, (VALUE)&arg, bl_proc, data2);
980 }
981 
982 VALUE
984 {
985  return rb_call(obj, idEach, 0, 0, CALL_FCALL);
986 }
987 
988 static VALUE
989 eval_string_with_cref(VALUE self, VALUE src, VALUE scope, NODE *cref, const char *volatile file, volatile int line)
990 {
991  int state;
992  VALUE result = Qundef;
993  VALUE envval;
994  rb_binding_t *bind = 0;
995  rb_thread_t *th = GET_THREAD();
996  rb_env_t *env = NULL;
997  rb_block_t block;
998  volatile int parse_in_eval;
999  volatile int mild_compile_error;
1000 
1001  if (file == 0) {
1002  file = rb_sourcefile();
1003  line = rb_sourceline();
1004  }
1005 
1006  parse_in_eval = th->parse_in_eval;
1007  mild_compile_error = th->mild_compile_error;
1008  PUSH_TAG();
1009  if ((state = EXEC_TAG()) == 0) {
1010  rb_iseq_t *iseq;
1011  volatile VALUE iseqval;
1012 
1013  if (scope != Qnil) {
1014  if (rb_obj_is_kind_of(scope, rb_cBinding)) {
1015  GetBindingPtr(scope, bind);
1016  envval = bind->env;
1017  if (strcmp(file, "(eval)") == 0 && bind->filename != Qnil) {
1018  file = RSTRING_PTR(bind->filename);
1019  line = bind->line_no;
1020  }
1021  }
1022  else {
1024  "wrong argument type %s (expected Binding)",
1025  rb_obj_classname(scope));
1026  }
1027  GetEnvPtr(envval, env);
1028  th->base_block = &env->block;
1029  }
1030  else {
1032 
1033  if (cfp != 0) {
1034  block = *RUBY_VM_GET_BLOCK_PTR_IN_CFP(cfp);
1035  th->base_block = &block;
1036  th->base_block->self = self;
1037  th->base_block->iseq = cfp->iseq; /* TODO */
1038  }
1039  else {
1040  rb_raise(rb_eRuntimeError, "Can't eval on top of Fiber or Thread");
1041  }
1042  }
1043 
1044  /* make eval iseq */
1045  th->parse_in_eval++;
1046  th->mild_compile_error++;
1047  iseqval = rb_iseq_compile(src, rb_str_new2(file), INT2FIX(line));
1048  th->mild_compile_error--;
1049  th->parse_in_eval--;
1050 
1051  vm_set_eval_stack(th, iseqval, cref);
1052  th->base_block = 0;
1053 
1054  if (0) { /* for debug */
1055  VALUE disasm = rb_iseq_disasm(iseqval);
1056  printf("%s\n", StringValuePtr(disasm));
1057  }
1058 
1059  /* save new env */
1060  GetISeqPtr(iseqval, iseq);
1061  if (bind && iseq->local_table_size > 0) {
1062  bind->env = rb_vm_make_env_object(th, th->cfp);
1063  }
1064 
1065  /* kick */
1066  CHECK_STACK_OVERFLOW(th->cfp, iseq->stack_max);
1067  result = vm_exec(th);
1068  }
1069  POP_TAG();
1070  th->mild_compile_error = mild_compile_error;
1071  th->parse_in_eval = parse_in_eval;
1072 
1073  if (state) {
1074  if (state == TAG_RAISE) {
1075  VALUE errinfo = th->errinfo;
1076  if (strcmp(file, "(eval)") == 0) {
1077  VALUE mesg, errat, bt2;
1078  ID id_mesg;
1079 
1080  CONST_ID(id_mesg, "mesg");
1081  errat = rb_get_backtrace(errinfo);
1082  mesg = rb_attr_get(errinfo, id_mesg);
1083  if (!NIL_P(errat) && TYPE(errat) == T_ARRAY &&
1084  (bt2 = vm_backtrace(th, -2), RARRAY_LEN(bt2) > 0)) {
1085  if (!NIL_P(mesg) && TYPE(mesg) == T_STRING && !RSTRING_LEN(mesg)) {
1086  if (OBJ_FROZEN(mesg)) {
1087  VALUE m = rb_str_cat(rb_str_dup(RARRAY_PTR(errat)[0]), ": ", 2);
1088  rb_ivar_set(errinfo, id_mesg, rb_str_append(m, mesg));
1089  }
1090  else {
1091  rb_str_update(mesg, 0, 0, rb_str_new2(": "));
1092  rb_str_update(mesg, 0, 0, RARRAY_PTR(errat)[0]);
1093  }
1094  }
1095  RARRAY_PTR(errat)[0] = RARRAY_PTR(bt2)[0];
1096  }
1097  }
1098  rb_exc_raise(errinfo);
1099  }
1100  JUMP_TAG(state);
1101  }
1102  return result;
1103 }
1104 
1105 static VALUE
1106 eval_string(VALUE self, VALUE src, VALUE scope, const char *file, int line)
1107 {
1108  return eval_string_with_cref(self, src, scope, 0, file, line);
1109 }
1110 
1111 /*
1112  * call-seq:
1113  * eval(string [, binding [, filename [,lineno]]]) -> obj
1114  *
1115  * Evaluates the Ruby expression(s) in <em>string</em>. If
1116  * <em>binding</em> is given, which must be a <code>Binding</code>
1117  * object, the evaluation is performed in its context. If the
1118  * optional <em>filename</em> and <em>lineno</em> parameters are
1119  * present, they will be used when reporting syntax errors.
1120  *
1121  * def get_binding(str)
1122  * return binding
1123  * end
1124  * str = "hello"
1125  * eval "str + ' Fred'" #=> "hello Fred"
1126  * eval "str + ' Fred'", get_binding("bye") #=> "bye Fred"
1127  */
1128 
1129 VALUE
1130 rb_f_eval(int argc, VALUE *argv, VALUE self)
1131 {
1132  VALUE src, scope, vfile, vline;
1133  const char *file = "(eval)";
1134  int line = 1;
1135 
1136  rb_scan_args(argc, argv, "13", &src, &scope, &vfile, &vline);
1137  if (rb_safe_level() >= 4) {
1138  StringValue(src);
1139  if (!NIL_P(scope) && !OBJ_TAINTED(scope)) {
1141  "Insecure: can't modify trusted binding");
1142  }
1143  }
1144  else {
1145  SafeStringValue(src);
1146  }
1147  if (argc >= 3) {
1148  StringValue(vfile);
1149  }
1150  if (argc >= 4) {
1151  line = NUM2INT(vline);
1152  }
1153 
1154  if (!NIL_P(vfile))
1155  file = RSTRING_PTR(vfile);
1156  return eval_string(self, src, scope, file, line);
1157 }
1158 
1159 VALUE
1160 rb_eval_string(const char *str)
1161 {
1162  return eval_string(rb_vm_top_self(), rb_str_new2(str), Qnil, "(eval)", 1);
1163 }
1164 
1165 VALUE
1166 rb_eval_string_protect(const char *str, int *state)
1167 {
1168  return rb_protect((VALUE (*)(VALUE))rb_eval_string, (VALUE)str, state);
1169 }
1170 
1171 VALUE
1172 rb_eval_string_wrap(const char *str, int *state)
1173 {
1174  int status;
1175  rb_thread_t *th = GET_THREAD();
1176  VALUE self = th->top_self;
1177  VALUE wrapper = th->top_wrapper;
1178  VALUE val;
1179 
1180  th->top_wrapper = rb_module_new();
1183 
1184  val = rb_eval_string_protect(str, &status);
1185 
1186  th->top_self = self;
1187  th->top_wrapper = wrapper;
1188 
1189  if (state) {
1190  *state = status;
1191  }
1192  else if (status) {
1193  JUMP_TAG(status);
1194  }
1195  return val;
1196 }
1197 
1198 VALUE
1199 rb_eval_cmd(VALUE cmd, VALUE arg, int level)
1200 {
1201  int state;
1202  VALUE val = Qnil; /* OK */
1203  volatile int safe = rb_safe_level();
1204 
1205  if (OBJ_TAINTED(cmd)) {
1206  level = 4;
1207  }
1208 
1209  if (TYPE(cmd) != T_STRING) {
1210  PUSH_TAG();
1211  rb_set_safe_level_force(level);
1212  if ((state = EXEC_TAG()) == 0) {
1213  val = rb_funcall2(cmd, rb_intern("call"), RARRAY_LENINT(arg),
1214  RARRAY_PTR(arg));
1215  }
1216  POP_TAG();
1217 
1219 
1220  if (state)
1221  JUMP_TAG(state);
1222  return val;
1223  }
1224 
1225  PUSH_TAG();
1226  if ((state = EXEC_TAG()) == 0) {
1227  val = eval_string(rb_vm_top_self(), cmd, Qnil, 0, 0);
1228  }
1229  POP_TAG();
1230 
1232  if (state) JUMP_TAG(state);
1233  return val;
1234 }
1235 
1236 /* block eval under the class/module context */
1237 
1238 static VALUE
1239 yield_under(VALUE under, VALUE self, VALUE values)
1240 {
1241  rb_thread_t *th = GET_THREAD();
1242  rb_block_t block, *blockptr;
1243  NODE *cref;
1244 
1245  if ((blockptr = GC_GUARDED_PTR_REF(th->cfp->lfp[0])) != 0) {
1246  block = *blockptr;
1247  block.self = self;
1248  th->cfp->lfp[0] = GC_GUARDED_PTR(&block);
1249  }
1250  cref = vm_cref_push(th, under, NOEX_PUBLIC, blockptr);
1252 
1253  if (values == Qundef) {
1254  return vm_yield_with_cref(th, 1, &self, cref);
1255  }
1256  else {
1257  return vm_yield_with_cref(th, RARRAY_LENINT(values), RARRAY_PTR(values), cref);
1258  }
1259 }
1260 
1261 /* string eval under the class/module context */
1262 static VALUE
1263 eval_under(VALUE under, VALUE self, VALUE src, const char *file, int line)
1264 {
1265  NODE *cref = vm_cref_push(GET_THREAD(), under, NOEX_PUBLIC, NULL);
1266 
1267  if (rb_safe_level() >= 4) {
1268  StringValue(src);
1269  }
1270  else {
1271  SafeStringValue(src);
1272  }
1273 
1274  return eval_string_with_cref(self, src, Qnil, cref, file, line);
1275 }
1276 
1277 static VALUE
1278 specific_eval(int argc, VALUE *argv, VALUE klass, VALUE self)
1279 {
1280  if (rb_block_given_p()) {
1281  if (argc > 0) {
1282  rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc);
1283  }
1284  return yield_under(klass, self, Qundef);
1285  }
1286  else {
1287  const char *file = "(eval)";
1288  int line = 1;
1289 
1290  if (argc == 0) {
1291  rb_raise(rb_eArgError, "block not supplied");
1292  }
1293  else {
1294  if (rb_safe_level() >= 4) {
1295  StringValue(argv[0]);
1296  }
1297  else {
1298  SafeStringValue(argv[0]);
1299  }
1300  if (argc > 3) {
1301  const char *name = rb_id2name(rb_frame_callee());
1303  "wrong number of arguments: %s(src) or %s{..}",
1304  name, name);
1305  }
1306  if (argc > 2)
1307  line = NUM2INT(argv[2]);
1308  if (argc > 1) {
1309  file = StringValuePtr(argv[1]);
1310  }
1311  }
1312  return eval_under(klass, self, argv[0], file, line);
1313  }
1314 }
1315 
1316 /*
1317  * call-seq:
1318  * obj.instance_eval(string [, filename [, lineno]] ) -> obj
1319  * obj.instance_eval {| | block } -> obj
1320  *
1321  * Evaluates a string containing Ruby source code, or the given block,
1322  * within the context of the receiver (_obj_). In order to set the
1323  * context, the variable +self+ is set to _obj_ while
1324  * the code is executing, giving the code access to _obj_'s
1325  * instance variables. In the version of <code>instance_eval</code>
1326  * that takes a +String+, the optional second and third
1327  * parameters supply a filename and starting line number that are used
1328  * when reporting compilation errors.
1329  *
1330  * class KlassWithSecret
1331  * def initialize
1332  * @secret = 99
1333  * end
1334  * end
1335  * k = KlassWithSecret.new
1336  * k.instance_eval { @secret } #=> 99
1337  */
1338 
1339 VALUE
1340 rb_obj_instance_eval(int argc, VALUE *argv, VALUE self)
1341 {
1342  VALUE klass;
1343 
1344  if (SPECIAL_CONST_P(self)) {
1345  klass = Qnil;
1346  }
1347  else {
1348  klass = rb_singleton_class(self);
1349  }
1350  return specific_eval(argc, argv, klass, self);
1351 }
1352 
1353 /*
1354  * call-seq:
1355  * obj.instance_exec(arg...) {|var...| block } -> obj
1356  *
1357  * Executes the given block within the context of the receiver
1358  * (_obj_). In order to set the context, the variable +self+ is set
1359  * to _obj_ while the code is executing, giving the code access to
1360  * _obj_'s instance variables. Arguments are passed as block parameters.
1361  *
1362  * class KlassWithSecret
1363  * def initialize
1364  * @secret = 99
1365  * end
1366  * end
1367  * k = KlassWithSecret.new
1368  * k.instance_exec(5) {|x| @secret+x } #=> 104
1369  */
1370 
1371 VALUE
1372 rb_obj_instance_exec(int argc, VALUE *argv, VALUE self)
1373 {
1374  VALUE klass;
1375 
1376  if (SPECIAL_CONST_P(self)) {
1377  klass = Qnil;
1378  }
1379  else {
1380  klass = rb_singleton_class(self);
1381  }
1382  return yield_under(klass, self, rb_ary_new4(argc, argv));
1383 }
1384 
1385 /*
1386  * call-seq:
1387  * mod.class_eval(string [, filename [, lineno]]) -> obj
1388  * mod.module_eval {|| block } -> obj
1389  *
1390  * Evaluates the string or block in the context of _mod_. This can
1391  * be used to add methods to a class. <code>module_eval</code> returns
1392  * the result of evaluating its argument. The optional _filename_
1393  * and _lineno_ parameters set the text for error messages.
1394  *
1395  * class Thing
1396  * end
1397  * a = %q{def hello() "Hello there!" end}
1398  * Thing.module_eval(a)
1399  * puts Thing.new.hello()
1400  * Thing.module_eval("invalid code", "dummy", 123)
1401  *
1402  * <em>produces:</em>
1403  *
1404  * Hello there!
1405  * dummy:123:in `module_eval': undefined local variable
1406  * or method `code' for Thing:Class
1407  */
1408 
1409 VALUE
1411 {
1412  return specific_eval(argc, argv, mod, mod);
1413 }
1414 
1415 /*
1416  * call-seq:
1417  * mod.module_exec(arg...) {|var...| block } -> obj
1418  * mod.class_exec(arg...) {|var...| block } -> obj
1419  *
1420  * Evaluates the given block in the context of the class/module.
1421  * The method defined in the block will belong to the receiver.
1422  *
1423  * class Thing
1424  * end
1425  * Thing.class_exec{
1426  * def hello() "Hello there!" end
1427  * }
1428  * puts Thing.new.hello()
1429  *
1430  * <em>produces:</em>
1431  *
1432  * Hello there!
1433  */
1434 
1435 VALUE
1437 {
1438  return yield_under(mod, mod, rb_ary_new4(argc, argv));
1439 }
1440 
1441 /*
1442  * call-seq:
1443  * throw(tag [, obj])
1444  *
1445  * Transfers control to the end of the active +catch+ block
1446  * waiting for _tag_. Raises +ArgumentError+ if there
1447  * is no +catch+ block for the _tag_. The optional second
1448  * parameter supplies a return value for the +catch+ block,
1449  * which otherwise defaults to +nil+. For examples, see
1450  * <code>Kernel::catch</code>.
1451  */
1452 
1453 static VALUE
1454 rb_f_throw(int argc, VALUE *argv)
1455 {
1456  VALUE tag, value;
1457 
1458  rb_scan_args(argc, argv, "11", &tag, &value);
1459  rb_throw_obj(tag, value);
1460  return Qnil; /* not reached */
1461 }
1462 
1463 void
1465 {
1466  rb_thread_t *th = GET_THREAD();
1467  struct rb_vm_tag *tt = th->tag;
1468 
1469  while (tt) {
1470  if (tt->tag == tag) {
1471  tt->retval = value;
1472  break;
1473  }
1474  tt = tt->prev;
1475  }
1476  if (!tt) {
1477  VALUE desc = rb_inspect(tag);
1478  RB_GC_GUARD(desc);
1479  rb_raise(rb_eArgError, "uncaught throw %s", RSTRING_PTR(desc));
1480  }
1482  th->errinfo = NEW_THROW_OBJECT(tag, 0, TAG_THROW);
1483 
1485 }
1486 
1487 void
1488 rb_throw(const char *tag, VALUE val)
1489 {
1490  rb_throw_obj(ID2SYM(rb_intern(tag)), val);
1491 }
1492 
1493 static VALUE
1495 {
1496  return rb_yield_0(1, &tag);
1497 }
1498 
1499 /*
1500  * call-seq:
1501  * catch([arg]) {|tag| block } -> obj
1502  *
1503  * +catch+ executes its block. If a +throw+ is
1504  * executed, Ruby searches up its stack for a +catch+ block
1505  * with a tag corresponding to the +throw+'s
1506  * _tag_. If found, that block is terminated, and
1507  * +catch+ returns the value given to +throw+. If
1508  * +throw+ is not called, the block terminates normally, and
1509  * the value of +catch+ is the value of the last expression
1510  * evaluated. +catch+ expressions may be nested, and the
1511  * +throw+ call need not be in lexical scope.
1512  *
1513  * def routine(n)
1514  * puts n
1515  * throw :done if n <= 0
1516  * routine(n-1)
1517  * end
1518  *
1519  *
1520  * catch(:done) { routine(3) }
1521  *
1522  * <em>produces:</em>
1523  *
1524  * 3
1525  * 2
1526  * 1
1527  * 0
1528  *
1529  * when _arg_ is given, +catch+ yields it as is, or when no
1530  * _arg_ is given, +catch+ assigns a new unique object to
1531  * +throw+. this is useful for nested +catch+. _arg_ can
1532  * be an arbitrary object, not only Symbol.
1533  *
1534  */
1535 
1536 static VALUE
1537 rb_f_catch(int argc, VALUE *argv)
1538 {
1539  VALUE tag;
1540 
1541  if (argc == 0) {
1542  tag = rb_obj_alloc(rb_cObject);
1543  }
1544  else {
1545  rb_scan_args(argc, argv, "01", &tag);
1546  }
1547  return rb_catch_obj(tag, catch_i, 0);
1548 }
1549 
1550 VALUE
1551 rb_catch(const char *tag, VALUE (*func)(), VALUE data)
1552 {
1553  VALUE vtag = tag ? ID2SYM(rb_intern(tag)) : rb_obj_alloc(rb_cObject);
1554  return rb_catch_obj(vtag, func, data);
1555 }
1556 
1557 VALUE
1559 {
1560  int state;
1561  volatile VALUE val = Qnil; /* OK */
1562  rb_thread_t *th = GET_THREAD();
1563  rb_control_frame_t *saved_cfp = th->cfp;
1564 
1565  PUSH_TAG();
1566 
1567  th->tag->tag = tag;
1568 
1569  if ((state = EXEC_TAG()) == 0) {
1570  /* call with argc=1, argv = [tag], block = Qnil to insure compatibility */
1571  val = (*func)(tag, data, 1, &tag, Qnil);
1572  }
1573  else if (state == TAG_THROW && RNODE(th->errinfo)->u1.value == tag) {
1574  th->cfp = saved_cfp;
1575  val = th->tag->retval;
1576  th->errinfo = Qnil;
1577  state = 0;
1578  }
1579  POP_TAG();
1580  if (state)
1581  JUMP_TAG(state);
1582 
1583  return val;
1584 }
1585 
1586 /*
1587  * call-seq:
1588  * caller(start=1) -> array or nil
1589  *
1590  * Returns the current execution stack---an array containing strings in
1591  * the form ``<em>file:line</em>'' or ``<em>file:line: in
1592  * `method'</em>''. The optional _start_ parameter
1593  * determines the number of initial stack entries to omit from the
1594  * result.
1595  *
1596  * Returns +nil+ if _start_ is greater than the size of
1597  * current execution stack.
1598  *
1599  * def a(skip)
1600  * caller(skip)
1601  * end
1602  * def b(skip)
1603  * a(skip)
1604  * end
1605  * def c(skip)
1606  * b(skip)
1607  * end
1608  * c(0) #=> ["prog:2:in `a'", "prog:5:in `b'", "prog:8:in `c'", "prog:10:in `<main>'"]
1609  * c(1) #=> ["prog:5:in `b'", "prog:8:in `c'", "prog:11:in `<main>'"]
1610  * c(2) #=> ["prog:8:in `c'", "prog:12:in `<main>'"]
1611  * c(3) #=> ["prog:13:in `<main>'"]
1612  * c(4) #=> []
1613  * c(5) #=> nil
1614  */
1615 
1616 static VALUE
1617 rb_f_caller(int argc, VALUE *argv)
1618 {
1619  VALUE level;
1620  int lev;
1621 
1622  rb_scan_args(argc, argv, "01", &level);
1623 
1624  if (NIL_P(level))
1625  lev = 1;
1626  else
1627  lev = NUM2INT(level);
1628  if (lev < 0)
1629  rb_raise(rb_eArgError, "negative level (%d)", lev);
1630 
1631  return vm_backtrace(GET_THREAD(), lev);
1632 }
1633 
1634 static int
1635 print_backtrace(void *arg, VALUE file, int line, VALUE method)
1636 {
1637  FILE *fp = arg;
1638  const char *filename = NIL_P(file) ? "ruby" : RSTRING_PTR(file);
1639  if (NIL_P(method)) {
1640  fprintf(fp, "\tfrom %s:%d:in unknown method\n",
1641  filename, line);
1642  }
1643  else {
1644  fprintf(fp, "\tfrom %s:%d:in `%s'\n",
1645  filename, line, RSTRING_PTR(method));
1646  }
1647  return FALSE;
1648 }
1649 
1650 void
1652 {
1654 }
1655 
1656 VALUE
1658 {
1659  return vm_backtrace(GET_THREAD(), -1);
1660 }
1661 
1662 VALUE
1664 {
1665  rb_thread_t *th;
1666  GetThreadPtr(thval, th);
1667 
1668  switch (th->status) {
1669  case THREAD_RUNNABLE:
1670  case THREAD_STOPPED:
1672  break;
1673  case THREAD_TO_KILL:
1674  case THREAD_KILLED:
1675  return Qnil;
1676  }
1677 
1678  return vm_backtrace(th, 0);
1679 }
1680 
1681 int
1683 {
1684  return vm_backtrace_each(GET_THREAD(), -1, NULL, iter, arg);
1685 }
1686 
1687 /*
1688  * call-seq:
1689  * local_variables -> array
1690  *
1691  * Returns the names of the current local variables.
1692  *
1693  * fred = 1
1694  * for i in 1..10
1695  * # ...
1696  * end
1697  * local_variables #=> [:fred, :i]
1698  */
1699 
1700 static VALUE
1702 {
1703  VALUE ary = rb_ary_new();
1704  rb_thread_t *th = GET_THREAD();
1705  rb_control_frame_t *cfp =
1707  int i;
1708 
1709  while (cfp) {
1710  if (cfp->iseq) {
1711  for (i = 0; i < cfp->iseq->local_table_size; i++) {
1712  ID lid = cfp->iseq->local_table[i];
1713  if (lid) {
1714  const char *vname = rb_id2name(lid);
1715  /* should skip temporary variable */
1716  if (vname) {
1717  rb_ary_push(ary, ID2SYM(lid));
1718  }
1719  }
1720  }
1721  }
1722  if (cfp->lfp != cfp->dfp) {
1723  /* block */
1724  VALUE *dfp = GC_GUARDED_PTR_REF(cfp->dfp[0]);
1725 
1726  if (vm_collect_local_variables_in_heap(th, dfp, ary)) {
1727  break;
1728  }
1729  else {
1730  while (cfp->dfp != dfp) {
1731  cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
1732  }
1733  }
1734  }
1735  else {
1736  break;
1737  }
1738  }
1739  return ary;
1740 }
1741 
1742 /*
1743  * call-seq:
1744  * block_given? -> true or false
1745  * iterator? -> true or false
1746  *
1747  * Returns <code>true</code> if <code>yield</code> would execute a
1748  * block in the current context. The <code>iterator?</code> form
1749  * is mildly deprecated.
1750  *
1751  * def try
1752  * if block_given?
1753  * yield
1754  * else
1755  * "no block"
1756  * end
1757  * end
1758  * try #=> "no block"
1759  * try { "hello" } #=> "hello"
1760  * try do "hello" end #=> "hello"
1761  */
1762 
1763 
1764 VALUE
1766 {
1767  rb_thread_t *th = GET_THREAD();
1768  rb_control_frame_t *cfp = th->cfp;
1770 
1771  if (cfp != 0 &&
1772  (cfp->lfp[0] & 0x02) == 0 &&
1773  GC_GUARDED_PTR_REF(cfp->lfp[0])) {
1774  return Qtrue;
1775  }
1776  else {
1777  return Qfalse;
1778  }
1779 }
1780 
1781 VALUE
1783 {
1784  rb_thread_t *th = GET_THREAD();
1785  rb_control_frame_t *cfp = th->cfp;
1787  if (cfp != 0) return cfp->iseq->filepath;
1788  return Qnil;
1789 }
1790 
1791 void
1793 {
1794  rb_define_global_function("eval", rb_f_eval, -1);
1795  rb_define_global_function("local_variables", rb_f_local_variables, 0);
1797  rb_define_global_function("block_given?", rb_f_block_given_p, 0);
1798 
1799  rb_define_global_function("catch", rb_f_catch, -1);
1800  rb_define_global_function("throw", rb_f_throw, -1);
1801 
1803 
1804  rb_define_method(rb_cBasicObject, "instance_eval", rb_obj_instance_eval, -1);
1805  rb_define_method(rb_cBasicObject, "instance_exec", rb_obj_instance_exec, -1);
1807 
1808 #if 1
1810  VM_METHOD_TYPE_OPTIMIZED, (void *)OPTIMIZED_METHOD_TYPE_SEND, 0);
1812  VM_METHOD_TYPE_OPTIMIZED, (void *)OPTIMIZED_METHOD_TYPE_SEND, 0);
1813 #else
1814  rb_define_method(rb_cBasicObject, "__send__", rb_f_send, -1);
1815  rb_define_method(rb_mKernel, "send", rb_f_send, -1);
1816 #endif
1817  rb_define_method(rb_mKernel, "public_send", rb_f_public_send, -1);
1818 
1819  rb_define_method(rb_cModule, "module_exec", rb_mod_module_exec, -1);
1820  rb_define_method(rb_cModule, "class_exec", rb_mod_module_exec, -1);
1821  rb_define_method(rb_cModule, "module_eval", rb_mod_module_eval, -1);
1822  rb_define_method(rb_cModule, "class_eval", rb_mod_module_eval, -1);
1823 
1824  rb_define_global_function("caller", rb_f_caller, -1);
1825 }
1826 
VALUE rb_f_public_send(int argc, VALUE *argv, VALUE recv)
Definition: vm_eval.c:767
const rb_block_t * passed_block
Definition: vm_core.h:411
VALUE rb_vm_call(rb_thread_t *th, VALUE recv, VALUE id, int argc, const VALUE *argv, const rb_method_entry_t *me)
Definition: vm_eval.c:152
#define RSTRING_LEN(string)
Definition: generator.h:45
rb_control_frame_t * cfp
Definition: vm_core.h:400
#define T_SYMBOL
Definition: ruby.h:430
#define T_OBJECT
Definition: ruby.h:413
VALUE rb_ary_unshift(VALUE ary, VALUE item)
Definition: array.c:939
#define UNDEFINED_METHOD_ENTRY_P(me)
Definition: method.h:88
VALUE rb_make_backtrace(void)
Definition: vm_eval.c:1657
static VALUE vm_search_normal_superclass(VALUE klass, VALUE recv)
VALUE rb_ary_new4(long n, const VALUE *elts)
Definition: array.c:366
static int vm_collect_local_variables_in_heap(rb_thread_t *th, VALUE *dfp, VALUE ary)
#define RUBY_EVENT_C_RETURN
Definition: ruby.h:1409
void rb_bug(const char *fmt,...)
Definition: error.c:265
rb_method_type_t type
Definition: method.h:60
VALUE * argv
Definition: vm_eval.c:957
#define FALSE
Definition: nkf.h:185
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:65
static VALUE iterate_method(VALUE obj)
Definition: vm_eval.c:961
static VALUE rb_call0(VALUE recv, ID mid, int argc, const VALUE *argv, call_type scope, VALUE self)
Definition: vm_eval.c:225
static VALUE rb_vm_set_finish_env(rb_thread_t *th)
static rb_control_frame_t * vm_get_ruby_level_caller_cfp(rb_thread_t *th, rb_control_frame_t *cfp)
Definition: vm.c:181
int i
Definition: win32ole.c:776
VALUE rb_current_realfilepath(void)
Definition: vm_eval.c:1782
VALUE rb_mod_module_eval(int argc, VALUE *argv, VALUE mod)
Definition: vm_eval.c:1410
#define T_FIXNUM
Definition: ruby.h:425
VALUE rb_yield_values(int n,...)
Definition: vm_eval.c:792
#define T_MATCH
Definition: ruby.h:429
static void stack_check(void)
Definition: vm_eval.c:196
static VALUE check_funcall(VALUE recv, ID mid, int argc, VALUE *argv)
Definition: vm_eval.c:267
#define NUM2INT(x)
Definition: ruby.h:536
#define TAG_THROW
Definition: eval_intern.h:158
#define VM_FRAME_MAGIC_CFUNC
Definition: vm_core.h:577
static VALUE send_internal(int argc, const VALUE *argv, VALUE recv, call_type scope)
Definition: vm_eval.c:715
static VALUE vm_call0(rb_thread_t *th, VALUE recv, VALUE id, int argc, const VALUE *argv, const rb_method_entry_t *me)
Definition: vm_eval.c:35
void rb_throw(const char *tag, VALUE val)
Definition: vm_eval.c:1488
#define RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)
Definition: vm_core.h:611
#define GetProcPtr(obj, ptr)
Definition: vm_core.h:523
rb_method_flag_t flag
Definition: method.h:76
VALUE rb_eval_string_protect(const char *str, int *state)
Definition: vm_eval.c:1166
VALUE rb_yield_splat(VALUE values)
Definition: vm_eval.c:820
#define CLASS_OF(v)
Definition: ruby.h:376
rb_block_t block
Definition: vm_core.h:544
union rb_method_definition_struct::@42 body
#define T_MODULE
Definition: ruby.h:416
VALUE rb_str_cat(VALUE, const char *, long)
Definition: string.c:1881
VALUE rb_call_super(int argc, const VALUE *argv)
Definition: vm_eval.c:189
#define Qtrue
Definition: ruby.h:366
rb_iseq_t * iseq
Definition: vm_core.h:350
#define TAG_BREAK
Definition: eval_intern.h:153
#define GET_THROWOBJ_CATCH_POINT(obj)
Definition: eval_intern.h:170
const int id
Definition: nkf.c:209
static void raise_method_missing(rb_thread_t *th, int argc, const VALUE *argv, VALUE obj, int last_call_status)
Definition: vm_eval.c:506
void rb_define_private_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1221
ID rb_frame_this_func(void)
Definition: eval.c:801
#define sysstack_error
Definition: vm_core.h:681
VALUE rb_eTypeError
Definition: error.c:467
VALUE rb_f_eval(int argc, VALUE *argv, VALUE self)
Definition: vm_eval.c:1130
VALUE rb_name_err_mesg_new(VALUE obj, VALUE mesg, VALUE recv, VALUE method)
Definition: error.c:906
#define TH_JUMP_TAG(th, st)
Definition: eval_intern.h:133
#define T_RATIONAL
Definition: ruby.h:431
static VALUE check_funcall_failed(struct rescue_funcall_args *args, VALUE e)
Definition: vm_eval.c:258
VALUE rb_ary_push(VALUE ary, VALUE item)
Definition: array.c:740
int rb_backtrace_each(rb_backtrace_iter_func *iter, void *arg)
Definition: vm_eval.c:1682
VALUE rb_ary_tmp_new(long capa)
Definition: array.c:380
VALUE rb_each(VALUE obj)
Definition: vm_eval.c:983
#define RUBY_VM_GET_BLOCK_PTR_IN_CFP(cfp)
Definition: vm_core.h:624
VALUE rb_catch_obj(VALUE tag, VALUE(*func)(), VALUE data)
Definition: vm_eval.c:1558
int local_table_size
Definition: vm_core.h:183
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *state)
Definition: eval.c:704
#define RSTRING_PTR(string)
Definition: generator.h:42
#define PRIxVALUE
Definition: ruby.h:130
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:1574
#define VM_FRAME_TYPE(cfp)
Definition: vm_core.h:585
static VALUE rb_yield_0(int argc, const VALUE *argv)
Definition: vm_eval.c:775
void rb_str_update(VALUE, long, long, VALUE)
Definition: string.c:3342
VALUE rb_ary_clear(VALUE ary)
Definition: array.c:2870
#define new_args(f, o, r, p, b)
Definition: ripper.c:678
ID called_id
Definition: method.h:79
#define TH_EXEC_TAG()
Definition: eval_intern.h:128
VALUE rb_obj_is_kind_of(VALUE, VALUE)
Definition: object.c:525
#define T_HASH
Definition: ruby.h:421
#define RARRAY_LEN(ARRAY)
Definition: generator.h:39
size_t stack_max
Definition: vm_core.h:224
VALUE rb_eSecurityError
Definition: error.c:476
void Init_vm_eval(void)
Definition: vm_eval.c:1792
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:1551
static VALUE catch_i(VALUE tag, VALUE data)
Definition: vm_eval.c:1494
static int print_backtrace(void *arg, VALUE file, int line, VALUE method)
Definition: vm_eval.c:1635
#define T_ARRAY
Definition: ruby.h:420
#define TAG_RAISE
Definition: eval_intern.h:157
#define GetEnvPtr(obj, ptr)
Definition: vm_core.h:536
#define PUSH_TAG()
Definition: eval_intern.h:125
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
Definition: class.c:1371
VALUE env
Definition: vm_core.h:551
VALUE rb_eval_string_wrap(const char *str, int *state)
Definition: vm_eval.c:1172
#define NOEX_OK
Definition: vm_eval.c:208
#define T_UNDEF
Definition: ruby.h:433
rb_control_frame_t * rb_vm_get_ruby_level_next_cfp(rb_thread_t *th, rb_control_frame_t *cfp)
Definition: vm.c:169
unsigned short line_no
Definition: vm_core.h:553
#define CHECK_STACK_OVERFLOW(cfp, margin)
Definition: eval_intern.h:177
#define ID2SYM(i)
Definition: cparse.c:63
const rb_method_entry_t * me
Definition: vm_core.h:343
#define OBJ_TAINTED(x)
Definition: ruby.h:963
const char * rb_obj_classname(VALUE)
Definition: variable.c:318
#define GET_THREAD()
Definition: vm_core.h:690
static rb_control_frame_t * vm_push_frame(rb_thread_t *th, const rb_iseq_t *iseq, VALUE type, VALUE self, VALUE specval, const VALUE *pc, VALUE *sp, VALUE *lfp, int local_size)
Definition: vm_insnhelper.c:26
Definition: ripper.y:236
VALUE rb_check_funcall(VALUE recv, ID mid, int argc, VALUE *argv)
Definition: vm_eval.c:312
void rb_exc_raise(VALUE mesg)
Definition: eval.c:460
int args
Definition: win32ole.c:777
#define idRespond_to
Definition: ripper.c:298
VALUE rb_singleton_class(VALUE obj)
Returns the singleton class of obj.
Definition: class.c:1315
VALUE rb_eNameError
Definition: error.c:472
#define TH_POP_TAG()
Definition: eval_intern.h:118
rb_method_cfunc_t cfunc
Definition: method.h:64
#define RUBY_VM_CHECK_INTS()
Definition: vm_core.h:727
RUBY_EXTERN VALUE rb_cBinding
Definition: ruby.h:1249
VALUE rb_class_new_instance(int, VALUE *, VALUE)
Definition: object.c:1638
static VALUE rb_f_local_variables(void)
Definition: vm_eval.c:1701
int rb_block_given_p(void)
Definition: eval.c:604
#define EXEC_TAG()
Definition: eval_intern.h:130
static VALUE rb_f_catch(int argc, VALUE *argv)
Definition: vm_eval.c:1537
#define NEW_IFUNC(f, c)
VALUE rb_mod_module_exec(int argc, VALUE *argv, VALUE mod)
Definition: vm_eval.c:1436
static void vm_setup_method(rb_thread_t *th, rb_control_frame_t *cfp, VALUE recv, int argc, const rb_block_t *blockptr, VALUE flag, const rb_method_entry_t *me)
void rb_raise_method_missing(rb_thread_t *th, int argc, VALUE *argv, VALUE obj, int call_status)
Definition: vm_eval.c:601
RUBY_EXTERN VALUE rb_cObject
Definition: ruby.h:1246
VALUE rb_eRuntimeError
Definition: error.c:466
VALUE filepath
Definition: vm_core.h:170
#define SYM2ID(v)
Definition: cparse.c:66
#define T_NIL
Definition: ruby.h:412
#define GetBindingPtr(obj, ptr)
Definition: vm_core.h:547
RUBY_EXTERN VALUE rb_cBasicObject
Definition: ruby.h:1245
VALUE rb_funcall(VALUE recv, ID mid, int n,...)
Calls a method.
Definition: vm_eval.c:638
VALUE rb_funcall2(VALUE recv, ID mid, int argc, const VALUE *argv)
Calls a method.
Definition: vm_eval.c:669
VALUE rb_ary_new(void)
Definition: array.c:339
#define T_TRUE
Definition: ruby.h:426
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:396
#define NOEX_MISSING
Definition: vm_eval.c:503
#define RCLASS_SUPER(c)
Definition: ripper.y:55
static VALUE rb_f_caller(int argc, VALUE *argv)
Definition: vm_eval.c:1617
RUBY_EXTERN VALUE rb_mKernel
Definition: ruby.h:1234
#define JUMP_TAG(st)
Definition: eval_intern.h:137
#define NIL_P(v)
Definition: ruby.h:374
int ruby_stack_check(void)
Definition: gc.c:1484
#define PASS_PASSED_BLOCK()
Definition: eval_intern.h:12
#define UNLIKELY(x)
Definition: vm_core.h:111
VALUE rb_eNoMethodError
Definition: error.c:475
VALUE rb_get_backtrace(VALUE info)
Definition: eval_error.c:53
VALUE tag
Definition: vm_core.h:371
#define OBJ_FROZEN(x)
Definition: ruby.h:969
static const char * rb_type_str(enum ruby_value_type type)
Definition: vm_eval.c:318
VALUE top_self
Definition: vm_core.h:417
#define T_FLOAT
Definition: ruby.h:417
int rb_method_entry_arity(const rb_method_entry_t *me)
Definition: proc.c:1576
#define TYPE(x)
Definition: ruby.h:441
int argc
Definition: ruby.c:120
#define Qfalse
Definition: ruby.h:365
#define rb_sourcefile()
Definition: tcltklib.c:93
#define ALLOCA_N(type, n)
Definition: ruby.h:1038
Definition: method.h:75
RUBY_EXTERN VALUE rb_cModule
Definition: ruby.h:1265
#define T_BIGNUM
Definition: ruby.h:423
VALUE rb_vm_invoke_proc(rb_thread_t *th, rb_proc_t *proc, VALUE self, int argc, const VALUE *argv, const rb_block_t *blockptr)
Definition: vm.c:674
rb_block_t * base_block
Definition: vm_core.h:421
#define MEMCPY(p1, p2, type, n)
Definition: ruby.h:1053
#define T_NODE
Definition: ruby.h:434
#define ID_ALLOCATOR
Definition: intern.h:54
VALUE rb_obj_alloc(VALUE)
Definition: object.c:1600
int err
Definition: win32.c:78
#define RUBY_EVENT_C_CALL
Definition: ruby.h:1408
arg
Definition: ripper.y:1283
RUBY_FUNC_EXPORTED VALUE rb_vm_make_env_object(rb_thread_t *th, rb_control_frame_t *cfp)
Definition: vm.c:474
static VALUE rb_f_loop(VALUE self)
Definition: vm_eval.c:860
#define POP_TAG()
Definition: eval_intern.h:126
#define T_COMPLEX
Definition: ruby.h:432
void rb_throw_obj(VALUE tag, VALUE value)
Definition: vm_eval.c:1464
ID * local_table
Definition: vm_core.h:182
static VALUE call_cfunc(VALUE(*func)(), VALUE recv, int len, int argc, const VALUE *argv)
VALUE rb_vm_top_self()
Definition: vm.c:2255
VALUE(* func)(ANYARGS)
Definition: method.h:48
VALUE klass
Definition: method.h:80
#define GC_GUARDED_PTR(p)
Definition: vm_core.h:607
#define init(n)
Definition: init.c:3
VALUE rb_const_get(VALUE, ID)
Definition: variable.c:1635
SSL_METHOD *(* func)(void)
Definition: ossl_ssl.c:104
#define T_DATA
Definition: ruby.h:428
static VALUE vm_exec(rb_thread_t *th)
#define RB_GC_GUARD(object)
Definition: generator.h:50
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:276
VALUE rb_eval_string(const char *str)
Definition: vm_eval.c:1160
VALUE rb_iterate(VALUE(*it_proc)(VALUE), VALUE data1, VALUE(*bl_proc)(ANYARGS), VALUE data2)
Definition: vm_eval.c:873
int rb_scan_args(int argc, const VALUE *argv, const char *fmt,...)
Definition: class.c:1415
#define rb_thread_raised_set(th, f)
Definition: eval_intern.h:193
VALUE rb_ivar_set(VALUE, ID, VALUE)
Definition: variable.c:1038
VALUE rb_f_send(int argc, VALUE *argv, VALUE recv)
Definition: vm_eval.c:750
unsigned long ID
Definition: ruby.h:89
#define NULL
static VALUE vm_call_bmethod(rb_thread_t *th, VALUE recv, int argc, const VALUE *argv, const rb_block_t *blockptr, const rb_method_entry_t *me)
#define T_STRUCT
Definition: ruby.h:422
#define Qnil
Definition: ruby.h:367
static VALUE eval_under(VALUE under, VALUE self, VALUE src, const char *file, int line)
Definition: vm_eval.c:1263
VALUE rb_eStopIteration
Definition: enumerator.c:102
int type
Definition: tcltklib.c:107
#define BUILTIN_TYPE(x)
Definition: ruby.h:438
unsigned long VALUE
Definition: ruby.h:88
static VALUE result
Definition: nkf.c:40
static VALUE rb_f_throw(int argc, VALUE *argv)
Definition: vm_eval.c:1454
static void vm_pop_frame(rb_thread_t *th)
Definition: vm_insnhelper.c:81
#define RBASIC(obj)
Definition: ruby.h:904
VALUE rb_funcall3(VALUE recv, ID mid, int argc, const VALUE *argv)
Calls a method.
Definition: vm_eval.c:684
const char * rb_class2name(VALUE)
Definition: variable.c:311
void rb_extend_object(VALUE obj, VALUE module)
Definition: eval.c:888
VALUE rb_obj_instance_eval(int argc, VALUE *argv, VALUE self)
Definition: vm_eval.c:1340
static VALUE vm_yield_with_cref(rb_thread_t *th, int argc, const VALUE *argv, const NODE *cref)
static VALUE vm_call_super(rb_thread_t *th, int argc, const VALUE *argv)
Definition: vm_eval.c:159
VALUE rb_rescue2(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*r_proc)(ANYARGS), VALUE data2,...)
Definition: eval.c:634
#define TH_PUSH_TAG(th)
Definition: eval_intern.h:111
#define RARRAY_PTR(ARRAY)
Definition: generator.h:36
int rb_backtrace_iter_func(void *, VALUE, int, VALUE)
Definition: vm_core.h:670
#define RARRAY_LENINT(ary)
Definition: ruby.h:718
VALUE flags
Definition: ripper.y:237
VALUE rb_str_dup(VALUE)
Definition: string.c:905
call_type
Definition: vm_eval.c:25
ruby_value_type
Definition: ruby.h:378
VALUE rb_block_call(VALUE obj, ID mid, int argc, VALUE *argv, VALUE(*bl_proc)(ANYARGS), VALUE data2)
Definition: vm_eval.c:970
rb_method_entry_t * rb_method_entry(VALUE klass, ID id)
Definition: vm_method.c:416
#define NEW_THROW_OBJECT(val, pt, st)
Definition: eval_intern.h:162
int rb_respond_to(VALUE, ID)
Definition: vm_method.c:1231
#define IMMEDIATE_P(x)
Definition: ruby.h:343
void rb_set_safe_level_force(int)
Definition: safe.c:34
enum rb_thread_status status
Definition: vm_core.h:428
void rb_backtrace(void)
Definition: vm_eval.c:1651
#define va_init_list(a, b)
Definition: tcltklib.c:57
static VALUE loop_i(void)
Definition: vm_eval.c:832
#define EXEC_EVENT_HOOK(th, flag, self, id, klass)
Definition: vm_core.h:743
#define SYMBOL_P(v)
Definition: cparse.c:69
VALUE rb_thread_backtrace(VALUE thval)
Definition: vm_eval.c:1663
#define INT2FIX(i)
Definition: ruby.h:225
VALUE top_wrapper
Definition: vm_core.h:418
int rb_sourceline(void)
Definition: vm.c:888
VALUE rb_obj_instance_exec(int argc, VALUE *argv, VALUE self)
Definition: vm_eval.c:1372
rb_block_t block
Definition: vm_core.h:527
VALUE rb_module_new(void)
Definition: class.c:565
ID rb_frame_callee(void)
Definition: eval.c:807
int mild_compile_error
Definition: vm_core.h:450
VALUE rb_funcall_with_block(VALUE recv, ID mid, int argc, const VALUE *argv, VALUE pass_procval)
Definition: vm_eval.c:698
rb_method_definition_t * def
Definition: method.h:78
#define ANYARGS
Definition: defines.h:57
VALUE rb_check_array_type(VALUE ary)
Definition: array.c:472
static VALUE eval_string_with_cref(VALUE self, VALUE src, VALUE scope, NODE *cref, const char *volatile file, volatile int line)
Definition: vm_eval.c:989
static int vm_backtrace_each(rb_thread_t *th, int lev, void(*init)(void *), rb_backtrace_iter_func *iter, void *arg)
static rb_method_entry_t * rb_search_method_entry(VALUE recv, ID mid)
Definition: vm_eval.c:353
static VALUE yield_under(VALUE under, VALUE self, VALUE values)
Definition: vm_eval.c:1239
#define RTEST(v)
Definition: ruby.h:373
#define T_STRING
Definition: ruby.h:418
static VALUE vm_backtrace(rb_thread_t *th, int lev)
int rb_method_basic_definition_p(VALUE, ID)
Definition: vm_method.c:1194
v
Definition: win32ole.c:790
#define T_FALSE
Definition: ruby.h:427
#define T_FILE
Definition: ruby.h:424
void rb_trap_restore_mask(void)
Definition: signal.c:897
rb_iseq_t * iseq
Definition: vm_core.h:336
static VALUE eval_string(VALUE self, VALUE src, VALUE scope, const char *file, int line)
Definition: vm_eval.c:1106
VALUE rb_apply(VALUE recv, ID mid, VALUE args)
Calls a method.
Definition: vm_eval.c:617
static VALUE rb_call(VALUE recv, ID mid, int argc, const VALUE *argv, call_type scope)
Definition: vm_eval.c:454
VALUE rb_yield_values2(int argc, const VALUE *argv)
Definition: vm_eval.c:814
VALUE rb_funcall_passing_block(VALUE recv, ID mid, int argc, const VALUE *argv)
Definition: vm_eval.c:690
#define NOEX_SAFE(n)
Definition: method.h:28
static VALUE specific_eval(int argc, VALUE *argv, VALUE klass, VALUE self)
Definition: vm_eval.c:1278
#define GetThreadPtr(obj, ptr)
Definition: vm_core.h:356
enum rb_method_definition_struct::@42::method_optimized_type optimize_type
#define rb_thread_raised_p(th, f)
Definition: eval_intern.h:195
#define RETURN_ENUMERATOR(obj, argc, argv)
Definition: intern.h:210
#define SafeStringValue(v)
Definition: ruby.h:472
VALUE rb_eNotImpError
Definition: error.c:477
VALUE rb_f_block_given_p(void)
Definition: vm_eval.c:1765
#define T_CLASS
Definition: ruby.h:414
#define rb_safe_level()
Definition: tcltklib.c:90
const char * name
Definition: nkf.c:208
NORETURN(static void raise_method_missing(rb_thread_t *th, int argc, const VALUE *argv, VALUE obj, int call_status))
#define GetISeqPtr(obj, ptr)
Definition: vm_core.h:146
VALUE rb_yield(VALUE val)
Definition: vm_eval.c:781
const char * rb_id2name(ID id)
Definition: ripper.c:15493
#define StringValuePtr(v)
Definition: ruby.h:467
struct rb_vm_tag * tag
Definition: vm_core.h:446
VALUE rb_inspect(VALUE)
Definition: object.c:372
struct rb_vm_tag * prev
Definition: vm_core.h:373
#define PASS_PASSED_BLOCK_TH(th)
Definition: eval_intern.h:7
static VALUE rb_method_missing(int argc, const VALUE *argv, VALUE obj)
Definition: vm_eval.c:496
static void vm_set_eval_stack(rb_thread_t *th, VALUE iseqval, const NODE *cref)
VALUE retval
Definition: vm_core.h:372
#define GC_GUARDED_PTR_REF(p)
Definition: vm_core.h:608
#define CONST_ID(var, str)
Definition: ruby.h:1127
#define SPECIAL_CONST_P(x)
Definition: ruby.h:953
state
Definition: gb18030.c:213
#define rb_intern(str)
VALUE filename
Definition: vm_core.h:552
#define T_ZOMBIE
Definition: ruby.h:435
#define NODE_FL_CREF_PUSHED_BY_EVAL
#define mod(x, y)
#define T_NONE
Definition: ruby.h:411
#define env
VALUE rb_eval_cmd(VALUE cmd, VALUE arg, int level)
Definition: vm_eval.c:1199
#define Qundef
Definition: ruby.h:368
#define T_ICLASS
Definition: ruby.h:415
int method_missing_reason
Definition: vm_core.h:488
#define RNODE(obj)
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1209
VALUE rb_str_append(VALUE, VALUE)
Definition: string.c:2039
VALUE rb_iseq_disasm(VALUE self)
Definition: iseq.c:923
VALUE rb_str_new2(const char *)
static VALUE method_missing(VALUE obj, ID id, int argc, const VALUE *argv, int call_status)
Definition: vm_eval.c:564
ID rb_to_id(VALUE)
Definition: string.c:7732
VALUE rb_eArgError
Definition: error.c:468
#define T_REGEXP
Definition: ruby.h:419
VALUE rb_obj_clone(VALUE)
Definition: object.c:279
VALUE rb_iseq_compile(VALUE src, VALUE file, VALUE line)
Definition: iseq.c:575
static VALUE check_funcall_exec(struct rescue_funcall_args *args)
Definition: vm_eval.c:247
VALUE rb_attr_get(VALUE, ID)
Definition: variable.c:1032
#define type_case(t)
char ** argv
Definition: ruby.c:121
#define TAG_RETRY
Definition: eval_intern.h:155
#define StringValue(v)
Definition: ruby.h:466