Ruby  2.1.10p492(2016-04-01revision54464)
eval.c
Go to the documentation of this file.
1 /**********************************************************************
2 
3  eval.c -
4 
5  $Author: nagachika $
6  created at: Thu Jun 10 14:22:17 JST 1993
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 #include "eval_intern.h"
15 #include "iseq.h"
16 #include "gc.h"
17 #include "ruby/vm.h"
18 #include "ruby/encoding.h"
19 #include "internal.h"
20 #include "vm_core.h"
21 #include "probes_helper.h"
22 
24 
25 NODE *rb_vm_get_cref(const rb_iseq_t *, const VALUE *);
26 
29 
30 #define exception_error GET_VM()->special_exceptions[ruby_error_reenter]
31 
32 #include "eval_error.c"
33 #include "eval_jump.c"
34 
35 #define CLASS_OR_MODULE_P(obj) \
36  (!SPECIAL_CONST_P(obj) && \
37  (BUILTIN_TYPE(obj) == T_CLASS || BUILTIN_TYPE(obj) == T_MODULE))
38 
39 /* Initializes the Ruby VM and builtin libraries.
40  * @retval 0 if succeeded.
41  * @retval non-zero an error occurred.
42  */
43 int
45 {
46  static int initialized = 0;
47  int state;
48 
49  if (initialized)
50  return 0;
51  initialized = 1;
52 
53  ruby_init_stack((void *)&state);
54  Init_BareVM();
55  Init_heap();
56 
57  PUSH_TAG();
58  if ((state = EXEC_TAG()) == 0) {
59  rb_call_inits();
61  GET_VM()->running = 1;
62  }
63  POP_TAG();
64 
65  return state;
66 }
67 
68 /* Calls ruby_setup() and check error.
69  *
70  * Prints errors and calls exit(3) if an error occurred.
71  */
72 void
73 ruby_init(void)
74 {
75  int state = ruby_setup();
76  if (state) {
77  error_print();
78  exit(EXIT_FAILURE);
79  }
80 }
81 
92 void *
93 ruby_options(int argc, char **argv)
94 {
95  int state;
96  void *volatile iseq = 0;
97 
98  ruby_init_stack((void *)&iseq);
99  PUSH_TAG();
100  if ((state = EXEC_TAG()) == 0) {
102  }
103  else {
105  state = error_handle(state);
106  iseq = (void *)INT2FIX(state);
107  }
108  POP_TAG();
109  return iseq;
110 }
111 
112 static void
114 {
115  PUSH_TAG();
116  if (EXEC_TAG() == 0) {
117  rb_trap_exit();
118  }
119  POP_TAG();
122 }
123 
124 static void
126 {
128  GET_THREAD()->errinfo = Qnil;
130 }
131 
139 void
141 {
142  ruby_finalize_0();
143  ruby_finalize_1();
144 }
145 
156 int
157 ruby_cleanup(volatile int ex)
158 {
159  int state;
160  volatile VALUE errs[2];
161  rb_thread_t *th = GET_THREAD();
162  int nerr;
163 
166  PUSH_TAG();
167  if ((state = EXEC_TAG()) == 0) {
168  SAVE_ROOT_JMPBUF(th, { RUBY_VM_CHECK_INTS(th); });
169  }
170  POP_TAG();
171 
172  errs[1] = th->errinfo;
173  th->safe_level = 0;
174  ruby_init_stack(&errs[STACK_UPPER(errs, 0, 1)]);
175 
176  PUSH_TAG();
177  if ((state = EXEC_TAG()) == 0) {
179  }
180  POP_TAG();
181 
182  /* protect from Thread#raise */
183  th->status = THREAD_KILLED;
184 
185  errs[0] = th->errinfo;
186  PUSH_TAG();
187  if ((state = EXEC_TAG()) == 0) {
189  }
190  else if (ex == 0) {
191  ex = state;
192  }
193  th->errinfo = errs[1];
194  ex = error_handle(ex);
195 
196 #if EXIT_SUCCESS != 0 || EXIT_FAILURE != 1
197  switch (ex) {
198 #if EXIT_SUCCESS != 0
199  case 0: ex = EXIT_SUCCESS; break;
200 #endif
201 #if EXIT_FAILURE != 1
202  case 1: ex = EXIT_FAILURE; break;
203 #endif
204  }
205 #endif
206 
207  state = 0;
208  for (nerr = 0; nerr < numberof(errs); ++nerr) {
209  VALUE err = errs[nerr];
210 
211  if (!RTEST(err)) continue;
212 
213  /* th->errinfo contains a NODE while break'ing */
214  if (RB_TYPE_P(err, T_NODE)) continue;
215 
217  ex = sysexit_status(err);
218  break;
219  }
220  else if (rb_obj_is_kind_of(err, rb_eSignal)) {
221  VALUE sig = rb_iv_get(err, "signo");
222  state = NUM2INT(sig);
223  break;
224  }
225  else if (ex == EXIT_SUCCESS) {
226  ex = EXIT_FAILURE;
227  }
228  }
229 
230  ruby_finalize_1();
231 
232  /* unlock again if finalizer took mutexes. */
234  POP_TAG();
237  if (state) ruby_default_signal(state);
238 
239  return ex;
240 }
241 
242 static int
244 {
245  volatile int state;
246  VALUE iseq = (VALUE)n;
247  rb_thread_t *th = GET_THREAD();
248 
249  if (!n) return 0;
250 
251  PUSH_TAG();
252  if ((state = EXEC_TAG()) == 0) {
253  SAVE_ROOT_JMPBUF(th, {
254  th->base_block = 0;
255  rb_iseq_eval_main(iseq);
256  });
257  }
258  POP_TAG();
259  return state;
260 }
261 
263 void
264 ruby_stop(int ex)
265 {
266  exit(ruby_cleanup(ex));
267 }
268 
281 int
282 ruby_executable_node(void *n, int *status)
283 {
284  VALUE v = (VALUE)n;
285  int s;
286 
287  switch (v) {
288  case Qtrue: s = EXIT_SUCCESS; break;
289  case Qfalse: s = EXIT_FAILURE; break;
290  default:
291  if (!FIXNUM_P(v)) return TRUE;
292  s = FIX2INT(v);
293  }
294  if (status) *status = s;
295  return FALSE;
296 }
297 
302 int
304 {
305  int status;
306  if (!ruby_executable_node(n, &status)) {
307  ruby_cleanup(0);
308  return status;
309  }
310  return ruby_cleanup(ruby_exec_node(n));
311 }
312 
314 int
316 {
317  ruby_init_stack((void *)&n);
318  return ruby_exec_internal(n);
319 }
320 
321 /*
322  * call-seq:
323  * Module.nesting -> array
324  *
325  * Returns the list of +Modules+ nested at the point of call.
326  *
327  * module M1
328  * module M2
329  * $a = Module.nesting
330  * end
331  * end
332  * $a #=> [M1::M2, M1]
333  * $a[0].name #=> "M1::M2"
334  */
335 
336 static VALUE
338 {
339  VALUE ary = rb_ary_new();
340  const NODE *cref = rb_vm_cref();
341 
342  while (cref && cref->nd_next) {
343  VALUE klass = cref->nd_clss;
344  if (!(cref->flags & NODE_FL_CREF_PUSHED_BY_EVAL) &&
345  !NIL_P(klass)) {
346  rb_ary_push(ary, klass);
347  }
348  cref = cref->nd_next;
349  }
350  return ary;
351 }
352 
353 /*
354  * call-seq:
355  * Module.constants -> array
356  * Module.constants(inherited) -> array
357  *
358  * In the first form, returns an array of the names of all
359  * constants accessible from the point of call.
360  * This list includes the names of all modules and classes
361  * defined in the global scope.
362  *
363  * Module.constants.first(4)
364  * # => [:ARGF, :ARGV, :ArgumentError, :Array]
365  *
366  * Module.constants.include?(:SEEK_SET) # => false
367  *
368  * class IO
369  * Module.constants.include?(:SEEK_SET) # => true
370  * end
371  *
372  * The second form calls the instance method +constants+.
373  */
374 
375 static VALUE
377 {
378  const NODE *cref = rb_vm_cref();
379  VALUE klass;
380  VALUE cbase = 0;
381  void *data = 0;
382 
383  if (argc > 0 || mod != rb_cModule) {
384  return rb_mod_constants(argc, argv, mod);
385  }
386 
387  while (cref) {
388  klass = cref->nd_clss;
389  if (!(cref->flags & NODE_FL_CREF_PUSHED_BY_EVAL) &&
390  !NIL_P(klass)) {
391  data = rb_mod_const_at(cref->nd_clss, data);
392  if (!cbase) {
393  cbase = klass;
394  }
395  }
396  cref = cref->nd_next;
397  }
398 
399  if (cbase) {
400  data = rb_mod_const_of(cbase, data);
401  }
402  return rb_const_list(data);
403 }
404 
405 void
407 {
408  if (SPECIAL_CONST_P(klass)) {
409  noclass:
410  Check_Type(klass, T_CLASS);
411  }
412  if (OBJ_FROZEN(klass)) {
413  const char *desc;
414 
415  if (FL_TEST(klass, FL_SINGLETON))
416  desc = "object";
417  else {
418  switch (BUILTIN_TYPE(klass)) {
419  case T_MODULE:
420  case T_ICLASS:
421  desc = "module";
422  break;
423  case T_CLASS:
424  desc = "class";
425  break;
426  default:
427  goto noclass;
428  }
429  }
430  rb_error_frozen(desc);
431  }
432 }
433 
434 NORETURN(static void rb_longjmp(int, volatile VALUE));
435 static VALUE get_errinfo(void);
437 
438 static VALUE
440 {
441  ID id_cause;
442  CONST_ID(id_cause, "cause");
443 
444 #if SUPPORT_JOKE
445  if (NIL_P(cause)) {
446  ID id_true_cause;
447  CONST_ID(id_true_cause, "true_cause");
448 
449  cause = rb_attr_get(rb_eFatal, id_true_cause);
450  if (NIL_P(cause)) {
451  cause = rb_exc_new_cstr(rb_eFatal, "because using such Ruby");
452  rb_ivar_set(cause, id_cause, INT2FIX(42)); /* the answer */
453  OBJ_FREEZE(cause);
454  rb_ivar_set(rb_eFatal, id_true_cause, cause);
455  }
456  }
457 #endif
458  if (!NIL_P(cause) && cause != exc) {
459  rb_ivar_set(exc, id_cause, cause);
460  }
461  return exc;
462 }
463 
464 static void
465 setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg)
466 {
467  VALUE at;
468  VALUE e;
469  const char *file;
470  volatile int line = 0;
471 
472  if (NIL_P(mesg)) {
473  mesg = th->errinfo;
475  }
476  if (NIL_P(mesg)) {
477  mesg = rb_exc_new(rb_eRuntimeError, 0, 0);
478  }
480 
481  file = rb_sourcefile();
482  if (file) line = rb_sourceline();
483  if (file && !NIL_P(mesg)) {
484  if (mesg == sysstack_error) {
485  at = rb_enc_sprintf(rb_usascii_encoding(), "%s:%d", file, line);
486  at = rb_ary_new3(1, at);
487  rb_iv_set(mesg, "bt", at);
488  }
489  else {
490  at = get_backtrace(mesg);
491  if (NIL_P(at)) {
492  at = rb_vm_backtrace_object();
493  if (OBJ_FROZEN(mesg)) {
494  mesg = rb_obj_dup(mesg);
495  }
496  rb_iv_set(mesg, "bt_locations", at);
497  set_backtrace(mesg, at);
498  }
499  }
500  }
501 
502  if (!NIL_P(mesg)) {
503  th->errinfo = mesg;
504  }
505 
506  if (RTEST(ruby_debug) && !NIL_P(e = th->errinfo) &&
508  int status;
509 
510  mesg = e;
511  PUSH_TAG();
512  if ((status = EXEC_TAG()) == 0) {
513  th->errinfo = Qnil;
514  e = rb_obj_as_string(mesg);
515  th->errinfo = mesg;
516  if (file && line) {
517  warn_printf("Exception `%s' at %s:%d - %"PRIsVALUE"\n",
518  rb_obj_classname(th->errinfo), file, line, e);
519  }
520  else if (file) {
521  warn_printf("Exception `%s' at %s - %"PRIsVALUE"\n",
522  rb_obj_classname(th->errinfo), file, e);
523  }
524  else {
525  warn_printf("Exception `%s' - %"PRIsVALUE"\n",
526  rb_obj_classname(th->errinfo), e);
527  }
528  }
529  POP_TAG();
530  if (status == TAG_FATAL && th->errinfo == exception_error) {
531  th->errinfo = mesg;
532  }
533  else if (status) {
535  JUMP_TAG(status);
536  }
537  }
538 
539  if (rb_threadptr_set_raised(th)) {
540  th->errinfo = exception_error;
543  }
544 
545  if (tag != TAG_FATAL) {
548  rb_sourcefile(),
549  rb_sourceline());
550  }
551  EXEC_EVENT_HOOK(th, RUBY_EVENT_RAISE, th->cfp->self, 0, 0, mesg);
552  }
553 }
554 
555 static void
556 rb_longjmp(int tag, volatile VALUE mesg)
557 {
558  rb_thread_t *th = GET_THREAD();
559  setup_exception(th, tag, mesg);
561  JUMP_TAG(tag);
562 }
563 
564 static VALUE make_exception(int argc, VALUE *argv, int isstr);
565 
566 void
568 {
569  if (!NIL_P(mesg)) {
570  mesg = make_exception(1, &mesg, FALSE);
571  }
572  rb_longjmp(TAG_RAISE, mesg);
573 }
574 
575 void
577 {
578  if (!NIL_P(mesg)) {
579  mesg = make_exception(1, &mesg, FALSE);
580  }
581  rb_longjmp(TAG_FATAL, mesg);
582 }
583 
584 void
586 {
587  rb_raise(rb_eInterrupt, "%s", "");
588 }
589 
590 /*
591  * call-seq:
592  * raise
593  * raise(string)
594  * raise(exception [, string [, array]])
595  * fail
596  * fail(string)
597  * fail(exception [, string [, array]])
598  *
599  * With no arguments, raises the exception in <code>$!</code> or raises
600  * a <code>RuntimeError</code> if <code>$!</code> is +nil+.
601  * With a single +String+ argument, raises a
602  * +RuntimeError+ with the string as a message. Otherwise,
603  * the first parameter should be the name of an +Exception+
604  * class (or an object that returns an +Exception+ object when sent
605  * an +exception+ message). The optional second parameter sets the
606  * message associated with the exception, and the third parameter is an
607  * array of callback information. Exceptions are caught by the
608  * +rescue+ clause of <code>begin...end</code> blocks.
609  *
610  * raise "Failed to create socket"
611  * raise ArgumentError, "No parameters", caller
612  */
613 
614 static VALUE
616 {
617  VALUE err;
618  if (argc == 0) {
619  err = get_errinfo();
620  if (!NIL_P(err)) {
621  argc = 1;
622  argv = &err;
623  }
624  }
626 
627  UNREACHABLE;
628 }
629 
630 static VALUE
631 make_exception(int argc, VALUE *argv, int isstr)
632 {
633  VALUE mesg, exc;
634  ID exception;
635  int n;
636 
637  mesg = Qnil;
638  switch (argc) {
639  case 0:
640  break;
641  case 1:
642  exc = argv[0];
643  if (NIL_P(exc))
644  break;
645  if (isstr) {
646  mesg = rb_check_string_type(exc);
647  if (!NIL_P(mesg)) {
648  mesg = rb_exc_new3(rb_eRuntimeError, mesg);
649  break;
650  }
651  }
652  n = 0;
653  goto exception_call;
654 
655  case 2:
656  case 3:
657  exc = argv[0];
658  n = 1;
659  exception_call:
660  if (exc == sysstack_error) return exc;
661  CONST_ID(exception, "exception");
662  mesg = rb_check_funcall(exc, exception, n, argv+1);
663  if (mesg == Qundef) {
664  rb_raise(rb_eTypeError, "exception class/object expected");
665  }
666  break;
667  default:
668  rb_check_arity(argc, 0, 3);
669  break;
670  }
671  if (argc > 0) {
672  if (!rb_obj_is_kind_of(mesg, rb_eException))
673  rb_raise(rb_eTypeError, "exception object expected");
674  if (argc > 2)
675  set_backtrace(mesg, argv[2]);
676  }
677 
678  return mesg;
679 }
680 
681 VALUE
683 {
684  return make_exception(argc, argv, TRUE);
685 }
686 
687 void
689 {
690  rb_thread_t *th = GET_THREAD();
691  rb_control_frame_t *cfp = th->cfp;
692  VALUE klass = cfp->me->klass;
693  VALUE self = cfp->self;
694  ID mid = cfp->me->called_id;
695 
697  EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, self, mid, klass, Qnil);
698 
699  setup_exception(th, TAG_RAISE, mesg);
700 
703 }
704 
705 void
706 rb_jump_tag(int tag)
707 {
708  JUMP_TAG(tag);
709 }
710 
711 int
713 {
714  rb_thread_t *th = GET_THREAD();
715 
717  return TRUE;
718  }
719  else {
720  return FALSE;
721  }
722 }
723 
724 int
726 {
727  return rb_block_given_p();
728 }
729 
731 
732 void
734 {
735  if (!rb_block_given_p()) {
736  rb_vm_localjump_error("no block given", Qnil, 0);
737  }
738 }
739 
740 VALUE
741 rb_rescue2(VALUE (* b_proc) (ANYARGS), VALUE data1,
742  VALUE (* r_proc) (ANYARGS), VALUE data2, ...)
743 {
744  int state;
745  rb_thread_t *th = GET_THREAD();
746  rb_control_frame_t *cfp = th->cfp;
747  volatile VALUE result = Qfalse;
748  volatile VALUE e_info = th->errinfo;
749  va_list args;
750 
751  TH_PUSH_TAG(th);
752  if ((state = TH_EXEC_TAG()) == 0) {
753  retry_entry:
754  result = (*b_proc) (data1);
755  }
756  else if (result) {
757  /* escape from r_proc */
758  if (state == TAG_RETRY) {
759  state = 0;
760  th->errinfo = Qnil;
761  result = Qfalse;
762  goto retry_entry;
763  }
764  }
765  else {
766  rb_vm_rewind_cfp(th, cfp);
767 
768  if (state == TAG_RAISE) {
769  int handle = FALSE;
770  VALUE eclass;
771 
772  va_init_list(args, data2);
773  while ((eclass = va_arg(args, VALUE)) != 0) {
774  if (rb_obj_is_kind_of(th->errinfo, eclass)) {
775  handle = TRUE;
776  break;
777  }
778  }
779  va_end(args);
780 
781  if (handle) {
782  result = Qnil;
783  state = 0;
784  if (r_proc) {
785  result = (*r_proc) (data2, th->errinfo);
786  }
787  th->errinfo = e_info;
788  }
789  }
790  }
791  TH_POP_TAG();
792  if (state)
793  JUMP_TAG(state);
794 
795  return result;
796 }
797 
798 VALUE
799 rb_rescue(VALUE (* b_proc)(ANYARGS), VALUE data1,
800  VALUE (* r_proc)(ANYARGS), VALUE data2)
801 {
802  return rb_rescue2(b_proc, data1, r_proc, data2, rb_eStandardError,
803  (VALUE)0);
804 }
805 
806 VALUE
807 rb_protect(VALUE (* proc) (VALUE), VALUE data, int * state)
808 {
809  volatile VALUE result = Qnil;
810  volatile int status;
811  rb_thread_t *th = GET_THREAD();
812  rb_control_frame_t *cfp = th->cfp;
813  struct rb_vm_protect_tag protect_tag;
814  rb_jmpbuf_t org_jmpbuf;
815 
816  protect_tag.prev = th->protect_tag;
817 
818  TH_PUSH_TAG(th);
819  th->protect_tag = &protect_tag;
820  MEMCPY(&org_jmpbuf, &(th)->root_jmpbuf, rb_jmpbuf_t, 1);
821  if ((status = TH_EXEC_TAG()) == 0) {
822  SAVE_ROOT_JMPBUF(th, result = (*proc) (data));
823  }
824  else {
825  rb_vm_rewind_cfp(th, cfp);
826  }
827  MEMCPY(&(th)->root_jmpbuf, &org_jmpbuf, rb_jmpbuf_t, 1);
828  th->protect_tag = protect_tag.prev;
829  TH_POP_TAG();
830 
831  if (state) {
832  *state = status;
833  }
834 
835  return result;
836 }
837 
838 VALUE
839 rb_ensure(VALUE (*b_proc)(ANYARGS), VALUE data1, VALUE (*e_proc)(ANYARGS), VALUE data2)
840 {
841  int state;
842  volatile VALUE result = Qnil;
843  volatile VALUE errinfo;
844  rb_thread_t *const th = GET_THREAD();
845  rb_ensure_list_t ensure_list;
846  ensure_list.entry.marker = 0;
847  ensure_list.entry.e_proc = e_proc;
848  ensure_list.entry.data2 = data2;
849  ensure_list.next = th->ensure_list;
850  th->ensure_list = &ensure_list;
851  PUSH_TAG();
852  if ((state = EXEC_TAG()) == 0) {
853  result = (*b_proc) (data1);
854  }
855  POP_TAG();
856  /* TODO: fix me */
857  /* retval = prot_tag ? prot_tag->retval : Qnil; */ /* save retval */
858  errinfo = th->errinfo;
859  th->ensure_list=ensure_list.next;
860  (*ensure_list.entry.e_proc)(ensure_list.entry.data2);
861  th->errinfo = errinfo;
862  if (state)
863  JUMP_TAG(state);
864  return result;
865 }
866 
867 static const rb_method_entry_t *
869 {
870  rb_thread_t *th = GET_THREAD();
871  rb_control_frame_t *cfp_limit;
872 
873  cfp_limit = (rb_control_frame_t *)(th->stack + th->stack_size);
874  while (cfp_limit > cfp) {
875  if (cfp->iseq == iseq)
876  return cfp->me;
878  }
879  return 0;
880 }
881 
882 static ID
884 {
885  const rb_method_entry_t *me_local;
886  rb_iseq_t *iseq = cfp->iseq;
887  if (cfp->me) {
888  return cfp->me->def->original_id;
889  }
890  while (iseq) {
891  if (RUBY_VM_IFUNC_P(iseq)) {
892  NODE *ifunc = (NODE *)iseq;
893  if (ifunc->nd_aid) return ifunc->nd_aid;
894  return idIFUNC;
895  }
896  me_local = method_entry_of_iseq(cfp, iseq);
897  if (me_local) {
898  cfp->me = me_local;
899  return me_local->def->original_id;
900  }
901  if (iseq->defined_method_id) {
902  return iseq->defined_method_id;
903  }
904  if (iseq->local_iseq == iseq) {
905  break;
906  }
907  iseq = iseq->parent_iseq;
908  }
909  return 0;
910 }
911 
912 static ID
914 {
915  const rb_method_entry_t *me_local;
916  rb_iseq_t *iseq = cfp->iseq;
917  if (cfp->me) {
918  return cfp->me->called_id;
919  }
920  while (iseq) {
921  if (RUBY_VM_IFUNC_P(iseq)) {
922  NODE *ifunc = (NODE *)iseq;
923  if (ifunc->nd_aid) return ifunc->nd_aid;
924  return idIFUNC;
925  }
926  me_local = method_entry_of_iseq(cfp, iseq);
927  if (me_local) {
928  cfp->me = me_local;
929  return me_local->called_id;
930  }
931  if (iseq->defined_method_id) {
932  return iseq->defined_method_id;
933  }
934  if (iseq->local_iseq == iseq) {
935  break;
936  }
937  iseq = iseq->parent_iseq;
938  }
939  return 0;
940 }
941 
942 ID
944 {
945  return frame_func_id(GET_THREAD()->cfp);
946 }
947 
948 ID
950 {
951  return frame_called_id(GET_THREAD()->cfp);
952 }
953 
954 static rb_control_frame_t *
956 {
958  /* check if prev_cfp can be accessible */
959  if ((void *)(th->stack + th->stack_size) == (void *)(prev_cfp)) {
960  return 0;
961  }
962  return prev_cfp;
963 }
964 
965 static ID
967 {
969  if (!prev_cfp) return 0;
970  return frame_called_id(prev_cfp);
971 }
972 
973 static ID
975 {
977  if (!prev_cfp) return 0;
978  return frame_func_id(prev_cfp);
979 }
980 
981 ID
983 {
984  rb_thread_t *th = GET_THREAD();
985  rb_control_frame_t *cfp = th->cfp;
986  ID mid;
987 
988  while (!(mid = frame_func_id(cfp)) &&
989  (cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp),
991  return mid;
992 }
993 
994 /*
995  * call-seq:
996  * append_features(mod) -> mod
997  *
998  * When this module is included in another, Ruby calls
999  * <code>append_features</code> in this module, passing it the
1000  * receiving module in _mod_. Ruby's default implementation is
1001  * to add the constants, methods, and module variables of this module
1002  * to _mod_ if this module has not already been added to
1003  * _mod_ or one of its ancestors. See also <code>Module#include</code>.
1004  */
1005 
1006 static VALUE
1008 {
1009  if (!CLASS_OR_MODULE_P(include)) {
1010  Check_Type(include, T_CLASS);
1011  }
1012  rb_include_module(include, module);
1013 
1014  return module;
1015 }
1016 
1017 /*
1018  * call-seq:
1019  * include(module, ...) -> self
1020  *
1021  * Invokes <code>Module.append_features</code> on each parameter in reverse order.
1022  */
1023 
1024 static VALUE
1026 {
1027  int i;
1028  ID id_append_features, id_included;
1029 
1030  CONST_ID(id_append_features, "append_features");
1031  CONST_ID(id_included, "included");
1032 
1033  for (i = 0; i < argc; i++)
1034  Check_Type(argv[i], T_MODULE);
1035  while (argc--) {
1036  rb_funcall(argv[argc], id_append_features, 1, module);
1037  rb_funcall(argv[argc], id_included, 1, module);
1038  }
1039  return module;
1040 }
1041 
1042 /*
1043  * call-seq:
1044  * prepend_features(mod) -> mod
1045  *
1046  * When this module is prepended in another, Ruby calls
1047  * <code>prepend_features</code> in this module, passing it the
1048  * receiving module in _mod_. Ruby's default implementation is
1049  * to overlay the constants, methods, and module variables of this module
1050  * to _mod_ if this module has not already been added to
1051  * _mod_ or one of its ancestors. See also <code>Module#prepend</code>.
1052  */
1053 
1054 static VALUE
1056 {
1057  if (!CLASS_OR_MODULE_P(prepend)) {
1058  Check_Type(prepend, T_CLASS);
1059  }
1060  rb_prepend_module(prepend, module);
1061 
1062  return module;
1063 }
1064 
1065 /*
1066  * call-seq:
1067  * prepend(module, ...) -> self
1068  *
1069  * Invokes <code>Module.prepend_features</code> on each parameter in reverse order.
1070  */
1071 
1072 static VALUE
1074 {
1075  int i;
1076  ID id_prepend_features, id_prepended;
1077 
1078  CONST_ID(id_prepend_features, "prepend_features");
1079  CONST_ID(id_prepended, "prepended");
1080  for (i = 0; i < argc; i++)
1081  Check_Type(argv[i], T_MODULE);
1082  while (argc--) {
1083  rb_funcall(argv[argc], id_prepend_features, 1, module);
1084  rb_funcall(argv[argc], id_prepended, 1, module);
1085  }
1086  return module;
1087 }
1088 
1089 static VALUE
1091 {
1092  VALUE hash = rb_hash_new();
1093 
1094  rb_funcall(hash, rb_intern("compare_by_identity"), 0);
1095  RBASIC_CLEAR_CLASS(hash); /* hide from ObjectSpace */
1096  return hash;
1097 }
1098 
1099 void
1100 rb_using_refinement(NODE *cref, VALUE klass, VALUE module)
1101 {
1102  VALUE iclass, c, superclass = klass;
1103 
1104  Check_Type(klass, T_CLASS);
1105  Check_Type(module, T_MODULE);
1106  if (NIL_P(cref->nd_refinements)) {
1107  RB_OBJ_WRITE(cref, &cref->nd_refinements, hidden_identity_hash_new());
1108  }
1109  else {
1110  if (cref->flags & NODE_FL_CREF_OMOD_SHARED) {
1111  RB_OBJ_WRITE(cref, &cref->nd_refinements, rb_hash_dup(cref->nd_refinements));
1112  cref->flags &= ~NODE_FL_CREF_OMOD_SHARED;
1113  }
1114  if (!NIL_P(c = rb_hash_lookup(cref->nd_refinements, klass))) {
1115  superclass = c;
1116  while (c && RB_TYPE_P(c, T_ICLASS)) {
1117  if (RBASIC(c)->klass == module) {
1118  /* already used refinement */
1119  return;
1120  }
1121  c = RCLASS_SUPER(c);
1122  }
1123  }
1124  }
1125  FL_SET(module, RMODULE_IS_OVERLAID);
1126  c = iclass = rb_include_class_new(module, superclass);
1127  RCLASS_REFINED_CLASS(c) = klass;
1128 
1131 
1132  module = RCLASS_SUPER(module);
1133  while (module && module != klass) {
1134  FL_SET(module, RMODULE_IS_OVERLAID);
1136  RCLASS_REFINED_CLASS(c) = klass;
1137  module = RCLASS_SUPER(module);
1138  }
1139  rb_hash_aset(cref->nd_refinements, klass, iclass);
1140 }
1141 
1142 static int
1143 using_refinement(VALUE klass, VALUE module, VALUE arg)
1144 {
1145  NODE *cref = (NODE *) arg;
1146 
1147  rb_using_refinement(cref, klass, module);
1148  return ST_CONTINUE;
1149 }
1150 
1151 static void
1153 {
1154  ID id_refinements;
1155  VALUE super, module, refinements;
1156 
1157  super = RCLASS_SUPER(klass);
1158  if (super) {
1159  using_module_recursive(cref, super);
1160  }
1161  switch (BUILTIN_TYPE(klass)) {
1162  case T_MODULE:
1163  module = klass;
1164  break;
1165 
1166  case T_ICLASS:
1167  module = RBASIC(klass)->klass;
1168  break;
1169 
1170  default:
1171  rb_raise(rb_eTypeError, "wrong argument type %s (expected Module)",
1172  rb_obj_classname(klass));
1173  break;
1174  }
1175  CONST_ID(id_refinements, "__refinements__");
1176  refinements = rb_attr_get(module, id_refinements);
1177  if (NIL_P(refinements)) return;
1178  rb_hash_foreach(refinements, using_refinement, (VALUE) cref);
1179 }
1180 
1181 void
1183 {
1184  Check_Type(module, T_MODULE);
1185  using_module_recursive(cref, module);
1187 }
1188 
1189 VALUE
1191 {
1192  ID id_refined_class;
1193 
1194  CONST_ID(id_refined_class, "__refined_class__");
1195  return rb_attr_get(module, id_refined_class);
1196 }
1197 
1198 static void
1199 add_activated_refinement(VALUE activated_refinements,
1200  VALUE klass, VALUE refinement)
1201 {
1202  VALUE iclass, c, superclass = klass;
1203 
1204  if (!NIL_P(c = rb_hash_lookup(activated_refinements, klass))) {
1205  superclass = c;
1206  while (c && RB_TYPE_P(c, T_ICLASS)) {
1207  if (RBASIC(c)->klass == refinement) {
1208  /* already used refinement */
1209  return;
1210  }
1211  c = RCLASS_SUPER(c);
1212  }
1213  }
1214  FL_SET(refinement, RMODULE_IS_OVERLAID);
1215  c = iclass = rb_include_class_new(refinement, superclass);
1216  RCLASS_REFINED_CLASS(c) = klass;
1217  refinement = RCLASS_SUPER(refinement);
1218  while (refinement) {
1219  FL_SET(refinement, RMODULE_IS_OVERLAID);
1220  c = RCLASS_SET_SUPER(c, rb_include_class_new(refinement, RCLASS_SUPER(c)));
1221  RCLASS_REFINED_CLASS(c) = klass;
1222  refinement = RCLASS_SUPER(refinement);
1223  }
1224  rb_hash_aset(activated_refinements, klass, iclass);
1225 }
1226 
1227 VALUE rb_yield_refine_block(VALUE refinement, VALUE refinements);
1228 
1229 /*
1230  * call-seq:
1231  * refine(klass) { block } -> module
1232  *
1233  * Refine <i>klass</i> in the receiver.
1234  *
1235  * Returns an overlaid module.
1236  */
1237 
1238 static VALUE
1239 rb_mod_refine(VALUE module, VALUE klass)
1240 {
1241  VALUE refinement;
1242  ID id_refinements, id_activated_refinements,
1243  id_refined_class, id_defined_at;
1244  VALUE refinements, activated_refinements;
1245  rb_thread_t *th = GET_THREAD();
1247 
1248  if (!block) {
1249  rb_raise(rb_eArgError, "no block given");
1250  }
1251  if (block->proc) {
1253  "can't pass a Proc as a block to Module#refine");
1254  }
1255  Check_Type(klass, T_CLASS);
1256  CONST_ID(id_refinements, "__refinements__");
1257  refinements = rb_attr_get(module, id_refinements);
1258  if (NIL_P(refinements)) {
1259  refinements = hidden_identity_hash_new();
1260  rb_ivar_set(module, id_refinements, refinements);
1261  }
1262  CONST_ID(id_activated_refinements, "__activated_refinements__");
1263  activated_refinements = rb_attr_get(module, id_activated_refinements);
1264  if (NIL_P(activated_refinements)) {
1265  activated_refinements = hidden_identity_hash_new();
1266  rb_ivar_set(module, id_activated_refinements,
1267  activated_refinements);
1268  }
1269  refinement = rb_hash_lookup(refinements, klass);
1270  if (NIL_P(refinement)) {
1271  refinement = rb_module_new();
1272  RCLASS_SET_SUPER(refinement, klass);
1273  FL_SET(refinement, RMODULE_IS_REFINEMENT);
1274  CONST_ID(id_refined_class, "__refined_class__");
1275  rb_ivar_set(refinement, id_refined_class, klass);
1276  CONST_ID(id_defined_at, "__defined_at__");
1277  rb_ivar_set(refinement, id_defined_at, module);
1278  rb_hash_aset(refinements, klass, refinement);
1279  add_activated_refinement(activated_refinements, klass, refinement);
1280  }
1281  rb_yield_refine_block(refinement, activated_refinements);
1282  return refinement;
1283 }
1284 
1285 /*
1286  * call-seq:
1287  * using(module) -> self
1288  *
1289  * Import class refinements from <i>module</i> into the current class or
1290  * module definition.
1291  */
1292 
1293 static VALUE
1294 mod_using(VALUE self, VALUE module)
1295 {
1296  NODE *cref = rb_vm_cref();
1298 
1299  if (prev_frame_func()) {
1301  "Module#using is not permitted in methods");
1302  }
1303  if (prev_cfp && prev_cfp->self != self) {
1304  rb_raise(rb_eRuntimeError, "Module#using is not called on self");
1305  }
1306  rb_using_module(cref, module);
1307  return self;
1308 }
1309 
1310 void
1312 {
1314  rb_funcall2(obj, idInitialize, argc, argv);
1315 }
1316 
1317 void
1319 {
1320  rb_include_module(rb_singleton_class(obj), module);
1321 }
1322 
1323 /*
1324  * call-seq:
1325  * extend_object(obj) -> obj
1326  *
1327  * Extends the specified object by adding this module's constants and
1328  * methods (which are added as singleton methods). This is the callback
1329  * method used by <code>Object#extend</code>.
1330  *
1331  * module Picky
1332  * def Picky.extend_object(o)
1333  * if String === o
1334  * puts "Can't add Picky to a String"
1335  * else
1336  * puts "Picky added to #{o.class}"
1337  * super
1338  * end
1339  * end
1340  * end
1341  * (s = Array.new).extend Picky # Call Object.extend
1342  * (s = "quick brown fox").extend Picky
1343  *
1344  * <em>produces:</em>
1345  *
1346  * Picky added to Array
1347  * Can't add Picky to a String
1348  */
1349 
1350 static VALUE
1352 {
1353  rb_extend_object(obj, mod);
1354  return obj;
1355 }
1356 
1357 /*
1358  * call-seq:
1359  * obj.extend(module, ...) -> obj
1360  *
1361  * Adds to _obj_ the instance methods from each module given as a
1362  * parameter.
1363  *
1364  * module Mod
1365  * def hello
1366  * "Hello from Mod.\n"
1367  * end
1368  * end
1369  *
1370  * class Klass
1371  * def hello
1372  * "Hello from Klass.\n"
1373  * end
1374  * end
1375  *
1376  * k = Klass.new
1377  * k.hello #=> "Hello from Klass.\n"
1378  * k.extend(Mod) #=> #<Klass:0x401b3bc8>
1379  * k.hello #=> "Hello from Mod.\n"
1380  */
1381 
1382 static VALUE
1384 {
1385  int i;
1386  ID id_extend_object, id_extended;
1387 
1388  CONST_ID(id_extend_object, "extend_object");
1389  CONST_ID(id_extended, "extended");
1390 
1392  for (i = 0; i < argc; i++)
1393  Check_Type(argv[i], T_MODULE);
1394  while (argc--) {
1395  rb_funcall(argv[argc], id_extend_object, 1, obj);
1396  rb_funcall(argv[argc], id_extended, 1, obj);
1397  }
1398  return obj;
1399 }
1400 
1401 /*
1402  * call-seq:
1403  * include(module, ...) -> self
1404  *
1405  * Invokes <code>Module.append_features</code>
1406  * on each parameter in turn. Effectively adds the methods and constants
1407  * in each module to the receiver.
1408  */
1409 
1410 static VALUE
1412 {
1413  rb_thread_t *th = GET_THREAD();
1414 
1415  if (th->top_wrapper) {
1416  rb_warning("main.include in the wrapped load is effective only in wrapper module");
1417  return rb_mod_include(argc, argv, th->top_wrapper);
1418  }
1419  return rb_mod_include(argc, argv, rb_cObject);
1420 }
1421 
1422 /*
1423  * call-seq:
1424  * using(module) -> self
1425  *
1426  * Import class refinements from <i>module</i> into the scope where
1427  * <code>using</code> is called.
1428  */
1429 
1430 static VALUE
1431 top_using(VALUE self, VALUE module)
1432 {
1433  NODE *cref = rb_vm_cref();
1435 
1436  if (cref->nd_next || (prev_cfp && prev_cfp->me)) {
1438  "main.using is permitted only at toplevel");
1439  }
1440  rb_using_module(cref, module);
1441  return self;
1442 }
1443 
1444 static VALUE *
1446 {
1447  rb_control_frame_t *cfp = th->cfp;
1449 
1450  while (RUBY_VM_VALID_CONTROL_FRAME_P(cfp, end_cfp)) {
1451  if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) {
1452  if (cfp->iseq->type == ISEQ_TYPE_RESCUE) {
1453  return &cfp->ep[-2];
1454  }
1455  else if (cfp->iseq->type == ISEQ_TYPE_ENSURE &&
1456  !RB_TYPE_P(cfp->ep[-2], T_NODE) &&
1457  !FIXNUM_P(cfp->ep[-2])) {
1458  return &cfp->ep[-2];
1459  }
1460  }
1461  cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
1462  }
1463  return 0;
1464 }
1465 
1466 static VALUE
1468 {
1469  VALUE *ptr = errinfo_place(th);
1470  if (ptr) {
1471  return *ptr;
1472  }
1473  else {
1474  return th->errinfo;
1475  }
1476 }
1477 
1478 static VALUE
1480 {
1481  return get_thread_errinfo(GET_THREAD());
1482 }
1483 
1484 static VALUE
1486 {
1487  return get_errinfo();
1488 }
1489 
1490 #if 0
1491 static void
1492 errinfo_setter(VALUE val, ID id, VALUE *var)
1493 {
1495  rb_raise(rb_eTypeError, "assigning non-exception to $!");
1496  }
1497  else {
1498  VALUE *ptr = errinfo_place(GET_THREAD());
1499  if (ptr) {
1500  *ptr = val;
1501  }
1502  else {
1503  rb_raise(rb_eRuntimeError, "errinfo_setter: not in rescue clause.");
1504  }
1505  }
1506 }
1507 #endif
1508 
1509 VALUE
1511 {
1512  rb_thread_t *th = GET_THREAD();
1513  return th->errinfo;
1514 }
1515 
1516 void
1518 {
1520  rb_raise(rb_eTypeError, "assigning non-exception to $!");
1521  }
1522  GET_THREAD()->errinfo = err;
1523 }
1524 
1525 VALUE
1527 {
1528  return get_errinfo();
1529 }
1530 
1531 static VALUE
1533 {
1534  VALUE err = get_errinfo();
1535  if (!NIL_P(err)) {
1536  return get_backtrace(err);
1537  }
1538  else {
1539  return Qnil;
1540  }
1541 }
1542 
1543 static void
1545 {
1546  VALUE err = get_errinfo();
1547  if (NIL_P(err)) {
1548  rb_raise(rb_eArgError, "$! not set");
1549  }
1550  set_backtrace(err, val);
1551 }
1552 
1553 /*
1554  * call-seq:
1555  * __method__ -> symbol
1556  *
1557  * Returns the name at the definition of the current method as a
1558  * Symbol.
1559  * If called outside of a method, it returns <code>nil</code>.
1560  *
1561  */
1562 
1563 static VALUE
1565 {
1566  ID fname = prev_frame_func(); /* need *method* ID */
1567 
1568  if (fname) {
1569  return ID2SYM(fname);
1570  }
1571  else {
1572  return Qnil;
1573  }
1574 }
1575 
1576 /*
1577  * call-seq:
1578  * __callee__ -> symbol
1579  *
1580  * Returns the called name of the current method as a Symbol.
1581  * If called outside of a method, it returns <code>nil</code>.
1582  *
1583  */
1584 
1585 static VALUE
1587 {
1588  ID fname = prev_frame_callee(); /* need *callee* ID */
1589 
1590  if (fname) {
1591  return ID2SYM(fname);
1592  }
1593  else {
1594  return Qnil;
1595  }
1596 }
1597 
1598 /*
1599  * call-seq:
1600  * __dir__ -> string
1601  *
1602  * Returns the canonicalized absolute path of the directory of the file from
1603  * which this method is called. It means symlinks in the path is resolved.
1604  * If <code>__FILE__</code> is <code>nil</code>, it returns <code>nil</code>.
1605  * The return value equals to <code>File.dirname(File.realpath(__FILE__))</code>.
1606  *
1607  */
1608 static VALUE
1610 {
1611  VALUE base = rb_current_realfilepath();
1612  if (NIL_P(base)) {
1613  return Qnil;
1614  }
1615  base = rb_file_dirname(base);
1616  return base;
1617 }
1618 
1619 void
1621 {
1624 
1625  rb_define_global_function("raise", rb_f_raise, -1);
1627 
1628  rb_define_global_function("global_variables", rb_f_global_variables, 0); /* in variable.c */
1629 
1630  rb_define_global_function("__method__", rb_f_method_name, 0);
1631  rb_define_global_function("__callee__", rb_f_callee_name, 0);
1633 
1634  rb_define_method(rb_cModule, "include", rb_mod_include, -1);
1635  rb_define_method(rb_cModule, "prepend", rb_mod_prepend, -1);
1636 
1642  rb_undef_method(rb_cClass, "refine");
1643 
1644  rb_undef_method(rb_cClass, "module_function");
1645 
1646  Init_vm_eval();
1647  Init_eval_method();
1648 
1651 
1653  "include", top_include, -1);
1655  "using", top_using, 1);
1656 
1657  rb_define_method(rb_mKernel, "extend", rb_obj_extend, -1);
1658 
1659  rb_define_global_function("trace_var", rb_f_trace_var, -1); /* in variable.c */
1660  rb_define_global_function("untrace_var", rb_f_untrace_var, -1); /* in variable.c */
1661 
1663  rb_obj_freeze(rb_str_new2("exception reentered")));
1666 }
#define RBASIC_CLEAR_CLASS(obj)
Definition: internal.h:609
static void ruby_finalize_0(void)
Definition: eval.c:113
int ruby_run_node(void *n)
Runs the given compiled source and exits this process.
Definition: eval.c:303
rb_control_frame_t * cfp
Definition: vm_core.h:531
void rb_threadptr_unlock_all_locking_mutexes(rb_thread_t *th)
Definition: thread.c:404
VALUE rb_eStandardError
Definition: error.c:546
VALUE rb_eLocalJumpError
Definition: eval.c:27
#define RUBY_VM_CHECK_INTS(th)
Definition: vm_core.h:991
VALUE rb_exc_new(VALUE etype, const char *ptr, long len)
Definition: error.c:573
int ruby_cleanup(volatile int ex)
Destructs the VM.
Definition: eval.c:157
struct rb_ensure_entry entry
Definition: vm_core.h:521
void rb_raise_jump(VALUE mesg)
Definition: eval.c:688
static const rb_method_entry_t * method_entry_of_iseq(rb_control_frame_t *cfp, rb_iseq_t *iseq)
Definition: eval.c:868
VALUE rb_vm_backtrace_object(void)
Definition: vm_backtrace.c:536
void rb_call_inits(void)
Definition: inits.c:18
void rb_interrupt(void)
Definition: eval.c:585
#define RUBY_EVENT_C_RETURN
Definition: ruby.h:1721
#define FALSE
Definition: nkf.h:174
static VALUE rb_f_raise(int argc, VALUE *argv)
Definition: eval.c:615
#define rb_hash_lookup
Definition: tcltklib.c:269
struct rb_vm_protect_tag * protect_tag
Definition: vm_core.h:594
#define RUBY_VM_IFUNC_P(ptr)
Definition: vm_core.h:834
VALUE rb_make_exception(int argc, VALUE *argv)
Definition: eval.c:682
#define INTERNAL_EXCEPTION_P(exc)
Definition: eval_intern.h:175
VALUE rb_eSignal
Definition: error.c:544
void ruby_finalize(void)
Runs the VM finalization processes.
Definition: eval.c:140
void rb_define_virtual_variable(const char *, VALUE(*)(ANYARGS), void(*)(ANYARGS))
Definition: variable.c:616
VALUE rb_hash_dup(VALUE hash)
Definition: hash.c:329
#define NUM2INT(x)
Definition: ruby.h:630
VALUE rb_errinfo(void)
Definition: eval.c:1510
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
Definition: class.c:1646
static VALUE exc_setup_cause(VALUE exc, VALUE cause)
Definition: eval.c:439
#define RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)
Definition: vm_core.h:825
void Init_BareVM(void)
Definition: vm.c:2800
#define RUBY_VM_NORMAL_ISEQ_P(ptr)
Definition: vm_core.h:835
#define T_MODULE
Definition: ruby.h:480
#define RUBY_EVENT_RAISE
Definition: ruby.h:1722
void * ruby_options(int argc, char **argv)
Processes command line arguments and compiles the Ruby source to execute.
Definition: eval.c:93
#define Qtrue
Definition: ruby.h:426
VALUE rb_current_realfilepath(void)
Definition: vm_eval.c:1964
void rb_error_frozen(const char *what)
Definition: error.c:2077
void rb_exec_end_proc(void)
Definition: eval_jump.c:112
#define RUBY_DTRACE_RAISE(arg0, arg1, arg2)
Definition: probes.h:37
void rb_using_refinement(NODE *cref, VALUE klass, VALUE module)
Definition: eval.c:1100
#define CLASS_OR_MODULE_P(obj)
Definition: eval.c:35
VALUE rb_refinement_module_get_refined_class(VALUE module)
Definition: eval.c:1190
static void set_backtrace(VALUE info, VALUE bt)
Definition: eval_error.c:63
void rb_define_private_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1491
VALUE data2
Definition: vm_core.h:516
ID rb_frame_this_func(void)
Definition: eval.c:943
#define sysstack_error
Definition: vm_core.h:901
VALUE rb_eTypeError
Definition: error.c:548
static int sysexit_status(VALUE err)
Definition: eval_error.c:238
static VALUE rb_mod_include(int argc, VALUE *argv, VALUE module)
Definition: eval.c:1025
#define rb_check_arity
Definition: intern.h:296
int ruby_exec_node(void *n)
Runs the given compiled source.
Definition: eval.c:315
#define UNREACHABLE
Definition: ruby.h:42
static ID frame_func_id(rb_control_frame_t *cfp)
Definition: eval.c:883
VALUE rb_ary_push(VALUE ary, VALUE item)
Definition: array.c:900
static void add_activated_refinement(VALUE activated_refinements, VALUE klass, VALUE refinement)
Definition: eval.c:1199
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
Definition: vm_eval.c:781
#define STACK_UPPER(x, a, b)
Definition: gc.h:74
VALUE rb_iv_set(VALUE, const char *, VALUE)
Definition: variable.c:2612
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *state)
Definition: eval.c:807
VALUE rb_iv_get(VALUE, const char *)
Definition: variable.c:2604
struct rb_iseq_struct * local_iseq
Definition: vm_core.h:297
#define Check_Type(v, t)
Definition: ruby.h:532
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:1857
struct rb_vm_protect_tag * prev
Definition: vm_core.h:496
void Init_vm_eval(void)
Definition: vm_eval.c:1974
NODE * rb_vm_cref(void)
Definition: vm.c:1015
ID called_id
Definition: method.h:101
#define TH_EXEC_TAG()
Definition: eval_intern.h:165
VALUE rb_obj_is_kind_of(VALUE, VALUE)
Definition: object.c:646
void Init_heap(void)
Definition: gc.c:1661
#define RCLASS_M_TBL_WRAPPER(c)
Definition: internal.h:294
static VALUE mod_using(VALUE self, VALUE module)
Definition: eval.c:1294
void rb_vm_localjump_error(const char *mesg, VALUE value, int reason)
Definition: vm.c:1094
void rb_include_module(VALUE klass, VALUE module)
Definition: class.c:808
ID defined_method_id
Definition: vm_core.h:319
#define RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp)
Definition: vm_core.h:831
static VALUE errinfo_getter(ID id)
Definition: eval.c:1485
#define TAG_RAISE
Definition: eval_intern.h:193
#define PUSH_TAG()
Definition: eval_intern.h:141
static VALUE rb_obj_extend(int argc, VALUE *argv, VALUE obj)
Definition: eval.c:1383
void Init_eval(void)
Definition: eval.c:1620
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
Definition: class.c:1675
#define FIXNUM_P(f)
Definition: ruby.h:347
void rb_undef_method(VALUE klass, const char *name)
Definition: class.c:1497
VALUE rb_rubylevel_errinfo(void)
Definition: eval.c:1526
VALUE rb_iseq_eval_main(VALUE iseqval)
Definition: vm.c:1659
ID rb_frame_last_func(void)
Definition: eval.c:982
void rb_thread_terminate_all(void)
Definition: thread.c:421
const char * rb_obj_classname(VALUE)
Definition: variable.c:406
VALUE rb_enc_sprintf(rb_encoding *enc, const char *format,...)
Definition: sprintf.c:1231
#define TAG_FATAL
Definition: eval_intern.h:195
Definition: node.h:239
int rb_iterator_p(void)
Definition: eval.c:725
void rb_hash_foreach(VALUE hash, int(*func)(ANYARGS), VALUE farg)
Definition: hash.c:273
void rb_exc_raise(VALUE mesg)
Definition: eval.c:567
#define FL_SINGLETON
Definition: ruby.h:1133
void rb_prepend_module(VALUE klass, VALUE module)
Definition: class.c:921
NORETURN(void rb_raise_jump(VALUE))
VALUE * stack
Definition: vm_core.h:529
VALUE rb_obj_dup(VALUE)
Definition: object.c:406
VALUE rb_singleton_class(VALUE obj)
Returns the singleton class of obj.
Definition: class.c:1619
#define RB_TYPE_P(obj, type)
Definition: ruby.h:1672
enum rb_iseq_struct::iseq_type type
#define TH_POP_TAG()
Definition: eval_intern.h:128
static VALUE rb_f_method_name(void)
Definition: eval.c:1564
#define FL_TEST(x, f)
Definition: ruby.h:1169
static VALUE rb_mod_prepend_features(VALUE module, VALUE prepend)
Definition: eval.c:1055
VALUE rb_rescue(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*r_proc)(ANYARGS), VALUE data2)
Definition: eval.c:799
static ID prev_frame_callee(void)
Definition: eval.c:966
static VALUE get_backtrace(VALUE info)
Definition: eval_error.c:44
static VALUE f_current_dirname(void)
Definition: eval.c:1609
static ID frame_called_id(rb_control_frame_t *cfp)
Definition: eval.c:913
static int error_handle(int ex)
Definition: eval_error.c:245
int rb_block_given_p(void)
Definition: eval.c:712
void * rb_mod_const_at(VALUE, void *)
Definition: variable.c:2004
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
Definition: hash.c:1402
#define EXEC_TAG()
Definition: eval_intern.h:168
int rb_threadptr_set_raised(rb_thread_t *th)
Definition: thread.c:2100
void ruby_init(void)
Definition: eval.c:73
#define val
RUBY_EXTERN VALUE rb_cObject
Definition: ruby.h:1561
VALUE rb_eRuntimeError
Definition: error.c:547
#define RMODULE_IS_REFINEMENT
Definition: ruby.h:802
VALUE rb_eSysStackError
Definition: eval.c:28
VALUE(* e_proc)(ANYARGS)
Definition: vm_core.h:515
VALUE rb_obj_as_string(VALUE)
Definition: string.c:1011
VALUE rb_yield_refine_block(VALUE refinement, VALUE refinements)
Definition: vm_eval.c:1534
VALUE rb_ary_new(void)
Definition: array.c:499
#define OBJ_WB_UNPROTECT(x)
Definition: ruby.h:1199
#define exception_error
Definition: eval.c:30
RUBY_EXTERN VALUE rb_mKernel
Definition: ruby.h:1549
#define JUMP_TAG(st)
Definition: eval_intern.h:173
rb_iseq_t * iseq
Definition: vm_core.h:448
#define NIL_P(v)
Definition: ruby.h:438
#define RMODULE_IS_OVERLAID
Definition: ruby.h:801
static VALUE RCLASS_SET_SUPER(VALUE klass, VALUE super)
Definition: internal.h:319
void rb_thread_stop_timer_thread(int close_anyway)
Definition: thread.c:3860
#define PASS_PASSED_BLOCK()
Definition: eval_intern.h:12
static VALUE rb_mod_prepend(int argc, VALUE *argv, VALUE module)
Definition: eval.c:1073
static VALUE rb_mod_extend_object(VALUE mod, VALUE obj)
Definition: eval.c:1351
#define OBJ_FROZEN(x)
Definition: ruby.h:1193
void rb_threadptr_check_signal(rb_thread_t *mth)
Definition: thread.c:3819
int argc
Definition: ruby.c:131
#define Qfalse
Definition: ruby.h:425
#define rb_sourcefile()
Definition: tcltklib.c:98
Definition: method.h:97
RUBY_EXTERN VALUE rb_cModule
Definition: ruby.h:1580
rb_block_t * base_block
Definition: vm_core.h:555
#define MEMCPY(p1, p2, type, n)
Definition: ruby.h:1360
#define T_NODE
Definition: ruby.h:498
void ruby_stop(int ex)
Calls ruby_cleanup() and exits the process.
Definition: eval.c:264
#define rb_str_new2
Definition: intern.h:840
int err
Definition: win32.c:114
#define OBJ_FREEZE(x)
Definition: ruby.h:1194
#define EXIT_FAILURE
Definition: eval_intern.h:24
VALUE rb_mod_constants(int, VALUE *, VALUE)
Definition: variable.c:2071
#define POP_TAG()
Definition: eval_intern.h:142
static VALUE hidden_identity_hash_new()
Definition: eval.c:1090
VALUE rb_vm_top_self()
Definition: vm.c:2834
VALUE klass
Definition: method.h:102
void rb_trap_exit(void)
Definition: signal.c:861
#define numberof(array)
Definition: etc.c:602
#define rb_thread_raised_clear(th)
Definition: eval_intern.h:226
#define RCLASS_REFINED_CLASS(c)
Definition: internal.h:298
void rb_need_block(void)
Definition: eval.c:733
#define TRUE
Definition: nkf.h:175
#define EXIT_SUCCESS
Definition: error.c:29
static VALUE rb_mod_nesting(void)
Definition: eval.c:337
Definition: id.h:99
VALUE rb_include_class_new(VALUE module, VALUE super)
Definition: class.c:773
static ID prev_frame_func(void)
Definition: eval.c:974
void ruby_prog_init(void)
Defines built-in variables.
Definition: ruby.c:1913
VALUE rb_file_dirname(VALUE fname)
Definition: file.c:3911
VALUE rb_hash_new(void)
Definition: hash.c:307
static void ruby_finalize_1(void)
Definition: eval.c:125
void * rb_mod_const_of(VALUE, void *)
Definition: variable.c:2017
VALUE rb_ivar_set(VALUE, ID, VALUE)
Definition: variable.c:1133
struct rb_iseq_struct * parent_iseq
Definition: vm_core.h:296
#define PRIsVALUE
Definition: ruby.h:137
VALUE rb_eInterrupt
Definition: error.c:543
unsigned long ID
Definition: ruby.h:89
rb_encoding * rb_usascii_encoding(void)
Definition: encoding.c:1272
#define Qnil
Definition: ruby.h:427
void rb_clear_method_cache_by_class(VALUE)
Definition: vm_method.c:66
VALUE rb_const_list(void *)
Definition: variable.c:2039
#define BUILTIN_TYPE(x)
Definition: ruby.h:502
#define OBJ_TAINT(x)
Definition: ruby.h:1184
unsigned long VALUE
Definition: ruby.h:88
#define SAVE_ROOT_JMPBUF(th, stmt)
Definition: eval_intern.h:112
#define rb_funcall2
Definition: ruby.h:1464
static VALUE result
Definition: nkf.c:40
RUBY_JMP_BUF rb_jmpbuf_t
Definition: vm_core.h:482
int ruby_vm_destruct(ruby_vm_t *vm)
#define RBASIC(obj)
Definition: ruby.h:1116
static void setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg)
Definition: eval.c:465
void rb_extend_object(VALUE obj, VALUE module)
Definition: eval.c:1318
int rb_threadptr_reset_raised(rb_thread_t *th)
Definition: thread.c:2110
#define FIX2INT(x)
Definition: ruby.h:632
VALUE rb_rescue2(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*r_proc)(ANYARGS), VALUE data2,...)
Definition: eval.c:741
#define rb_ary_new3
Definition: intern.h:91
#define TH_PUSH_TAG(th)
Definition: eval_intern.h:122
VALUE rb_check_funcall(VALUE, ID, int, const VALUE *)
Definition: vm_eval.c:410
void ruby_init_stack(volatile VALUE *)
VALUE rb_ensure(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*e_proc)(ANYARGS), VALUE data2)
Definition: eval.c:839
static VALUE get_errinfo(void)
Definition: eval.c:1479
struct rb_ensure_list * next
Definition: vm_core.h:520
RUBY_EXTERN VALUE rb_cClass
Definition: ruby.h:1565
VALUE flags
Definition: node.h:240
void rb_jump_tag(int tag)
Definition: eval.c:706
#define RUBY_VM_END_CONTROL_FRAME(th)
Definition: vm_core.h:827
void rb_using_module(NODE *cref, VALUE module)
Definition: eval.c:1182
static void using_module_recursive(NODE *cref, VALUE klass)
Definition: eval.c:1152
static int ruby_exec_internal(void *n)
Definition: eval.c:243
enum rb_thread_status status
Definition: vm_core.h:562
#define RUBY_DTRACE_RAISE_ENABLED()
Definition: probes.h:36
#define va_init_list(a, b)
Definition: tcltklib.c:62
static void warn_printf(const char *fmt,...)
Definition: eval_error.c:7
#define rb_exc_new3
Definition: intern.h:248
static VALUE top_include(int argc, VALUE *argv, VALUE self)
Definition: eval.c:1411
static rb_control_frame_t * previous_frame(rb_thread_t *th)
Definition: eval.c:955
VALUE rb_exc_new_cstr(VALUE etype, const char *s)
Definition: error.c:579
static VALUE top_using(VALUE self, VALUE module)
Definition: eval.c:1431
#define INT2FIX(i)
Definition: ruby.h:231
VALUE top_wrapper
Definition: vm_core.h:552
#define UNLIMITED_ARGUMENTS
Definition: intern.h:44
#define RCLASS_SUPER(c)
Definition: classext.h:16
int rb_sourceline(void)
Definition: vm.c:1001
VALUE rb_module_new(void)
Definition: class.c:708
void * ruby_process_options(int, char **)
Definition: ruby.c:1960
ID rb_frame_callee(void)
Definition: eval.c:949
rb_method_definition_t * def
Definition: method.h:100
void rb_set_errinfo(VALUE err)
Definition: eval.c:1517
#define ANYARGS
Definition: defines.h:98
const rb_method_entry_t * me
Definition: vm_core.h:455
VALUE marker
Definition: vm_core.h:514
static VALUE * errinfo_place(rb_thread_t *th)
Definition: eval.c:1445
void ruby_sig_finalize(void)
Definition: signal.c:1244
VALUE rb_check_string_type(VALUE)
Definition: string.c:1678
#define RTEST(v)
Definition: ruby.h:437
rb_block_t * rb_vm_control_frame_block_ptr(rb_control_frame_t *cfp)
Definition: vm.c:59
VALUE rb_f_global_variables(void)
Definition: variable.c:853
#define NODE_FL_CREF_OMOD_SHARED
Definition: node.h:277
rb_ensure_list_t * ensure_list
Definition: vm_core.h:646
static unsigned int hash(const char *str, unsigned int len)
Definition: lex.c:56
#define T_CLASS
Definition: ruby.h:478
#define EXEC_EVENT_HOOK(th_, flag_, self_, id_, klass_, data_)
Definition: vm_core.h:1036
void rb_frozen_class_p(VALUE klass)
Definition: eval.c:406
#define ruby_debug
Definition: ruby.h:1484
NODE * rb_vm_get_cref(const rb_iseq_t *, const VALUE *)
#define FL_SET(x, f)
Definition: ruby.h:1175
#define ID2SYM(x)
Definition: ruby.h:355
VALUE rb_eFatal
Definition: error.c:545
size_t stack_size
Definition: vm_core.h:530
void * data
Definition: error.c:276
static VALUE rb_mod_s_constants(int argc, VALUE *argv, VALUE mod)
Definition: eval.c:376
void rb_vm_rewind_cfp(rb_thread_t *th, rb_control_frame_t *cfp)
Definition: vm.c:291
void rb_warning(const char *fmt,...)
Definition: error.c:236
VALUE rb_f_untrace_var(int, VALUE *)
Definition: variable.c:715
#define CONST_ID(var, str)
Definition: ruby.h:1436
static void rb_longjmp(int tag, volatile VALUE mesg)
Definition: eval.c:556
void rb_gc_call_finalizer_at_exit(void)
Definition: gc.c:2144
VALUE rb_obj_freeze(VALUE)
Definition: object.c:1070
#define SPECIAL_CONST_P(x)
Definition: ruby.h:1165
static void error_print(void)
Definition: eval_error.c:80
static VALUE get_thread_errinfo(rb_thread_t *th)
Definition: eval.c:1467
static int using_refinement(VALUE klass, VALUE module, VALUE arg)
Definition: eval.c:1143
#define RUBY_VM_VALID_CONTROL_FRAME_P(cfp, ecfp)
Definition: vm_core.h:829
static VALUE rb_mod_append_features(VALUE module, VALUE include)
Definition: eval.c:1007
#define rb_intern(str)
#define mod(x, y)
Definition: date_strftime.c:28
VALUE rb_f_trace_var(int, VALUE *)
Definition: variable.c:656
static VALUE errat_getter(ID id)
Definition: eval.c:1532
void rb_clear_trace_func(void)
Definition: vm_trace.c:225
void rb_exc_fatal(VALUE mesg)
Definition: eval.c:576
VALUE rb_eSystemExit
Definition: error.c:542
#define Qundef
Definition: ruby.h:428
#define T_ICLASS
Definition: ruby.h:479
void ruby_default_signal(int)
Definition: signal.c:340
void rb_threadptr_interrupt(rb_thread_t *th)
Definition: thread.c:359
void rb_obj_call_init(VALUE obj, int argc, VALUE *argv)
Definition: eval.c:1311
static rb_thread_t * GET_THREAD(void)
Definition: vm_core.h:929
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1479
VALUE rb_eThreadError
Definition: eval.c:730
VALUE rb_eArgError
Definition: error.c:549
static void errat_setter(VALUE val, ID id, VALUE *var)
Definition: eval.c:1544
int ruby_executable_node(void *n, int *status)
Checks the return value of ruby_options().
Definition: eval.c:282
#define RB_OBJ_WRITE(a, slot, b)
Definition: ruby.h:1221
VALUE rb_attr_get(VALUE, ID)
Definition: variable.c:1127
int ruby_setup(void)
Definition: eval.c:44
char ** argv
Definition: ruby.c:132
#define TAG_RETRY
Definition: eval_intern.h:191
static VALUE make_exception(int argc, VALUE *argv, int isstr)
Definition: eval.c:631
static VALUE rb_f_callee_name(void)
Definition: eval.c:1586
VALUE rb_eException
Definition: error.c:541
void Init_eval_method(void)
Definition: vm_method.c:1720
static VALUE rb_mod_refine(VALUE module, VALUE klass)
Definition: eval.c:1239
#define NODE_FL_CREF_PUSHED_BY_EVAL
Definition: node.h:276
#define GET_VM()
Definition: vm_core.h:922