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