Ruby 2.1.5p273(2014-11-13revision48405)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

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