Ruby  2.0.0p598(2014-11-13revision48408)
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];
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;
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
262 {
263  exit(ruby_cleanup(ex));
264 }
265 
278 int
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 {
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 {
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 {
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;
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
772 {
773  volatile VALUE result = Qnil;
774  int status;
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 {
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 /*
935  * call-seq:
936  * append_features(mod) -> mod
937  *
938  * When this module is included in another, Ruby calls
939  * <code>append_features</code> in this module, passing it the
940  * receiving module in _mod_. Ruby's default implementation is
941  * to add the constants, methods, and module variables of this module
942  * to _mod_ if this module has not already been added to
943  * _mod_ or one of its ancestors. See also <code>Module#include</code>.
944  */
945 
946 static VALUE
948 {
949  switch (TYPE(include)) {
950  case T_CLASS:
951  case T_MODULE:
952  break;
953  default:
954  Check_Type(include, T_CLASS);
955  break;
956  }
957  rb_include_module(include, module);
958 
959  return module;
960 }
961 
962 /*
963  * call-seq:
964  * include(module, ...) -> self
965  *
966  * Invokes <code>Module.append_features</code> on each parameter in reverse order.
967  */
968 
969 static VALUE
971 {
972  int i;
973  ID id_append_features, id_included;
974 
975  CONST_ID(id_append_features, "append_features");
976  CONST_ID(id_included, "included");
977 
978  for (i = 0; i < argc; i++)
979  Check_Type(argv[i], T_MODULE);
980  while (argc--) {
981  rb_funcall(argv[argc], id_append_features, 1, module);
982  rb_funcall(argv[argc], id_included, 1, module);
983  }
984  return module;
985 }
986 
987 /*
988  * call-seq:
989  * prepend_features(mod) -> mod
990  *
991  * When this module is prepended in another, Ruby calls
992  * <code>prepend_features</code> in this module, passing it the
993  * receiving module in _mod_. Ruby's default implementation is
994  * to overlay the constants, methods, and module variables of this module
995  * to _mod_ if this module has not already been added to
996  * _mod_ or one of its ancestors. See also <code>Module#prepend</code>.
997  */
998 
999 static VALUE
1001 {
1002  switch (TYPE(prepend)) {
1003  case T_CLASS:
1004  case T_MODULE:
1005  break;
1006  default:
1007  Check_Type(prepend, T_CLASS);
1008  break;
1009  }
1010  rb_prepend_module(prepend, module);
1011 
1012  return module;
1013 }
1014 
1015 /*
1016  * call-seq:
1017  * prepend(module, ...) -> self
1018  *
1019  * Invokes <code>Module.prepend_features</code> on each parameter in reverse order.
1020  */
1021 
1022 static VALUE
1024 {
1025  int i;
1026  ID id_prepend_features, id_prepended;
1027 
1028  CONST_ID(id_prepend_features, "prepend_features");
1029  CONST_ID(id_prepended, "prepended");
1030  for (i = 0; i < argc; i++)
1031  Check_Type(argv[i], T_MODULE);
1032  while (argc--) {
1033  rb_funcall(argv[argc], id_prepend_features, 1, module);
1034  rb_funcall(argv[argc], id_prepended, 1, module);
1035  }
1036  return module;
1037 }
1038 
1039 static void
1041 {
1042  static int warned = 0;
1043 
1044  if (warned)
1045  return;
1046  rb_warn("Refinements are experimental, and the behavior may change in future versions of Ruby!");
1047  warned = 1;
1048 }
1049 
1050 static VALUE
1052 {
1053  VALUE hash = rb_hash_new();
1054 
1055  rb_funcall(hash, rb_intern("compare_by_identity"), 0);
1056  RBASIC(hash)->klass = 0; /* hide from ObjectSpace */
1057  return hash;
1058 }
1059 
1060 void
1062 {
1063  VALUE iclass, c, superclass = klass;
1064 
1065  Check_Type(klass, T_CLASS);
1066  Check_Type(module, T_MODULE);
1067  if (NIL_P(cref->nd_refinements)) {
1068  cref->nd_refinements = hidden_identity_hash_new();
1069  }
1070  else {
1071  if (cref->flags & NODE_FL_CREF_OMOD_SHARED) {
1072  cref->nd_refinements = rb_hash_dup(cref->nd_refinements);
1073  cref->flags &= ~NODE_FL_CREF_OMOD_SHARED;
1074  }
1075  if (!NIL_P(c = rb_hash_lookup(cref->nd_refinements, klass))) {
1076  superclass = c;
1077  while (c && RB_TYPE_P(c, T_ICLASS)) {
1078  if (RBASIC(c)->klass == module) {
1079  /* already used refinement */
1080  return;
1081  }
1082  c = RCLASS_SUPER(c);
1083  }
1084  }
1085  }
1086  FL_SET(module, RMODULE_IS_OVERLAID);
1087  c = iclass = rb_include_class_new(module, superclass);
1089  RCLASS_M_TBL(c) = RCLASS_M_TBL(module);
1090  module = RCLASS_SUPER(module);
1091  while (module && module != klass) {
1092  FL_SET(module, RMODULE_IS_OVERLAID);
1093  c = RCLASS_SUPER(c) = rb_include_class_new(module, RCLASS_SUPER(c));
1095  module = RCLASS_SUPER(module);
1096  }
1097  rb_hash_aset(cref->nd_refinements, klass, iclass);
1098 }
1099 
1100 static int
1102 {
1103  NODE *cref = (NODE *) arg;
1104 
1105  rb_using_refinement(cref, klass, module);
1106  return ST_CONTINUE;
1107 }
1108 
1109 void
1111 {
1112  ID id_refinements;
1113  VALUE refinements;
1114 
1115  Check_Type(module, T_MODULE);
1116  CONST_ID(id_refinements, "__refinements__");
1117  refinements = rb_attr_get(module, id_refinements);
1118  if (NIL_P(refinements)) return;
1119  rb_hash_foreach(refinements, using_refinement, (VALUE) cref);
1120 }
1121 
1123 {
1124  ID id_refined_class;
1125 
1126  CONST_ID(id_refined_class, "__refined_class__");
1127  return rb_attr_get(module, id_refined_class);
1128 }
1129 
1130 static void
1131 add_activated_refinement(VALUE activated_refinements,
1132  VALUE klass, VALUE refinement)
1133 {
1134  VALUE iclass, c, superclass = klass;
1135 
1136  if (!NIL_P(c = rb_hash_lookup(activated_refinements, klass))) {
1137  superclass = c;
1138  while (c && RB_TYPE_P(c, T_ICLASS)) {
1139  if (RBASIC(c)->klass == refinement) {
1140  /* already used refinement */
1141  return;
1142  }
1143  c = RCLASS_SUPER(c);
1144  }
1145  }
1146  FL_SET(refinement, RMODULE_IS_OVERLAID);
1147  c = iclass = rb_include_class_new(refinement, superclass);
1149  refinement = RCLASS_SUPER(refinement);
1150  while (refinement) {
1151  FL_SET(refinement, RMODULE_IS_OVERLAID);
1152  c = RCLASS_SUPER(c) =
1153  rb_include_class_new(refinement, RCLASS_SUPER(c));
1155  refinement = RCLASS_SUPER(refinement);
1156  }
1157  rb_hash_aset(activated_refinements, klass, iclass);
1158 }
1159 
1160 VALUE rb_yield_refine_block(VALUE refinement, VALUE refinements);
1161 
1162 /*
1163  * call-seq:
1164  * refine(klass) { block } -> module
1165  *
1166  * Refine <i>klass</i> in the receiver.
1167  *
1168  * Returns an overlaid module.
1169  */
1170 
1171 static VALUE
1173 {
1174  VALUE refinement;
1175  ID id_refinements, id_activated_refinements,
1176  id_refined_class, id_defined_at;
1177  VALUE refinements, activated_refinements;
1178  rb_thread_t *th = GET_THREAD();
1180 
1182  if (!block) {
1183  rb_raise(rb_eArgError, "no block given");
1184  }
1185  if (block->proc) {
1187  "can't pass a Proc as a block to Module#refine");
1188  }
1189  Check_Type(klass, T_CLASS);
1190  CONST_ID(id_refinements, "__refinements__");
1191  refinements = rb_attr_get(module, id_refinements);
1192  if (NIL_P(refinements)) {
1193  refinements = hidden_identity_hash_new();
1194  rb_ivar_set(module, id_refinements, refinements);
1195  }
1196  CONST_ID(id_activated_refinements, "__activated_refinements__");
1197  activated_refinements = rb_attr_get(module, id_activated_refinements);
1198  if (NIL_P(activated_refinements)) {
1199  activated_refinements = hidden_identity_hash_new();
1200  rb_ivar_set(module, id_activated_refinements,
1201  activated_refinements);
1202  }
1203  refinement = rb_hash_lookup(refinements, klass);
1204  if (NIL_P(refinement)) {
1205  refinement = rb_module_new();
1206  RCLASS_SUPER(refinement) = klass;
1207  FL_SET(refinement, RMODULE_IS_REFINEMENT);
1208  CONST_ID(id_refined_class, "__refined_class__");
1209  rb_ivar_set(refinement, id_refined_class, klass);
1210  CONST_ID(id_defined_at, "__defined_at__");
1211  rb_ivar_set(refinement, id_defined_at, module);
1212  rb_hash_aset(refinements, klass, refinement);
1213  add_activated_refinement(activated_refinements, klass, refinement);
1214  }
1215  rb_yield_refine_block(refinement, activated_refinements);
1216  return refinement;
1217 }
1218 
1219 void
1221 {
1223  rb_funcall2(obj, idInitialize, argc, argv);
1224 }
1225 
1226 void
1228 {
1229  rb_include_module(rb_singleton_class(obj), module);
1230 }
1231 
1232 /*
1233  * call-seq:
1234  * extend_object(obj) -> obj
1235  *
1236  * Extends the specified object by adding this module's constants and
1237  * methods (which are added as singleton methods). This is the callback
1238  * method used by <code>Object#extend</code>.
1239  *
1240  * module Picky
1241  * def Picky.extend_object(o)
1242  * if String === o
1243  * puts "Can't add Picky to a String"
1244  * else
1245  * puts "Picky added to #{o.class}"
1246  * super
1247  * end
1248  * end
1249  * end
1250  * (s = Array.new).extend Picky # Call Object.extend
1251  * (s = "quick brown fox").extend Picky
1252  *
1253  * <em>produces:</em>
1254  *
1255  * Picky added to Array
1256  * Can't add Picky to a String
1257  */
1258 
1259 static VALUE
1261 {
1262  rb_extend_object(obj, mod);
1263  return obj;
1264 }
1265 
1266 /*
1267  * call-seq:
1268  * obj.extend(module, ...) -> obj
1269  *
1270  * Adds to _obj_ the instance methods from each module given as a
1271  * parameter.
1272  *
1273  * module Mod
1274  * def hello
1275  * "Hello from Mod.\n"
1276  * end
1277  * end
1278  *
1279  * class Klass
1280  * def hello
1281  * "Hello from Klass.\n"
1282  * end
1283  * end
1284  *
1285  * k = Klass.new
1286  * k.hello #=> "Hello from Klass.\n"
1287  * k.extend(Mod) #=> #<Klass:0x401b3bc8>
1288  * k.hello #=> "Hello from Mod.\n"
1289  */
1290 
1291 static VALUE
1293 {
1294  int i;
1295  ID id_extend_object, id_extended;
1296 
1297  CONST_ID(id_extend_object, "extend_object");
1298  CONST_ID(id_extended, "extended");
1299 
1301  for (i = 0; i < argc; i++)
1302  Check_Type(argv[i], T_MODULE);
1303  while (argc--) {
1304  rb_funcall(argv[argc], id_extend_object, 1, obj);
1305  rb_funcall(argv[argc], id_extended, 1, obj);
1306  }
1307  return obj;
1308 }
1309 
1310 /*
1311  * call-seq:
1312  * include(module, ...) -> self
1313  *
1314  * Invokes <code>Module.append_features</code>
1315  * on each parameter in turn. Effectively adds the methods and constants
1316  * in each module to the receiver.
1317  */
1318 
1319 static VALUE
1321 {
1322  rb_thread_t *th = GET_THREAD();
1323 
1324  rb_secure(4);
1325  if (th->top_wrapper) {
1326  rb_warning("main.include in the wrapped load is effective only in wrapper module");
1327  return rb_mod_include(argc, argv, th->top_wrapper);
1328  }
1329  return rb_mod_include(argc, argv, rb_cObject);
1330 }
1331 
1332 /*
1333  * call-seq:
1334  * using(module) -> self
1335  *
1336  * Import class refinements from <i>module</i> into the scope where
1337  * <code>using</code> is called.
1338  */
1339 
1340 static VALUE
1341 top_using(VALUE self, VALUE module)
1342 {
1343  NODE *cref = rb_vm_cref();
1345 
1347  if (cref->nd_next || (prev_cfp && prev_cfp->me)) {
1348  rb_raise(rb_eRuntimeError, "using is permitted only at toplevel");
1349  }
1350  Check_Type(module, T_MODULE);
1351  rb_using_module(cref, module);
1352  rb_clear_cache();
1353  return self;
1354 }
1355 
1356 static VALUE *
1358 {
1359  rb_control_frame_t *cfp = th->cfp;
1361 
1362  while (RUBY_VM_VALID_CONTROL_FRAME_P(cfp, end_cfp)) {
1363  if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) {
1364  if (cfp->iseq->type == ISEQ_TYPE_RESCUE) {
1365  return &cfp->ep[-2];
1366  }
1367  else if (cfp->iseq->type == ISEQ_TYPE_ENSURE &&
1368  !RB_TYPE_P(cfp->ep[-2], T_NODE) &&
1369  !FIXNUM_P(cfp->ep[-2])) {
1370  return &cfp->ep[-2];
1371  }
1372  }
1373  cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
1374  }
1375  return 0;
1376 }
1377 
1378 static VALUE
1380 {
1381  VALUE *ptr = errinfo_place(th);
1382  if (ptr) {
1383  return *ptr;
1384  }
1385  else {
1386  return th->errinfo;
1387  }
1388 }
1389 
1390 static VALUE
1392 {
1393  return get_thread_errinfo(GET_THREAD());
1394 }
1395 
1396 static VALUE
1398 {
1399  return get_errinfo();
1400 }
1401 
1402 #if 0
1403 static void
1404 errinfo_setter(VALUE val, ID id, VALUE *var)
1405 {
1406  if (!NIL_P(val) && !rb_obj_is_kind_of(val, rb_eException)) {
1407  rb_raise(rb_eTypeError, "assigning non-exception to $!");
1408  }
1409  else {
1411  if (ptr) {
1412  *ptr = val;
1413  }
1414  else {
1415  rb_raise(rb_eRuntimeError, "errinfo_setter: not in rescue clause.");
1416  }
1417  }
1418 }
1419 #endif
1420 
1421 VALUE
1423 {
1424  rb_thread_t *th = GET_THREAD();
1425  return th->errinfo;
1426 }
1427 
1428 void
1430 {
1431  if (!NIL_P(err) && !rb_obj_is_kind_of(err, rb_eException)) {
1432  rb_raise(rb_eTypeError, "assigning non-exception to $!");
1433  }
1434  GET_THREAD()->errinfo = err;
1435 }
1436 
1437 VALUE
1439 {
1440  return get_errinfo();
1441 }
1442 
1443 static VALUE
1445 {
1446  VALUE err = get_errinfo();
1447  if (!NIL_P(err)) {
1448  return get_backtrace(err);
1449  }
1450  else {
1451  return Qnil;
1452  }
1453 }
1454 
1455 static void
1456 errat_setter(VALUE val, ID id, VALUE *var)
1457 {
1458  VALUE err = get_errinfo();
1459  if (NIL_P(err)) {
1460  rb_raise(rb_eArgError, "$! not set");
1461  }
1462  set_backtrace(err, val);
1463 }
1464 
1465 /*
1466  * call-seq:
1467  * __method__ -> symbol
1468  * __callee__ -> symbol
1469  *
1470  * Returns the name of the current method as a Symbol.
1471  * If called outside of a method, it returns <code>nil</code>.
1472  *
1473  */
1474 
1475 static VALUE
1477 {
1478  ID fname = rb_frame_caller(); /* need *caller* ID */
1479 
1480  if (fname) {
1481  return ID2SYM(fname);
1482  }
1483  else {
1484  return Qnil;
1485  }
1486 }
1487 
1488 static VALUE
1490 {
1491  ID fname = rb_frame_callee(); /* need *callee* ID */
1492 
1493  if (fname) {
1494  return ID2SYM(fname);
1495  }
1496  else {
1497  return Qnil;
1498  }
1499 }
1500 
1501 /*
1502  * call-seq:
1503  * __dir__ -> string
1504  *
1505  * Returns the canonicalized absolute path of the directory of the file from
1506  * which this method is called. It means symlinks in the path is resolved.
1507  * If <code>__FILE__</code> is <code>nil</code>, it returns <code>nil</code>.
1508  * The return value equals to <code>File.dirname(File.realpath(__FILE__))</code>.
1509  *
1510  */
1511 static VALUE
1513 {
1514  VALUE base = rb_current_realfilepath();
1515  if (NIL_P(base)) {
1516  return Qnil;
1517  }
1518  base = rb_file_dirname(base);
1519  return base;
1520 }
1521 
1522 void
1524 {
1527 
1528  rb_define_global_function("raise", rb_f_raise, -1);
1530 
1531  rb_define_global_function("global_variables", rb_f_global_variables, 0); /* in variable.c */
1532 
1533  rb_define_global_function("__method__", rb_f_method_name, 0);
1534  rb_define_global_function("__callee__", rb_f_callee_name, 0);
1536 
1543  rb_undef_method(rb_cClass, "refine");
1544 
1545  rb_undef_method(rb_cClass, "module_function");
1546 
1547  Init_vm_eval();
1548  Init_eval_method();
1549 
1552 
1554  "include", top_include, -1);
1556  "using", top_using, 1);
1557 
1558  rb_define_method(rb_mKernel, "extend", rb_obj_extend, -1);
1559 
1560  rb_define_global_function("trace_var", rb_f_trace_var, -1); /* in variable.c */
1561  rb_define_global_function("untrace_var", rb_f_untrace_var, -1); /* in variable.c */
1562 
1564  rb_obj_freeze(rb_str_new2("exception reentered")));
1567 }
VALUE data
Definition: tcltklib.c:3367
#define RB_TYPE_P(obj, type)
static void ruby_finalize_0(void)
Definition: eval.c:111
VALUE rb_const_list(void *)
Definition: variable.c:2017
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:953
VALUE rb_exc_new(VALUE etype, const char *ptr, long len)
Definition: error.c:541
ssize_t n
Definition: bigdecimal.c:5676
int register char * block
Definition: crypt.c:949
int ruby_cleanup(volatile int ex)
Destructs the VM.
Definition: eval.c:155
volatile VALUE ary
Definition: tcltklib.c:9712
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
VALUE rb_f_trace_var(int, VALUE *)
Definition: variable.c:646
static void warn_refinements_once()
Definition: eval.c:1040
void rb_interrupt(void)
Definition: eval.c:545
#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
RUBY_EXTERN VALUE rb_cModule
Definition: ripper.y:1445
struct rb_vm_protect_tag * protect_tag
Definition: vm_core.h:562
static VALUE VALUE th
Definition: tcltklib.c:2947
#define RUBY_VM_IFUNC_P(ptr)
Definition: vm_core.h:798
VALUE rb_make_exception(int argc, VALUE *argv)
Definition: eval.c:642
#define INTERNAL_EXCEPTION_P(exc)
Definition: eval_intern.h:150
const char * rb_obj_classname(VALUE)
Definition: variable.c:396
void * rb_mod_const_at(VALUE, void *)
Definition: variable.c:1982
VALUE rb_iv_set(VALUE, const char *, VALUE)
Definition: variable.c:2594
VALUE rb_eSignal
Definition: error.c:512
#define UNLIMITED_ARGUMENTS
void ruby_finalize(void)
Runs the VM finalization processes.
Definition: eval.c:138
#define FL_TEST(x, f)
void rb_define_singleton_method(VALUE obj, const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a singleton method for obj.
Definition: class.c:1501
#define RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)
Definition: vm_core.h:789
#define RUBY_VM_NORMAL_ISEQ_P(ptr)
Definition: vm_core.h:799
#define FL_SET(x, f)
#define T_ICLASS
VALUE proc
Definition: tcltklib.c:2958
void rb_secure(int)
Definition: safe.c:79
ssize_t i
Definition: bigdecimal.c:5676
void rb_error_frozen(const char *what)
Definition: error.c:1980
void rb_exec_end_proc(void)
Definition: eval_jump.c:97
#define T_NODE
#define RUBY_EVENT_C_RETURN
#define RUBY_DTRACE_RAISE(arg0, arg1, arg2)
Definition: probes.h:48
void rb_using_refinement(NODE *cref, VALUE klass, VALUE module)
Definition: eval.c:1061
VALUE rb_refinement_module_get_refined_class(VALUE module)
Definition: eval.c:1122
static void set_backtrace(VALUE info, VALUE bt)
Definition: eval_error.c:62
VALUE rb_iv_get(VALUE, const char *)
Definition: variable.c:2586
void rb_define_private_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1360
ID rb_frame_this_func(void)
Definition: eval.c:902
int status
Definition: tcltklib.c:2196
#define sysstack_error
Definition: vm_core.h:866
VALUE rb_obj_freeze(VALUE)
Definition: object.c:1012
VALUE rb_eTypeError
Definition: error.c:516
#define OBJ_FREEZE(x)
static int sysexit_status(VALUE err)
Definition: eval_error.c:233
VALUE rb_obj_dup(VALUE)
Definition: object.c:347
static VALUE rb_mod_include(int argc, VALUE *argv, VALUE module)
Definition: eval.c:970
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
void Init_BareVM(void)
Definition: vm.c:2461
#define TYPE(x)
void rb_call_inits(void)
Definition: inits.c:18
NIL_P(eventloop_thread)
Definition: tcltklib.c:4067
static void add_activated_refinement(VALUE activated_refinements, VALUE klass, VALUE refinement)
Definition: eval.c:1131
#define STACK_UPPER(x, a, b)
Definition: gc.h:74
VALUE var
Definition: tcltklib.c:5516
VALUE rb_protect(VALUE(*proc)(VALUE), VALUE data, int *state)
Definition: eval.c:771
VALUE rb_funcall(VALUE, ID, int,...)
Calls a method.
Definition: vm_eval.c:773
struct rb_iseq_struct * local_iseq
Definition: vm_core.h:286
void rb_raise(VALUE exc, const char *fmt,...)
Definition: error.c:1788
struct rb_vm_protect_tag * prev
Definition: vm_core.h:476
return Qtrue
Definition: tcltklib.c:9609
NODE * rb_vm_cref(void)
Definition: vm.c:898
VALUE rb_obj_class(VALUE)
Definition: object.c:194
ID called_id
Definition: method.h:99
#define TH_EXEC_TAG()
Definition: eval_intern.h:139
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:699
ID defined_method_id
Definition: vm_core.h:308
static VALUE errinfo_getter(ID id)
Definition: eval.c:1397
#define TAG_RAISE
Definition: eval_intern.h:168
#define PUSH_TAG()
Definition: eval_intern.h:136
#define rb_str_new2
static VALUE rb_obj_extend(int argc, VALUE *argv, VALUE obj)
Definition: eval.c:1292
void Init_eval(void)
Definition: eval.c:1523
void rb_define_global_function(const char *name, VALUE(*func)(ANYARGS), int argc)
Defines a global function.
Definition: class.c:1530
int state
Definition: tcltklib.c:1461
#define ID2SYM(x)
VALUE VALUE args
Definition: tcltklib.c:2560
void rb_undef_method(VALUE klass, const char *name)
Definition: class.c:1366
VALUE rb_rubylevel_errinfo(void)
Definition: eval.c:1438
VALUE rb_iseq_eval_main(VALUE iseqval)
Definition: vm.c:1511
void rb_thread_terminate_all(void)
Definition: thread.c:409
VALUE rb_enc_sprintf(rb_encoding *enc, const char *format,...)
Definition: sprintf.c:1256
void rb_hash_foreach(VALUE, int(*)(ANYARGS), VALUE)
Definition: hash.c:200
#define TAG_FATAL
Definition: eval_intern.h:170
Definition: ripper.y:240
int rb_iterator_p(void)
Definition: eval.c:685
#define NORETURN(x)
Definition: ruby.h:31
void rb_exc_raise(VALUE mesg)
Definition: eval.c:527
void rb_prepend_module(VALUE klass, VALUE module)
Definition: class.c:805
VALUE * stack
Definition: vm_core.h:498
VALUE rb_singleton_class(VALUE obj)
Returns the singleton class of obj.
Definition: class.c:1474
enum rb_iseq_struct::iseq_type type
VALUE hash
Definition: tkutil.c:267
VALUE rb_f_untrace_var(int, VALUE *)
Definition: variable.c:706
#define NODE_FL_CREF_OMOD_SHARED
#define TH_POP_TAG()
Definition: eval_intern.h:129
VALUE rb_file_dirname(VALUE fname)
Definition: file.c:3803
static VALUE rb_f_method_name(void)
Definition: eval.c:1476
static VALUE rb_mod_prepend_features(VALUE module, VALUE prepend)
Definition: eval.c:1000
VALUE rb_rescue(VALUE(*b_proc)(ANYARGS), VALUE data1, VALUE(*r_proc)(ANYARGS), VALUE data2)
Definition: eval.c:763
#define FIXNUM_P(f)
return Qfalse
Definition: tcltklib.c:6778
static VALUE get_backtrace(VALUE info)
Definition: eval_error.c:43
static VALUE f_current_dirname(void)
Definition: eval.c:1512
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
#define EXEC_TAG()
Definition: eval_intern.h:141
int rb_threadptr_set_raised(rb_thread_t *th)
Definition: thread.c:2048
void Init_heap(void)
Definition: gc.c:1039
#define Qnil
Definition: tcltklib.c:1895
void ruby_init(void)
Definition: eval.c:71
#define val
Definition: tcltklib.c:1948
VALUE rb_eRuntimeError
Definition: error.c:515
VALUE rb_eSysStackError
Definition: eval.c:30
RUBY_EXTERN VALUE rb_mKernel
Definition: ripper.y:1414
VALUE rb_yield_refine_block(VALUE refinement, VALUE refinements)
Definition: vm_eval.c:1506
VALUE rb_ary_new(void)
Definition: array.c:424
#define Check_Type(v, t)
#define exception_error
Definition: eval.c:32
unsigned long ID
Definition: ripper.y:105
va_end(args)
#define RCLASS_SUPER(c)
#define JUMP_TAG(st)
Definition: eval_intern.h:148
rb_iseq_t * iseq
Definition: vm_core.h:428
void rb_thread_stop_timer_thread(int close_anyway)
Definition: thread.c:3773
#define PASS_PASSED_BLOCK()
Definition: eval_intern.h:12
static VALUE rb_mod_prepend(int argc, VALUE *argv, VALUE module)
Definition: eval.c:1023
static VALUE rb_mod_extend_object(VALUE mod, VALUE obj)
Definition: eval.c:1260
static VALUE VALUE obj
Definition: tcltklib.c:3157
#define FIX2INT(x)
#define INT2FIX(i)
void rb_clear_cache(void)
Definition: vm_method.c:46
#define ANYARGS
void rb_trap_exit(void)
Definition: signal.c:716
void rb_threadptr_check_signal(rb_thread_t *mth)
Definition: thread.c:3732
#define rb_sourcefile()
Definition: tcltklib.c:97
Definition: method.h:95
rb_block_t * base_block
Definition: vm_core.h:524
void ruby_stop(int ex)
Calls ruby_cleanup() and exits the process.
Definition: eval.c:261
int err
Definition: win32.c:87
#define EXIT_FAILURE
Definition: eval_intern.h:24
#define POP_TAG()
Definition: eval_intern.h:137
VALUE rb_check_funcall(VALUE, ID, int, VALUE *)
Definition: vm_eval.c:408
static VALUE hidden_identity_hash_new()
Definition: eval.c:1051
VALUE rb_vm_top_self()
Definition: vm.c:2494
VALUE klass
Definition: method.h:100
void * ruby_process_options(int, char **)
Definition: ruby.c:1897
#define rb_thread_raised_clear(th)
Definition: eval_intern.h:201
void rb_need_block(void)
Definition: eval.c:693
VALUE rb_obj_as_string(VALUE)
Definition: string.c:895
VALUE * argv
Definition: tcltklib.c:1970
VALUE rb_hash_aset(VALUE, VALUE, VALUE)
#define RTEST(v)
#define TRUE
Definition: nkf.h:175
q result
Definition: tcltklib.c:7069
#define EXIT_SUCCESS
Definition: error.c:31
void * rb_mod_const_of(VALUE, void *)
Definition: variable.c:1995
static VALUE rb_mod_nesting(void)
Definition: eval.c:334
VALUE rb_include_class_new(VALUE module, VALUE super)
Definition: class.c:667
void ruby_prog_init(void)
Defines built-in variables.
Definition: ruby.c:1853
register char * s
Definition: os2.c:56
#define CONST_ID(var, str)
static void ruby_finalize_1(void)
Definition: eval.c:123
VALUE rb_f_global_variables(void)
Definition: variable.c:847
struct rb_iseq_struct * parent_iseq
Definition: vm_core.h:285
VALUE rb_eInterrupt
Definition: error.c:511
rb_encoding * rb_usascii_encoding(void)
Definition: encoding.c:1181
static ID rb_frame_caller(void)
Definition: eval.c:927
#define OBJ_FROZEN(x)
int argc
Definition: tcltklib.c:1969
#define SAVE_ROOT_JMPBUF(th, stmt)
Definition: eval_intern.h:112
ssize_t ex
Definition: bigdecimal.c:5108
RUBY_JMP_BUF rb_jmpbuf_t
Definition: vm_core.h:462
int ruby_vm_destruct(ruby_vm_t *vm)
Definition: vm.c:1665
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:1227
int rb_threadptr_reset_raised(rb_thread_t *th)
Definition: thread.c:2058
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
VALUE rb_attr_get(VALUE, ID)
Definition: variable.c:1122
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:1391
int rb_sourceline(void)
Definition: vm.c:884
VALUE flags
Definition: ripper.y:241
void rb_jump_tag(int tag)
Definition: eval.c:666
#define ruby_run_node
Definition: goruby.c:3
return ptr
Definition: tcltklib.c:784
VALUE rb_mod_constants(int, VALUE *, VALUE)
Definition: variable.c:2046
VpDivd * c
Definition: bigdecimal.c:1219
#define RUBY_VM_END_CONTROL_FRAME(th)
Definition: vm_core.h:791
void rb_using_module(NODE *cref, VALUE module)
Definition: eval.c:1110
#define ruby_options
Definition: goruby.c:2
#define MEMCPY(p1, p2, type, n)
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
VALUE rb_ivar_set(VALUE, ID, VALUE)
Definition: variable.c:1128
arg
Definition: ripper.y:1317
static VALUE top_include(int argc, VALUE *argv, VALUE self)
Definition: eval.c:1320
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:1341
#define RMODULE_IS_OVERLAID
VALUE top_wrapper
Definition: vm_core.h:521
#define FL_SINGLETON
VALUE rb_module_new(void)
Definition: class.c:600
#define Qundef
VALUE rb_obj_is_kind_of(VALUE, VALUE)
Definition: object.c:593
VALUE rb_exc_new3(VALUE etype, VALUE str)
Definition: error.c:553
ID rb_frame_callee(void)
Definition: eval.c:919
#define T_CLASS
VALUE rb_hash_dup(VALUE)
Definition: hash.c:240
rb_method_definition_t * def
Definition: method.h:98
void rb_set_errinfo(VALUE err)
Definition: eval.c:1429
const rb_method_entry_t * me
Definition: vm_core.h:435
static VALUE * errinfo_place(rb_thread_t *th)
Definition: eval.c:1357
void ruby_sig_finalize(void)
Definition: signal.c:1099
RUBY_EXTERN VALUE rb_cClass
Definition: ripper.y:1430
ruby_debug
Definition: tcltklib.c:5816
RUBY_EXTERN VALUE rb_cObject
Definition: ripper.y:1426
#define RBASIC(obj)
klass
Definition: tcltklib.c:3503
void ruby_default_signal(int)
Definition: signal.c:323
rb_block_t * rb_vm_control_frame_block_ptr(rb_control_frame_t *cfp)
Definition: vm.c:61
void rb_define_virtual_variable(const char *, VALUE(*)(ANYARGS), void(*)(ANYARGS))
Definition: variable.c:606
#define RUBY_EVENT_RAISE
#define T_MODULE
#define EXEC_EVENT_HOOK(th_, flag_, self_, id_, klass_, data_)
Definition: vm_core.h:998
void rb_frozen_class_p(VALUE klass)
Definition: eval.c:403
NODE * rb_vm_get_cref(const rb_iseq_t *, const VALUE *)
#define NUM2INT(x)
VALUE rb_hash_new(void)
Definition: hash.c:234
#define rb_errinfo()
Definition: tcltklib.c:89
void rb_gc_call_finalizer_at_exit(void)
Definition: gc.c:1484
VALUE rb_eFatal
Definition: error.c:513
size_t stack_size
Definition: vm_core.h:499
#define rb_check_arity(argc, min, max)
#define PRIsVALUE
BDIGIT e
Definition: bigdecimal.c:5106
static VALUE rb_mod_s_constants(int argc, VALUE *argv, VALUE mod)
Definition: eval.c:373
VALUE rb_funcall2(VALUE, ID, int, const VALUE *)
Calls a method.
Definition: vm_eval.c:804
unsigned long VALUE
Definition: ripper.y:104
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
VALUE rb_current_realfilepath(void)
Definition: vm_eval.c:1934
#define numberof(array)
Definition: eval.c:23
static void rb_longjmp(int tag, volatile VALUE mesg)
Definition: eval.c:516
#define RMODULE_IS_REFINEMENT
void Init_vm_eval(void)
Definition: vm_eval.c:1944
static void error_print(void)
Definition: eval_error.c:79
static VALUE get_thread_errinfo(rb_thread_t *th)
Definition: eval.c:1379
static int using_refinement(VALUE klass, VALUE module, VALUE arg)
Definition: eval.c:1101
void rb_clear_trace_func(void)
Definition: vm_trace.c:215
#define OBJ_TAINT(x)
#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:947
#define rb_intern(str)
BDIGIT v
Definition: bigdecimal.c:5677
#define NODE_FL_CREF_PUSHED_BY_EVAL
#define mod(x, y)
Definition: date_strftime.c:28
#define RCLASS_M_TBL(c)
VALUE rb_vm_backtrace_object()
Definition: vm_backtrace.c:532
static VALUE errat_getter(ID id)
Definition: eval.c:1444
void rb_exc_fatal(VALUE mesg)
Definition: eval.c:536
VALUE rb_eSystemExit
Definition: error.c:510
#define RCLASS_REFINED_CLASS(c)
VALUE rb_check_string_type(VALUE)
Definition: string.c:1509
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:1220
static rb_thread_t * GET_THREAD(void)
Definition: vm_core.h:888
void rb_define_method(VALUE klass, const char *name, VALUE(*func)(ANYARGS), int argc)
Definition: class.c:1348
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:1456
void Init_eval_method(void)
Definition: vm_method.c:1652
int ruby_executable_node(void *n, int *status)
Checks the return value of ruby_options().
Definition: eval.c:279
int ruby_setup(void)
Definition: eval.c:42
#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:1489
VALUE rb_eException
Definition: error.c:509
static VALUE rb_mod_refine(VALUE module, VALUE klass)
Definition: eval.c:1172
#define GET_VM()
Definition: vm_core.h:881