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