Ruby
2.0.0p247(2013-06-27revision41674)
|
00001 /********************************************************************** 00002 00003 eval.c - 00004 00005 $Author: nobu $ 00006 created at: Thu Jun 10 14:22:17 JST 1993 00007 00008 Copyright (C) 1993-2007 Yukihiro Matsumoto 00009 Copyright (C) 2000 Network Applied Communication Laboratory, Inc. 00010 Copyright (C) 2000 Information-technology Promotion Agency, Japan 00011 00012 **********************************************************************/ 00013 00014 #include "eval_intern.h" 00015 #include "iseq.h" 00016 #include "gc.h" 00017 #include "ruby/vm.h" 00018 #include "ruby/encoding.h" 00019 #include "internal.h" 00020 #include "vm_core.h" 00021 #include "probes_helper.h" 00022 00023 #define numberof(array) (int)(sizeof(array) / sizeof((array)[0])) 00024 00025 NORETURN(void rb_raise_jump(VALUE)); 00026 00027 NODE *rb_vm_get_cref(const rb_iseq_t *, const VALUE *); 00028 00029 VALUE rb_eLocalJumpError; 00030 VALUE rb_eSysStackError; 00031 00032 #define exception_error GET_VM()->special_exceptions[ruby_error_reenter] 00033 00034 #include "eval_error.c" 00035 #include "eval_jump.c" 00036 00037 /* Initializes the Ruby VM and builtin libraries. 00038 * @retval 0 if succeeded. 00039 * @retval non-zero an error occured. 00040 */ 00041 int 00042 ruby_setup(void) 00043 { 00044 static int initialized = 0; 00045 int state; 00046 00047 if (initialized) 00048 return 0; 00049 initialized = 1; 00050 00051 ruby_init_stack((void *)&state); 00052 Init_BareVM(); 00053 Init_heap(); 00054 00055 PUSH_TAG(); 00056 if ((state = EXEC_TAG()) == 0) { 00057 rb_call_inits(); 00058 ruby_prog_init(); 00059 GET_VM()->running = 1; 00060 } 00061 POP_TAG(); 00062 00063 return state; 00064 } 00065 00066 /* Calls ruby_setup() and check error. 00067 * 00068 * Prints errors and calls exit(3) if an error occured. 00069 */ 00070 void 00071 ruby_init(void) 00072 { 00073 int state = ruby_setup(); 00074 if (state) { 00075 error_print(); 00076 exit(EXIT_FAILURE); 00077 } 00078 } 00079 00090 void * 00091 ruby_options(int argc, char **argv) 00092 { 00093 int state; 00094 void *volatile iseq = 0; 00095 00096 ruby_init_stack((void *)&iseq); 00097 PUSH_TAG(); 00098 if ((state = EXEC_TAG()) == 0) { 00099 SAVE_ROOT_JMPBUF(GET_THREAD(), iseq = ruby_process_options(argc, argv)); 00100 } 00101 else { 00102 rb_clear_trace_func(); 00103 state = error_handle(state); 00104 iseq = (void *)INT2FIX(state); 00105 } 00106 POP_TAG(); 00107 return iseq; 00108 } 00109 00110 static void 00111 ruby_finalize_0(void) 00112 { 00113 PUSH_TAG(); 00114 if (EXEC_TAG() == 0) { 00115 rb_trap_exit(); 00116 } 00117 POP_TAG(); 00118 rb_exec_end_proc(); 00119 rb_clear_trace_func(); 00120 } 00121 00122 static void 00123 ruby_finalize_1(void) 00124 { 00125 ruby_sig_finalize(); 00126 GET_THREAD()->errinfo = Qnil; 00127 rb_gc_call_finalizer_at_exit(); 00128 } 00129 00137 void 00138 ruby_finalize(void) 00139 { 00140 ruby_finalize_0(); 00141 ruby_finalize_1(); 00142 } 00143 00154 int 00155 ruby_cleanup(volatile int ex) 00156 { 00157 int state; 00158 volatile VALUE errs[2]; 00159 rb_thread_t *th = GET_THREAD(); 00160 int nerr; 00161 00162 rb_threadptr_interrupt(th); 00163 rb_threadptr_check_signal(th); 00164 PUSH_TAG(); 00165 if ((state = EXEC_TAG()) == 0) { 00166 SAVE_ROOT_JMPBUF(th, { RUBY_VM_CHECK_INTS(th); }); 00167 } 00168 POP_TAG(); 00169 00170 errs[1] = th->errinfo; 00171 th->safe_level = 0; 00172 ruby_init_stack(&errs[STACK_UPPER(errs, 0, 1)]); 00173 00174 PUSH_TAG(); 00175 if ((state = EXEC_TAG()) == 0) { 00176 SAVE_ROOT_JMPBUF(th, ruby_finalize_0()); 00177 } 00178 POP_TAG(); 00179 00180 /* protect from Thread#raise */ 00181 th->status = THREAD_KILLED; 00182 00183 errs[0] = th->errinfo; 00184 PUSH_TAG(); 00185 if ((state = EXEC_TAG()) == 0) { 00186 SAVE_ROOT_JMPBUF(th, rb_thread_terminate_all()); 00187 } 00188 else if (ex == 0) { 00189 ex = state; 00190 } 00191 th->errinfo = errs[1]; 00192 ex = error_handle(ex); 00193 ruby_finalize_1(); 00194 00195 /* unlock again if finalizer took mutexes. */ 00196 rb_threadptr_unlock_all_locking_mutexes(GET_THREAD()); 00197 POP_TAG(); 00198 rb_thread_stop_timer_thread(1); 00199 00200 #if EXIT_SUCCESS != 0 || EXIT_FAILURE != 1 00201 switch (ex) { 00202 #if EXIT_SUCCESS != 0 00203 case 0: ex = EXIT_SUCCESS; break; 00204 #endif 00205 #if EXIT_FAILURE != 1 00206 case 1: ex = EXIT_FAILURE; break; 00207 #endif 00208 } 00209 #endif 00210 00211 state = 0; 00212 for (nerr = 0; nerr < numberof(errs); ++nerr) { 00213 VALUE err = errs[nerr]; 00214 00215 if (!RTEST(err)) continue; 00216 00217 /* th->errinfo contains a NODE while break'ing */ 00218 if (RB_TYPE_P(err, T_NODE)) continue; 00219 00220 if (rb_obj_is_kind_of(err, rb_eSystemExit)) { 00221 ex = sysexit_status(err); 00222 break; 00223 } 00224 else if (rb_obj_is_kind_of(err, rb_eSignal)) { 00225 VALUE sig = rb_iv_get(err, "signo"); 00226 state = NUM2INT(sig); 00227 break; 00228 } 00229 else if (ex == EXIT_SUCCESS) { 00230 ex = EXIT_FAILURE; 00231 } 00232 } 00233 ruby_vm_destruct(GET_VM()); 00234 if (state) ruby_default_signal(state); 00235 00236 return ex; 00237 } 00238 00239 static int 00240 ruby_exec_internal(void *n) 00241 { 00242 volatile int state; 00243 VALUE iseq = (VALUE)n; 00244 rb_thread_t *th = GET_THREAD(); 00245 00246 if (!n) return 0; 00247 00248 PUSH_TAG(); 00249 if ((state = EXEC_TAG()) == 0) { 00250 SAVE_ROOT_JMPBUF(th, { 00251 th->base_block = 0; 00252 rb_iseq_eval_main(iseq); 00253 }); 00254 } 00255 POP_TAG(); 00256 return state; 00257 } 00258 00260 void 00261 ruby_stop(int ex) 00262 { 00263 exit(ruby_cleanup(ex)); 00264 } 00265 00278 int 00279 ruby_executable_node(void *n, int *status) 00280 { 00281 VALUE v = (VALUE)n; 00282 int s; 00283 00284 switch (v) { 00285 case Qtrue: s = EXIT_SUCCESS; break; 00286 case Qfalse: s = EXIT_FAILURE; break; 00287 default: 00288 if (!FIXNUM_P(v)) return TRUE; 00289 s = FIX2INT(v); 00290 } 00291 if (status) *status = s; 00292 return FALSE; 00293 } 00294 00299 int 00300 ruby_run_node(void *n) 00301 { 00302 int status; 00303 if (!ruby_executable_node(n, &status)) { 00304 ruby_cleanup(0); 00305 return status; 00306 } 00307 return ruby_cleanup(ruby_exec_node(n)); 00308 } 00309 00311 int 00312 ruby_exec_node(void *n) 00313 { 00314 ruby_init_stack((void *)&n); 00315 return ruby_exec_internal(n); 00316 } 00317 00318 /* 00319 * call-seq: 00320 * Module.nesting -> array 00321 * 00322 * Returns the list of +Modules+ nested at the point of call. 00323 * 00324 * module M1 00325 * module M2 00326 * $a = Module.nesting 00327 * end 00328 * end 00329 * $a #=> [M1::M2, M1] 00330 * $a[0].name #=> "M1::M2" 00331 */ 00332 00333 static VALUE 00334 rb_mod_nesting(void) 00335 { 00336 VALUE ary = rb_ary_new(); 00337 const NODE *cref = rb_vm_cref(); 00338 00339 while (cref && cref->nd_next) { 00340 VALUE klass = cref->nd_clss; 00341 if (!(cref->flags & NODE_FL_CREF_PUSHED_BY_EVAL) && 00342 !NIL_P(klass)) { 00343 rb_ary_push(ary, klass); 00344 } 00345 cref = cref->nd_next; 00346 } 00347 return ary; 00348 } 00349 00350 /* 00351 * call-seq: 00352 * Module.constants -> array 00353 * Module.constants(inherited) -> array 00354 * 00355 * In the first form, returns an array of the names of all 00356 * constants accessible from the point of call. 00357 * This list includes the names of all modules and classes 00358 * defined in the global scope. 00359 * 00360 * Module.constants.first(4) 00361 * # => [:ARGF, :ARGV, :ArgumentError, :Array] 00362 * 00363 * Module.constants.include?(:SEEK_SET) # => false 00364 * 00365 * class IO 00366 * Module.constants.include?(:SEEK_SET) # => true 00367 * end 00368 * 00369 * The second form calls the instance method +constants+. 00370 */ 00371 00372 static VALUE 00373 rb_mod_s_constants(int argc, VALUE *argv, VALUE mod) 00374 { 00375 const NODE *cref = rb_vm_cref(); 00376 VALUE klass; 00377 VALUE cbase = 0; 00378 void *data = 0; 00379 00380 if (argc > 0) { 00381 return rb_mod_constants(argc, argv, rb_cModule); 00382 } 00383 00384 while (cref) { 00385 klass = cref->nd_clss; 00386 if (!(cref->flags & NODE_FL_CREF_PUSHED_BY_EVAL) && 00387 !NIL_P(klass)) { 00388 data = rb_mod_const_at(cref->nd_clss, data); 00389 if (!cbase) { 00390 cbase = klass; 00391 } 00392 } 00393 cref = cref->nd_next; 00394 } 00395 00396 if (cbase) { 00397 data = rb_mod_const_of(cbase, data); 00398 } 00399 return rb_const_list(data); 00400 } 00401 00402 void 00403 rb_frozen_class_p(VALUE klass) 00404 { 00405 const char *desc = "something(?!)"; 00406 00407 if (OBJ_FROZEN(klass)) { 00408 if (FL_TEST(klass, FL_SINGLETON)) 00409 desc = "object"; 00410 else { 00411 switch (TYPE(klass)) { 00412 case T_MODULE: 00413 case T_ICLASS: 00414 desc = "module"; 00415 break; 00416 case T_CLASS: 00417 desc = "class"; 00418 break; 00419 } 00420 } 00421 rb_error_frozen(desc); 00422 } 00423 } 00424 00425 NORETURN(static void rb_longjmp(int, volatile VALUE)); 00426 00427 static void 00428 setup_exception(rb_thread_t *th, int tag, volatile VALUE mesg) 00429 { 00430 VALUE at; 00431 VALUE e; 00432 const char *file; 00433 volatile int line = 0; 00434 00435 if (NIL_P(mesg)) { 00436 mesg = th->errinfo; 00437 if (INTERNAL_EXCEPTION_P(mesg)) JUMP_TAG(TAG_FATAL); 00438 } 00439 if (NIL_P(mesg)) { 00440 mesg = rb_exc_new(rb_eRuntimeError, 0, 0); 00441 } 00442 00443 file = rb_sourcefile(); 00444 if (file) line = rb_sourceline(); 00445 if (file && !NIL_P(mesg)) { 00446 if (mesg == sysstack_error) { 00447 at = rb_enc_sprintf(rb_usascii_encoding(), "%s:%d", file, line); 00448 at = rb_ary_new3(1, at); 00449 rb_iv_set(mesg, "bt", at); 00450 } 00451 else { 00452 at = get_backtrace(mesg); 00453 if (NIL_P(at)) { 00454 at = rb_vm_backtrace_object(); 00455 if (OBJ_FROZEN(mesg)) { 00456 mesg = rb_obj_dup(mesg); 00457 } 00458 set_backtrace(mesg, at); 00459 } 00460 } 00461 } 00462 if (!NIL_P(mesg)) { 00463 th->errinfo = mesg; 00464 } 00465 00466 if (RTEST(ruby_debug) && !NIL_P(e = th->errinfo) && 00467 !rb_obj_is_kind_of(e, rb_eSystemExit)) { 00468 int status; 00469 00470 PUSH_TAG(); 00471 if ((status = EXEC_TAG()) == 0) { 00472 RB_GC_GUARD(e) = rb_obj_as_string(e); 00473 if (file && line) { 00474 warn_printf("Exception `%s' at %s:%d - %s\n", 00475 rb_obj_classname(th->errinfo), 00476 file, line, RSTRING_PTR(e)); 00477 } 00478 else if (file) { 00479 warn_printf("Exception `%s' at %s - %s\n", 00480 rb_obj_classname(th->errinfo), 00481 file, RSTRING_PTR(e)); 00482 } 00483 else { 00484 warn_printf("Exception `%s' - %s\n", 00485 rb_obj_classname(th->errinfo), 00486 RSTRING_PTR(e)); 00487 } 00488 } 00489 POP_TAG(); 00490 if (status == TAG_FATAL && th->errinfo == exception_error) { 00491 th->errinfo = mesg; 00492 } 00493 else if (status) { 00494 rb_threadptr_reset_raised(th); 00495 JUMP_TAG(status); 00496 } 00497 } 00498 00499 if (rb_threadptr_set_raised(th)) { 00500 th->errinfo = exception_error; 00501 rb_threadptr_reset_raised(th); 00502 JUMP_TAG(TAG_FATAL); 00503 } 00504 00505 if (tag != TAG_FATAL) { 00506 if (RUBY_DTRACE_RAISE_ENABLED()) { 00507 RUBY_DTRACE_RAISE(rb_obj_classname(th->errinfo), 00508 rb_sourcefile(), 00509 rb_sourceline()); 00510 } 00511 EXEC_EVENT_HOOK(th, RUBY_EVENT_RAISE, th->cfp->self, 0, 0, mesg); 00512 } 00513 } 00514 00515 static void 00516 rb_longjmp(int tag, volatile VALUE mesg) 00517 { 00518 rb_thread_t *th = GET_THREAD(); 00519 setup_exception(th, tag, mesg); 00520 rb_thread_raised_clear(th); 00521 JUMP_TAG(tag); 00522 } 00523 00524 static VALUE make_exception(int argc, VALUE *argv, int isstr); 00525 00526 void 00527 rb_exc_raise(VALUE mesg) 00528 { 00529 if (!NIL_P(mesg)) { 00530 mesg = make_exception(1, &mesg, FALSE); 00531 } 00532 rb_longjmp(TAG_RAISE, mesg); 00533 } 00534 00535 void 00536 rb_exc_fatal(VALUE mesg) 00537 { 00538 if (!NIL_P(mesg)) { 00539 mesg = make_exception(1, &mesg, FALSE); 00540 } 00541 rb_longjmp(TAG_FATAL, mesg); 00542 } 00543 00544 void 00545 rb_interrupt(void) 00546 { 00547 rb_raise(rb_eInterrupt, "%s", ""); 00548 } 00549 00550 static VALUE get_errinfo(void); 00551 00552 /* 00553 * call-seq: 00554 * raise 00555 * raise(string) 00556 * raise(exception [, string [, array]]) 00557 * fail 00558 * fail(string) 00559 * fail(exception [, string [, array]]) 00560 * 00561 * With no arguments, raises the exception in <code>$!</code> or raises 00562 * a <code>RuntimeError</code> if <code>$!</code> is +nil+. 00563 * With a single +String+ argument, raises a 00564 * +RuntimeError+ with the string as a message. Otherwise, 00565 * the first parameter should be the name of an +Exception+ 00566 * class (or an object that returns an +Exception+ object when sent 00567 * an +exception+ message). The optional second parameter sets the 00568 * message associated with the exception, and the third parameter is an 00569 * array of callback information. Exceptions are caught by the 00570 * +rescue+ clause of <code>begin...end</code> blocks. 00571 * 00572 * raise "Failed to create socket" 00573 * raise ArgumentError, "No parameters", caller 00574 */ 00575 00576 static VALUE 00577 rb_f_raise(int argc, VALUE *argv) 00578 { 00579 VALUE err; 00580 if (argc == 0) { 00581 err = get_errinfo(); 00582 if (!NIL_P(err)) { 00583 argc = 1; 00584 argv = &err; 00585 } 00586 } 00587 rb_raise_jump(rb_make_exception(argc, argv)); 00588 00589 UNREACHABLE; 00590 } 00591 00592 static VALUE 00593 make_exception(int argc, VALUE *argv, int isstr) 00594 { 00595 VALUE mesg; 00596 ID exception; 00597 int n; 00598 00599 mesg = Qnil; 00600 switch (argc) { 00601 case 0: 00602 break; 00603 case 1: 00604 if (NIL_P(argv[0])) 00605 break; 00606 if (isstr) { 00607 mesg = rb_check_string_type(argv[0]); 00608 if (!NIL_P(mesg)) { 00609 mesg = rb_exc_new3(rb_eRuntimeError, mesg); 00610 break; 00611 } 00612 } 00613 n = 0; 00614 goto exception_call; 00615 00616 case 2: 00617 case 3: 00618 n = 1; 00619 exception_call: 00620 if (argv[0] == sysstack_error) return argv[0]; 00621 CONST_ID(exception, "exception"); 00622 mesg = rb_check_funcall(argv[0], exception, n, argv+1); 00623 if (mesg == Qundef) { 00624 rb_raise(rb_eTypeError, "exception class/object expected"); 00625 } 00626 break; 00627 default: 00628 rb_check_arity(argc, 0, 3); 00629 break; 00630 } 00631 if (argc > 0) { 00632 if (!rb_obj_is_kind_of(mesg, rb_eException)) 00633 rb_raise(rb_eTypeError, "exception object expected"); 00634 if (argc > 2) 00635 set_backtrace(mesg, argv[2]); 00636 } 00637 00638 return mesg; 00639 } 00640 00641 VALUE 00642 rb_make_exception(int argc, VALUE *argv) 00643 { 00644 return make_exception(argc, argv, TRUE); 00645 } 00646 00647 void 00648 rb_raise_jump(VALUE mesg) 00649 { 00650 rb_thread_t *th = GET_THREAD(); 00651 rb_control_frame_t *cfp = th->cfp; 00652 VALUE klass = cfp->me->klass; 00653 VALUE self = cfp->self; 00654 ID mid = cfp->me->called_id; 00655 00656 th->cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp); 00657 00658 setup_exception(th, TAG_RAISE, mesg); 00659 00660 EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, self, mid, klass, Qnil); 00661 rb_thread_raised_clear(th); 00662 JUMP_TAG(TAG_RAISE); 00663 } 00664 00665 void 00666 rb_jump_tag(int tag) 00667 { 00668 JUMP_TAG(tag); 00669 } 00670 00671 int 00672 rb_block_given_p(void) 00673 { 00674 rb_thread_t *th = GET_THREAD(); 00675 00676 if (rb_vm_control_frame_block_ptr(th->cfp)) { 00677 return TRUE; 00678 } 00679 else { 00680 return FALSE; 00681 } 00682 } 00683 00684 int 00685 rb_iterator_p(void) 00686 { 00687 return rb_block_given_p(); 00688 } 00689 00690 VALUE rb_eThreadError; 00691 00692 void 00693 rb_need_block(void) 00694 { 00695 if (!rb_block_given_p()) { 00696 rb_vm_localjump_error("no block given", Qnil, 0); 00697 } 00698 } 00699 00700 VALUE 00701 rb_rescue2(VALUE (* b_proc) (ANYARGS), VALUE data1, 00702 VALUE (* r_proc) (ANYARGS), VALUE data2, ...) 00703 { 00704 int state; 00705 rb_thread_t *th = GET_THREAD(); 00706 rb_control_frame_t *cfp = th->cfp; 00707 volatile VALUE result; 00708 volatile VALUE e_info = th->errinfo; 00709 va_list args; 00710 00711 TH_PUSH_TAG(th); 00712 if ((state = TH_EXEC_TAG()) == 0) { 00713 retry_entry: 00714 result = (*b_proc) (data1); 00715 } 00716 else { 00717 th->cfp = cfp; /* restore */ 00718 00719 if (state == TAG_RAISE) { 00720 int handle = FALSE; 00721 VALUE eclass; 00722 00723 va_init_list(args, data2); 00724 while ((eclass = va_arg(args, VALUE)) != 0) { 00725 if (rb_obj_is_kind_of(th->errinfo, eclass)) { 00726 handle = TRUE; 00727 break; 00728 } 00729 } 00730 va_end(args); 00731 00732 if (handle) { 00733 if (r_proc) { 00734 PUSH_TAG(); 00735 if ((state = EXEC_TAG()) == 0) { 00736 result = (*r_proc) (data2, th->errinfo); 00737 } 00738 POP_TAG(); 00739 if (state == TAG_RETRY) { 00740 state = 0; 00741 th->errinfo = Qnil; 00742 goto retry_entry; 00743 } 00744 } 00745 else { 00746 result = Qnil; 00747 state = 0; 00748 } 00749 if (state == 0) { 00750 th->errinfo = e_info; 00751 } 00752 } 00753 } 00754 } 00755 TH_POP_TAG(); 00756 if (state) 00757 JUMP_TAG(state); 00758 00759 return result; 00760 } 00761 00762 VALUE 00763 rb_rescue(VALUE (* b_proc)(ANYARGS), VALUE data1, 00764 VALUE (* r_proc)(ANYARGS), VALUE data2) 00765 { 00766 return rb_rescue2(b_proc, data1, r_proc, data2, rb_eStandardError, 00767 (VALUE)0); 00768 } 00769 00770 VALUE 00771 rb_protect(VALUE (* proc) (VALUE), VALUE data, int * state) 00772 { 00773 volatile VALUE result = Qnil; 00774 int status; 00775 rb_thread_t *th = GET_THREAD(); 00776 rb_control_frame_t *cfp = th->cfp; 00777 struct rb_vm_protect_tag protect_tag; 00778 rb_jmpbuf_t org_jmpbuf; 00779 00780 protect_tag.prev = th->protect_tag; 00781 00782 TH_PUSH_TAG(th); 00783 th->protect_tag = &protect_tag; 00784 MEMCPY(&org_jmpbuf, &(th)->root_jmpbuf, rb_jmpbuf_t, 1); 00785 if ((status = TH_EXEC_TAG()) == 0) { 00786 SAVE_ROOT_JMPBUF(th, result = (*proc) (data)); 00787 } 00788 MEMCPY(&(th)->root_jmpbuf, &org_jmpbuf, rb_jmpbuf_t, 1); 00789 th->protect_tag = protect_tag.prev; 00790 TH_POP_TAG(); 00791 00792 if (state) { 00793 *state = status; 00794 } 00795 if (status != 0) { 00796 th->cfp = cfp; 00797 return Qnil; 00798 } 00799 00800 return result; 00801 } 00802 00803 VALUE 00804 rb_ensure(VALUE (*b_proc)(ANYARGS), VALUE data1, VALUE (*e_proc)(ANYARGS), VALUE data2) 00805 { 00806 int state; 00807 volatile VALUE result = Qnil; 00808 volatile VALUE errinfo; 00809 rb_thread_t *const th = GET_THREAD(); 00810 00811 PUSH_TAG(); 00812 if ((state = EXEC_TAG()) == 0) { 00813 result = (*b_proc) (data1); 00814 } 00815 POP_TAG(); 00816 /* TODO: fix me */ 00817 /* retval = prot_tag ? prot_tag->retval : Qnil; */ /* save retval */ 00818 errinfo = th->errinfo; 00819 (*e_proc) (data2); 00820 th->errinfo = errinfo; 00821 if (state) 00822 JUMP_TAG(state); 00823 return result; 00824 } 00825 00826 static const rb_method_entry_t * 00827 method_entry_of_iseq(rb_control_frame_t *cfp, rb_iseq_t *iseq) 00828 { 00829 rb_thread_t *th = GET_THREAD(); 00830 rb_control_frame_t *cfp_limit; 00831 00832 cfp_limit = (rb_control_frame_t *)(th->stack + th->stack_size); 00833 while (cfp_limit > cfp) { 00834 if (cfp->iseq == iseq) 00835 return cfp->me; 00836 cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp); 00837 } 00838 return 0; 00839 } 00840 00841 static ID 00842 frame_func_id(rb_control_frame_t *cfp) 00843 { 00844 const rb_method_entry_t *me_local; 00845 rb_iseq_t *iseq = cfp->iseq; 00846 if (cfp->me) { 00847 return cfp->me->def->original_id; 00848 } 00849 while (iseq) { 00850 if (RUBY_VM_IFUNC_P(iseq)) { 00851 NODE *ifunc = (NODE *)iseq; 00852 if (ifunc->nd_aid) return ifunc->nd_aid; 00853 return rb_intern("<ifunc>"); 00854 } 00855 me_local = method_entry_of_iseq(cfp, iseq); 00856 if (me_local) { 00857 cfp->me = me_local; 00858 return me_local->def->original_id; 00859 } 00860 if (iseq->defined_method_id) { 00861 return iseq->defined_method_id; 00862 } 00863 if (iseq->local_iseq == iseq) { 00864 break; 00865 } 00866 iseq = iseq->parent_iseq; 00867 } 00868 return 0; 00869 } 00870 00871 static ID 00872 frame_called_id(rb_control_frame_t *cfp) 00873 { 00874 const rb_method_entry_t *me_local; 00875 rb_iseq_t *iseq = cfp->iseq; 00876 if (cfp->me) { 00877 return cfp->me->called_id; 00878 } 00879 while (iseq) { 00880 if (RUBY_VM_IFUNC_P(iseq)) { 00881 NODE *ifunc = (NODE *)iseq; 00882 if (ifunc->nd_aid) return ifunc->nd_aid; 00883 return rb_intern("<ifunc>"); 00884 } 00885 me_local = method_entry_of_iseq(cfp, iseq); 00886 if (me_local) { 00887 cfp->me = me_local; 00888 return me_local->called_id; 00889 } 00890 if (iseq->defined_method_id) { 00891 return iseq->defined_method_id; 00892 } 00893 if (iseq->local_iseq == iseq) { 00894 break; 00895 } 00896 iseq = iseq->parent_iseq; 00897 } 00898 return 0; 00899 } 00900 00901 ID 00902 rb_frame_this_func(void) 00903 { 00904 return frame_func_id(GET_THREAD()->cfp); 00905 } 00906 00907 static rb_control_frame_t * 00908 previous_frame(rb_thread_t *th) 00909 { 00910 rb_control_frame_t *prev_cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp); 00911 /* check if prev_cfp can be accessible */ 00912 if ((void *)(th->stack + th->stack_size) == (void *)(prev_cfp)) { 00913 return 0; 00914 } 00915 return prev_cfp; 00916 } 00917 00918 ID 00919 rb_frame_callee(void) 00920 { 00921 rb_control_frame_t *prev_cfp = previous_frame(GET_THREAD()); 00922 if (!prev_cfp) return 0; 00923 return frame_called_id(prev_cfp); 00924 } 00925 00926 static ID 00927 rb_frame_caller(void) 00928 { 00929 rb_control_frame_t *prev_cfp = previous_frame(GET_THREAD()); 00930 if (!prev_cfp) return 0; 00931 return frame_func_id(prev_cfp); 00932 } 00933 00934 void 00935 rb_frame_pop(void) 00936 { 00937 rb_thread_t *th = GET_THREAD(); 00938 th->cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp); 00939 } 00940 00941 /* 00942 * call-seq: 00943 * append_features(mod) -> mod 00944 * 00945 * When this module is included in another, Ruby calls 00946 * <code>append_features</code> in this module, passing it the 00947 * receiving module in _mod_. Ruby's default implementation is 00948 * to add the constants, methods, and module variables of this module 00949 * to _mod_ if this module has not already been added to 00950 * _mod_ or one of its ancestors. See also <code>Module#include</code>. 00951 */ 00952 00953 static VALUE 00954 rb_mod_append_features(VALUE module, VALUE include) 00955 { 00956 switch (TYPE(include)) { 00957 case T_CLASS: 00958 case T_MODULE: 00959 break; 00960 default: 00961 Check_Type(include, T_CLASS); 00962 break; 00963 } 00964 rb_include_module(include, module); 00965 00966 return module; 00967 } 00968 00969 /* 00970 * call-seq: 00971 * include(module, ...) -> self 00972 * 00973 * Invokes <code>Module.append_features</code> on each parameter in reverse order. 00974 */ 00975 00976 static VALUE 00977 rb_mod_include(int argc, VALUE *argv, VALUE module) 00978 { 00979 int i; 00980 ID id_append_features, id_included; 00981 00982 CONST_ID(id_append_features, "append_features"); 00983 CONST_ID(id_included, "included"); 00984 00985 for (i = 0; i < argc; i++) 00986 Check_Type(argv[i], T_MODULE); 00987 while (argc--) { 00988 rb_funcall(argv[argc], id_append_features, 1, module); 00989 rb_funcall(argv[argc], id_included, 1, module); 00990 } 00991 return module; 00992 } 00993 00994 /* 00995 * call-seq: 00996 * prepend_features(mod) -> mod 00997 * 00998 * When this module is prepended in another, Ruby calls 00999 * <code>prepend_features</code> in this module, passing it the 01000 * receiving module in _mod_. Ruby's default implementation is 01001 * to overlay the constants, methods, and module variables of this module 01002 * to _mod_ if this module has not already been added to 01003 * _mod_ or one of its ancestors. See also <code>Module#prepend</code>. 01004 */ 01005 01006 static VALUE 01007 rb_mod_prepend_features(VALUE module, VALUE prepend) 01008 { 01009 switch (TYPE(prepend)) { 01010 case T_CLASS: 01011 case T_MODULE: 01012 break; 01013 default: 01014 Check_Type(prepend, T_CLASS); 01015 break; 01016 } 01017 rb_prepend_module(prepend, module); 01018 01019 return module; 01020 } 01021 01022 /* 01023 * call-seq: 01024 * prepend(module, ...) -> self 01025 * 01026 * Invokes <code>Module.prepend_features</code> on each parameter in reverse order. 01027 */ 01028 01029 static VALUE 01030 rb_mod_prepend(int argc, VALUE *argv, VALUE module) 01031 { 01032 int i; 01033 ID id_prepend_features, id_prepended; 01034 01035 CONST_ID(id_prepend_features, "prepend_features"); 01036 CONST_ID(id_prepended, "prepended"); 01037 for (i = 0; i < argc; i++) 01038 Check_Type(argv[i], T_MODULE); 01039 while (argc--) { 01040 rb_funcall(argv[argc], id_prepend_features, 1, module); 01041 rb_funcall(argv[argc], id_prepended, 1, module); 01042 } 01043 return module; 01044 } 01045 01046 static void 01047 warn_refinements_once() 01048 { 01049 static int warned = 0; 01050 01051 if (warned) 01052 return; 01053 rb_warn("Refinements are experimental, and the behavior may change in future versions of Ruby!"); 01054 warned = 1; 01055 } 01056 01057 static VALUE 01058 hidden_identity_hash_new() 01059 { 01060 VALUE hash = rb_hash_new(); 01061 01062 rb_funcall(hash, rb_intern("compare_by_identity"), 0); 01063 RBASIC(hash)->klass = 0; /* hide from ObjectSpace */ 01064 return hash; 01065 } 01066 01067 void 01068 rb_using_refinement(NODE *cref, VALUE klass, VALUE module) 01069 { 01070 VALUE iclass, c, superclass = klass; 01071 01072 Check_Type(klass, T_CLASS); 01073 Check_Type(module, T_MODULE); 01074 if (NIL_P(cref->nd_refinements)) { 01075 cref->nd_refinements = hidden_identity_hash_new(); 01076 } 01077 else { 01078 if (cref->flags & NODE_FL_CREF_OMOD_SHARED) { 01079 cref->nd_refinements = rb_hash_dup(cref->nd_refinements); 01080 cref->flags &= ~NODE_FL_CREF_OMOD_SHARED; 01081 } 01082 if (!NIL_P(c = rb_hash_lookup(cref->nd_refinements, klass))) { 01083 superclass = c; 01084 while (c && RB_TYPE_P(c, T_ICLASS)) { 01085 if (RBASIC(c)->klass == module) { 01086 /* already used refinement */ 01087 return; 01088 } 01089 c = RCLASS_SUPER(c); 01090 } 01091 } 01092 } 01093 FL_SET(module, RMODULE_IS_OVERLAID); 01094 c = iclass = rb_include_class_new(module, superclass); 01095 RCLASS_REFINED_CLASS(c) = klass; 01096 RCLASS_M_TBL(c) = RCLASS_M_TBL(module); 01097 module = RCLASS_SUPER(module); 01098 while (module && module != klass) { 01099 FL_SET(module, RMODULE_IS_OVERLAID); 01100 c = RCLASS_SUPER(c) = rb_include_class_new(module, RCLASS_SUPER(c)); 01101 RCLASS_REFINED_CLASS(c) = klass; 01102 module = RCLASS_SUPER(module); 01103 } 01104 rb_hash_aset(cref->nd_refinements, klass, iclass); 01105 } 01106 01107 static int 01108 using_refinement(VALUE klass, VALUE module, VALUE arg) 01109 { 01110 NODE *cref = (NODE *) arg; 01111 01112 rb_using_refinement(cref, klass, module); 01113 return ST_CONTINUE; 01114 } 01115 01116 void 01117 rb_using_module(NODE *cref, VALUE module) 01118 { 01119 ID id_refinements; 01120 VALUE refinements; 01121 01122 Check_Type(module, T_MODULE); 01123 CONST_ID(id_refinements, "__refinements__"); 01124 refinements = rb_attr_get(module, id_refinements); 01125 if (NIL_P(refinements)) return; 01126 rb_hash_foreach(refinements, using_refinement, (VALUE) cref); 01127 } 01128 01129 VALUE rb_refinement_module_get_refined_class(VALUE module) 01130 { 01131 ID id_refined_class; 01132 01133 CONST_ID(id_refined_class, "__refined_class__"); 01134 return rb_attr_get(module, id_refined_class); 01135 } 01136 01137 static void 01138 add_activated_refinement(VALUE activated_refinements, 01139 VALUE klass, VALUE refinement) 01140 { 01141 VALUE iclass, c, superclass = klass; 01142 01143 if (!NIL_P(c = rb_hash_lookup(activated_refinements, klass))) { 01144 superclass = c; 01145 while (c && RB_TYPE_P(c, T_ICLASS)) { 01146 if (RBASIC(c)->klass == refinement) { 01147 /* already used refinement */ 01148 return; 01149 } 01150 c = RCLASS_SUPER(c); 01151 } 01152 } 01153 FL_SET(refinement, RMODULE_IS_OVERLAID); 01154 c = iclass = rb_include_class_new(refinement, superclass); 01155 RCLASS_REFINED_CLASS(c) = klass; 01156 refinement = RCLASS_SUPER(refinement); 01157 while (refinement) { 01158 FL_SET(refinement, RMODULE_IS_OVERLAID); 01159 c = RCLASS_SUPER(c) = 01160 rb_include_class_new(refinement, RCLASS_SUPER(c)); 01161 RCLASS_REFINED_CLASS(c) = klass; 01162 refinement = RCLASS_SUPER(refinement); 01163 } 01164 rb_hash_aset(activated_refinements, klass, iclass); 01165 } 01166 01167 VALUE rb_yield_refine_block(VALUE refinement, VALUE refinements); 01168 01169 /* 01170 * call-seq: 01171 * refine(klass) { block } -> module 01172 * 01173 * Refine <i>klass</i> in the receiver. 01174 * 01175 * Returns an overlaid module. 01176 */ 01177 01178 static VALUE 01179 rb_mod_refine(VALUE module, VALUE klass) 01180 { 01181 VALUE refinement; 01182 ID id_refinements, id_activated_refinements, 01183 id_refined_class, id_defined_at; 01184 VALUE refinements, activated_refinements; 01185 rb_thread_t *th = GET_THREAD(); 01186 rb_block_t *block = rb_vm_control_frame_block_ptr(th->cfp); 01187 01188 warn_refinements_once(); 01189 if (!block) { 01190 rb_raise(rb_eArgError, "no block given"); 01191 } 01192 if (block->proc) { 01193 rb_raise(rb_eArgError, 01194 "can't pass a Proc as a block to Module#refine"); 01195 } 01196 Check_Type(klass, T_CLASS); 01197 CONST_ID(id_refinements, "__refinements__"); 01198 refinements = rb_attr_get(module, id_refinements); 01199 if (NIL_P(refinements)) { 01200 refinements = hidden_identity_hash_new(); 01201 rb_ivar_set(module, id_refinements, refinements); 01202 } 01203 CONST_ID(id_activated_refinements, "__activated_refinements__"); 01204 activated_refinements = rb_attr_get(module, id_activated_refinements); 01205 if (NIL_P(activated_refinements)) { 01206 activated_refinements = hidden_identity_hash_new(); 01207 rb_ivar_set(module, id_activated_refinements, 01208 activated_refinements); 01209 } 01210 refinement = rb_hash_lookup(refinements, klass); 01211 if (NIL_P(refinement)) { 01212 refinement = rb_module_new(); 01213 RCLASS_SUPER(refinement) = klass; 01214 FL_SET(refinement, RMODULE_IS_REFINEMENT); 01215 CONST_ID(id_refined_class, "__refined_class__"); 01216 rb_ivar_set(refinement, id_refined_class, klass); 01217 CONST_ID(id_defined_at, "__defined_at__"); 01218 rb_ivar_set(refinement, id_defined_at, module); 01219 rb_hash_aset(refinements, klass, refinement); 01220 add_activated_refinement(activated_refinements, klass, refinement); 01221 } 01222 rb_yield_refine_block(refinement, activated_refinements); 01223 return refinement; 01224 } 01225 01226 void 01227 rb_obj_call_init(VALUE obj, int argc, VALUE *argv) 01228 { 01229 PASS_PASSED_BLOCK(); 01230 rb_funcall2(obj, idInitialize, argc, argv); 01231 } 01232 01233 void 01234 rb_extend_object(VALUE obj, VALUE module) 01235 { 01236 rb_include_module(rb_singleton_class(obj), module); 01237 } 01238 01239 /* 01240 * call-seq: 01241 * extend_object(obj) -> obj 01242 * 01243 * Extends the specified object by adding this module's constants and 01244 * methods (which are added as singleton methods). This is the callback 01245 * method used by <code>Object#extend</code>. 01246 * 01247 * module Picky 01248 * def Picky.extend_object(o) 01249 * if String === o 01250 * puts "Can't add Picky to a String" 01251 * else 01252 * puts "Picky added to #{o.class}" 01253 * super 01254 * end 01255 * end 01256 * end 01257 * (s = Array.new).extend Picky # Call Object.extend 01258 * (s = "quick brown fox").extend Picky 01259 * 01260 * <em>produces:</em> 01261 * 01262 * Picky added to Array 01263 * Can't add Picky to a String 01264 */ 01265 01266 static VALUE 01267 rb_mod_extend_object(VALUE mod, VALUE obj) 01268 { 01269 rb_extend_object(obj, mod); 01270 return obj; 01271 } 01272 01273 /* 01274 * call-seq: 01275 * obj.extend(module, ...) -> obj 01276 * 01277 * Adds to _obj_ the instance methods from each module given as a 01278 * parameter. 01279 * 01280 * module Mod 01281 * def hello 01282 * "Hello from Mod.\n" 01283 * end 01284 * end 01285 * 01286 * class Klass 01287 * def hello 01288 * "Hello from Klass.\n" 01289 * end 01290 * end 01291 * 01292 * k = Klass.new 01293 * k.hello #=> "Hello from Klass.\n" 01294 * k.extend(Mod) #=> #<Klass:0x401b3bc8> 01295 * k.hello #=> "Hello from Mod.\n" 01296 */ 01297 01298 static VALUE 01299 rb_obj_extend(int argc, VALUE *argv, VALUE obj) 01300 { 01301 int i; 01302 ID id_extend_object, id_extended; 01303 01304 CONST_ID(id_extend_object, "extend_object"); 01305 CONST_ID(id_extended, "extended"); 01306 01307 rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS); 01308 for (i = 0; i < argc; i++) 01309 Check_Type(argv[i], T_MODULE); 01310 while (argc--) { 01311 rb_funcall(argv[argc], id_extend_object, 1, obj); 01312 rb_funcall(argv[argc], id_extended, 1, obj); 01313 } 01314 return obj; 01315 } 01316 01317 /* 01318 * call-seq: 01319 * include(module, ...) -> self 01320 * 01321 * Invokes <code>Module.append_features</code> 01322 * on each parameter in turn. Effectively adds the methods and constants 01323 * in each module to the receiver. 01324 */ 01325 01326 static VALUE 01327 top_include(int argc, VALUE *argv, VALUE self) 01328 { 01329 rb_thread_t *th = GET_THREAD(); 01330 01331 rb_secure(4); 01332 if (th->top_wrapper) { 01333 rb_warning("main.include in the wrapped load is effective only in wrapper module"); 01334 return rb_mod_include(argc, argv, th->top_wrapper); 01335 } 01336 return rb_mod_include(argc, argv, rb_cObject); 01337 } 01338 01339 /* 01340 * call-seq: 01341 * using(module) -> self 01342 * 01343 * Import class refinements from <i>module</i> into the scope where 01344 * <code>using</code> is called. 01345 */ 01346 01347 static VALUE 01348 top_using(VALUE self, VALUE module) 01349 { 01350 NODE *cref = rb_vm_cref(); 01351 rb_control_frame_t *prev_cfp = previous_frame(GET_THREAD()); 01352 01353 warn_refinements_once(); 01354 if (cref->nd_next || (prev_cfp && prev_cfp->me)) { 01355 rb_raise(rb_eRuntimeError, "using is permitted only at toplevel"); 01356 } 01357 Check_Type(module, T_MODULE); 01358 rb_using_module(cref, module); 01359 rb_clear_cache(); 01360 return self; 01361 } 01362 01363 static VALUE * 01364 errinfo_place(rb_thread_t *th) 01365 { 01366 rb_control_frame_t *cfp = th->cfp; 01367 rb_control_frame_t *end_cfp = RUBY_VM_END_CONTROL_FRAME(th); 01368 01369 while (RUBY_VM_VALID_CONTROL_FRAME_P(cfp, end_cfp)) { 01370 if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) { 01371 if (cfp->iseq->type == ISEQ_TYPE_RESCUE) { 01372 return &cfp->ep[-2]; 01373 } 01374 else if (cfp->iseq->type == ISEQ_TYPE_ENSURE && 01375 !RB_TYPE_P(cfp->ep[-2], T_NODE) && 01376 !FIXNUM_P(cfp->ep[-2])) { 01377 return &cfp->ep[-2]; 01378 } 01379 } 01380 cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp); 01381 } 01382 return 0; 01383 } 01384 01385 static VALUE 01386 get_thread_errinfo(rb_thread_t *th) 01387 { 01388 VALUE *ptr = errinfo_place(th); 01389 if (ptr) { 01390 return *ptr; 01391 } 01392 else { 01393 return th->errinfo; 01394 } 01395 } 01396 01397 static VALUE 01398 get_errinfo(void) 01399 { 01400 return get_thread_errinfo(GET_THREAD()); 01401 } 01402 01403 static VALUE 01404 errinfo_getter(ID id) 01405 { 01406 return get_errinfo(); 01407 } 01408 01409 #if 0 01410 static void 01411 errinfo_setter(VALUE val, ID id, VALUE *var) 01412 { 01413 if (!NIL_P(val) && !rb_obj_is_kind_of(val, rb_eException)) { 01414 rb_raise(rb_eTypeError, "assigning non-exception to $!"); 01415 } 01416 else { 01417 VALUE *ptr = errinfo_place(GET_THREAD()); 01418 if (ptr) { 01419 *ptr = val; 01420 } 01421 else { 01422 rb_raise(rb_eRuntimeError, "errinfo_setter: not in rescue clause."); 01423 } 01424 } 01425 } 01426 #endif 01427 01428 VALUE 01429 rb_errinfo(void) 01430 { 01431 rb_thread_t *th = GET_THREAD(); 01432 return th->errinfo; 01433 } 01434 01435 void 01436 rb_set_errinfo(VALUE err) 01437 { 01438 if (!NIL_P(err) && !rb_obj_is_kind_of(err, rb_eException)) { 01439 rb_raise(rb_eTypeError, "assigning non-exception to $!"); 01440 } 01441 GET_THREAD()->errinfo = err; 01442 } 01443 01444 VALUE 01445 rb_rubylevel_errinfo(void) 01446 { 01447 return get_errinfo(); 01448 } 01449 01450 static VALUE 01451 errat_getter(ID id) 01452 { 01453 VALUE err = get_errinfo(); 01454 if (!NIL_P(err)) { 01455 return get_backtrace(err); 01456 } 01457 else { 01458 return Qnil; 01459 } 01460 } 01461 01462 static void 01463 errat_setter(VALUE val, ID id, VALUE *var) 01464 { 01465 VALUE err = get_errinfo(); 01466 if (NIL_P(err)) { 01467 rb_raise(rb_eArgError, "$! not set"); 01468 } 01469 set_backtrace(err, val); 01470 } 01471 01472 /* 01473 * call-seq: 01474 * __method__ -> symbol 01475 * __callee__ -> symbol 01476 * 01477 * Returns the name of the current method as a Symbol. 01478 * If called outside of a method, it returns <code>nil</code>. 01479 * 01480 */ 01481 01482 static VALUE 01483 rb_f_method_name(void) 01484 { 01485 ID fname = rb_frame_caller(); /* need *caller* ID */ 01486 01487 if (fname) { 01488 return ID2SYM(fname); 01489 } 01490 else { 01491 return Qnil; 01492 } 01493 } 01494 01495 static VALUE 01496 rb_f_callee_name(void) 01497 { 01498 ID fname = rb_frame_callee(); /* need *callee* ID */ 01499 01500 if (fname) { 01501 return ID2SYM(fname); 01502 } 01503 else { 01504 return Qnil; 01505 } 01506 } 01507 01508 /* 01509 * call-seq: 01510 * __dir__ -> string 01511 * 01512 * Returns the canonicalized absolute path of the directory of the file from 01513 * which this method is called. It means symlinks in the path is resolved. 01514 * If <code>__FILE__</code> is <code>nil</code>, it returns <code>nil</code>. 01515 * The return value equals to <code>File.dirname(File.realpath(__FILE__))</code>. 01516 * 01517 */ 01518 static VALUE 01519 f_current_dirname(void) 01520 { 01521 VALUE base = rb_current_realfilepath(); 01522 if (NIL_P(base)) { 01523 return Qnil; 01524 } 01525 base = rb_file_dirname(base); 01526 return base; 01527 } 01528 01529 void 01530 Init_eval(void) 01531 { 01532 rb_define_virtual_variable("$@", errat_getter, errat_setter); 01533 rb_define_virtual_variable("$!", errinfo_getter, 0); 01534 01535 rb_define_global_function("raise", rb_f_raise, -1); 01536 rb_define_global_function("fail", rb_f_raise, -1); 01537 01538 rb_define_global_function("global_variables", rb_f_global_variables, 0); /* in variable.c */ 01539 01540 rb_define_global_function("__method__", rb_f_method_name, 0); 01541 rb_define_global_function("__callee__", rb_f_callee_name, 0); 01542 rb_define_global_function("__dir__", f_current_dirname, 0); 01543 01544 rb_define_private_method(rb_cModule, "append_features", rb_mod_append_features, 1); 01545 rb_define_private_method(rb_cModule, "extend_object", rb_mod_extend_object, 1); 01546 rb_define_private_method(rb_cModule, "include", rb_mod_include, -1); 01547 rb_define_private_method(rb_cModule, "prepend_features", rb_mod_prepend_features, 1); 01548 rb_define_private_method(rb_cModule, "prepend", rb_mod_prepend, -1); 01549 rb_define_private_method(rb_cModule, "refine", rb_mod_refine, 1); 01550 rb_undef_method(rb_cClass, "refine"); 01551 01552 rb_undef_method(rb_cClass, "module_function"); 01553 01554 Init_vm_eval(); 01555 Init_eval_method(); 01556 01557 rb_define_singleton_method(rb_cModule, "nesting", rb_mod_nesting, 0); 01558 rb_define_singleton_method(rb_cModule, "constants", rb_mod_s_constants, -1); 01559 01560 rb_define_private_method(rb_singleton_class(rb_vm_top_self()), 01561 "include", top_include, -1); 01562 rb_define_private_method(rb_singleton_class(rb_vm_top_self()), 01563 "using", top_using, 1); 01564 01565 rb_define_method(rb_mKernel, "extend", rb_obj_extend, -1); 01566 01567 rb_define_global_function("trace_var", rb_f_trace_var, -1); /* in variable.c */ 01568 rb_define_global_function("untrace_var", rb_f_untrace_var, -1); /* in variable.c */ 01569 01570 exception_error = rb_exc_new3(rb_eFatal, 01571 rb_obj_freeze(rb_str_new2("exception reentered"))); 01572 OBJ_TAINT(exception_error); 01573 OBJ_FREEZE(exception_error); 01574 } 01575