Ruby  2.0.0p645(2015-04-13revision50299)
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  RB_GC_GUARD(tmp);
981  return v;
982 }
983 
984 static VALUE
985 loop_i(void)
986 {
987  for (;;) {
988  rb_yield_0(0, 0);
989  }
990  return Qnil;
991 }
992 
993 static VALUE
995 {
996  return DBL2NUM(INFINITY);
997 }
998 
999 /*
1000  * call-seq:
1001  * loop { block }
1002  * loop -> an_enumerator
1003  *
1004  * Repeatedly executes the block.
1005  *
1006  * If no block is given, an enumerator is returned instead.
1007  *
1008  * loop do
1009  * print "Input: "
1010  * line = gets
1011  * break if !line or line =~ /^qQ/
1012  * # ...
1013  * end
1014  *
1015  * StopIteration raised in the block breaks the loop.
1016  */
1017 
1018 static VALUE
1020 {
1022  rb_rescue2(loop_i, (VALUE)0, 0, 0, rb_eStopIteration, (VALUE)0);
1023  return Qnil; /* dummy */
1024 }
1025 
1026 #if VMDEBUG
1027 static const char *
1028 vm_frametype_name(const rb_control_frame_t *cfp);
1029 #endif
1030 
1031 VALUE
1032 rb_iterate(VALUE (* it_proc) (VALUE), VALUE data1,
1033  VALUE (* bl_proc) (ANYARGS), VALUE data2)
1034 {
1035  int state;
1036  volatile VALUE retval = Qnil;
1037  NODE *node = NEW_IFUNC(bl_proc, data2);
1038  rb_thread_t *th = GET_THREAD();
1039  rb_control_frame_t *volatile cfp = th->cfp;
1040 
1041  node->nd_aid = rb_frame_this_func();
1042  TH_PUSH_TAG(th);
1043  state = TH_EXEC_TAG();
1044  if (state == 0) {
1045  iter_retry:
1046  {
1047  rb_block_t *blockptr;
1048  if (bl_proc) {
1049  blockptr = RUBY_VM_GET_BLOCK_PTR_IN_CFP(th->cfp);
1050  blockptr->iseq = (void *)node;
1051  blockptr->proc = 0;
1052  }
1053  else {
1054  blockptr = VM_CF_BLOCK_PTR(th->cfp);
1055  }
1056  th->passed_block = blockptr;
1057  }
1058  retval = (*it_proc) (data1);
1059  }
1060  else {
1061  VALUE err = th->errinfo;
1062  if (state == TAG_BREAK) {
1063  VALUE *escape_ep = GET_THROWOBJ_CATCH_POINT(err);
1064  VALUE *cep = cfp->ep;
1065 
1066  if (cep == escape_ep) {
1067  state = 0;
1068  th->state = 0;
1069  th->errinfo = Qnil;
1070  retval = GET_THROWOBJ_VAL(err);
1071 
1072  rb_vm_rewind_cfp(th, cfp);
1073  }
1074  else{
1075  /* SDR(); printf("%p, %p\n", cdfp, escape_dfp); */
1076  }
1077  }
1078  else if (state == TAG_RETRY) {
1079  VALUE *escape_ep = GET_THROWOBJ_CATCH_POINT(err);
1080  VALUE *cep = cfp->ep;
1081 
1082  if (cep == escape_ep) {
1083  rb_vm_rewind_cfp(th, cfp);
1084 
1085  state = 0;
1086  th->state = 0;
1087  th->errinfo = Qnil;
1088  goto iter_retry;
1089  }
1090  }
1091  }
1092  TH_POP_TAG();
1093 
1094  switch (state) {
1095  case 0:
1096  break;
1097  default:
1098  TH_JUMP_TAG(th, state);
1099  }
1100  return retval;
1101 }
1102 
1106  int argc;
1108 };
1109 
1110 static VALUE
1112 {
1113  const struct iter_method_arg * arg =
1114  (struct iter_method_arg *) obj;
1115 
1116  return rb_call(arg->obj, arg->mid, arg->argc, arg->argv, CALL_FCALL);
1117 }
1118 
1119 VALUE
1121  VALUE (*bl_proc) (ANYARGS), VALUE data2)
1122 {
1123  struct iter_method_arg arg;
1124 
1125  arg.obj = obj;
1126  arg.mid = mid;
1127  arg.argc = argc;
1128  arg.argv = argv;
1129  return rb_iterate(iterate_method, (VALUE)&arg, bl_proc, data2);
1130 }
1131 
1132 static VALUE
1134 {
1135  const struct iter_method_arg * arg =
1136  (struct iter_method_arg *) obj;
1137 
1138  return rb_check_funcall(arg->obj, arg->mid, arg->argc, arg->argv);
1139 }
1140 
1141 VALUE
1142 rb_check_block_call(VALUE obj, ID mid, int argc, VALUE * argv,
1143  VALUE (*bl_proc) (ANYARGS), VALUE data2)
1144 {
1145  struct iter_method_arg arg;
1146 
1147  arg.obj = obj;
1148  arg.mid = mid;
1149  arg.argc = argc;
1150  arg.argv = argv;
1151  return rb_iterate(iterate_check_method, (VALUE)&arg, bl_proc, data2);
1152 }
1153 
1154 VALUE
1156 {
1157  return rb_call(obj, idEach, 0, 0, CALL_FCALL);
1158 }
1159 
1160 static VALUE
1161 eval_string_with_cref(VALUE self, VALUE src, VALUE scope, NODE *cref, volatile VALUE file, volatile int line)
1162 {
1163  int state;
1164  VALUE result = Qundef;
1165  VALUE envval;
1166  rb_thread_t *th = GET_THREAD();
1167  rb_env_t *env = NULL;
1168  rb_block_t block, *base_block;
1169  volatile int parse_in_eval;
1170  volatile int mild_compile_error;
1171 
1172  if (file == 0) {
1173  file = rb_sourcefilename();
1174  line = rb_sourceline();
1175  }
1176 
1177  parse_in_eval = th->parse_in_eval;
1178  mild_compile_error = th->mild_compile_error;
1179  TH_PUSH_TAG(th);
1180  if ((state = TH_EXEC_TAG()) == 0) {
1181  rb_binding_t *bind = 0;
1182  rb_iseq_t *iseq;
1183  volatile VALUE iseqval;
1184  VALUE absolute_path = Qnil;
1185  VALUE fname;
1186 
1187  if (file != Qundef) {
1188  absolute_path = file;
1189  }
1190 
1191  if (!NIL_P(scope)) {
1192  if (rb_obj_is_kind_of(scope, rb_cBinding)) {
1193  GetBindingPtr(scope, bind);
1194  envval = bind->env;
1195  if (NIL_P(absolute_path) && !NIL_P(bind->path)) {
1196  file = bind->path;
1197  line = bind->first_lineno;
1198  absolute_path = rb_current_realfilepath();
1199  }
1200  }
1201  else {
1203  "wrong argument type %s (expected Binding)",
1204  rb_obj_classname(scope));
1205  }
1206  GetEnvPtr(envval, env);
1207  base_block = &env->block;
1208  }
1209  else {
1211 
1212  if (cfp != 0) {
1213  block = *RUBY_VM_GET_BLOCK_PTR_IN_CFP(cfp);
1214  base_block = &block;
1215  base_block->self = self;
1216  base_block->iseq = cfp->iseq; /* TODO */
1217  }
1218  else {
1219  rb_raise(rb_eRuntimeError, "Can't eval on top of Fiber or Thread");
1220  }
1221  }
1222 
1223  if ((fname = file) == Qundef) {
1224  fname = rb_usascii_str_new_cstr("(eval)");
1225  }
1226 
1227  /* make eval iseq */
1228  th->parse_in_eval++;
1229  th->mild_compile_error++;
1230  iseqval = rb_iseq_compile_with_option(src, fname, absolute_path, INT2FIX(line), base_block, Qnil);
1231  th->mild_compile_error--;
1232  th->parse_in_eval--;
1233 
1234  vm_set_eval_stack(th, iseqval, cref, base_block);
1235  th->cfp->klass = CLASS_OF(base_block->self);
1236 
1237  if (0) { /* for debug */
1238  VALUE disasm = rb_iseq_disasm(iseqval);
1239  printf("%s\n", StringValuePtr(disasm));
1240  }
1241 
1242  /* save new env */
1243  GetISeqPtr(iseqval, iseq);
1244  if (bind && iseq->local_table_size > 0) {
1245  bind->env = rb_vm_make_env_object(th, th->cfp);
1246  }
1247 
1248  /* kick */
1250  result = vm_exec(th);
1251  }
1252  TH_POP_TAG();
1253  th->mild_compile_error = mild_compile_error;
1254  th->parse_in_eval = parse_in_eval;
1255 
1256  if (state) {
1257  if (state == TAG_RAISE) {
1258  VALUE errinfo = th->errinfo;
1259  if (file == Qundef) {
1260  VALUE mesg, errat, bt2;
1261  ID id_mesg;
1262 
1263  CONST_ID(id_mesg, "mesg");
1264  errat = rb_get_backtrace(errinfo);
1265  mesg = rb_attr_get(errinfo, id_mesg);
1266  if (!NIL_P(errat) && RB_TYPE_P(errat, T_ARRAY) &&
1267  (bt2 = vm_backtrace_str_ary(th, 0, 0), RARRAY_LEN(bt2) > 0)) {
1268  if (!NIL_P(mesg) && RB_TYPE_P(mesg, T_STRING) && !RSTRING_LEN(mesg)) {
1269  if (OBJ_FROZEN(mesg)) {
1270  VALUE m = rb_str_cat(rb_str_dup(RARRAY_PTR(errat)[0]), ": ", 2);
1271  rb_ivar_set(errinfo, id_mesg, rb_str_append(m, mesg));
1272  }
1273  else {
1274  rb_str_update(mesg, 0, 0, rb_str_new2(": "));
1275  rb_str_update(mesg, 0, 0, RARRAY_PTR(errat)[0]);
1276  }
1277  }
1278  RARRAY_PTR(errat)[0] = RARRAY_PTR(bt2)[0];
1279  }
1280  }
1281  rb_exc_raise(errinfo);
1282  }
1283  JUMP_TAG(state);
1284  }
1285  return result;
1286 }
1287 
1288 static VALUE
1289 eval_string(VALUE self, VALUE src, VALUE scope, VALUE file, int line)
1290 {
1291  return eval_string_with_cref(self, src, scope, 0, file, line);
1292 }
1293 
1294 /*
1295  * call-seq:
1296  * eval(string [, binding [, filename [,lineno]]]) -> obj
1297  *
1298  * Evaluates the Ruby expression(s) in <em>string</em>. If
1299  * <em>binding</em> is given, which must be a <code>Binding</code>
1300  * object, the evaluation is performed in its context. If the
1301  * optional <em>filename</em> and <em>lineno</em> parameters are
1302  * present, they will be used when reporting syntax errors.
1303  *
1304  * def get_binding(str)
1305  * return binding
1306  * end
1307  * str = "hello"
1308  * eval "str + ' Fred'" #=> "hello Fred"
1309  * eval "str + ' Fred'", get_binding("bye") #=> "bye Fred"
1310  */
1311 
1312 VALUE
1313 rb_f_eval(int argc, VALUE *argv, VALUE self)
1314 {
1315  VALUE src, scope, vfile, vline;
1316  VALUE file = Qundef;
1317  int line = 1;
1318 
1319  rb_scan_args(argc, argv, "13", &src, &scope, &vfile, &vline);
1320  if (rb_safe_level() >= 4) {
1321  StringValue(src);
1322  if (!NIL_P(scope) && !OBJ_TAINTED(scope)) {
1324  "Insecure: can't modify trusted binding");
1325  }
1326  }
1327  else {
1328  SafeStringValue(src);
1329  }
1330  if (argc >= 3) {
1331  StringValue(vfile);
1332  }
1333  if (argc >= 4) {
1334  line = NUM2INT(vline);
1335  }
1336 
1337  if (!NIL_P(vfile))
1338  file = vfile;
1339  return eval_string(self, src, scope, file, line);
1340 }
1341 
1343 VALUE
1344 ruby_eval_string_from_file(const char *str, const char *filename)
1345 {
1346  VALUE file = filename ? rb_str_new_cstr(filename) : 0;
1347  return eval_string(rb_vm_top_self(), rb_str_new2(str), Qnil, file, 1);
1348 }
1349 
1353 };
1354 
1355 static VALUE
1357 {
1358  const struct eval_string_from_file_arg *const arg = (struct eval_string_from_file_arg*)data;
1359  return eval_string(rb_vm_top_self(), arg->str, Qnil, arg->filename, 1);
1360 }
1361 
1362 VALUE
1363 ruby_eval_string_from_file_protect(const char *str, const char *filename, int *state)
1364 {
1365  struct eval_string_from_file_arg arg;
1366  arg.str = rb_str_new_cstr(str);
1367  arg.filename = filename ? rb_str_new_cstr(filename) : 0;
1368  return rb_protect((VALUE (*)(VALUE))eval_string_from_file_helper, (VALUE)&arg, state);
1369 }
1370 
1383 VALUE
1384 rb_eval_string(const char *str)
1385 {
1386  return ruby_eval_string_from_file(str, "eval");
1387 }
1388 
1399 VALUE
1401 {
1402  return rb_protect((VALUE (*)(VALUE))rb_eval_string, (VALUE)str, state);
1403 }
1404 
1416 VALUE
1417 rb_eval_string_wrap(const char *str, int *state)
1418 {
1419  int status;
1420  rb_thread_t *th = GET_THREAD();
1421  VALUE self = th->top_self;
1422  VALUE wrapper = th->top_wrapper;
1423  VALUE val;
1424 
1425  th->top_wrapper = rb_module_new();
1428 
1429  val = rb_eval_string_protect(str, &status);
1430 
1431  th->top_self = self;
1432  th->top_wrapper = wrapper;
1433 
1434  if (state) {
1435  *state = status;
1436  }
1437  else if (status) {
1438  JUMP_TAG(status);
1439  }
1440  return val;
1441 }
1442 
1443 VALUE
1445 {
1446  int state;
1447  VALUE val = Qnil; /* OK */
1448  volatile int safe = rb_safe_level();
1449 
1450  if (OBJ_TAINTED(cmd)) {
1451  level = 4;
1452  }
1453 
1454  if (!RB_TYPE_P(cmd, T_STRING)) {
1455  PUSH_TAG();
1456  rb_set_safe_level_force(level);
1457  if ((state = EXEC_TAG()) == 0) {
1458  val = rb_funcall2(cmd, rb_intern("call"), RARRAY_LENINT(arg),
1459  RARRAY_PTR(arg));
1460  }
1461  POP_TAG();
1462 
1464 
1465  if (state)
1466  JUMP_TAG(state);
1467  return val;
1468  }
1469 
1470  PUSH_TAG();
1471  if ((state = EXEC_TAG()) == 0) {
1472  val = eval_string(rb_vm_top_self(), cmd, Qnil, 0, 0);
1473  }
1474  POP_TAG();
1475 
1477  if (state) JUMP_TAG(state);
1478  return val;
1479 }
1480 
1481 /* block eval under the class/module context */
1482 
1483 static VALUE
1484 yield_under(VALUE under, VALUE self, VALUE values)
1485 {
1486  rb_thread_t *th = GET_THREAD();
1487  rb_block_t block, *blockptr;
1488  NODE *cref;
1489 
1490  if ((blockptr = VM_CF_BLOCK_PTR(th->cfp)) != 0) {
1491  block = *blockptr;
1492  block.self = self;
1493  VM_CF_LEP(th->cfp)[0] = VM_ENVVAL_BLOCK_PTR(&block);
1494  }
1495  cref = vm_cref_push(th, under, NOEX_PUBLIC, blockptr);
1497 
1498  if (values == Qundef) {
1499  return vm_yield_with_cref(th, 1, &self, cref);
1500  }
1501  else {
1502  return vm_yield_with_cref(th, RARRAY_LENINT(values), RARRAY_PTR(values), cref);
1503  }
1504 }
1505 
1506 VALUE
1507 rb_yield_refine_block(VALUE refinement, VALUE refinements)
1508 {
1509  rb_thread_t *th = GET_THREAD();
1510  rb_block_t block, *blockptr;
1511  NODE *cref;
1512 
1513  if ((blockptr = VM_CF_BLOCK_PTR(th->cfp)) != 0) {
1514  block = *blockptr;
1515  block.self = refinement;
1516  VM_CF_LEP(th->cfp)[0] = VM_ENVVAL_BLOCK_PTR(&block);
1517  }
1518  cref = vm_cref_push(th, refinement, NOEX_PUBLIC, blockptr);
1520  cref->nd_refinements = refinements;
1521 
1522  return vm_yield_with_cref(th, 0, NULL, cref);
1523 }
1524 
1525 /* string eval under the class/module context */
1526 static VALUE
1527 eval_under(VALUE under, VALUE self, VALUE src, VALUE file, int line)
1528 {
1529  NODE *cref = vm_cref_push(GET_THREAD(), under, NOEX_PUBLIC, NULL);
1530 
1531  if (SPECIAL_CONST_P(self) && !NIL_P(under)) {
1533  }
1534  if (rb_safe_level() >= 4) {
1535  StringValue(src);
1536  }
1537  else {
1538  SafeStringValue(src);
1539  }
1540 
1541  return eval_string_with_cref(self, src, Qnil, cref, file, line);
1542 }
1543 
1544 static VALUE
1545 specific_eval(int argc, VALUE *argv, VALUE klass, VALUE self)
1546 {
1547  if (rb_block_given_p()) {
1548  rb_check_arity(argc, 0, 0);
1549  return yield_under(klass, self, Qundef);
1550  }
1551  else {
1552  VALUE file = Qundef;
1553  int line = 1;
1554 
1555  rb_check_arity(argc, 1, 3);
1556  if (rb_safe_level() >= 4) {
1557  StringValue(argv[0]);
1558  }
1559  else {
1560  SafeStringValue(argv[0]);
1561  }
1562  if (argc > 2)
1563  line = NUM2INT(argv[2]);
1564  if (argc > 1) {
1565  file = argv[1];
1566  if (!NIL_P(file)) StringValue(file);
1567  }
1568  return eval_under(klass, self, argv[0], file, line);
1569  }
1570 }
1571 
1572 /*
1573  * call-seq:
1574  * obj.instance_eval(string [, filename [, lineno]] ) -> obj
1575  * obj.instance_eval {| | block } -> obj
1576  *
1577  * Evaluates a string containing Ruby source code, or the given block,
1578  * within the context of the receiver (_obj_). In order to set the
1579  * context, the variable +self+ is set to _obj_ while
1580  * the code is executing, giving the code access to _obj_'s
1581  * instance variables. In the version of <code>instance_eval</code>
1582  * that takes a +String+, the optional second and third
1583  * parameters supply a filename and starting line number that are used
1584  * when reporting compilation errors.
1585  *
1586  * class KlassWithSecret
1587  * def initialize
1588  * @secret = 99
1589  * end
1590  * end
1591  * k = KlassWithSecret.new
1592  * k.instance_eval { @secret } #=> 99
1593  */
1594 
1595 VALUE
1596 rb_obj_instance_eval(int argc, VALUE *argv, VALUE self)
1597 {
1598  VALUE klass;
1599 
1600  if (SPECIAL_CONST_P(self)) {
1601  klass = rb_special_singleton_class(self);
1602  }
1603  else {
1604  klass = rb_singleton_class(self);
1605  }
1606  return specific_eval(argc, argv, klass, self);
1607 }
1608 
1609 /*
1610  * call-seq:
1611  * obj.instance_exec(arg...) {|var...| block } -> obj
1612  *
1613  * Executes the given block within the context of the receiver
1614  * (_obj_). In order to set the context, the variable +self+ is set
1615  * to _obj_ while the code is executing, giving the code access to
1616  * _obj_'s instance variables. Arguments are passed as block parameters.
1617  *
1618  * class KlassWithSecret
1619  * def initialize
1620  * @secret = 99
1621  * end
1622  * end
1623  * k = KlassWithSecret.new
1624  * k.instance_exec(5) {|x| @secret+x } #=> 104
1625  */
1626 
1627 VALUE
1628 rb_obj_instance_exec(int argc, VALUE *argv, VALUE self)
1629 {
1630  VALUE klass;
1631 
1632  if (SPECIAL_CONST_P(self)) {
1633  klass = rb_special_singleton_class(self);
1634  }
1635  else {
1636  klass = rb_singleton_class(self);
1637  }
1638  return yield_under(klass, self, rb_ary_new4(argc, argv));
1639 }
1640 
1641 /*
1642  * call-seq:
1643  * mod.class_eval(string [, filename [, lineno]]) -> obj
1644  * mod.module_eval {|| block } -> obj
1645  *
1646  * Evaluates the string or block in the context of _mod_, except that when
1647  * a block is given, constant/class variable lookup is not affected. This
1648  * can be used to add methods to a class. <code>module_eval</code> returns
1649  * the result of evaluating its argument. The optional _filename_ and
1650  * _lineno_ parameters set the text for error messages.
1651  *
1652  * class Thing
1653  * end
1654  * a = %q{def hello() "Hello there!" end}
1655  * Thing.module_eval(a)
1656  * puts Thing.new.hello()
1657  * Thing.module_eval("invalid code", "dummy", 123)
1658  *
1659  * <em>produces:</em>
1660  *
1661  * Hello there!
1662  * dummy:123:in `module_eval': undefined local variable
1663  * or method `code' for Thing:Class
1664  */
1665 
1666 VALUE
1668 {
1669  return specific_eval(argc, argv, mod, mod);
1670 }
1671 
1672 /*
1673  * call-seq:
1674  * mod.module_exec(arg...) {|var...| block } -> obj
1675  * mod.class_exec(arg...) {|var...| block } -> obj
1676  *
1677  * Evaluates the given block in the context of the class/module.
1678  * The method defined in the block will belong to the receiver.
1679  *
1680  * class Thing
1681  * end
1682  * Thing.class_exec{
1683  * def hello() "Hello there!" end
1684  * }
1685  * puts Thing.new.hello()
1686  *
1687  * <em>produces:</em>
1688  *
1689  * Hello there!
1690  */
1691 
1692 VALUE
1694 {
1695  return yield_under(mod, mod, rb_ary_new4(argc, argv));
1696 }
1697 
1698 /*
1699  * call-seq:
1700  * throw(tag [, obj])
1701  *
1702  * Transfers control to the end of the active +catch+ block
1703  * waiting for _tag_. Raises +ArgumentError+ if there
1704  * is no +catch+ block for the _tag_. The optional second
1705  * parameter supplies a return value for the +catch+ block,
1706  * which otherwise defaults to +nil+. For examples, see
1707  * <code>Kernel::catch</code>.
1708  */
1709 
1710 static VALUE
1711 rb_f_throw(int argc, VALUE *argv)
1712 {
1713  VALUE tag, value;
1714 
1715  rb_scan_args(argc, argv, "11", &tag, &value);
1716  rb_throw_obj(tag, value);
1717  UNREACHABLE;
1718 }
1719 
1720 void
1722 {
1723  rb_thread_t *th = GET_THREAD();
1724  struct rb_vm_tag *tt = th->tag;
1725 
1726  while (tt) {
1727  if (tt->tag == tag) {
1728  tt->retval = value;
1729  break;
1730  }
1731  tt = tt->prev;
1732  }
1733  if (!tt) {
1734  VALUE desc = rb_inspect(tag);
1735  RB_GC_GUARD(desc);
1736  rb_raise(rb_eArgError, "uncaught throw %s", RSTRING_PTR(desc));
1737  }
1738  th->errinfo = NEW_THROW_OBJECT(tag, 0, TAG_THROW);
1739 
1741 }
1742 
1743 void
1744 rb_throw(const char *tag, VALUE val)
1745 {
1746  rb_throw_obj(ID2SYM(rb_intern(tag)), val);
1747 }
1748 
1749 static VALUE
1751 {
1752  return rb_yield_0(1, &tag);
1753 }
1754 
1755 /*
1756  * call-seq:
1757  * catch([arg]) {|tag| block } -> obj
1758  *
1759  * +catch+ executes its block. If a +throw+ is
1760  * executed, Ruby searches up its stack for a +catch+ block
1761  * with a tag corresponding to the +throw+'s
1762  * _tag_. If found, that block is terminated, and
1763  * +catch+ returns the value given to +throw+. If
1764  * +throw+ is not called, the block terminates normally, and
1765  * the value of +catch+ is the value of the last expression
1766  * evaluated. +catch+ expressions may be nested, and the
1767  * +throw+ call need not be in lexical scope.
1768  *
1769  * def routine(n)
1770  * puts n
1771  * throw :done if n <= 0
1772  * routine(n-1)
1773  * end
1774  *
1775  *
1776  * catch(:done) { routine(3) }
1777  *
1778  * <em>produces:</em>
1779  *
1780  * 3
1781  * 2
1782  * 1
1783  * 0
1784  *
1785  * when _arg_ is given, +catch+ yields it as is, or when no
1786  * _arg_ is given, +catch+ assigns a new unique object to
1787  * +throw+. this is useful for nested +catch+. _arg_ can
1788  * be an arbitrary object, not only Symbol.
1789  *
1790  */
1791 
1792 static VALUE
1793 rb_f_catch(int argc, VALUE *argv)
1794 {
1795  VALUE tag;
1796 
1797  if (argc == 0) {
1798  tag = rb_obj_alloc(rb_cObject);
1799  }
1800  else {
1801  rb_scan_args(argc, argv, "01", &tag);
1802  }
1803  return rb_catch_obj(tag, catch_i, 0);
1804 }
1805 
1806 VALUE
1807 rb_catch(const char *tag, VALUE (*func)(), VALUE data)
1808 {
1809  VALUE vtag = tag ? ID2SYM(rb_intern(tag)) : rb_obj_alloc(rb_cObject);
1810  return rb_catch_obj(vtag, func, data);
1811 }
1812 
1813 VALUE
1815 {
1816  int state;
1817  volatile VALUE val = Qnil; /* OK */
1818  rb_thread_t *th = GET_THREAD();
1819  rb_control_frame_t *saved_cfp = th->cfp;
1820 
1821  TH_PUSH_TAG(th);
1822 
1823  th->tag->tag = tag;
1824 
1825  if ((state = TH_EXEC_TAG()) == 0) {
1826  /* call with argc=1, argv = [tag], block = Qnil to insure compatibility */
1827  val = (*func)(tag, data, 1, &tag, Qnil);
1828  }
1829  else if (state == TAG_THROW && RNODE(th->errinfo)->u1.value == tag) {
1830  rb_vm_rewind_cfp(th, saved_cfp);
1831  val = th->tag->retval;
1832  th->errinfo = Qnil;
1833  state = 0;
1834  }
1835  TH_POP_TAG();
1836  if (state)
1837  JUMP_TAG(state);
1838 
1839  return val;
1840 }
1841 
1842 /*
1843  * call-seq:
1844  * local_variables -> array
1845  *
1846  * Returns the names of the current local variables.
1847  *
1848  * fred = 1
1849  * for i in 1..10
1850  * # ...
1851  * end
1852  * local_variables #=> [:fred, :i]
1853  */
1854 
1855 static VALUE
1857 {
1858  VALUE ary = rb_ary_new();
1859  rb_thread_t *th = GET_THREAD();
1860  rb_control_frame_t *cfp =
1862  int i;
1863 
1864  while (cfp) {
1865  if (cfp->iseq) {
1866  for (i = 0; i < cfp->iseq->local_table_size; i++) {
1867  ID lid = cfp->iseq->local_table[i];
1868  if (lid) {
1869  const char *vname = rb_id2name(lid);
1870  /* should skip temporary variable */
1871  if (vname) {
1872  rb_ary_push(ary, ID2SYM(lid));
1873  }
1874  }
1875  }
1876  }
1877  if (!VM_EP_LEP_P(cfp->ep)) {
1878  /* block */
1879  VALUE *ep = VM_CF_PREV_EP(cfp);
1880 
1881  if (vm_collect_local_variables_in_heap(th, ep, ary)) {
1882  break;
1883  }
1884  else {
1885  while (cfp->ep != ep) {
1886  cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
1887  }
1888  }
1889  }
1890  else {
1891  break;
1892  }
1893  }
1894  return ary;
1895 }
1896 
1897 /*
1898  * call-seq:
1899  * block_given? -> true or false
1900  * iterator? -> true or false
1901  *
1902  * Returns <code>true</code> if <code>yield</code> would execute a
1903  * block in the current context. The <code>iterator?</code> form
1904  * is mildly deprecated.
1905  *
1906  * def try
1907  * if block_given?
1908  * yield
1909  * else
1910  * "no block"
1911  * end
1912  * end
1913  * try #=> "no block"
1914  * try { "hello" } #=> "hello"
1915  * try do "hello" end #=> "hello"
1916  */
1917 
1918 
1919 VALUE
1921 {
1922  rb_thread_t *th = GET_THREAD();
1923  rb_control_frame_t *cfp = th->cfp;
1925 
1926  if (cfp != 0 && VM_CF_BLOCK_PTR(cfp)) {
1927  return Qtrue;
1928  }
1929  else {
1930  return Qfalse;
1931  }
1932 }
1933 
1934 VALUE
1936 {
1937  rb_thread_t *th = GET_THREAD();
1938  rb_control_frame_t *cfp = th->cfp;
1940  if (cfp != 0) return cfp->iseq->location.absolute_path;
1941  return Qnil;
1942 }
1943 
1944 void
1946 {
1947  rb_define_global_function("eval", rb_f_eval, -1);
1948  rb_define_global_function("local_variables", rb_f_local_variables, 0);
1950  rb_define_global_function("block_given?", rb_f_block_given_p, 0);
1951 
1952  rb_define_global_function("catch", rb_f_catch, -1);
1953  rb_define_global_function("throw", rb_f_throw, -1);
1954 
1956 
1957  rb_define_method(rb_cBasicObject, "instance_eval", rb_obj_instance_eval, -1);
1958  rb_define_method(rb_cBasicObject, "instance_exec", rb_obj_instance_exec, -1);
1960 
1961 #if 1
1963  VM_METHOD_TYPE_OPTIMIZED, (void *)OPTIMIZED_METHOD_TYPE_SEND, 0);
1965  VM_METHOD_TYPE_OPTIMIZED, (void *)OPTIMIZED_METHOD_TYPE_SEND, 0);
1966 #else
1967  rb_define_method(rb_cBasicObject, "__send__", rb_f_send, -1);
1968  rb_define_method(rb_mKernel, "send", rb_f_send, -1);
1969 #endif
1970  rb_define_method(rb_mKernel, "public_send", rb_f_public_send, -1);
1971 
1972  rb_define_method(rb_cModule, "module_exec", rb_mod_module_exec, -1);
1973  rb_define_method(rb_cModule, "class_exec", rb_mod_module_exec, -1);
1974  rb_define_method(rb_cModule, "module_eval", rb_mod_module_eval, -1);
1975  rb_define_method(rb_cModule, "class_eval", rb_mod_module_eval, -1);
1976 }
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:955
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:1628
VALUE * argv
Definition: vm_eval.c:1107
#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:1111
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:16946
VALUE rb_mod_module_eval(int, VALUE *, VALUE)
Definition: vm_eval.c:1667
static void stack_check(void)
Definition: vm_eval.c:280
VALUE rb_eval_cmd(VALUE, VALUE, int)
Definition: vm_eval.c:1444
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:1744
#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:1417
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:1356
ID rb_frame_this_func(void)
Definition: eval.c:902
int status
Definition: tcltklib.c:2196
#define sysstack_error
Definition: vm_core.h:868
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:1750
#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:1526
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:17106
#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:1344
#define T_FLOAT
VALUE rb_iterate(VALUE(*)(VALUE), VALUE, VALUE(*)(ANYARGS), VALUE)
Definition: vm_eval.c:1032
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:1470
VALUE rb_obj_instance_eval(int, VALUE *, VALUE)
Definition: vm_eval.c:1596
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:1856
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:1793
#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:1391
VALUE rb_eval_string_protect(const char *, int *)
Evaluates the given string in an isolated binding.
Definition: vm_eval.c:1400
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:1507
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:1133
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:1527
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:1019
#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:1721
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:1384
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:1570
#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:1120
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:1711
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:1240
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:1142
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:1155
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:8172
#define va_init_list(a, b)
Definition: tcltklib.c:61
static VALUE loop_i(void)
Definition: vm_eval.c:985
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:1356
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:585
#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:1532
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:1484
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:1363
#define RBASIC(obj)
#define RARRAY_LENINT(ary)
klass
Definition: tcltklib.c:3503
int rb_respond_to(VALUE, ID)
Definition: vm_method.c:1598
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:1545
#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:1920
#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:1000
VALUE rb_f_eval(int argc, VALUE *argv, VALUE self)
Definition: vm_eval.c:1313
#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:17012
static VALUE rb_f_loop_size(VALUE self, VALUE args)
Definition: vm_eval.c:994
#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:1935
static VALUE eval_string_with_cref(VALUE self, VALUE src, VALUE scope, NODE *cref, volatile VALUE file, volatile int line)
Definition: vm_eval.c:1161
void Init_vm_eval(void)
Definition: vm_eval.c:1945
#define CHECK_VM_STACK_OVERFLOW(cfp, margin)
Definition: vm_core.h:870
#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:1289
#define NULL
Definition: _sdbm.c:102
#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:890
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1344
#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:1693
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