Ruby  2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)
eval.c
Go to the documentation of this file.
1 /**********************************************************************
2 
3  eval.c -
4 
5  $Author$
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 "internal.h"
15 #include "eval_intern.h"
16 #include "iseq.h"
17 #include "gc.h"
18 #include "ruby/vm.h"
19 #include "vm_core.h"
20 #include "mjit.h"
21 #include "probes.h"
22 #include "probes_helper.h"
23 #ifdef HAVE_SYS_PRCTL_H
24 #include <sys/prctl.h>
25 #endif
26 
27 NORETURN(void rb_raise_jump(VALUE, VALUE));
29 
30 static int rb_ec_cleanup(rb_execution_context_t *ec, volatile int ex);
31 static int rb_ec_exec_node(rb_execution_context_t *ec, void *n);
32 
35 
38 #define id_cause ruby_static_id_cause
39 
40 #define exception_error GET_VM()->special_exceptions[ruby_error_reenter]
41 
42 #include "eval_error.c"
43 #include "eval_jump.c"
44 
45 #define CLASS_OR_MODULE_P(obj) \
46  (!SPECIAL_CONST_P(obj) && \
47  (BUILTIN_TYPE(obj) == T_CLASS || BUILTIN_TYPE(obj) == T_MODULE))
48 
54 int
56 {
57  enum ruby_tag_type state;
58 
59  if (GET_VM())
60  return 0;
61 
62  ruby_init_stack((void *)&state);
63 
64  /*
65  * Disable THP early before mallocs happen because we want this to
66  * affect as many future pages as possible for CoW-friendliness
67  */
68 #if defined(__linux__) && defined(PR_SET_THP_DISABLE)
69  prctl(PR_SET_THP_DISABLE, 1, 0, 0, 0);
70 #endif
71  Init_BareVM();
72  Init_heap();
75 
77  if ((state = EC_EXEC_TAG()) == TAG_NONE) {
78  rb_call_inits();
80  GET_VM()->running = 1;
81  }
82  EC_POP_TAG();
83 
84  return state;
85 }
86 
92 void
93 ruby_init(void)
94 {
95  int state = ruby_setup();
96  if (state) {
97  if (RTEST(ruby_debug))
98  error_print(GET_EC());
100  }
101 }
102 
113 void *
114 ruby_options(int argc, char **argv)
115 {
117  enum ruby_tag_type state;
118  void *volatile iseq = 0;
119 
120  ruby_init_stack((void *)&iseq);
121  EC_PUSH_TAG(ec);
122  if ((state = EC_EXEC_TAG()) == TAG_NONE) {
124  }
125  else {
127  state = error_handle(ec, state);
128  iseq = (void *)INT2FIX(state);
129  }
130  EC_POP_TAG();
131  return iseq;
132 }
133 
134 static void
135 rb_ec_teardown(rb_execution_context_t *ec)
136 {
137  EC_PUSH_TAG(ec);
138  if (EC_EXEC_TAG() == TAG_NONE) {
139  rb_vm_trap_exit(rb_ec_vm_ptr(ec));
140  }
141  EC_POP_TAG();
142  rb_ec_exec_end_proc(ec);
144 }
145 
146 static void
147 rb_ec_finalize(rb_execution_context_t *ec)
148 {
150  ec->errinfo = Qnil;
151  rb_objspace_call_finalizer(rb_ec_vm_ptr(ec)->objspace);
152 }
153 
161 void
163 {
165  rb_ec_teardown(ec);
166  rb_ec_finalize(ec);
167 }
168 
179 int
180 ruby_cleanup(volatile int ex)
181 {
182  return rb_ec_cleanup(GET_EC(), ex);
183 }
184 
185 static int
186 rb_ec_cleanup(rb_execution_context_t *ec, volatile int ex)
187 {
188  int state;
189  volatile VALUE errs[2] = { Qundef, Qundef };
190  int nerr;
191  rb_thread_t *th = rb_ec_thread_ptr(ec);
192  rb_thread_t *const volatile th0 = th;
193  volatile int sysex = EXIT_SUCCESS;
194  volatile int step = 0;
195 
198  EC_PUSH_TAG(ec);
199  if ((state = EC_EXEC_TAG()) == TAG_NONE) {
200  th = th0;
201  SAVE_ROOT_JMPBUF(th, { RUBY_VM_CHECK_INTS(ec); });
202 
203  step_0: step++;
204  th = th0;
205  errs[1] = ec->errinfo;
206  if (THROW_DATA_P(ec->errinfo)) ec->errinfo = Qnil;
207  ruby_init_stack(&errs[STACK_UPPER(errs, 0, 1)]);
208 
209  SAVE_ROOT_JMPBUF(th, rb_ec_teardown(ec));
210 
211  step_1: step++;
212  th = th0;
213  /* protect from Thread#raise */
214  th->status = THREAD_KILLED;
215 
216  errs[0] = ec->errinfo;
218  }
219  else {
220  switch (step) {
221  case 0: goto step_0;
222  case 1: goto step_1;
223  }
224  if (ex == 0) ex = state;
225  }
226  th = th0;
227  ec->errinfo = errs[1];
228  sysex = error_handle(ec, ex);
229 
230  state = 0;
231  for (nerr = 0; nerr < numberof(errs); ++nerr) {
232  VALUE err = ATOMIC_VALUE_EXCHANGE(errs[nerr], Qnil);
233 
234  if (!RTEST(err)) continue;
235 
236  /* ec->errinfo contains a NODE while break'ing */
237  if (THROW_DATA_P(err)) continue;
238 
240  sysex = sysexit_status(err);
241  break;
242  }
243  else if (rb_obj_is_kind_of(err, rb_eSignal)) {
245  state = NUM2INT(sig);
246  break;
247  }
248  else if (sysex == EXIT_SUCCESS) {
249  sysex = EXIT_FAILURE;
250  }
251  }
252 
253  mjit_finish(true); // We still need ISeqs here.
254 
255  rb_ec_finalize(ec);
256 
257  /* unlock again if finalizer took mutexes. */
259  EC_POP_TAG();
261  ruby_vm_destruct(th->vm);
262  if (state) ruby_default_signal(state);
263 
264  return sysex;
265 }
266 
267 static int
268 rb_ec_exec_node(rb_execution_context_t *ec, void *n)
269 {
270  volatile int state;
271  rb_iseq_t *iseq = (rb_iseq_t *)n;
272  if (!n) return 0;
273 
274  EC_PUSH_TAG(ec);
275  if ((state = EC_EXEC_TAG()) == TAG_NONE) {
276  rb_thread_t *const th = rb_ec_thread_ptr(ec);
277  SAVE_ROOT_JMPBUF(th, {
279  });
280  }
281  EC_POP_TAG();
282  return state;
283 }
284 
286 void
287 ruby_stop(int ex)
288 {
289  exit(ruby_cleanup(ex));
290 }
291 
304 int
305 ruby_executable_node(void *n, int *status)
306 {
307  VALUE v = (VALUE)n;
308  int s;
309 
310  switch (v) {
311  case Qtrue: s = EXIT_SUCCESS; break;
312  case Qfalse: s = EXIT_FAILURE; break;
313  default:
314  if (!FIXNUM_P(v)) return TRUE;
315  s = FIX2INT(v);
316  }
317  if (status) *status = s;
318  return FALSE;
319 }
320 
325 int
327 {
329  int status;
330  if (!ruby_executable_node(n, &status)) {
331  rb_ec_cleanup(ec, 0);
332  return status;
333  }
334  ruby_init_stack((void *)&status);
335  return rb_ec_cleanup(ec, rb_ec_exec_node(ec, n));
336 }
337 
339 int
341 {
342  ruby_init_stack((void *)&n);
343  return rb_ec_exec_node(GET_EC(), n);
344 }
345 
346 /*
347  * call-seq:
348  * Module.nesting -> array
349  *
350  * Returns the list of +Modules+ nested at the point of call.
351  *
352  * module M1
353  * module M2
354  * $a = Module.nesting
355  * end
356  * end
357  * $a #=> [M1::M2, M1]
358  * $a[0].name #=> "M1::M2"
359  */
360 
361 static VALUE
362 rb_mod_nesting(VALUE _)
363 {
364  VALUE ary = rb_ary_new();
365  const rb_cref_t *cref = rb_vm_cref();
366 
367  while (cref && CREF_NEXT(cref)) {
368  VALUE klass = CREF_CLASS(cref);
369  if (!CREF_PUSHED_BY_EVAL(cref) &&
370  !NIL_P(klass)) {
372  }
373  cref = CREF_NEXT(cref);
374  }
375  return ary;
376 }
377 
378 /*
379  * call-seq:
380  * Module.constants -> array
381  * Module.constants(inherited) -> array
382  *
383  * In the first form, returns an array of the names of all
384  * constants accessible from the point of call.
385  * This list includes the names of all modules and classes
386  * defined in the global scope.
387  *
388  * Module.constants.first(4)
389  * # => [:ARGF, :ARGV, :ArgumentError, :Array]
390  *
391  * Module.constants.include?(:SEEK_SET) # => false
392  *
393  * class IO
394  * Module.constants.include?(:SEEK_SET) # => true
395  * end
396  *
397  * The second form calls the instance method +constants+.
398  */
399 
400 static VALUE
401 rb_mod_s_constants(int argc, VALUE *argv, VALUE mod)
402 {
403  const rb_cref_t *cref = rb_vm_cref();
404  VALUE klass;
405  VALUE cbase = 0;
406  void *data = 0;
407 
408  if (argc > 0 || mod != rb_cModule) {
409  return rb_mod_constants(argc, argv, mod);
410  }
411 
412  while (cref) {
413  klass = CREF_CLASS(cref);
414  if (!CREF_PUSHED_BY_EVAL(cref) &&
415  !NIL_P(klass)) {
416  data = rb_mod_const_at(CREF_CLASS(cref), data);
417  if (!cbase) {
418  cbase = klass;
419  }
420  }
421  cref = CREF_NEXT(cref);
422  }
423 
424  if (cbase) {
425  data = rb_mod_const_of(cbase, data);
426  }
427  return rb_const_list(data);
428 }
429 
436 void
438 {
439  if (SPECIAL_CONST_P(klass)) {
440  noclass:
442  }
443  if (OBJ_FROZEN(klass)) {
444  const char *desc;
445 
446  if (FL_TEST(klass, FL_SINGLETON)) {
447  desc = "object";
449  if (!SPECIAL_CONST_P(klass)) {
450  switch (BUILTIN_TYPE(klass)) {
451  case T_MODULE:
452  case T_ICLASS:
453  desc = "Module";
454  break;
455  case T_CLASS:
456  desc = "Class";
457  break;
458  }
459  }
460  }
461  else {
462  switch (BUILTIN_TYPE(klass)) {
463  case T_MODULE:
464  case T_ICLASS:
465  desc = "module";
466  break;
467  case T_CLASS:
468  desc = "class";
469  break;
470  default:
471  goto noclass;
472  }
473  }
474  rb_frozen_error_raise(klass, "can't modify frozen %s: %"PRIsVALUE, desc, klass);
475  }
476 }
477 
478 NORETURN(static void rb_longjmp(rb_execution_context_t *, int, volatile VALUE, VALUE));
479 static VALUE get_errinfo(void);
480 #define get_ec_errinfo(ec) rb_ec_get_errinfo(ec)
481 
482 static VALUE
483 exc_setup_cause(VALUE exc, VALUE cause)
484 {
485 #if OPT_SUPPORT_JOKE
486  if (NIL_P(cause)) {
487  ID id_true_cause;
488  CONST_ID(id_true_cause, "true_cause");
489 
490  cause = rb_attr_get(rb_eFatal, id_true_cause);
491  if (NIL_P(cause)) {
492  cause = rb_exc_new_cstr(rb_eFatal, "because using such Ruby");
493  rb_ivar_set(cause, id_cause, INT2FIX(42)); /* the answer */
494  OBJ_FREEZE(cause);
495  rb_ivar_set(rb_eFatal, id_true_cause, cause);
496  }
497  }
498 #endif
499  if (!NIL_P(cause) && cause != exc) {
500  rb_ivar_set(exc, id_cause, cause);
501  if (!rb_ivar_defined(cause, id_cause)) {
502  rb_ivar_set(cause, id_cause, Qnil);
503  }
504  }
505  return exc;
506 }
507 
508 static inline VALUE
509 exc_setup_message(const rb_execution_context_t *ec, VALUE mesg, VALUE *cause)
510 {
511  int nocause = 0;
512  int nocircular = 0;
513 
514  if (NIL_P(mesg)) {
515  mesg = ec->errinfo;
517  nocause = 1;
518  }
519  if (NIL_P(mesg)) {
520  mesg = rb_exc_new(rb_eRuntimeError, 0, 0);
521  nocause = 0;
522  nocircular = 1;
523  }
524  if (*cause == Qundef) {
525  if (nocause) {
526  *cause = Qnil;
527  nocircular = 1;
528  }
529  else if (!rb_ivar_defined(mesg, id_cause)) {
530  *cause = get_ec_errinfo(ec);
531  }
532  else {
533  nocircular = 1;
534  }
535  }
536  else if (!NIL_P(*cause) && !rb_obj_is_kind_of(*cause, rb_eException)) {
537  rb_raise(rb_eTypeError, "exception object expected");
538  }
539 
540  if (!nocircular && !NIL_P(*cause) && *cause != Qundef && *cause != mesg) {
541  VALUE c = *cause;
542  while (!NIL_P(c = rb_attr_get(c, id_cause))) {
543  if (c == mesg) {
544  rb_raise(rb_eArgError, "circular causes");
545  }
546  }
547  }
548  return mesg;
549 }
550 
551 static void
552 setup_exception(rb_execution_context_t *ec, int tag, volatile VALUE mesg, VALUE cause)
553 {
554  VALUE e;
555  int line;
556  const char *file = rb_source_location_cstr(&line);
557  const char *const volatile file0 = file;
558 
559  if ((file && !NIL_P(mesg)) || (cause != Qundef)) {
560  volatile int state = 0;
561 
562  EC_PUSH_TAG(ec);
563  if (EC_EXEC_TAG() == TAG_NONE && !(state = rb_ec_set_raised(ec))) {
564  VALUE bt = rb_get_backtrace(mesg);
565  if (!NIL_P(bt) || cause == Qundef) {
566  if (OBJ_FROZEN(mesg)) {
567  mesg = rb_obj_dup(mesg);
568  }
569  }
570  if (cause != Qundef && !THROW_DATA_P(cause)) {
571  exc_setup_cause(mesg, cause);
572  }
573  if (NIL_P(bt)) {
574  VALUE at = rb_ec_backtrace_object(ec);
575  rb_ivar_set(mesg, idBt_locations, at);
576  set_backtrace(mesg, at);
577  }
578  rb_ec_reset_raised(ec);
579  }
580  EC_POP_TAG();
581  file = file0;
582  if (state) goto fatal;
583  }
584 
585  if (!NIL_P(mesg)) {
586  ec->errinfo = mesg;
587  }
588 
589  if (RTEST(ruby_debug) && !NIL_P(e = ec->errinfo) &&
591  enum ruby_tag_type state;
592 
593  mesg = e;
594  EC_PUSH_TAG(ec);
595  if ((state = EC_EXEC_TAG()) == TAG_NONE) {
596  ec->errinfo = Qnil;
597  e = rb_obj_as_string(mesg);
598  ec->errinfo = mesg;
599  if (file && line) {
600  e = rb_sprintf("Exception `%"PRIsVALUE"' at %s:%d - %"PRIsVALUE"\n",
601  rb_obj_class(mesg), file, line, e);
602  }
603  else if (file) {
604  e = rb_sprintf("Exception `%"PRIsVALUE"' at %s - %"PRIsVALUE"\n",
605  rb_obj_class(mesg), file, e);
606  }
607  else {
608  e = rb_sprintf("Exception `%"PRIsVALUE"' - %"PRIsVALUE"\n",
609  rb_obj_class(mesg), e);
610  }
611  warn_print_str(e);
612  }
613  EC_POP_TAG();
614  if (state == TAG_FATAL && ec->errinfo == exception_error) {
615  ec->errinfo = mesg;
616  }
617  else if (state) {
618  rb_ec_reset_raised(ec);
619  EC_JUMP_TAG(ec, state);
620  }
621  }
622 
623  if (rb_ec_set_raised(ec)) {
624  fatal:
625  ec->errinfo = exception_error;
626  rb_ec_reset_raised(ec);
627  EC_JUMP_TAG(ec, TAG_FATAL);
628  }
629 
630  if (tag != TAG_FATAL) {
632  EXEC_EVENT_HOOK(ec, RUBY_EVENT_RAISE, ec->cfp->self, 0, 0, 0, mesg);
633  }
634 }
635 
637 void
638 rb_ec_setup_exception(const rb_execution_context_t *ec, VALUE mesg, VALUE cause)
639 {
640  if (cause == Qundef) {
641  cause = get_ec_errinfo(ec);
642  }
643  if (cause != mesg) {
644  rb_ivar_set(mesg, id_cause, cause);
645  }
646 }
647 
648 static void
649 rb_longjmp(rb_execution_context_t *ec, int tag, volatile VALUE mesg, VALUE cause)
650 {
651  mesg = exc_setup_message(ec, mesg, &cause);
652  setup_exception(ec, tag, mesg, cause);
653  rb_ec_raised_clear(ec);
654  EC_JUMP_TAG(ec, tag);
655 }
656 
657 static VALUE make_exception(int argc, const VALUE *argv, int isstr);
658 
666 void
668 {
669  if (!NIL_P(mesg)) {
670  mesg = make_exception(1, &mesg, FALSE);
671  }
672  rb_longjmp(GET_EC(), TAG_RAISE, mesg, Qundef);
673 }
674 
682 void
684 {
685  if (!NIL_P(mesg)) {
686  mesg = make_exception(1, &mesg, FALSE);
687  }
688  rb_longjmp(GET_EC(), TAG_FATAL, mesg, Qnil);
689 }
690 
695 void
697 {
699 }
700 
701 enum {raise_opt_cause, raise_max_opt}; /*< \private */
702 
703 static int
704 extract_raise_opts(int argc, const VALUE *argv, VALUE *opts)
705 {
706  int i;
707  if (argc > 0) {
708  VALUE opt = argv[argc-1];
709  if (RB_TYPE_P(opt, T_HASH)) {
710  if (!RHASH_EMPTY_P(opt)) {
711  ID keywords[1];
712  CONST_ID(keywords[0], "cause");
713  rb_get_kwargs(opt, keywords, 0, -1-raise_max_opt, opts);
714  if (RHASH_EMPTY_P(opt)) --argc;
715  return argc;
716  }
717  }
718  }
719  for (i = 0; i < raise_max_opt; ++i) {
720  opts[i] = Qundef;
721  }
722  return argc;
723 }
724 
725 VALUE
727 {
728  VALUE err;
729  VALUE opts[raise_max_opt], *const cause = &opts[raise_opt_cause];
730 
731  argc = extract_raise_opts(argc, argv, opts);
732  if (argc == 0) {
733  if (*cause != Qundef) {
734  rb_raise(rb_eArgError, "only cause is given with no arguments");
735  }
736  err = get_errinfo();
737  if (!NIL_P(err)) {
738  argc = 1;
739  argv = &err;
740  }
741  }
742  rb_raise_jump(rb_make_exception(argc, argv), *cause);
743 
745 }
746 
747 /*
748  * call-seq:
749  * raise
750  * raise(string, cause: $!)
751  * raise(exception [, string [, array]], cause: $!)
752  * fail
753  * fail(string, cause: $!)
754  * fail(exception [, string [, array]], cause: $!)
755  *
756  * With no arguments, raises the exception in <code>$!</code> or raises
757  * a RuntimeError if <code>$!</code> is +nil+. With a single +String+
758  * argument, raises a +RuntimeError+ with the string as a message. Otherwise,
759  * the first parameter should be an +Exception+ class (or another
760  * object that returns an +Exception+ object when sent an +exception+
761  * message). The optional second parameter sets the message associated with
762  * the exception (accessible via Exception#message), and the third parameter
763  * is an array of callback information (accessible via Exception#backtrace).
764  * The +cause+ of the generated exception (accessible via Exception#cause)
765  * is automatically set to the "current" exception (<code>$!</code>), if any.
766  * An alternative value, either an +Exception+ object or +nil+, can be
767  * specified via the +:cause+ argument.
768  *
769  * Exceptions are caught by the +rescue+ clause of
770  * <code>begin...end</code> blocks.
771  *
772  * raise "Failed to create socket"
773  * raise ArgumentError, "No parameters", caller
774  */
775 
776 static VALUE
777 f_raise(int c, VALUE *v, VALUE _)
778 {
779  return rb_f_raise(c, v);
780 }
781 
782 static VALUE
783 make_exception(int argc, const VALUE *argv, int isstr)
784 {
785  VALUE mesg, exc;
786  int n;
787 
788  mesg = Qnil;
789  switch (argc) {
790  case 0:
791  break;
792  case 1:
793  exc = argv[0];
794  if (NIL_P(exc))
795  break;
796  if (isstr) {
797  mesg = rb_check_string_type(exc);
798  if (!NIL_P(mesg)) {
799  mesg = rb_exc_new3(rb_eRuntimeError, mesg);
800  break;
801  }
802  }
803  n = 0;
804  goto exception_call;
805 
806  case 2:
807  case 3:
808  exc = argv[0];
809  n = 1;
810  exception_call:
811  mesg = rb_check_funcall(exc, idException, n, argv+1);
812  if (mesg == Qundef) {
813  rb_raise(rb_eTypeError, "exception class/object expected");
814  }
815  break;
816  default:
817  rb_error_arity(argc, 0, 3);
818  }
819  if (argc > 0) {
820  if (!rb_obj_is_kind_of(mesg, rb_eException))
821  rb_raise(rb_eTypeError, "exception object expected");
822  if (argc > 2)
823  set_backtrace(mesg, argv[2]);
824  }
825 
826  return mesg;
827 }
828 
849 VALUE
851 {
852  return make_exception(argc, argv, TRUE);
853 }
854 
858 void
859 rb_raise_jump(VALUE mesg, VALUE cause)
860 {
862  const rb_control_frame_t *cfp = ec->cfp;
864  VALUE klass = me->owner;
865  VALUE self = cfp->self;
866  ID mid = me->called_id;
867 
868  rb_vm_pop_frame(ec);
870 
871  rb_longjmp(ec, TAG_RAISE, mesg, cause);
872 }
873 
882 void
883 rb_jump_tag(int tag)
884 {
885  if (UNLIKELY(tag < TAG_RETURN || tag > TAG_FATAL)) {
887  }
888  EC_JUMP_TAG(GET_EC(), tag);
889 }
890 
896 int
898 {
900  return FALSE;
901  }
902  else {
903  return TRUE;
904  }
905 }
906 
908 
909 int
911 {
912  return rb_vm_cframe_keyword_p(GET_EC()->cfp);
913 }
914 
915 /* -- Remove In 3.0 -- */
917 int
919 {
921 }
922 
924 
930 void
932 {
933  if (!rb_block_given_p()) {
934  rb_vm_localjump_error("no block given", Qnil, 0);
935  }
936 }
937 
960 VALUE
961 rb_rescue2(VALUE (* b_proc) (VALUE), VALUE data1,
962  VALUE (* r_proc) (VALUE, VALUE), VALUE data2, ...)
963 {
964  va_list ap;
965  va_start(ap, data2);
966  VALUE ret = rb_vrescue2(b_proc, data1, r_proc, data2, ap);
967  va_end(ap);
968  return ret;
969 }
970 
975 VALUE
976 rb_vrescue2(VALUE (* b_proc) (VALUE), VALUE data1,
977  VALUE (* r_proc) (VALUE, VALUE), VALUE data2,
978  va_list args)
979 {
980  enum ruby_tag_type state;
981  rb_execution_context_t * volatile ec = GET_EC();
982  rb_control_frame_t *volatile cfp = ec->cfp;
983  volatile VALUE result = Qfalse;
984  volatile VALUE e_info = ec->errinfo;
985 
986  EC_PUSH_TAG(ec);
987  if ((state = EC_EXEC_TAG()) == TAG_NONE) {
988  retry_entry:
989  result = (*b_proc) (data1);
990  }
991  else if (result) {
992  /* escape from r_proc */
993  if (state == TAG_RETRY) {
994  state = 0;
995  ec->errinfo = Qnil;
996  result = Qfalse;
997  goto retry_entry;
998  }
999  }
1000  else {
1001  rb_vm_rewind_cfp(ec, cfp);
1002 
1003  if (state == TAG_RAISE) {
1004  int handle = FALSE;
1005  VALUE eclass;
1006 
1007  while ((eclass = va_arg(args, VALUE)) != 0) {
1008  if (rb_obj_is_kind_of(ec->errinfo, eclass)) {
1009  handle = TRUE;
1010  break;
1011  }
1012  }
1013 
1014  if (handle) {
1015  result = Qnil;
1016  state = 0;
1017  if (r_proc) {
1018  result = (*r_proc) (data2, ec->errinfo);
1019  }
1020  ec->errinfo = e_info;
1021  }
1022  }
1023  }
1024  EC_POP_TAG();
1025  if (state)
1026  EC_JUMP_TAG(ec, state);
1027 
1028  return result;
1029 }
1030 
1045 VALUE
1046 rb_rescue(VALUE (* b_proc)(VALUE), VALUE data1,
1047  VALUE (* r_proc)(VALUE, VALUE), VALUE data2)
1048 {
1049  return rb_rescue2(b_proc, data1, r_proc, data2, rb_eStandardError,
1050  (VALUE)0);
1051 }
1052 
1070 VALUE
1071 rb_protect(VALUE (* proc) (VALUE), VALUE data, int *pstate)
1072 {
1073  volatile VALUE result = Qnil;
1074  volatile enum ruby_tag_type state;
1075  rb_execution_context_t * volatile ec = GET_EC();
1076  rb_control_frame_t *volatile cfp = ec->cfp;
1077  struct rb_vm_protect_tag protect_tag;
1078  rb_jmpbuf_t org_jmpbuf;
1079 
1080  protect_tag.prev = ec->protect_tag;
1081 
1082  EC_PUSH_TAG(ec);
1083  ec->protect_tag = &protect_tag;
1084  MEMCPY(&org_jmpbuf, &rb_ec_thread_ptr(ec)->root_jmpbuf, rb_jmpbuf_t, 1);
1085  if ((state = EC_EXEC_TAG()) == TAG_NONE) {
1086  SAVE_ROOT_JMPBUF(rb_ec_thread_ptr(ec), result = (*proc) (data));
1087  }
1088  else {
1089  rb_vm_rewind_cfp(ec, cfp);
1090  }
1091  MEMCPY(&rb_ec_thread_ptr(ec)->root_jmpbuf, &org_jmpbuf, rb_jmpbuf_t, 1);
1092  ec->protect_tag = protect_tag.prev;
1093  EC_POP_TAG();
1094 
1095  if (pstate != NULL) *pstate = state;
1096  return result;
1097 }
1098 
1113 VALUE
1114 rb_ensure(VALUE (*b_proc)(VALUE), VALUE data1, VALUE (*e_proc)(VALUE), VALUE data2)
1115 {
1116  int state;
1117  volatile VALUE result = Qnil;
1118  VALUE errinfo;
1119  rb_execution_context_t * volatile ec = GET_EC();
1120  rb_ensure_list_t ensure_list;
1121  ensure_list.entry.marker = 0;
1122  ensure_list.entry.e_proc = e_proc;
1123  ensure_list.entry.data2 = data2;
1124  ensure_list.next = ec->ensure_list;
1125  ec->ensure_list = &ensure_list;
1126  EC_PUSH_TAG(ec);
1127  if ((state = EC_EXEC_TAG()) == TAG_NONE) {
1128  result = (*b_proc) (data1);
1129  }
1130  EC_POP_TAG();
1131  errinfo = ec->errinfo;
1132  if (!NIL_P(errinfo) && !RB_TYPE_P(errinfo, T_OBJECT)) {
1133  ec->errinfo = Qnil;
1134  }
1135  ec->ensure_list=ensure_list.next;
1136  (*ensure_list.entry.e_proc)(ensure_list.entry.data2);
1137  ec->errinfo = errinfo;
1138  if (state)
1139  EC_JUMP_TAG(ec, state);
1140  return result;
1141 }
1142 
1143 static ID
1144 frame_func_id(const rb_control_frame_t *cfp)
1145 {
1147 
1148  if (me) {
1149  return me->def->original_id;
1150  }
1151  else {
1152  return 0;
1153  }
1154 }
1155 
1156 static ID
1157 frame_called_id(rb_control_frame_t *cfp)
1158 {
1160 
1161  if (me) {
1162  return me->called_id;
1163  }
1164  else {
1165  return 0;
1166  }
1167 }
1168 
1181 ID
1183 {
1184  return frame_func_id(GET_EC()->cfp);
1185 }
1186 
1198 ID
1200 {
1201  return frame_called_id(GET_EC()->cfp);
1202 }
1203 
1204 static rb_control_frame_t *
1205 previous_frame(const rb_execution_context_t *ec)
1206 {
1208  /* check if prev_cfp can be accessible */
1209  if ((void *)(ec->vm_stack + ec->vm_stack_size) == (void *)(prev_cfp)) {
1210  return 0;
1211  }
1212  return prev_cfp;
1213 }
1214 
1215 static ID
1216 prev_frame_callee(void)
1217 {
1218  rb_control_frame_t *prev_cfp = previous_frame(GET_EC());
1219  if (!prev_cfp) return 0;
1220  return frame_called_id(prev_cfp);
1221 }
1222 
1223 static ID
1224 prev_frame_func(void)
1225 {
1226  rb_control_frame_t *prev_cfp = previous_frame(GET_EC());
1227  if (!prev_cfp) return 0;
1228  return frame_func_id(prev_cfp);
1229 }
1230 
1237 ID
1239 {
1240  const rb_execution_context_t *ec = GET_EC();
1241  const rb_control_frame_t *cfp = ec->cfp;
1242  ID mid;
1243 
1244  while (!(mid = frame_func_id(cfp)) &&
1246  !RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(ec, cfp)));
1247  return mid;
1248 }
1249 
1250 /*
1251  * call-seq:
1252  * append_features(mod) -> mod
1253  *
1254  * When this module is included in another, Ruby calls
1255  * #append_features in this module, passing it the receiving module
1256  * in _mod_. Ruby's default implementation is to add the constants,
1257  * methods, and module variables of this module to _mod_ if this
1258  * module has not already been added to _mod_ or one of its
1259  * ancestors. See also Module#include.
1260  */
1261 
1262 static VALUE
1263 rb_mod_append_features(VALUE module, VALUE include)
1264 {
1265  if (!CLASS_OR_MODULE_P(include)) {
1266  Check_Type(include, T_CLASS);
1267  }
1268  rb_include_module(include, module);
1269 
1270  return module;
1271 }
1272 
1273 /*
1274  * call-seq:
1275  * include(module, ...) -> self
1276  *
1277  * Invokes Module.append_features on each parameter in reverse order.
1278  */
1279 
1280 static VALUE
1281 rb_mod_include(int argc, VALUE *argv, VALUE module)
1282 {
1283  int i;
1284  ID id_append_features, id_included;
1285 
1286  CONST_ID(id_append_features, "append_features");
1287  CONST_ID(id_included, "included");
1288 
1290  for (i = 0; i < argc; i++)
1292  while (argc--) {
1293  rb_funcall(argv[argc], id_append_features, 1, module);
1294  rb_funcall(argv[argc], id_included, 1, module);
1295  }
1296  return module;
1297 }
1298 
1299 /*
1300  * call-seq:
1301  * prepend_features(mod) -> mod
1302  *
1303  * When this module is prepended in another, Ruby calls
1304  * #prepend_features in this module, passing it the receiving module
1305  * in _mod_. Ruby's default implementation is to overlay the
1306  * constants, methods, and module variables of this module to _mod_
1307  * if this module has not already been added to _mod_ or one of its
1308  * ancestors. See also Module#prepend.
1309  */
1310 
1311 static VALUE
1312 rb_mod_prepend_features(VALUE module, VALUE prepend)
1313 {
1314  if (!CLASS_OR_MODULE_P(prepend)) {
1315  Check_Type(prepend, T_CLASS);
1316  }
1317  rb_prepend_module(prepend, module);
1318 
1319  return module;
1320 }
1321 
1322 /*
1323  * call-seq:
1324  * prepend(module, ...) -> self
1325  *
1326  * Invokes Module.prepend_features on each parameter in reverse order.
1327  */
1328 
1329 static VALUE
1330 rb_mod_prepend(int argc, VALUE *argv, VALUE module)
1331 {
1332  int i;
1333  ID id_prepend_features, id_prepended;
1334 
1335  CONST_ID(id_prepend_features, "prepend_features");
1336  CONST_ID(id_prepended, "prepended");
1337 
1339  for (i = 0; i < argc; i++)
1341  while (argc--) {
1342  rb_funcall(argv[argc], id_prepend_features, 1, module);
1343  rb_funcall(argv[argc], id_prepended, 1, module);
1344  }
1345  return module;
1346 }
1347 
1348 static void
1349 ensure_class_or_module(VALUE obj)
1350 {
1351  if (!RB_TYPE_P(obj, T_CLASS) && !RB_TYPE_P(obj, T_MODULE)) {
1353  "wrong argument type %"PRIsVALUE" (expected Class or Module)",
1354  rb_obj_class(obj));
1355  }
1356 }
1357 
1358 static VALUE
1359 hidden_identity_hash_new(void)
1360 {
1361  VALUE hash = rb_ident_hash_new();
1362 
1363  RBASIC_CLEAR_CLASS(hash); /* hide from ObjectSpace */
1364  return hash;
1365 }
1366 
1367 static VALUE
1368 refinement_superclass(VALUE superclass)
1369 {
1370  if (RB_TYPE_P(superclass, T_MODULE)) {
1371  /* FIXME: Should ancestors of superclass be used here? */
1372  return rb_include_class_new(superclass, rb_cBasicObject);
1373  }
1374  else {
1375  return superclass;
1376  }
1377 }
1378 
1383 void
1384 rb_using_refinement(rb_cref_t *cref, VALUE klass, VALUE module)
1385 {
1386  VALUE iclass, c, superclass = klass;
1387 
1388  ensure_class_or_module(klass);
1389  Check_Type(module, T_MODULE);
1390  if (NIL_P(CREF_REFINEMENTS(cref))) {
1391  CREF_REFINEMENTS_SET(cref, hidden_identity_hash_new());
1392  }
1393  else {
1394  if (CREF_OMOD_SHARED(cref)) {
1395  CREF_REFINEMENTS_SET(cref, rb_hash_dup(CREF_REFINEMENTS(cref)));
1396  CREF_OMOD_SHARED_UNSET(cref);
1397  }
1398  if (!NIL_P(c = rb_hash_lookup(CREF_REFINEMENTS(cref), klass))) {
1399  superclass = c;
1400  while (c && RB_TYPE_P(c, T_ICLASS)) {
1401  if (RBASIC(c)->klass == module) {
1402  /* already used refinement */
1403  return;
1404  }
1405  c = RCLASS_SUPER(c);
1406  }
1407  }
1408  }
1409  FL_SET(module, RMODULE_IS_OVERLAID);
1410  superclass = refinement_superclass(superclass);
1411  c = iclass = rb_include_class_new(module, superclass);
1413 
1415  RCLASS_M_TBL(OBJ_WB_UNPROTECT(module)); /* TODO: check unprotecting */
1416 
1417  module = RCLASS_SUPER(module);
1418  while (module && module != klass) {
1419  FL_SET(module, RMODULE_IS_OVERLAID);
1420  c = RCLASS_SET_SUPER(c, rb_include_class_new(module, RCLASS_SUPER(c)));
1422  module = RCLASS_SUPER(module);
1423  }
1424  rb_hash_aset(CREF_REFINEMENTS(cref), klass, iclass);
1425 }
1426 
1427 static int
1428 using_refinement(VALUE klass, VALUE module, VALUE arg)
1429 {
1430  rb_cref_t *cref = (rb_cref_t *) arg;
1431 
1432  rb_using_refinement(cref, klass, module);
1433  return ST_CONTINUE;
1434 }
1435 
1436 static void
1437 using_module_recursive(const rb_cref_t *cref, VALUE klass)
1438 {
1439  ID id_refinements;
1440  VALUE super, module, refinements;
1441 
1442  super = RCLASS_SUPER(klass);
1443  if (super) {
1444  using_module_recursive(cref, super);
1445  }
1446  switch (BUILTIN_TYPE(klass)) {
1447  case T_MODULE:
1448  module = klass;
1449  break;
1450 
1451  case T_ICLASS:
1452  module = RBASIC(klass)->klass;
1453  break;
1454 
1455  default:
1456  rb_raise(rb_eTypeError, "wrong argument type %s (expected Module)",
1458  break;
1459  }
1460  CONST_ID(id_refinements, "__refinements__");
1461  refinements = rb_attr_get(module, id_refinements);
1462  if (NIL_P(refinements)) return;
1463  rb_hash_foreach(refinements, using_refinement, (VALUE) cref);
1464 }
1465 
1470 void
1471 rb_using_module(const rb_cref_t *cref, VALUE module)
1472 {
1473  Check_Type(module, T_MODULE);
1474  using_module_recursive(cref, module);
1476 }
1477 
1479 VALUE
1480 rb_refinement_module_get_refined_class(VALUE module)
1481 {
1482  ID id_refined_class;
1483 
1484  CONST_ID(id_refined_class, "__refined_class__");
1485  return rb_attr_get(module, id_refined_class);
1486 }
1487 
1488 static void
1489 add_activated_refinement(VALUE activated_refinements,
1490  VALUE klass, VALUE refinement)
1491 {
1492  VALUE iclass, c, superclass = klass;
1493 
1494  if (!NIL_P(c = rb_hash_lookup(activated_refinements, klass))) {
1495  superclass = c;
1496  while (c && RB_TYPE_P(c, T_ICLASS)) {
1497  if (RBASIC(c)->klass == refinement) {
1498  /* already used refinement */
1499  return;
1500  }
1501  c = RCLASS_SUPER(c);
1502  }
1503  }
1504  FL_SET(refinement, RMODULE_IS_OVERLAID);
1505  superclass = refinement_superclass(superclass);
1506  c = iclass = rb_include_class_new(refinement, superclass);
1508  refinement = RCLASS_SUPER(refinement);
1509  while (refinement && refinement != klass) {
1510  FL_SET(refinement, RMODULE_IS_OVERLAID);
1511  c = RCLASS_SET_SUPER(c, rb_include_class_new(refinement, RCLASS_SUPER(c)));
1513  refinement = RCLASS_SUPER(refinement);
1514  }
1515  rb_hash_aset(activated_refinements, klass, iclass);
1516 }
1517 
1518 /*
1519  * call-seq:
1520  * refine(mod) { block } -> module
1521  *
1522  * Refine <i>mod</i> in the receiver.
1523  *
1524  * Returns a module, where refined methods are defined.
1525  */
1526 
1527 static VALUE
1528 rb_mod_refine(VALUE module, VALUE klass)
1529 {
1530  VALUE refinement;
1531  ID id_refinements, id_activated_refinements,
1532  id_refined_class, id_defined_at;
1533  VALUE refinements, activated_refinements;
1534  rb_thread_t *th = GET_THREAD();
1536 
1538  rb_raise(rb_eArgError, "no block given");
1539  }
1540  if (vm_block_handler_type(block_handler) != block_handler_type_iseq) {
1541  rb_raise(rb_eArgError, "can't pass a Proc as a block to Module#refine");
1542  }
1543 
1544  ensure_class_or_module(klass);
1545  if (RB_TYPE_P(klass, T_MODULE)) {
1547  }
1548  CONST_ID(id_refinements, "__refinements__");
1549  refinements = rb_attr_get(module, id_refinements);
1550  if (NIL_P(refinements)) {
1551  refinements = hidden_identity_hash_new();
1552  rb_ivar_set(module, id_refinements, refinements);
1553  }
1554  CONST_ID(id_activated_refinements, "__activated_refinements__");
1555  activated_refinements = rb_attr_get(module, id_activated_refinements);
1556  if (NIL_P(activated_refinements)) {
1557  activated_refinements = hidden_identity_hash_new();
1558  rb_ivar_set(module, id_activated_refinements,
1559  activated_refinements);
1560  }
1561  refinement = rb_hash_lookup(refinements, klass);
1562  if (NIL_P(refinement)) {
1563  VALUE superclass = refinement_superclass(klass);
1564  refinement = rb_module_new();
1565  RCLASS_SET_SUPER(refinement, superclass);
1566  FL_SET(refinement, RMODULE_IS_REFINEMENT);
1567  CONST_ID(id_refined_class, "__refined_class__");
1568  rb_ivar_set(refinement, id_refined_class, klass);
1569  CONST_ID(id_defined_at, "__defined_at__");
1570  rb_ivar_set(refinement, id_defined_at, module);
1571  rb_hash_aset(refinements, klass, refinement);
1572  add_activated_refinement(activated_refinements, klass, refinement);
1573  }
1574  rb_yield_refine_block(refinement, activated_refinements);
1575  return refinement;
1576 }
1577 
1578 static void
1579 ignored_block(VALUE module, const char *klass)
1580 {
1581  const char *anon = "";
1582  Check_Type(module, T_MODULE);
1583  if (!RTEST(rb_search_class_path(module))) {
1584  anon = ", maybe for Module.new";
1585  }
1586  rb_warn("%s""using doesn't call the given block""%s.", klass, anon);
1587 }
1588 
1589 /*
1590  * call-seq:
1591  * using(module) -> self
1592  *
1593  * Import class refinements from <i>module</i> into the current class or
1594  * module definition.
1595  */
1596 
1597 static VALUE
1598 mod_using(VALUE self, VALUE module)
1599 {
1600  rb_control_frame_t *prev_cfp = previous_frame(GET_EC());
1601 
1602  if (prev_frame_func()) {
1604  "Module#using is not permitted in methods");
1605  }
1606  if (prev_cfp && prev_cfp->self != self) {
1607  rb_raise(rb_eRuntimeError, "Module#using is not called on self");
1608  }
1609  if (rb_block_given_p()) {
1610  ignored_block(module, "Module#");
1611  }
1612  rb_using_module(rb_vm_cref_replace_with_duplicated_cref(), module);
1613  return self;
1614 }
1615 
1616 static int
1617 used_modules_i(VALUE _, VALUE mod, VALUE ary)
1618 {
1619  ID id_defined_at;
1620  CONST_ID(id_defined_at, "__defined_at__");
1621  while (FL_TEST(rb_class_of(mod), RMODULE_IS_REFINEMENT)) {
1622  rb_ary_push(ary, rb_attr_get(rb_class_of(mod), id_defined_at));
1623  mod = RCLASS_SUPER(mod);
1624  }
1625  return ST_CONTINUE;
1626 }
1627 
1628 /*
1629  * call-seq:
1630  * used_modules -> array
1631  *
1632  * Returns an array of all modules used in the current scope. The ordering
1633  * of modules in the resulting array is not defined.
1634  *
1635  * module A
1636  * refine Object do
1637  * end
1638  * end
1639  *
1640  * module B
1641  * refine Object do
1642  * end
1643  * end
1644  *
1645  * using A
1646  * using B
1647  * p Module.used_modules
1648  *
1649  * <em>produces:</em>
1650  *
1651  * [B, A]
1652  */
1653 static VALUE
1654 rb_mod_s_used_modules(VALUE _)
1655 {
1656  const rb_cref_t *cref = rb_vm_cref();
1657  VALUE ary = rb_ary_new();
1658 
1659  while (cref) {
1660  if (!NIL_P(CREF_REFINEMENTS(cref))) {
1661  rb_hash_foreach(CREF_REFINEMENTS(cref), used_modules_i, ary);
1662  }
1663  cref = CREF_NEXT(cref);
1664  }
1665 
1666  return rb_funcall(ary, rb_intern("uniq"), 0);
1667 }
1668 
1679 void
1681 {
1684 }
1685 
1686 void
1687 rb_obj_call_init_kw(VALUE obj, int argc, const VALUE *argv, int kw_splat)
1688 {
1690  rb_funcallv_kw(obj, idInitialize, argc, argv, kw_splat);
1691 }
1692 
1699 void
1701 {
1703 }
1704 
1705 /*
1706  * call-seq:
1707  * extend_object(obj) -> obj
1708  *
1709  * Extends the specified object by adding this module's constants and
1710  * methods (which are added as singleton methods). This is the callback
1711  * method used by Object#extend.
1712  *
1713  * module Picky
1714  * def Picky.extend_object(o)
1715  * if String === o
1716  * puts "Can't add Picky to a String"
1717  * else
1718  * puts "Picky added to #{o.class}"
1719  * super
1720  * end
1721  * end
1722  * end
1723  * (s = Array.new).extend Picky # Call Object.extend
1724  * (s = "quick brown fox").extend Picky
1725  *
1726  * <em>produces:</em>
1727  *
1728  * Picky added to Array
1729  * Can't add Picky to a String
1730  */
1731 
1732 static VALUE
1733 rb_mod_extend_object(VALUE mod, VALUE obj)
1734 {
1736  return obj;
1737 }
1738 
1739 /*
1740  * call-seq:
1741  * obj.extend(module, ...) -> obj
1742  *
1743  * Adds to _obj_ the instance methods from each module given as a
1744  * parameter.
1745  *
1746  * module Mod
1747  * def hello
1748  * "Hello from Mod.\n"
1749  * end
1750  * end
1751  *
1752  * class Klass
1753  * def hello
1754  * "Hello from Klass.\n"
1755  * end
1756  * end
1757  *
1758  * k = Klass.new
1759  * k.hello #=> "Hello from Klass.\n"
1760  * k.extend(Mod) #=> #<Klass:0x401b3bc8>
1761  * k.hello #=> "Hello from Mod.\n"
1762  */
1763 
1764 static VALUE
1765 rb_obj_extend(int argc, VALUE *argv, VALUE obj)
1766 {
1767  int i;
1768  ID id_extend_object, id_extended;
1769 
1770  CONST_ID(id_extend_object, "extend_object");
1771  CONST_ID(id_extended, "extended");
1772 
1774  for (i = 0; i < argc; i++)
1776  while (argc--) {
1777  rb_funcall(argv[argc], id_extend_object, 1, obj);
1778  rb_funcall(argv[argc], id_extended, 1, obj);
1779  }
1780  return obj;
1781 }
1782 
1783 /*
1784  * call-seq:
1785  * include(module, ...) -> self
1786  *
1787  * Invokes Module.append_features on each parameter in turn.
1788  * Effectively adds the methods and constants in each module to the
1789  * receiver.
1790  */
1791 
1792 static VALUE
1793 top_include(int argc, VALUE *argv, VALUE self)
1794 {
1795  rb_thread_t *th = GET_THREAD();
1796 
1797  if (th->top_wrapper) {
1798  rb_warning("main.include in the wrapped load is effective only in wrapper module");
1799  return rb_mod_include(argc, argv, th->top_wrapper);
1800  }
1801  return rb_mod_include(argc, argv, rb_cObject);
1802 }
1803 
1804 /*
1805  * call-seq:
1806  * using(module) -> self
1807  *
1808  * Import class refinements from <i>module</i> into the scope where
1809  * #using is called.
1810  */
1811 
1812 static VALUE
1813 top_using(VALUE self, VALUE module)
1814 {
1815  const rb_cref_t *cref = rb_vm_cref();
1816  rb_control_frame_t *prev_cfp = previous_frame(GET_EC());
1817 
1818  if (CREF_NEXT(cref) || (prev_cfp && rb_vm_frame_method_entry(prev_cfp))) {
1819  rb_raise(rb_eRuntimeError, "main.using is permitted only at toplevel");
1820  }
1821  if (rb_block_given_p()) {
1822  ignored_block(module, "main.");
1823  }
1824  rb_using_module(rb_vm_cref_replace_with_duplicated_cref(), module);
1825  return self;
1826 }
1827 
1828 static const VALUE *
1829 errinfo_place(const rb_execution_context_t *ec)
1830 {
1831  const rb_control_frame_t *cfp = ec->cfp;
1832  const rb_control_frame_t *end_cfp = RUBY_VM_END_CONTROL_FRAME(ec);
1833 
1834  while (RUBY_VM_VALID_CONTROL_FRAME_P(cfp, end_cfp)) {
1835  if (VM_FRAME_RUBYFRAME_P(cfp)) {
1836  if (cfp->iseq->body->type == ISEQ_TYPE_RESCUE) {
1837  return &cfp->ep[VM_ENV_INDEX_LAST_LVAR];
1838  }
1839  else if (cfp->iseq->body->type == ISEQ_TYPE_ENSURE &&
1842  return &cfp->ep[VM_ENV_INDEX_LAST_LVAR];
1843  }
1844  }
1846  }
1847  return 0;
1848 }
1849 
1850 VALUE
1852 {
1853  const VALUE *ptr = errinfo_place(ec);
1854  if (ptr) {
1855  return *ptr;
1856  }
1857  else {
1858  return ec->errinfo;
1859  }
1860 }
1861 
1862 static VALUE
1863 get_errinfo(void)
1864 {
1865  return get_ec_errinfo(GET_EC());
1866 }
1867 
1868 static VALUE
1869 errinfo_getter(ID id, VALUE *_)
1870 {
1871  return get_errinfo();
1872 }
1873 
1880 VALUE
1882 {
1883  return GET_EC()->errinfo;
1884 }
1885 
1894 void
1896 {
1898  rb_raise(rb_eTypeError, "assigning non-exception to $!");
1899  }
1900  GET_EC()->errinfo = err;
1901 }
1902 
1903 static VALUE
1904 errat_getter(ID id, VALUE *_)
1905 {
1906  VALUE err = get_errinfo();
1907  if (!NIL_P(err)) {
1908  return rb_get_backtrace(err);
1909  }
1910  else {
1911  return Qnil;
1912  }
1913 }
1914 
1915 static void
1916 errat_setter(VALUE val, ID id, VALUE *var)
1917 {
1918  VALUE err = get_errinfo();
1919  if (NIL_P(err)) {
1920  rb_raise(rb_eArgError, "$! not set");
1921  }
1922  set_backtrace(err, val);
1923 }
1924 
1925 /*
1926  * call-seq:
1927  * __method__ -> symbol
1928  *
1929  * Returns the name at the definition of the current method as a
1930  * Symbol.
1931  * If called outside of a method, it returns <code>nil</code>.
1932  *
1933  */
1934 
1935 static VALUE
1936 rb_f_method_name(VALUE _)
1937 {
1938  ID fname = prev_frame_func(); /* need *method* ID */
1939 
1940  if (fname) {
1941  return ID2SYM(fname);
1942  }
1943  else {
1944  return Qnil;
1945  }
1946 }
1947 
1948 /*
1949  * call-seq:
1950  * __callee__ -> symbol
1951  *
1952  * Returns the called name of the current method as a Symbol.
1953  * If called outside of a method, it returns <code>nil</code>.
1954  *
1955  */
1956 
1957 static VALUE
1958 rb_f_callee_name(VALUE _)
1959 {
1960  ID fname = prev_frame_callee(); /* need *callee* ID */
1961 
1962  if (fname) {
1963  return ID2SYM(fname);
1964  }
1965  else {
1966  return Qnil;
1967  }
1968 }
1969 
1970 /*
1971  * call-seq:
1972  * __dir__ -> string
1973  *
1974  * Returns the canonicalized absolute path of the directory of the file from
1975  * which this method is called. It means symlinks in the path is resolved.
1976  * If <code>__FILE__</code> is <code>nil</code>, it returns <code>nil</code>.
1977  * The return value equals to <code>File.dirname(File.realpath(__FILE__))</code>.
1978  *
1979  */
1980 static VALUE
1981 f_current_dirname(VALUE _)
1982 {
1983  VALUE base = rb_current_realfilepath();
1984  if (NIL_P(base)) {
1985  return Qnil;
1986  }
1987  base = rb_file_dirname(base);
1988  return base;
1989 }
1990 
1991 /*
1992  * call-seq:
1993  * global_variables -> array
1994  *
1995  * Returns an array of the names of global variables.
1996  *
1997  * global_variables.grep /std/ #=> [:$stdin, :$stdout, :$stderr]
1998  */
1999 
2000 static VALUE
2001 f_global_variables(VALUE _)
2002 {
2003  return rb_f_global_variables();
2004 }
2005 
2006 /*
2007  * call-seq:
2008  * trace_var(symbol, cmd ) -> nil
2009  * trace_var(symbol) {|val| block } -> nil
2010  *
2011  * Controls tracing of assignments to global variables. The parameter
2012  * +symbol+ identifies the variable (as either a string name or a
2013  * symbol identifier). _cmd_ (which may be a string or a
2014  * +Proc+ object) or block is executed whenever the variable
2015  * is assigned. The block or +Proc+ object receives the
2016  * variable's new value as a parameter. Also see
2017  * Kernel::untrace_var.
2018  *
2019  * trace_var :$_, proc {|v| puts "$_ is now '#{v}'" }
2020  * $_ = "hello"
2021  * $_ = ' there'
2022  *
2023  * <em>produces:</em>
2024  *
2025  * $_ is now 'hello'
2026  * $_ is now ' there'
2027  */
2028 
2029 static VALUE
2030 f_trace_var(int c, const VALUE *a, VALUE _)
2031 {
2032  return rb_f_trace_var(c, a);
2033 }
2034 
2035 /*
2036  * call-seq:
2037  * untrace_var(symbol [, cmd] ) -> array or nil
2038  *
2039  * Removes tracing for the specified command on the given global
2040  * variable and returns +nil+. If no command is specified,
2041  * removes all tracing for that variable and returns an array
2042  * containing the commands actually removed.
2043  */
2044 
2045 static VALUE
2046 f_untrace_var(int c, const VALUE *a, VALUE _)
2047 {
2048  return rb_f_untrace_var(c, a);
2049 }
2050 
2051 void
2053 {
2054  rb_define_virtual_variable("$@", errat_getter, errat_setter);
2055  rb_define_virtual_variable("$!", errinfo_getter, 0);
2056 
2057  rb_define_global_function("raise", f_raise, -1);
2058  rb_define_global_function("fail", f_raise, -1);
2059 
2060  rb_define_global_function("global_variables", f_global_variables, 0);
2061 
2062  rb_define_global_function("__method__", rb_f_method_name, 0);
2063  rb_define_global_function("__callee__", rb_f_callee_name, 0);
2064  rb_define_global_function("__dir__", f_current_dirname, 0);
2065 
2066  rb_define_method(rb_cModule, "include", rb_mod_include, -1);
2067  rb_define_method(rb_cModule, "prepend", rb_mod_prepend, -1);
2068 
2069  rb_define_private_method(rb_cModule, "append_features", rb_mod_append_features, 1);
2070  rb_define_private_method(rb_cModule, "extend_object", rb_mod_extend_object, 1);
2071  rb_define_private_method(rb_cModule, "prepend_features", rb_mod_prepend_features, 1);
2072  rb_define_private_method(rb_cModule, "refine", rb_mod_refine, 1);
2073  rb_define_private_method(rb_cModule, "using", mod_using, 1);
2074  rb_define_singleton_method(rb_cModule, "used_modules",
2075  rb_mod_s_used_modules, 0);
2076  rb_undef_method(rb_cClass, "refine");
2077 
2078  rb_undef_method(rb_cClass, "module_function");
2079 
2080  Init_vm_eval();
2081  Init_eval_method();
2082 
2083  rb_define_singleton_method(rb_cModule, "nesting", rb_mod_nesting, 0);
2084  rb_define_singleton_method(rb_cModule, "constants", rb_mod_s_constants, -1);
2085 
2087  "include", top_include, -1);
2089  "using", top_using, 1);
2090 
2091  rb_define_method(rb_mKernel, "extend", rb_obj_extend, -1);
2092 
2093  rb_define_global_function("trace_var", f_trace_var, -1);
2094  rb_define_global_function("untrace_var", f_untrace_var, -1);
2095 
2097  rb_vm_register_special_exception(ruby_error_stackfatal, rb_eFatal, "machine stack overflow in critical region");
2098 
2099  id_signo = rb_intern_const("signo");
2100  id_status = rb_intern_const("status");
2101 }
rb_execution_context_struct::protect_tag
struct rb_vm_protect_tag * protect_tag
Definition: vm_core.h:850
rb_prepend_module
void rb_prepend_module(VALUE klass, VALUE module)
Definition: class.c:999
ATOMIC_VALUE_EXCHANGE
#define ATOMIC_VALUE_EXCHANGE(var, val)
Definition: ruby_atomic.h:216
ruby_stop
void ruby_stop(int ex)
Calls ruby_cleanup() and exits the process.
Definition: eval.c:287
rb_get_kwargs
int rb_get_kwargs(VALUE keyword_hash, const ID *table, int required, int optional, VALUE *values)
Definition: class.c:1886
UNLIKELY
#define UNLIKELY(x)
Definition: ffi_common.h:126
ID
unsigned long ID
Definition: ruby.h:103
rb_threadptr_interrupt
void rb_threadptr_interrupt(rb_thread_t *th)
Definition: thread.c:510
rb_check_funcall
VALUE rb_check_funcall(VALUE, ID, int, const VALUE *)
Definition: vm_eval.c:505
sig
int sig
Definition: rb_mjit_min_header-2.7.0.h:10422
rb_f_raise
VALUE rb_f_raise(int argc, VALUE *argv)
Definition: eval.c:726
Check_Type
#define Check_Type(v, t)
Definition: ruby.h:595
TRUE
#define TRUE
Definition: nkf.h:175
block_handler_type_iseq
@ block_handler_type_iseq
Definition: vm_core.h:738
STACK_UPPER
#define STACK_UPPER(x, a, b)
Definition: gc.h:83
rb_include_module
void rb_include_module(VALUE klass, VALUE module)
Definition: class.c:869
rb_exc_new
VALUE rb_exc_new(VALUE etype, const char *ptr, long len)
Definition: error.c:959
rb_objspace_call_finalizer
void rb_objspace_call_finalizer(rb_objspace_t *objspace)
Definition: gc.c:3441
ruby_options
void * ruby_options(int argc, char **argv)
Processes command line arguments and compiles the Ruby source to execute.
Definition: eval.c:114
rb_ec_raised_clear
#define rb_ec_raised_clear(ec)
Definition: eval_intern.h:261
rb_class_modify_check
void rb_class_modify_check(VALUE klass)
Asserts that klass is not a frozen class.
Definition: eval.c:437
rb_exc_new3
#define rb_exc_new3
Definition: intern.h:293
FIX2INT
#define FIX2INT(x)
Definition: ruby.h:717
rb_iseq_struct
Definition: vm_core.h:456
va_arg
#define va_arg(v, l)
Definition: rb_mjit_min_header-2.7.0.h:3980
rb_ident_hash_new
VALUE rb_ident_hash_new(void)
Definition: hash.c:4203
rb_threadptr_unlock_all_locking_mutexes
void rb_threadptr_unlock_all_locking_mutexes(rb_thread_t *th)
Definition: thread.c:542
rb_warn
void rb_warn(const char *fmt,...)
Definition: error.c:313
rb_block_given_p
int rb_block_given_p(void)
Determines if the current method is given a block.
Definition: eval.c:897
ruby_exec_node
int ruby_exec_node(void *n)
Runs the given compiled source.
Definition: eval.c:340
rb_warning
void rb_warning(const char *fmt,...)
Definition: error.c:334
gc.h
VM_ENV_INDEX_LAST_LVAR
#define VM_ENV_INDEX_LAST_LVAR
Definition: vm_core.h:1198
RBASIC_CLEAR_CLASS
#define RBASIC_CLEAR_CLASS(obj)
Definition: internal.h:1981
rb_funcallv_kw
VALUE rb_funcallv_kw(VALUE, ID, int, const VALUE *, int)
Definition: vm_eval.c:962
cbase
VALUE cbase
Definition: rb_mjit_min_header-2.7.0.h:16133
rb_vm_cframe_keyword_p
int rb_vm_cframe_keyword_p(const rb_control_frame_t *cfp)
Definition: vm.c:102
rb_search_class_path
VALUE rb_search_class_path(VALUE)
Definition: variable.c:175
INT2FIX
#define INT2FIX(i)
Definition: ruby.h:263
rb_mod_constants
VALUE rb_mod_constants(int, const VALUE *, VALUE)
Definition: variable.c:2626
rb_empty_keyword_given_p
int rb_empty_keyword_given_p(void)
Definition: eval.c:918
rb_thread_struct::top_wrapper
VALUE top_wrapper
Definition: vm_core.h:924
rb_callable_method_entry_struct::owner
const VALUE owner
Definition: method.h:64
rb_attr_get
VALUE rb_attr_get(VALUE, ID)
Definition: variable.c:1084
EXEC_EVENT_HOOK
#define EXEC_EVENT_HOOK(ec_, flag_, self_, id_, called_id_, klass_, data_)
Definition: vm_core.h:1935
VALUE
unsigned long VALUE
Definition: ruby.h:102
GET_VM
#define GET_VM()
Definition: vm_core.h:1764
rb_obj_as_string
VALUE rb_obj_as_string(VALUE)
Definition: string.c:1440
rb_module_new
VALUE rb_module_new(void)
Definition: class.c:758
rb_eArgError
VALUE rb_eArgError
Definition: error.c:923
rb_clear_method_cache_by_class
void rb_clear_method_cache_by_class(VALUE)
Definition: vm_method.c:93
rb_intern
#define rb_intern(str)
RB_TYPE_P
#define RB_TYPE_P(obj, type)
Definition: ruby.h:560
rb_vm_cref_replace_with_duplicated_cref
rb_cref_t * rb_vm_cref_replace_with_duplicated_cref(void)
Definition: vm.c:1391
rb_intern_const
#define rb_intern_const(str)
Definition: ruby.h:1879
exception_error
#define exception_error
Definition: eval.c:40
rb_callable_method_entry_struct
Definition: method.h:59
TAG_FATAL
#define TAG_FATAL
Definition: vm_core.h:205
ruby_run_node
int ruby_run_node(void *n)
Runs the given compiled source and exits this process.
Definition: eval.c:326
rb_cModule
RUBY_EXTERN VALUE rb_cModule
Definition: ruby.h:2034
ruby_error_stackfatal
@ ruby_error_stackfatal
Definition: vm_core.h:510
rb_obj_call_init_kw
void rb_obj_call_init_kw(VALUE obj, int argc, const VALUE *argv, int kw_splat)
Definition: eval.c:1687
rb_need_block
void rb_need_block(void)
Declares that the current method needs a block.
Definition: eval.c:931
rb_ensure_list::entry
struct rb_ensure_entry entry
Definition: vm_core.h:836
CLASS_OR_MODULE_P
#define CLASS_OR_MODULE_P(obj)
Definition: eval.c:45
rb_define_global_function
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
Definition: class.c:1787
rb_execution_context_struct::ensure_list
rb_ensure_list_t * ensure_list
Definition: vm_core.h:869
rb_ec_get_errinfo
VALUE rb_ec_get_errinfo(const rb_execution_context_t *ec)
Definition: eval.c:1851
EC_JUMP_TAG
#define EC_JUMP_TAG(ec, st)
Definition: eval_intern.h:184
rb_eSignal
VALUE rb_eSignal
Definition: error.c:917
rb_frame_last_func
ID rb_frame_last_func(void)
Returns the ID of the last method in the call stack.
Definition: eval.c:1238
idException
@ idException
Definition: rb_mjit_min_header-2.7.0.h:8729
rb_ensure_entry::marker
VALUE marker
Definition: vm_core.h:829
rb_check_string_type
VALUE rb_check_string_type(VALUE)
Definition: string.c:2314
Qundef
#define Qundef
Definition: ruby.h:470
THROW_DATA_P
#define THROW_DATA_P(err)
Definition: internal.h:1201
rb_define_singleton_method
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
Definition: class.c:1755
rb_make_exception
VALUE rb_make_exception(int argc, const VALUE *argv)
Make an Exception object from the list of arguments in a manner similar to Kernel#raise.
Definition: eval.c:850
EXIT_FAILURE
#define EXIT_FAILURE
Definition: eval_intern.h:32
idInitialize
@ idInitialize
Definition: rb_mjit_min_header-2.7.0.h:8709
rb_define_method
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1551
GET_EC
#define GET_EC()
Definition: vm_core.h:1766
RUBY_VM_CHECK_INTS
#define RUBY_VM_CHECK_INTS(ec)
Definition: vm_core.h:1862
ptr
struct RIMemo * ptr
Definition: debug.c:74
rb_vm_trap_exit
void rb_vm_trap_exit(rb_vm_t *vm)
Definition: signal.c:1060
Qfalse
#define Qfalse
Definition: ruby.h:467
THREAD_KILLED
@ THREAD_KILLED
Definition: vm_core.h:786
eval_jump.c
mjit_finish
void mjit_finish(_Bool close_handle_p)
rb_hash_dup
VALUE rb_hash_dup(VALUE hash)
Definition: hash.c:1537
rb_cClass
RUBY_EXTERN VALUE rb_cClass
Definition: ruby.h:2016
SPECIAL_CONST_P
#define SPECIAL_CONST_P(x)
Definition: ruby.h:1313
NORETURN
NORETURN(void rb_raise_jump(VALUE, VALUE))
ruby_finalize
void ruby_finalize(void)
Runs the VM finalization processes.
Definition: eval.c:162
ruby_setup
int ruby_setup(void)
Initializes the VM and builtin libraries.
Definition: eval.c:55
NULL
#define NULL
Definition: _sdbm.c:101
exit
void exit(int __status) __attribute__((__noreturn__))
vm.h
rb_vm_cframe_empty_keyword_p
int rb_vm_cframe_empty_keyword_p(const rb_control_frame_t *cfp)
Definition: vm.c:109
ruby_static_id_status
ID ruby_static_id_status
Definition: eval.c:36
ruby_error_reenter
@ ruby_error_reenter
Definition: vm_core.h:507
FL_TEST
#define FL_TEST(x, f)
Definition: ruby.h:1353
PRIsVALUE
#define PRIsVALUE
Definition: ruby.h:166
rb_vm_cref
rb_cref_t * rb_vm_cref(void)
Definition: vm.c:1384
FL_SET
#define FL_SET(x, f)
Definition: ruby.h:1359
ID2SYM
#define ID2SYM(x)
Definition: ruby.h:414
Init_vm_eval
void Init_vm_eval(void)
Definition: vm_eval.c:2470
OBJ_FREEZE
#define OBJ_FREEZE(x)
Definition: ruby.h:1377
rb_thread_struct::ec
rb_execution_context_t * ec
Definition: vm_core.h:915
T_OBJECT
#define T_OBJECT
Definition: ruby.h:523
RString::ary
char ary[RSTRING_EMBED_LEN_MAX+1]
Definition: ruby.h:999
block_handler
rb_control_frame_t struct rb_calling_info const struct rb_call_info VALUE block_handler
Definition: rb_mjit_min_header-2.7.0.h:15146
ruby_cleanup
int ruby_cleanup(volatile int ex)
Destructs the VM.
Definition: eval.c:180
rb_undef_method
void rb_undef_method(VALUE klass, const char *name)
Definition: class.c:1575
rb_protect
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *pstate)
Protects a function call from potential global escapes from the function.
Definition: eval.c:1071
rb_check_arity
#define rb_check_arity
Definition: intern.h:347
VM_BLOCK_HANDLER_NONE
#define VM_BLOCK_HANDLER_NONE
Definition: vm_core.h:1291
v
int VALUE v
Definition: rb_mjit_min_header-2.7.0.h:12332
rb_f_global_variables
VALUE rb_f_global_variables(void)
Definition: variable.c:728
rb_vm_register_special_exception
#define rb_vm_register_special_exception(sp, e, m)
Definition: vm_core.h:1726
UNLIMITED_ARGUMENTS
#define UNLIMITED_ARGUMENTS
Definition: intern.h:57
ruby_init
void ruby_init(void)
Calls ruby_setup() and check error.
Definition: eval.c:93
rb_raise
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:2669
e_proc
VALUE e_proc(VALUE)
Definition: cont.c:1515
rb_ivar_get
VALUE rb_ivar_get(VALUE, ID)
Definition: variable.c:1070
Init_BareVM
void Init_BareVM(void)
Definition: vm.c:3301
rb_execution_context_struct::cfp
rb_control_frame_t * cfp
Definition: vm_core.h:847
id_signo
#define id_signo
Definition: internal.h:1587
rb_callable_method_entry_struct::called_id
ID called_id
Definition: method.h:63
rb_exc_new_cstr
#define rb_exc_new_cstr(klass, ptr)
Definition: rb_mjit_min_header-2.7.0.h:6127
obj
const VALUE VALUE obj
Definition: rb_mjit_min_header-2.7.0.h:5742
RMODULE_IS_REFINEMENT
@ RMODULE_IS_REFINEMENT
Definition: ruby.h:956
rb_obj_class
VALUE rb_obj_class(VALUE)
Equivalent to Object#class in Ruby.
Definition: object.c:217
rb_vm_frame_block_handler
VALUE rb_vm_frame_block_handler(const rb_control_frame_t *cfp)
Definition: vm.c:115
probes.h
ruby_prog_init
void ruby_prog_init(void)
Defines built-in variables.
Definition: ruby.c:2341
T_ICLASS
#define T_ICLASS
Definition: ruby.h:525
rb_threadptr_check_signal
void rb_threadptr_check_signal(rb_thread_t *mth)
Definition: thread.c:4318
rb_yield_refine_block
VALUE rb_yield_refine_block(VALUE refinement, VALUE refinements)
Definition: vm_eval.c:1883
rb_eLocalJumpError
VALUE rb_eLocalJumpError
Definition: eval.c:33
OBJ_WB_UNPROTECT
#define OBJ_WB_UNPROTECT(x)
Definition: ruby.h:1495
EC_POP_TAG
#define EC_POP_TAG()
Definition: eval_intern.h:137
rb_vm_protect_tag
Definition: vm_core.h:812
ruby_process_options
void * ruby_process_options(int, char **)
Definition: ruby.c:2387
rb_cBasicObject
RUBY_EXTERN VALUE rb_cBasicObject
Definition: ruby.h:2009
INTERNAL_EXCEPTION_P
#define INTERNAL_EXCEPTION_P(exc)
Definition: eval_intern.h:186
raise_opt_cause
@ raise_opt_cause
Definition: eval.c:701
RCLASS_M_TBL
#define RCLASS_M_TBL(c)
Definition: internal.h:1069
ruby_vm_destruct
int ruby_vm_destruct(ruby_vm_t *vm)
RUBY_VM_VALID_CONTROL_FRAME_P
#define RUBY_VM_VALID_CONTROL_FRAME_P(cfp, ecfp)
Definition: vm_core.h:1387
ruby_init_stack
void ruby_init_stack(volatile VALUE *)
iseq.h
rb_const_list
VALUE rb_const_list(void *)
Definition: variable.c:2594
rb_frame_this_func
ID rb_frame_this_func(void)
The original name of the current method.
Definition: eval.c:1182
rb_thread_struct::status
enum rb_thread_status status
Definition: rb_mjit_min_header-2.7.0.h:9892
i
uint32_t i
Definition: rb_mjit_min_header-2.7.0.h:5464
rb_vm_top_self
VALUE rb_vm_top_self(void)
Definition: vm.c:3345
rb_ensure_entry::data2
VALUE data2
Definition: vm_core.h:831
RHASH_EMPTY_P
#define RHASH_EMPTY_P(h)
Definition: ruby.h:1131
rb_jump_tag
void rb_jump_tag(int tag)
Continues the exception caught by rb_protect() and rb_eval_string_protect().
Definition: eval.c:883
rb_execution_context_struct::errinfo
VALUE errinfo
Definition: vm_core.h:875
ruby_static_id_cause
ID ruby_static_id_cause
Definition: error.c:945
rb_cref_struct
CREF (Class REFerence)
Definition: method.h:41
mjit.h
rb_hash_lookup
VALUE rb_hash_lookup(VALUE hash, VALUE key)
Definition: hash.c:1990
rb_errinfo
VALUE rb_errinfo(void)
The current exception in the current thread.
Definition: eval.c:1881
rb_ary_push
VALUE rb_ary_push(VALUE ary, VALUE item)
Definition: array.c:1195
rb_include_class_new
VALUE rb_include_class_new(VALUE module, VALUE super)
Definition: class.c:825
EC_EXEC_TAG
#define EC_EXEC_TAG()
Definition: eval_intern.h:181
va_end
#define va_end(v)
Definition: rb_mjit_min_header-2.7.0.h:3979
rb_vrescue2
VALUE rb_vrescue2(VALUE(*b_proc)(VALUE), VALUE data1, VALUE(*r_proc)(VALUE, VALUE), VALUE data2, va_list args)
An equivalent of rescue clause.
Definition: eval.c:976
vm_core.h
rb_file_dirname
VALUE rb_file_dirname(VALUE fname)
Definition: file.c:4645
rb_iseq_constant_body::type
enum rb_iseq_constant_body::iseq_type type
rb_source_location_cstr
const char * rb_source_location_cstr(int *pline)
Definition: vm.c:1376
rb_eTypeError
VALUE rb_eTypeError
Definition: error.c:922
rb_execution_context_struct::vm_stack
VALUE * vm_stack
Definition: vm_core.h:845
rb_interrupt
void rb_interrupt(void)
Raises an Interrupt exception.
Definition: eval.c:696
id_status
#define id_status
Definition: internal.h:1588
rb_ec_set_raised
int rb_ec_set_raised(rb_execution_context_t *ec)
Definition: thread.c:2344
T_CLASS
#define T_CLASS
Definition: ruby.h:524
EXIT_SUCCESS
#define EXIT_SUCCESS
Definition: error.c:39
rb_eRuntimeError
VALUE rb_eRuntimeError
Definition: error.c:920
warn_print_str
#define warn_print_str(x)
Definition: eval_error.c:23
rb_mod_const_at
void * rb_mod_const_at(VALUE, void *)
Definition: variable.c:2559
probes_helper.h
mod
#define mod(x, y)
Definition: date_strftime.c:28
rb_control_frame_struct
Definition: vm_core.h:760
rb_eThreadError
VALUE rb_eThreadError
Definition: eval.c:923
FALSE
#define FALSE
Definition: nkf.h:174
FIXNUM_P
#define FIXNUM_P(f)
Definition: ruby.h:396
RCLASS_SUPER
#define RCLASS_SUPER(c)
Definition: classext.h:16
TAG_RETRY
#define TAG_RETRY
Definition: vm_core.h:201
ruby_static_id_signo
ID ruby_static_id_signo
Definition: eval.c:36
rb_jmpbuf_t
void * rb_jmpbuf_t[5]
Definition: vm_core.h:792
rb_frozen_error_raise
void rb_frozen_error_raise(VALUE frozen_obj, const char *fmt,...)
Definition: error.c:2980
rb_hash_foreach
void rb_hash_foreach(VALUE hash, rb_foreach_func *func, VALUE farg)
Definition: hash.c:1461
rb_error_arity
MJIT_STATIC void rb_error_arity(int argc, int min, int max)
Definition: vm_insnhelper.c:387
RB_OBJ_WRITE
#define RB_OBJ_WRITE(a, slot, b)
Definition: ruby.h:1508
rb_obj_dup
VALUE rb_obj_dup(VALUE)
Equivalent to Object#dup in Ruby.
Definition: object.c:420
me
const rb_callable_method_entry_t * me
Definition: rb_mjit_min_header-2.7.0.h:13226
CONST_ID
#define CONST_ID(var, str)
Definition: ruby.h:1841
rb_extend_object
void rb_extend_object(VALUE obj, VALUE module)
Extend the object with the module.
Definition: eval.c:1700
id_cause
#define id_cause
Definition: eval.c:38
rb_vm_encoded_insn_data_table_init
void rb_vm_encoded_insn_data_table_init(void)
Definition: iseq.c:3085
T_HASH
#define T_HASH
Definition: ruby.h:531
RCLASS_REFINED_CLASS
#define RCLASS_REFINED_CLASS(c)
Definition: internal.h:1076
rb_frame_callee
ID rb_frame_callee(void)
The name of the current method.
Definition: eval.c:1199
unknown_longjmp_status
#define unknown_longjmp_status(status)
Definition: eval_error.c:428
T_MODULE
#define T_MODULE
Definition: ruby.h:526
rb_vm_frame_method_entry
const MJIT_STATIC rb_callable_method_entry_t * rb_vm_frame_method_entry(const rb_control_frame_t *cfp)
Definition: rb_mjit_min_header-2.7.0.h:12521
TAG_RAISE
#define TAG_RAISE
Definition: vm_core.h:203
rb_thread_struct::vm
rb_vm_t * vm
Definition: vm_core.h:913
rb_current_realfilepath
VALUE rb_current_realfilepath(void)
Definition: vm_eval.c:2460
rb_cObject
RUBY_EXTERN VALUE rb_cObject
Definition: ruby.h:2010
n
const char size_t n
Definition: rb_mjit_min_header-2.7.0.h:5456
rb_exc_raise
void rb_exc_raise(VALUE mesg)
Raises an exception in the current thread.
Definition: eval.c:667
rb_funcall
#define rb_funcall(recv, mid, argc,...)
Definition: rb_mjit_min_header-2.7.0.h:6585
rb_execution_context_struct::vm_stack_size
size_t vm_stack_size
Definition: vm_core.h:846
rb_control_frame_struct::self
VALUE self
Definition: vm_core.h:764
internal.h
ruby_default_signal
void ruby_default_signal(int)
Definition: signal.c:402
rb_ensure_entry::e_proc
VALUE(* e_proc)(VALUE)
Definition: vm_core.h:830
arg
VALUE arg
Definition: rb_mjit_min_header-2.7.0.h:5601
rb_mKernel
RUBY_EXTERN VALUE rb_mKernel
Definition: ruby.h:1998
argv
char ** argv
Definition: ruby.c:223
rb_set_errinfo
void rb_set_errinfo(VALUE err)
Sets the current exception ($!) to the given value.
Definition: eval.c:1895
ruby_sig_finalize
void ruby_sig_finalize(void)
Definition: signal.c:1470
rb_vm_localjump_error
MJIT_FUNC_EXPORTED void rb_vm_localjump_error(const char *mesg, VALUE value, int reason)
Definition: vm.c:1471
ST_CONTINUE
@ ST_CONTINUE
Definition: st.h:99
rb_vm_rewind_cfp
void rb_vm_rewind_cfp(rb_execution_context_t *ec, rb_control_frame_t *cfp)
Definition: vm.c:604
rb_sprintf
VALUE rb_sprintf(const char *format,...)
Definition: sprintf.c:1197
klass
VALUE klass
Definition: rb_mjit_min_header-2.7.0.h:13254
rb_eSysStackError
VALUE rb_eSysStackError
Definition: eval.c:34
rb_ensure_list
Definition: vm_core.h:834
GET_THREAD
#define GET_THREAD()
Definition: vm_core.h:1765
PASS_PASSED_BLOCK_HANDLER
#define PASS_PASSED_BLOCK_HANDLER()
Definition: eval_intern.h:23
rb_thread_stop_timer_thread
void rb_thread_stop_timer_thread(void)
Definition: thread.c:4417
rb_control_frame_struct::iseq
const rb_iseq_t * iseq
Definition: vm_core.h:763
MEMCPY
#define MEMCPY(p1, p2, type, n)
Definition: ruby.h:1753
Init_heap
void Init_heap(void)
Definition: gc.c:2909
ruby_executable_node
int ruby_executable_node(void *n, int *status)
Checks the return value of ruby_options().
Definition: eval.c:305
rb_hash_aset
VALUE rb_hash_aset(VALUE hash, VALUE key, VALUE val)
Definition: hash.c:2779
idBt_locations
@ idBt_locations
Definition: rb_mjit_min_header-2.7.0.h:8726
Init_vm_objects
void Init_vm_objects(void)
Definition: vm.c:3324
rb_ivar_defined
VALUE rb_ivar_defined(VALUE, ID)
Definition: variable.c:1317
NIL_P
#define NIL_P(v)
Definition: ruby.h:482
eval_error.c
TAG_NONE
#define TAG_NONE
Definition: vm_core.h:197
rb_mod_const_of
void * rb_mod_const_of(VALUE, void *)
Definition: variable.c:2572
Init_eval_method
void Init_eval_method(void)
Definition: vm_method.c:2281
argc
int argc
Definition: ruby.c:222
rb_obj_classname
const char * rb_obj_classname(VALUE)
Definition: variable.c:289
RUBY_EVENT_RAISE
#define RUBY_EVENT_RAISE
Definition: ruby.h:2249
rb_singleton_class
VALUE rb_singleton_class(VALUE obj)
Returns the singleton class of obj.
Definition: class.c:1725
rb_call_inits
void rb_call_inits(void)
Definition: inits.c:19
RB_NO_KEYWORDS
#define RB_NO_KEYWORDS
Definition: ruby.h:1977
rb_obj_call_init
void rb_obj_call_init(VALUE obj, int argc, const VALUE *argv)
Calls #initialize method of obj with the given arguments.
Definition: eval.c:1680
raise_max_opt
@ raise_max_opt
Definition: eval.c:701
ruby_debug
#define ruby_debug
Definition: ruby.h:1926
err
int err
Definition: win32.c:135
BUILTIN_TYPE
#define BUILTIN_TYPE(x)
Definition: ruby.h:551
rb_ec_backtrace_object
VALUE rb_ec_backtrace_object(const rb_execution_context_t *ec)
Definition: vm_backtrace.c:557
rb_eException
VALUE rb_eException
Definition: error.c:914
rb_method_definition_struct::original_id
ID original_id
Definition: method.h:179
RUBY_DTRACE_HOOK
#define RUBY_DTRACE_HOOK(name, arg)
Definition: internal.h:2586
rb_vm_pop_frame
MJIT_STATIC void rb_vm_pop_frame(rb_execution_context_t *ec)
Definition: rb_mjit_min_header-2.7.0.h:12308
RBASIC
#define RBASIC(obj)
Definition: ruby.h:1267
rb_eFatal
VALUE rb_eFatal
Definition: error.c:918
_
#define _(args)
Definition: dln.h:28
EC_PUSH_TAG
#define EC_PUSH_TAG(ec)
Definition: eval_intern.h:130
RUBY_EVENT_C_RETURN
#define RUBY_EVENT_C_RETURN
Definition: ruby.h:2248
rb_callable_method_entry_struct::def
struct rb_method_definition_struct *const def
Definition: method.h:62
Qtrue
#define Qtrue
Definition: ruby.h:468
rb_get_backtrace
VALUE rb_get_backtrace(VALUE exc)
Definition: error.c:1229
rb_ec_reset_raised
int rb_ec_reset_raised(rb_execution_context_t *ec)
Definition: thread.c:2354
OBJ_FROZEN
#define OBJ_FROZEN(x)
Definition: ruby.h:1375
rb_rescue2
VALUE rb_rescue2(VALUE(*b_proc)(VALUE), VALUE data1, VALUE(*r_proc)(VALUE, VALUE), VALUE data2,...)
An equivalent of rescue clause.
Definition: eval.c:961
rb_control_frame_struct::ep
const VALUE * ep
Definition: vm_core.h:765
rb_vm_protect_tag::prev
struct rb_vm_protect_tag * prev
Definition: vm_core.h:813
rb_keyword_given_p
int rb_keyword_given_p(void)
Definition: eval.c:910
rb_iseq_struct::body
struct rb_iseq_constant_body * body
Definition: vm_core.h:460
va_start
#define va_start(v, l)
Definition: rb_mjit_min_header-2.7.0.h:3978
rb_ivar_set
VALUE rb_ivar_set(VALUE, ID, VALUE)
Definition: variable.c:1300
rb_exc_fatal
void rb_exc_fatal(VALUE mesg)
Raises a fatal error in the current thread.
Definition: eval.c:683
get_ec_errinfo
#define get_ec_errinfo(ec)
Definition: eval.c:480
Init_eval
void Init_eval(void)
Definition: eval.c:2052
FL_SINGLETON
#define FL_SINGLETON
Definition: ruby.h:1278
RCLASS_REFINED_BY_ANY
#define RCLASS_REFINED_BY_ANY
Definition: internal.h:1086
va_list
__gnuc_va_list va_list
Definition: rb_mjit_min_header-2.7.0.h:836
iseq
const rb_iseq_t * iseq
Definition: rb_mjit_min_header-2.7.0.h:13504
rb_f_trace_var
VALUE rb_f_trace_var(int, const VALUE *)
Definition: variable.c:528
SAVE_ROOT_JMPBUF
#define SAVE_ROOT_JMPBUF(th, stmt)
Definition: eval_intern.h:120
eval_intern.h
rb_ensure
VALUE rb_ensure(VALUE(*b_proc)(VALUE), VALUE data1, VALUE(*e_proc)(VALUE), VALUE data2)
An equivalent to ensure clause.
Definition: eval.c:1114
rb_ary_new
VALUE rb_ary_new(void)
Definition: array.c:723
ruby::backward::cxxanyargs::rb_define_virtual_variable
void rb_define_virtual_variable(const char *q, type *w, void_type *e)
Define a function-backended global variable.
Definition: cxxanyargs.hpp:59
NUM2INT
#define NUM2INT(x)
Definition: ruby.h:715
Qnil
#define Qnil
Definition: ruby.h:469
exc
const rb_iseq_t const VALUE exc
Definition: rb_mjit_min_header-2.7.0.h:13504
rb_eInterrupt
VALUE rb_eInterrupt
Definition: error.c:916
rb_ec_clear_current_thread_trace_func
void rb_ec_clear_current_thread_trace_func(const rb_execution_context_t *ec)
Definition: vm_trace.c:274
rb_eStandardError
VALUE rb_eStandardError
Definition: error.c:919
rb_iseq_eval_main
VALUE rb_iseq_eval_main(const rb_iseq_t *iseq)
Definition: vm.c:2173
numberof
#define numberof(array)
Definition: etc.c:618
rb_thread_struct
Definition: vm_core.h:910
UNREACHABLE_RETURN
#define UNREACHABLE_RETURN(val)
Definition: ruby.h:59
rb_rescue
VALUE rb_rescue(VALUE(*b_proc)(VALUE), VALUE data1, VALUE(*r_proc)(VALUE, VALUE), VALUE data2)
An equivalent of rescue clause.
Definition: eval.c:1046
rb_thread_terminate_all
void rb_thread_terminate_all(void)
Definition: thread.c:559
rb_define_private_method
void rb_define_private_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1569
rb_ensure_list::next
struct rb_ensure_list * next
Definition: vm_core.h:835
RUBY_VM_PREVIOUS_CONTROL_FRAME
#define RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)
Definition: vm_core.h:1384
id__attached__
@ id__attached__
Definition: rb_mjit_min_header-2.7.0.h:8708
rb_obj_is_kind_of
VALUE rb_obj_is_kind_of(VALUE, VALUE)
Determines if obj is a kind of c.
Definition: object.c:692
ruby_tag_type
ruby_tag_type
Definition: vm_core.h:184
RTEST
#define RTEST(v)
Definition: ruby.h:481
rb_eSystemExit
VALUE rb_eSystemExit
Definition: error.c:915
cfp
rb_control_frame_t * cfp
Definition: rb_mjit_min_header-2.7.0.h:14544
RMODULE_IS_OVERLAID
@ RMODULE_IS_OVERLAID
Definition: ruby.h:955
rb_f_untrace_var
VALUE rb_f_untrace_var(int, const VALUE *)
Definition: variable.c:574
rb_execution_context_struct
Definition: vm_core.h:843