From 97ba019c9410ccb5ec76f6b54fd2e140b7583038 Mon Sep 17 00:00:00 2001 From: ko1 Date: Sun, 24 Jun 2007 15:42:41 +0000 Subject: [PATCH] * vm.c: some refactoring. * rename th_* to vm_*. * remove unused variables functions. * add prototypes. * blockinlining.c, compile.c, cont.c, eval.c, eval_intern.h, eval_jump.h, eval_load.c, inits.c, insns.def, iseq.c, parse.y, proc.c, process.c, signal.c, thread.c, vm.c, vm_dump.c, vm_evalbody.ci, yarvcore.c, yarvcore.h: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12603 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 12 +++ blockinlining.c | 6 +- compile.c | 39 ++------ cont.c | 8 +- eval.c | 53 +++++----- eval_intern.h | 24 ++--- eval_jump.h | 1 - eval_load.c | 2 +- inits.c | 1 + insns.def | 54 +++++----- iseq.c | 2 +- parse.y | 28 ------ proc.c | 14 +-- process.c | 2 + signal.c | 2 +- thread.c | 16 +-- version.h | 6 +- vm.c | 257 ++++++++++++++++++++++++------------------------ vm_dump.c | 7 +- vm_evalbody.ci | 12 +-- yarvcore.c | 9 +- yarvcore.h | 18 ++-- 22 files changed, 262 insertions(+), 311 deletions(-) diff --git a/ChangeLog b/ChangeLog index 653919eb9e..62ca80880d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +Mon Jun 25 00:14:13 2007 Koichi Sasada + + * vm.c: some refactoring. + * rename th_* to vm_*. + * remove unused variables functions. + * add prototypes. + + * blockinlining.c, compile.c, cont.c, eval.c, eval_intern.h, + eval_jump.h, eval_load.c, inits.c, insns.def, iseq.c, parse.y, + proc.c, process.c, signal.c, thread.c, vm.c, vm_dump.c, + vm_evalbody.ci, yarvcore.c, yarvcore.h: ditto. + Sun Jun 24 22:32:00 2007 Koichi Sasada * eval_method.h (rb_add_method): fix to check 0. diff --git a/blockinlining.c b/blockinlining.c index 9913b035d6..4f491c1ba1 100644 --- a/blockinlining.c +++ b/blockinlining.c @@ -199,7 +199,7 @@ yarv_invoke_Integer_times_special_block(VALUE num) th->cfp->lfp[0] = GC_GUARDED_PTR(&block); argv[0] = INT2FIX(0); argv[1] = num; - val = th_yield(th, 2, argv); + val = vm_yield(th, 2, argv); if (val == Qundef) { return num; } @@ -318,7 +318,7 @@ yarv_invoke_Range_each_special_block(VALUE range, th->cfp->lfp[0] = GC_GUARDED_PTR(&block); argv[0] = beg; argv[1] = end; - val = th_yield(th, 2, argv); + val = vm_yield(th, 2, argv); if (val == Qundef) { return range; } @@ -448,7 +448,7 @@ yarv_invoke_Array_each_special_block(VALUE ary) th->cfp->lfp[0] = GC_GUARDED_PTR(&block); argv[0] = 0; argv[1] = ary; - val = th_yield(th, 2, argv); + val = vm_yield(th, 2, argv); if (val == Qundef) { return ary; } diff --git a/compile.c b/compile.c index 956978cc0f..d376dc40b3 100644 --- a/compile.c +++ b/compile.c @@ -90,7 +90,6 @@ static void dump_disasm_list(LINK_ELEMENT *elem); static int insn_data_length(INSN *iobj); static int insn_data_line_no(INSN *iobj); static int calc_sp_depth(int depth, INSN *iobj); -static int insn_ret_num(int insn); static void ADD_ELEM(LINK_ANCHOR *anchor, LINK_ELEMENT *elem); @@ -109,10 +108,7 @@ static int set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *anchor); static int set_exception_table(rb_iseq_t *iseq); static int set_local_table(rb_iseq_t *iseq, ID *tbl); -static int set_local_table_eval(rb_iseq_t *iseq, ID *tbl); static int set_arguments(rb_iseq_t *iseq, LINK_ANCHOR *anchor, NODE * node); -static NODE *set_block_local_tbl(rb_iseq_t *iseq, NODE * node, - LINK_ANCHOR *anchor); static int set_exception_tbl(rb_iseq_t *iseq); static int set_optargs_table(rb_iseq_t *iseq); @@ -218,7 +214,7 @@ rb_iseq_compile(VALUE self, NODE *node) return iseq_setup(iseq, ret); } -VALUE th_eval(void *); +VALUE vm_eval(void *); static int iseq_translate_direct_threaded_code(rb_iseq_t *iseq) @@ -226,7 +222,7 @@ iseq_translate_direct_threaded_code(rb_iseq_t *iseq) #if OPT_DIRECT_THREADED_CODE || OPT_CALL_THREADED_CODE #if OPT_DIRECT_THREADED_CODE - void **table = (void **)th_eval(0); + void **table = (void **)vm_eval(0); #else extern void **insns_address_table(); void **table = get_insns_address_table(); @@ -353,6 +349,7 @@ INSERT_ELEM_NEXT(LINK_ELEMENT *elem1, LINK_ELEMENT *elem2) } #endif +#if 0 /* unused */ /* * elemX, elem1 => elemX, elem2, elem1 */ @@ -366,6 +363,8 @@ INSERT_ELEM_PREV(LINK_ELEMENT *elem1, LINK_ELEMENT *elem2) elem2->prev->next = elem2; } } +#endif + /*******************************************/ /* @@ -417,6 +416,7 @@ POP_ELEMENT(LINK_ANCHOR *anchor) return elem; } +#if 0 /* unused */ static LINK_ELEMENT * SHIFT_ELEMENT(LINK_ANCHOR *anchor) { @@ -426,7 +426,9 @@ SHIFT_ELEMENT(LINK_ANCHOR *anchor) } return elem; } +#endif +#if 0 /* unused */ static int LIST_SIZE(LINK_ANCHOR *anchor) { @@ -438,6 +440,7 @@ LIST_SIZE(LINK_ANCHOR *anchor) } return size; } +#endif static int LIST_SIZE_ZERO(LINK_ANCHOR *anchor) @@ -779,12 +782,10 @@ set_arguments(rb_iseq_t *iseq, LINK_ANCHOR *optargs, NODE *node_args) if (node_args) { NODE *node_aux = node_args->nd_next; - int mandatory_len = 0; NODE *node_opt = node_args->nd_opt; ID rest_id = 0; ID block_id = 0; NODE *node_init = 0; - int d = iseq->local_size - iseq->local_table_size; if (nd_type(node_args) != NODE_ARGS) { rb_bug("set_arguments: NODE_ARGS is expected, but %s", @@ -934,24 +935,6 @@ set_local_table(rb_iseq_t *iseq, ID *tbl) return COMPILE_OK; } -static int -set_local_table_eval(rb_iseq_t *iseq, ID *tbl) -{ - int size; - if (tbl) { - size = *tbl; - } - else { - size = 0; - } - if (tbl) { - iseq->local_table = (ID *)ALLOC_N(ID *, size); - MEMCPY(iseq->local_table, tbl + 1, ID *, size); - } - iseq->local_table_size = iseq->local_size = size; - return COMPILE_OK; -} - /** ruby insn object array -> raw instruction sequence */ @@ -2130,8 +2113,8 @@ defined_expr(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE *vals = node; do { - NODE *val = vals->nd_head; defined_expr(iseq, ret, vals->nd_head, lfinish, Qfalse); + if (lfalse) { ADD_INSNL(ret, nd_line(node), branchunless, lfalse); } @@ -3723,8 +3706,6 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) if (node->nd_head) { if (nd_type(node->nd_head) == NODE_ARRAY) { - NODE *p; - argc = node->nd_head->nd_alen; compile_array(iseq, args, node->nd_head, Qfalse); POP_ELEMENT(args); diff --git a/cont.c b/cont.c index 3450593867..407325d7b9 100644 --- a/cont.c +++ b/cont.c @@ -157,7 +157,7 @@ cont_new(VALUE klass) return cont; } -void th_stack_to_heap(rb_thread_t *th); +void vm_stack_to_heap(rb_thread_t *th); static VALUE cont_capture(volatile int *stat) @@ -166,7 +166,7 @@ cont_capture(volatile int *stat) rb_thread_t *th; volatile VALUE contval; - th_stack_to_heap(GET_THREAD()); + vm_stack_to_heap(GET_THREAD()); cont = cont_new(rb_cCont); contval = cont->self; th = &cont->saved_thread; @@ -535,12 +535,12 @@ rb_fiber_start(void) th->local_lfp = proc->block.lfp; th->local_svar = Qnil; - cont->value = th_invoke_proc(th, proc, proc->block.self, 1, &args); + cont->value = vm_invoke_proc(th, proc, proc->block.self, 1, &args); } TH_POP_TAG(); if (state) { - th->thrown_errinfo = th_make_jump_tag_but_local_jump(state, th->errinfo); + th->thrown_errinfo = vm_make_jump_tag_but_local_jump(state, th->errinfo); th->interrupt_flag = 1; } diff --git a/eval.c b/eval.c index 692d967fa8..65f972918f 100644 --- a/eval.c +++ b/eval.c @@ -57,6 +57,9 @@ char **rb_origenviron; jmp_buf function_call_may_return_twice_jmp_buf; int function_call_may_return_twice_false = 0; +void rb_clear_trace_func(void); +void rb_thread_stop_timer_thread(void); + void rb_call_inits _((void)); void Init_stack _((VALUE *)); void Init_heap _((void)); @@ -155,7 +158,6 @@ ruby_cleanup(int ex) int state; volatile VALUE errs[2]; rb_thread_t *th = GET_THREAD(); - rb_vm_t *vm = th->vm; int nerr; errs[1] = th->errinfo; @@ -347,7 +349,7 @@ rb_eval_cmd(VALUE cmd, VALUE arg, int level) POP_TAG(); rb_set_safe_level_force(safe); - if (state) th_jump_tag_but_local_jump(state, val); + if (state) vm_jump_tag_but_local_jump(state, val); return val; } @@ -661,12 +663,12 @@ rb_mod_protected_method_defined(VALUE mod, VALUE mid) return Qfalse; } -NORETURN(void th_iter_break _((rb_thread_t *))); +NORETURN(void vm_iter_break _((rb_thread_t *))); void rb_iter_break() { - th_iter_break(GET_THREAD()); + vm_iter_break(GET_THREAD()); } NORETURN(static void rb_longjmp _((int, VALUE))); @@ -901,7 +903,7 @@ rb_f_block_given_p() { rb_thread_t *th = GET_THREAD(); rb_control_frame_t *cfp = th->cfp; - cfp = th_get_ruby_level_cfp(th, RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)); + cfp = vm_get_ruby_level_cfp(th, RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)); if (GC_GUARDED_PTR_REF(cfp->lfp[0])) { return Qtrue; } @@ -916,17 +918,16 @@ void rb_need_block() { if (!rb_block_given_p()) { - th_localjump_error("no block given", Qnil, 0); + vm_localjump_error("no block given", Qnil, 0); } } static inline VALUE rb_yield_0(int argc, VALUE *argv) { - return th_yield(GET_THREAD(), argc, argv); + return vm_yield(GET_THREAD(), argc, argv); } - VALUE rb_yield(VALUE val) { @@ -1429,7 +1430,7 @@ rb_call(VALUE klass, VALUE recv, ID mid, int argc, const VALUE *argv, int scope) //printf("%s with %d args\n", rb_id2name(mid), argc); */ val = - th_call0(GET_THREAD(), klass, recv, mid, id, argc, argv, body, + vm_call0(GET_THREAD(), klass, recv, mid, id, argc, argv, body, noex & NOEX_NOSUPER); /* //level--; @@ -1557,7 +1558,7 @@ rb_funcall3(VALUE recv, ID mid, int argc, const VALUE *argv) static VALUE backtrace(int lev) { - return th_backtrace(GET_THREAD(), lev); + return vm_backtrace(GET_THREAD(), lev); } /* @@ -1671,7 +1672,7 @@ const char * rb_sourcefile(void) { rb_thread_t *th = GET_THREAD(); - rb_control_frame_t *cfp = th_get_ruby_level_cfp(th, th->cfp); + rb_control_frame_t *cfp = vm_get_ruby_level_cfp(th, th->cfp); if (cfp) { return RSTRING_PTR(cfp->iseq->filename); @@ -1685,10 +1686,10 @@ int rb_sourceline(void) { rb_thread_t *th = GET_THREAD(); - rb_control_frame_t *cfp = th_get_ruby_level_cfp(th, th->cfp); + rb_control_frame_t *cfp = vm_get_ruby_level_cfp(th, th->cfp); if (cfp) { - return th_get_sourceline(cfp); + return vm_get_sourceline(cfp); } else { return 0; @@ -1733,16 +1734,16 @@ eval(VALUE self, VALUE src, VALUE scope, char *file, int line) th->base_block = &env->block; } else { - rb_control_frame_t *cfp = th_get_ruby_level_cfp(th, th->cfp); + rb_control_frame_t *cfp = vm_get_ruby_level_cfp(th, th->cfp); th->base_block = RUBY_VM_GET_BLOCK_PTR_IN_CFP(cfp); th->base_block->iseq = cfp->iseq; /* TODO */ } /* make eval iseq */ th->parse_in_eval++; - iseqval = th_compile(th, src, rb_str_new2(file), INT2FIX(line)); + iseqval = vm_compile(th, src, rb_str_new2(file), INT2FIX(line)); th->parse_in_eval--; - th_set_eval_stack(th, iseqval); + vm_set_eval_stack(th, iseqval); th->base_block = 0; if (0) { /* for debug */ @@ -1753,22 +1754,22 @@ eval(VALUE self, VALUE src, VALUE scope, char *file, int line) /* save new env */ GetISeqPtr(iseqval, iseq); if (bind && iseq->local_size > 0) { - bind->env = th_make_env_object(th, th->cfp); + bind->env = vm_make_env_object(th, th->cfp); } /* push tag */ if (stored_cref_stack) { stored_cref_stack = - th_set_special_cref(th, env->block.lfp, stored_cref_stack); + vm_set_special_cref(th, env->block.lfp, stored_cref_stack); } /* kick */ - result = th_eval_body(th); + result = vm_eval_body(th); } POP_TAG(); if (stored_cref_stack) { - th_set_special_cref(th, env->block.lfp, stored_cref_stack); + vm_set_special_cref(th, env->block.lfp, stored_cref_stack); } if (state) { @@ -1842,7 +1843,7 @@ rb_f_eval(int argc, VALUE *argv, VALUE self) return eval(self, src, scope, file, line); } -VALUE *th_cfp_svar(rb_control_frame_t *cfp, int idx); +VALUE *vm_cfp_svar(rb_control_frame_t *cfp, int idx); /* function to call func under the specified class/module context */ static VALUE @@ -1874,9 +1875,9 @@ exec_under(VALUE (*func) (VALUE), VALUE under, VALUE self, VALUE args) cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp); } - pcref = (NODE **) th_cfp_svar(cfp, -1); + pcref = (NODE **) vm_cfp_svar(cfp, -1); stored_cref = *pcref; - *pcref = th_cref_push(th, under, NOEX_PUBLIC); + *pcref = vm_cref_push(th, under, NOEX_PUBLIC); PUSH_TAG(); if ((state = EXEC_TAG()) == 0) { @@ -2590,7 +2591,7 @@ errat_setter(VALUE val, ID id, VALUE *var) * local_variables #=> ["fred", "i"] */ -int th_collect_local_variables_in_heap(rb_thread_t *th, VALUE *dfp, VALUE ary); +int vm_collect_local_variables_in_heap(rb_thread_t *th, VALUE *dfp, VALUE ary); static VALUE rb_f_local_variables(void) @@ -2598,7 +2599,7 @@ rb_f_local_variables(void) VALUE ary = rb_ary_new(); rb_thread_t *th = GET_THREAD(); rb_control_frame_t *cfp = - th_get_ruby_level_cfp(th, RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp)); + vm_get_ruby_level_cfp(th, RUBY_VM_PREVIOUS_CONTROL_FRAME(th->cfp)); int i; while (1) { @@ -2618,7 +2619,7 @@ rb_f_local_variables(void) /* block */ VALUE *dfp = GC_GUARDED_PTR_REF(cfp->dfp[0]); - if (th_collect_local_variables_in_heap(th, dfp, ary)) { + if (vm_collect_local_variables_in_heap(th, dfp, ary)) { break; } else { diff --git a/eval_intern.h b/eval_intern.h index 5d9195d935..a18fe59420 100644 --- a/eval_intern.h +++ b/eval_intern.h @@ -196,18 +196,18 @@ NORETURN(void rb_fiber_start(void)); NORETURN(void rb_raise_jump _((VALUE))); NORETURN(void print_undef _((VALUE, ID))); -NORETURN(void th_localjump_error(const char *, VALUE, int)); -NORETURN(void th_jump_tag_but_local_jump(int, VALUE)); +NORETURN(void vm_localjump_error(const char *, VALUE, int)); +NORETURN(void vm_jump_tag_but_local_jump(int, VALUE)); -VALUE th_compile(rb_thread_t *th, VALUE str, VALUE file, VALUE line); +VALUE vm_compile(rb_thread_t *th, VALUE str, VALUE file, VALUE line); -NODE *th_get_cref(rb_thread_t *th, rb_iseq_t *iseq, rb_control_frame_t *cfp); -NODE *th_cref_push(rb_thread_t *th, VALUE, int); -NODE *th_set_special_cref(rb_thread_t *th, VALUE *lfp, NODE * cref_stack); -VALUE th_make_jump_tag_but_local_jump(int state, VALUE val); +NODE *vm_get_cref(rb_thread_t *th, rb_iseq_t *iseq, rb_control_frame_t *cfp); +NODE *vm_cref_push(rb_thread_t *th, VALUE, int); +NODE *vm_set_special_cref(rb_thread_t *th, VALUE *lfp, NODE * cref_stack); +VALUE vm_make_jump_tag_but_local_jump(int state, VALUE val); static rb_control_frame_t * -th_get_ruby_level_cfp(rb_thread_t *th, rb_control_frame_t *cfp) +vm_get_ruby_level_cfp(rb_thread_t *th, rb_control_frame_t *cfp) { while (!RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp)) { if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) { @@ -222,17 +222,17 @@ static inline NODE * ruby_cref() { rb_thread_t *th = GET_THREAD(); - rb_control_frame_t *cfp = th_get_ruby_level_cfp(th, th->cfp); - return th_get_cref(th, cfp->iseq, cfp); + rb_control_frame_t *cfp = vm_get_ruby_level_cfp(th, th->cfp); + return vm_get_cref(th, cfp->iseq, cfp); } -VALUE th_get_cbase(rb_thread_t *th); +VALUE vm_get_cbase(rb_thread_t *th); VALUE rb_obj_is_proc(VALUE); void rb_vm_check_redefinition_opt_method(NODE *node); VALUE rb_vm_call_cfunc(VALUE recv, VALUE (*func)(VALUE), VALUE arg, rb_block_t *blockptr, VALUE filename); void rb_thread_terminate_all(void); -#define ruby_cbase() th_get_cbase(GET_THREAD()) +#define ruby_cbase() vm_get_cbase(GET_THREAD()) /* tracer */ diff --git a/eval_jump.h b/eval_jump.h index e281e420db..b929136afd 100644 --- a/eval_jump.h +++ b/eval_jump.h @@ -138,7 +138,6 @@ static VALUE terminate_process(int status, const char *mesg, long mlen) { VALUE args[2]; - rb_vm_t *vm = GET_THREAD()->vm; args[0] = INT2NUM(status); args[1] = rb_str_new(mesg, mlen); diff --git a/eval_load.c b/eval_load.c index 866c45bf82..c71880292c 100644 --- a/eval_load.c +++ b/eval_load.c @@ -202,7 +202,7 @@ rb_load(VALUE fname, int wrap) rb_exc_raise(GET_THREAD()->errinfo); } if (state) { - th_jump_tag_but_local_jump(state, Qundef); + vm_jump_tag_but_local_jump(state, Qundef); } if (!NIL_P(GET_THREAD()->errinfo)) { diff --git a/inits.c b/inits.c index ef94f993e7..3ace504244 100644 --- a/inits.c +++ b/inits.c @@ -48,6 +48,7 @@ void Init_version(void); void Init_ISeq(void); void Init_VM(void); void Init_Thread(void); +void Init_Cont(void); void rb_call_inits() diff --git a/insns.def b/insns.def index 6d16fe1b59..8ad42c7ca9 100644 --- a/insns.def +++ b/insns.def @@ -215,7 +215,7 @@ getclassvariable () (VALUE val) { - VALUE klass = eval_get_cvar_base(th, GET_ISEQ()); + VALUE klass = vm_get_cvar_base(th, GET_ISEQ()); val = rb_cvar_get(klass, id); } @@ -230,7 +230,7 @@ setclassvariable (VALUE val) () { - rb_cvar_set(eval_get_cvar_base(th, GET_ISEQ()), id, val); + rb_cvar_set(vm_get_cvar_base(th, GET_ISEQ()), id, val); } /** @@ -251,7 +251,7 @@ getconstant (VALUE klass) (VALUE val) { - val = eval_get_ev_const(th, GET_ISEQ(), klass, id, 0); + val = vm_get_ev_const(th, GET_ISEQ(), klass, id, 0); } /** @@ -275,7 +275,7 @@ setconstant () { if (klass == Qnil) { - klass = th_get_cbase(th); + klass = vm_get_cbase(th); } if (NIL_P(klass)) { rb_raise(rb_eTypeError, "no class/module to define constant"); @@ -448,7 +448,7 @@ toregexp (VALUE str) (VALUE val) { - volatile VALUE tmp = str; + volatile VALUE tmp = str; /* for GC */ val = rb_reg_new(RSTRING_PTR(str), RSTRING_LEN(str), flag); } @@ -842,8 +842,8 @@ definemethod (VALUE obj) () { - eval_define_method(th, obj, id, body, is_singleton, - get_cref(GET_ISEQ(), GET_LFP())); + vm_define_method(th, obj, id, body, is_singleton, + get_cref(GET_ISEQ(), GET_LFP())); } /** @@ -923,7 +923,7 @@ defined break; case DEFINED_CONST: klass = v; - if (eval_get_ev_const(th, GET_ISEQ(), klass, SYM2ID(obj), 1)) { + if (vm_get_ev_const(th, GET_ISEQ(), klass, SYM2ID(obj), 1)) { expr_type = "constant"; } break; @@ -1011,7 +1011,7 @@ postexe blockptr->iseq = blockiseq; blockptr->proc = 0; - proc = th_make_proc(th, GET_CFP(), blockptr); + proc = vm_make_proc(th, GET_CFP(), blockptr); rb_set_end_proc(call_yarv_end_proc, proc); } @@ -1059,7 +1059,7 @@ defineclass } if (cbase == Qnil) { - cbase = th_get_cbase(th); + cbase = vm_get_cbase(th); } /* find klass */ @@ -1097,7 +1097,7 @@ defineclass /* val is dummy. classdef returns class scope value */ /* super is dummy */ if (cbase == Qnil) { - cbase = th_get_cbase(th); + cbase = vm_get_cbase(th); } /* find klass */ @@ -1119,13 +1119,13 @@ defineclass rb_bug("unknown defineclass type: %d", define_type); } - COPY_CREF(klass_iseq->cref_stack, th_cref_push(th, klass, NOEX_PUBLIC)); + COPY_CREF(klass_iseq->cref_stack, vm_cref_push(th, klass, NOEX_PUBLIC)); /* enter scope */ - push_frame(th, klass_iseq, - FRAME_MAGIC_CLASS, klass, (VALUE) GET_DFP() | 0x02, - klass_iseq->iseq_encoded, GET_SP(), 0, - klass_iseq->local_size); + vm_push_frame(th, klass_iseq, + FRAME_MAGIC_CLASS, klass, (VALUE) GET_DFP() | 0x02, + klass_iseq->iseq_encoded, GET_SP(), 0, + klass_iseq->local_size); RESTORE_REGS(); INC_VM_STATE_VERSION(); @@ -1153,7 +1153,7 @@ send (VALUE val) // inc += - (op_argc + ((op_flag & VM_CALL_ARGS_BLOCKARG_BIT) ? 1 : 0)); { NODE *mn; - VALUE recv, klass, v; + VALUE recv, klass; rb_block_t *blockptr = 0; rb_num_t num = caller_setup_args(th, GET_CFP(), op_flag, op_argc, blockiseq, &blockptr); rb_num_t flag = op_flag; @@ -1171,7 +1171,7 @@ send klass = CLASS_OF(recv); - mn = eval_method_search(id, klass, ic); + mn = vm_method_search(id, klass, ic); /* send/funcall optimization */ if ((flag & VM_CALL_SEND_BIT) && mn && nd_type(mn->nd_body) == NODE_CFUNC) { @@ -1287,7 +1287,7 @@ invokeblock int argc = num; if (GET_ISEQ()->local_iseq->type != ISEQ_TYPE_METHOD || block == 0) { - th_localjump_error("no block given (yield)", Qnil, 0); + vm_localjump_error("no block given (yield)", Qnil, 0); } iseq = block->iseq; @@ -1297,14 +1297,14 @@ invokeblock DEC_SP(argc); - argc = th_yield_setup_args(th, iseq, argc, GET_SP(), + argc = vm_yield_setup_args(th, iseq, argc, GET_SP(), block_proc_is_lambda(block->proc)); INC_SP(argc); - push_frame(th, iseq, - FRAME_MAGIC_BLOCK, block->self, (VALUE) block->dfp, - iseq->iseq_encoded, GET_SP(), block->lfp, - iseq->local_size - argc); + vm_push_frame(th, iseq, + FRAME_MAGIC_BLOCK, block->self, (VALUE) block->dfp, + iseq->iseq_encoded, GET_SP(), block->lfp, + iseq->local_size - argc); reg_cfp->sp -= argc; RESTORE_REGS(); @@ -1312,7 +1312,7 @@ invokeblock /* unreachable */ } else { - val = th_yield_with_cfunc(th, block, block->self, + val = vm_yield_with_cfunc(th, block, block->self, num, STACK_ADDR_FROM_TOP(num)); POPN(num); } @@ -1337,7 +1337,7 @@ leave } RUBY_VM_CHECK_INTS(); - pop_frame(th); + vm_pop_frame(th); RESTORE_REGS(); } @@ -1416,7 +1416,7 @@ throw cfp++; } if (is_orphan) { - th_localjump_error("unexpected return", throwobj, + vm_localjump_error("unexpected return", throwobj, TAG_RETURN); } diff --git a/iseq.c b/iseq.c index 9e66f9b8ce..e7482e9ba1 100644 --- a/iseq.c +++ b/iseq.c @@ -719,7 +719,7 @@ ruby_iseq_disasm(VALUE self) VALUE str = rb_str_new(0, 0); VALUE child = rb_ary_new(); unsigned long size; - int i, d = iseqdat->local_size - iseqdat->local_table_size; + int i; ID *tbl; char buff[0x200]; diff --git a/parse.y b/parse.y index c2ca84ce3f..0738ed20e0 100644 --- a/parse.y +++ b/parse.y @@ -7946,22 +7946,6 @@ arg_blk_pass(NODE *node1, NODE *node2) return node1; } -static int -arg_dup_check(ID vid, VALUE m, VALUE list, NODE *node) -{ - VALUE sym; - - if (!vid) return 0; - if (is_junk_id(vid)) return 0; - sym = ID2SYM(vid); - if ((m && rb_ary_includes(m, sym)) || rb_ary_includes(list, sym)) { - ruby_sourceline = nd_line(node); - return 1; - } - rb_ary_push(list, sym); - return 0; -} - static NODE* new_args_gen(struct parser_params *parser, NODE *m, NODE *o, ID r, NODE *p, ID b) { @@ -8024,18 +8008,6 @@ vtable_tblcpy(ID *buf, const struct vtable *src) return 0; } -static ID* -vtable_to_tbl(const struct vtable *src) -{ - int cnt = vtable_size(src); - ID *buf; - - if (cnt <= 0) return 0; - buf = ALLOC_N(ID, cnt + 1); - vtable_tblcpy(buf+1, src); - return buf; -} - static ID* local_tbl_gen(struct parser_params *parser) { diff --git a/proc.c b/proc.c index 8671ce54d5..18ffb76661 100644 --- a/proc.c +++ b/proc.c @@ -182,12 +182,12 @@ VALUE rb_binding_new(void) { rb_thread_t *th = GET_THREAD(); - rb_control_frame_t *cfp = th_get_ruby_level_cfp(th, th->cfp); + rb_control_frame_t *cfp = vm_get_ruby_level_cfp(th, th->cfp); VALUE bindval = binding_alloc(rb_cBinding); rb_binding_t *bind; GetBindingPtr(bindval, bind); - bind->env = th_make_env_object(th, cfp); + bind->env = vm_make_env_object(th, cfp); bind->cref_stack = ruby_cref(); return bindval; } @@ -284,7 +284,7 @@ proc_new(VALUE klass, int is_lambda) } } - procval = th_make_proc(th, cfp, block); + procval = vm_make_proc(th, cfp, block); if (is_lambda) { rb_proc_t *proc; @@ -364,7 +364,7 @@ proc_invoke(VALUE self, VALUE args, VALUE alt_self, VALUE alt_klass) GetProcPtr(self, proc); /* ignore self and klass */ - return th_invoke_proc(GET_THREAD(), proc, proc->block.self, + return vm_invoke_proc(GET_THREAD(), proc, proc->block.self, RARRAY_LEN(args), RARRAY_PTR(args)); } @@ -408,7 +408,7 @@ proc_call(int argc, VALUE *argv, VALUE procval) rb_proc_t *proc; GetProcPtr(procval, proc); - return th_invoke_proc(GET_THREAD(), proc, proc->block.self, argc, argv); + return vm_invoke_proc(GET_THREAD(), proc, proc->block.self, argc, argv); } static VALUE @@ -416,7 +416,7 @@ proc_yield(int argc, VALUE *argv, VALUE procval) { rb_proc_t *proc; GetProcPtr(procval, proc); - return th_invoke_proc(GET_THREAD(), proc, proc->block.self, argc, argv); + return vm_invoke_proc(GET_THREAD(), proc, proc->block.self, argc, argv); } VALUE @@ -1034,7 +1034,7 @@ rb_method_call(int argc, VALUE *argv, VALUE method) } if ((state = EXEC_TAG()) == 0) { PASS_PASSED_BLOCK(); - result = th_call0(GET_THREAD(), + result = vm_call0(GET_THREAD(), data->klass, data->recv, data->id, data->oid, argc, argv, data->body, 0); } diff --git a/process.c b/process.c index b9fe24f4cf..854ab47b9c 100644 --- a/process.c +++ b/process.c @@ -937,6 +937,8 @@ char *strtok(); #endif void rb_thread_stop_timer_thread(void); +void rb_thread_start_timer_thread(void); +void rb_thread_reset_timer_thread(void); #define before_exec() \ (rb_enable_interrupt(), rb_thread_stop_timer_thread()) diff --git a/signal.c b/signal.c index ce57784fe9..e495f6211f 100644 --- a/signal.c +++ b/signal.c @@ -551,7 +551,7 @@ signal_exec(VALUE cmd, int sig) rb_proc_t *proc; VALUE signum = INT2FIX(sig); GetProcPtr(cmd, proc); - th_invoke_proc(GET_THREAD(), proc, proc->block.self, 1, &signum); + vm_invoke_proc(GET_THREAD(), proc, proc->block.self, 1, &signum); } void diff --git a/thread.c b/thread.c index 02cf11e15d..2ac91ab8b7 100644 --- a/thread.c +++ b/thread.c @@ -81,7 +81,6 @@ st_delete_wrap(st_table * table, VALUE key) #define THREAD_SYSTEM_DEPENDENT_IMPLEMENTATION static rb_unblock_function_t* set_unblock_function(rb_thread_t *th, rb_unblock_function_t *func); -static void clear_unblock_function(rb_thread_t *th); NOINLINE(void rb_gc_set_stack_end(VALUE **stack_end_p)); NOINLINE(void rb_gc_save_machine_context(rb_thread_t *)); @@ -210,14 +209,6 @@ set_unblock_function(rb_thread_t *th, rb_unblock_function_t *func) return oldfunc; } -static void -clear_unblock_function(rb_thread_t *th) -{ - native_mutex_lock(&th->interrupt_lock); - th->unblock_function = 0; - native_mutex_unlock(&th->interrupt_lock); -} - static void rb_thread_interrupt(rb_thread_t *th) { @@ -314,7 +305,7 @@ thread_start_func_2(rb_thread_t *th, VALUE *stack_start th->errinfo = Qnil; th->local_lfp = proc->block.lfp; th->local_svar = Qnil; - th->value = th_invoke_proc(th, proc, proc->block.self, + th->value = vm_invoke_proc(th, proc, proc->block.self, RARRAY_LEN(args), RARRAY_PTR(args)); } else { @@ -393,8 +384,6 @@ rb_thread_create(VALUE (*fn)(ANYARGS), void *arg) /* +infty, for this purpose */ #define DELAY_INFTY 1E30 -VALUE th_make_jump_tag_but_local_jump(int state, VALUE val); - static VALUE thread_join(rb_thread_t *target_th, double delay) { @@ -435,7 +424,7 @@ thread_join(rb_thread_t *target_th, double delay) /* */ } else if (TYPE(target_th->errinfo) == T_NODE) { - rb_exc_raise(th_make_jump_tag_but_local_jump( + rb_exc_raise(vm_make_jump_tag_but_local_jump( GET_THROWOBJ_STATE(err), GET_THROWOBJ_VAL(err))); } else { @@ -2716,7 +2705,6 @@ static void call_trace_func(rb_event_flag_t, VALUE data, VALUE self, ID id, VALU static VALUE set_trace_func(VALUE obj, VALUE trace) { - rb_vm_t *vm = GET_VM(); rb_remove_event_hook(call_trace_func); if (NIL_P(trace)) { diff --git a/version.h b/version.h index e426ec2ea9..6490eba3be 100644 --- a/version.h +++ b/version.h @@ -1,7 +1,7 @@ #define RUBY_VERSION "1.9.0" -#define RUBY_RELEASE_DATE "2007-06-24" +#define RUBY_RELEASE_DATE "2007-06-25" #define RUBY_VERSION_CODE 190 -#define RUBY_RELEASE_CODE 20070624 +#define RUBY_RELEASE_CODE 20070625 #define RUBY_PATCHLEVEL 0 #define RUBY_VERSION_MAJOR 1 @@ -9,7 +9,7 @@ #define RUBY_VERSION_TEENY 0 #define RUBY_RELEASE_YEAR 2007 #define RUBY_RELEASE_MONTH 6 -#define RUBY_RELEASE_DAY 24 +#define RUBY_RELEASE_DAY 25 #ifdef RUBY_EXTERN RUBY_EXTERN const char ruby_version[]; diff --git a/vm.c b/vm.c index 8ac65d0e35..cace275d85 100644 --- a/vm.c +++ b/vm.c @@ -12,7 +12,6 @@ #include "ruby/ruby.h" #include "ruby/node.h" #include "ruby/st.h" -// #define MARK_FREE_DEBUG 1 #include "gc.h" #include "yarvcore.h" @@ -40,14 +39,11 @@ void vm_analysis_operand(int insn, int n, VALUE op); void vm_analysis_register(int reg, int isset); void vm_analysis_insn(int insn); -static inline VALUE -th_yield_cfunc(rb_thread_t *th, rb_block_t *block, - VALUE self, int argc, VALUE *argv); - -VALUE th_invoke_proc(rb_thread_t *th, rb_proc_t *proc, +VALUE vm_invoke_proc(rb_thread_t *th, rb_proc_t *proc, VALUE self, int argc, VALUE *argv); -VALUE th_eval_body(rb_thread_t *th); +VALUE vm_eval_body(rb_thread_t *th); + static NODE *lfp_get_special_cref(VALUE *lfp); static NODE *lfp_set_special_cref(VALUE *lfp, NODE * cref); @@ -75,9 +71,9 @@ rb_vm_change_state(void) * prepare stack frame */ static inline rb_control_frame_t * -push_frame(rb_thread_t *th, rb_iseq_t *iseq, VALUE magic, - VALUE self, VALUE specval, VALUE *pc, - VALUE *sp, VALUE *lfp, int local_size) +vm_push_frame(rb_thread_t *th, rb_iseq_t *iseq, VALUE magic, + VALUE self, VALUE specval, VALUE *pc, + VALUE *sp, VALUE *lfp, int local_size) { VALUE *dfp; rb_control_frame_t *cfp; @@ -118,7 +114,7 @@ push_frame(rb_thread_t *th, rb_iseq_t *iseq, VALUE magic, } static inline void -pop_frame(rb_thread_t *th) +vm_pop_frame(rb_thread_t *th) { #if COLLECT_PROFILE rb_control_frame_t *cfp = th->cfp; @@ -141,17 +137,17 @@ pop_frame(rb_thread_t *th) } VALUE -th_set_finish_env(rb_thread_t *th) +vm_set_finish_env(rb_thread_t *th) { - push_frame(th, 0, FRAME_MAGIC_FINISH, - Qnil, th->cfp->lfp[0], 0, - th->cfp->sp, 0, 1); + vm_push_frame(th, 0, FRAME_MAGIC_FINISH, + Qnil, th->cfp->lfp[0], 0, + th->cfp->sp, 0, 1); th->cfp->pc = &yarv_finish_insn_seq[0]; return Qtrue; } void -th_set_top_stack(rb_thread_t *th, VALUE iseqval) +vm_set_top_stack(rb_thread_t *th, VALUE iseqval) { rb_iseq_t *iseq; GetISeqPtr(iseqval, iseq); @@ -161,32 +157,32 @@ th_set_top_stack(rb_thread_t *th, VALUE iseqval) } /* for return */ - th_set_finish_env(th); + vm_set_finish_env(th); - push_frame(th, iseq, FRAME_MAGIC_TOP, - th->top_self, 0, iseq->iseq_encoded, - th->cfp->sp, 0, iseq->local_size); + vm_push_frame(th, iseq, FRAME_MAGIC_TOP, + th->top_self, 0, iseq->iseq_encoded, + th->cfp->sp, 0, iseq->local_size); } VALUE -th_set_eval_stack(rb_thread_t *th, VALUE iseqval) +vm_set_eval_stack(rb_thread_t *th, VALUE iseqval) { rb_iseq_t *iseq; rb_block_t *block = th->base_block; GetISeqPtr(iseqval, iseq); /* for return */ - th_set_finish_env(th); - push_frame(th, iseq, FRAME_MAGIC_EVAL, block->self, - GC_GUARDED_PTR(block->dfp), iseq->iseq_encoded, - th->cfp->sp, block->lfp, iseq->local_size); + vm_set_finish_env(th); + vm_push_frame(th, iseq, FRAME_MAGIC_EVAL, block->self, + GC_GUARDED_PTR(block->dfp), iseq->iseq_encoded, + th->cfp->sp, block->lfp, iseq->local_size); return 0; } /* return opt_pc */ static inline int -callee_setup_arg(rb_thread_t *th, rb_iseq_t *iseq, - int argc, VALUE *argv, rb_block_t **block) +vm_callee_setup_arg(rb_thread_t *th, rb_iseq_t *iseq, + int argc, VALUE *argv, rb_block_t **block) { const int m = iseq->argc; const int orig_argc = argc; @@ -263,7 +259,7 @@ callee_setup_arg(rb_thread_t *th, rb_iseq_t *iseq, rb_proc_t *proc; th->mark_stack_len = orig_argc; /* for GC */ - blockval = th_make_proc(th, th->cfp, blockptr); + blockval = vm_make_proc(th, th->cfp, blockptr); th->mark_stack_len = 0; GetProcPtr(blockval, proc); @@ -318,7 +314,7 @@ caller_setup_args(rb_thread_t *th, rb_control_frame_t *cfp, /* expand top of stack? */ if (flag & VM_CALL_ARGS_SPLAT_BIT) { VALUE ary = *(cfp->sp - 1); - VALUE *ptr, *dst; + VALUE *ptr; int i; VALUE tmp = rb_check_convert_type(ary, T_ARRAY, "Array", "to_splat"); @@ -351,8 +347,8 @@ vm_call_cfunc(rb_thread_t *th, rb_control_frame_t *reg_cfp, int num, EXEC_EVENT_HOOK(th, RUBY_EVENT_C_CALL, recv, id, klass); { rb_control_frame_t *cfp = - push_frame(th, 0, FRAME_MAGIC_CFUNC, - recv, (VALUE) blockptr, 0, reg_cfp->sp, 0, 1); + vm_push_frame(th, 0, FRAME_MAGIC_CFUNC, + recv, (VALUE) blockptr, 0, reg_cfp->sp, 0, 1); cfp->method_id = id; cfp->method_klass = klass; @@ -364,7 +360,7 @@ vm_call_cfunc(rb_thread_t *th, rb_control_frame_t *reg_cfp, int num, if (reg_cfp != th->cfp + 1) { rb_bug("cfp consistency error - send"); } - pop_frame(th); + vm_pop_frame(th); } EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, recv, id, klass); @@ -384,7 +380,7 @@ vm_call_bmethod(rb_thread_t *th, ID id, VALUE procval, VALUE recv, (cfp-2)->method_klass = klass; GetProcPtr(procval, proc); - val = th_invoke_proc(th, proc, recv, argc, argv); + val = vm_invoke_proc(th, proc, recv, argc, argv); return val; } @@ -416,14 +412,14 @@ vm_setup_method(rb_thread_t *th, rb_control_frame_t *cfp, /* TODO: eliminate it */ GetISeqPtr(iseqval, iseq); - opt_pc = callee_setup_arg(th, iseq, argc, rsp, &blockptr); + opt_pc = vm_callee_setup_arg(th, iseq, argc, rsp, &blockptr); sp = rsp + iseq->arg_size; /* stack overflow check */ CHECK_STACK_OVERFLOW(cfp, iseq->stack_max + 0x10); if (flag & VM_CALL_TAILCALL_BIT) { - VALUE *p_rsp, *p_sp; + VALUE *p_rsp; cfp = ++th->cfp; /* pop cf */ p_rsp = th->cfp->sp; @@ -439,9 +435,9 @@ vm_setup_method(rb_thread_t *th, rb_control_frame_t *cfp, *sp++ = Qnil; } - push_frame(th, iseq, - FRAME_MAGIC_METHOD, recv, (VALUE) blockptr, - iseq->iseq_encoded + opt_pc, sp, 0, 0); + vm_push_frame(th, iseq, + FRAME_MAGIC_METHOD, recv, (VALUE) blockptr, + iseq->iseq_encoded + opt_pc, sp, 0, 0); } else { if (0) printf("local_size: %d, arg_size: %d\n", @@ -452,9 +448,9 @@ vm_setup_method(rb_thread_t *th, rb_control_frame_t *cfp, *sp++ = Qnil; } - push_frame(th, iseq, - FRAME_MAGIC_METHOD, recv, (VALUE) blockptr, - iseq->iseq_encoded + opt_pc, sp, 0, 0); + vm_push_frame(th, iseq, + FRAME_MAGIC_METHOD, recv, (VALUE) blockptr, + iseq->iseq_encoded + opt_pc, sp, 0, 0); cfp->sp = rsp - 1 /* recv */; } @@ -623,7 +619,7 @@ env_alloc(void) static int check_env(rb_env_t *env); static VALUE -th_make_env_each(rb_thread_t *th, rb_control_frame_t *cfp, +vm_make_env_each(rb_thread_t *th, rb_control_frame_t *cfp, VALUE *envptr, VALUE *endptr) { VALUE envval, penvval = 0; @@ -651,7 +647,7 @@ th_make_env_each(rb_thread_t *th, rb_control_frame_t *cfp, exit(0); } } - penvval = th_make_env_each(th, pcfp, penvptr, endptr); + penvval = vm_make_env_each(th, pcfp, penvptr, endptr); cfp->lfp = pcfp->lfp; *envptr = GC_GUARDED_PTR(pcfp->dfp); } @@ -771,7 +767,7 @@ collect_local_variables_in_env(rb_env_t *env, VALUE ary) } int -th_collect_local_variables_in_heap(rb_thread_t *th, VALUE *dfp, VALUE ary) +vm_collect_local_variables_in_heap(rb_thread_t *th, VALUE *dfp, VALUE ary) { if (ENV_IN_HEAP_P(dfp)) { rb_env_t *env; @@ -785,11 +781,11 @@ th_collect_local_variables_in_heap(rb_thread_t *th, VALUE *dfp, VALUE ary) } VALUE -th_make_env_object(rb_thread_t *th, rb_control_frame_t *cfp) +vm_make_env_object(rb_thread_t *th, rb_control_frame_t *cfp) { VALUE envval; // SDR2(cfp); - envval = th_make_env_each(th, cfp, cfp->dfp, cfp->lfp); + envval = vm_make_env_each(th, cfp, cfp->dfp, cfp->lfp); if (PROCDEBUG) { check_env_value(envval); } @@ -797,17 +793,17 @@ th_make_env_object(rb_thread_t *th, rb_control_frame_t *cfp) } void -th_stack_to_heap(rb_thread_t *th) +vm_stack_to_heap(rb_thread_t *th) { rb_control_frame_t *cfp = th->cfp; - while ((cfp = th_get_ruby_level_cfp(th, cfp)) != 0) { - th_make_env_object(th, cfp); + while ((cfp = vm_get_ruby_level_cfp(th, cfp)) != 0) { + vm_make_env_object(th, cfp); cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp); } } static VALUE -th_make_proc_from_block(rb_thread_t *th, rb_control_frame_t *cfp, +vm_make_proc_from_block(rb_thread_t *th, rb_control_frame_t *cfp, rb_block_t *block) { VALUE procval; @@ -820,12 +816,12 @@ th_make_proc_from_block(rb_thread_t *th, rb_control_frame_t *cfp, bcfp = RUBY_VM_GET_CFP_FROM_BLOCK_PTR(block); bdfp = bcfp->dfp; - block->proc = procval = th_make_proc(th, bcfp, block); + block->proc = procval = vm_make_proc(th, bcfp, block); return procval; } VALUE -th_make_proc(rb_thread_t *th, +vm_make_proc(rb_thread_t *th, rb_control_frame_t *cfp, rb_block_t *block) { VALUE procval, envval, blockprocval = 0; @@ -835,14 +831,14 @@ th_make_proc(rb_thread_t *th, if (!RUBY_VM_CLASS_SPECIAL_P(cfp->lfp[0])) { rb_proc_t *p; - blockprocval = th_make_proc_from_block( + blockprocval = vm_make_proc_from_block( th, cfp, (rb_block_t *)GC_GUARDED_PTR_REF(*cfp->lfp)); GetProcPtr(blockprocval, p); *cfp->lfp = GC_GUARDED_PTR(&p->block); } } - envval = th_make_env_object(th, cfp); + envval = vm_make_env_object(th, cfp); if (PROCDEBUG) { check_env_value(envval); @@ -872,7 +868,7 @@ th_make_proc(rb_thread_t *th, } VALUE -th_call0(rb_thread_t *th, VALUE klass, VALUE recv, +vm_call0(rb_thread_t *th, VALUE klass, VALUE recv, VALUE id, ID oid, int argc, const VALUE *argv, NODE * body, int nosuper) { @@ -892,9 +888,8 @@ th_call0(rb_thread_t *th, VALUE klass, VALUE recv, case RUBY_VM_METHOD_NODE:{ rb_control_frame_t *reg_cfp; int i; - const int flag = 0; - th_set_finish_env(th); + vm_set_finish_env(th); reg_cfp = th->cfp; CHECK_STACK_OVERFLOW(reg_cfp, argc); @@ -904,7 +899,7 @@ th_call0(rb_thread_t *th, VALUE klass, VALUE recv, } vm_setup_method(th, reg_cfp, argc, blockptr, 0, (VALUE)body->nd_body, recv, klass); - val = th_eval_body(th); + val = vm_eval_body(th); break; } case NODE_CFUNC: { @@ -912,8 +907,8 @@ th_call0(rb_thread_t *th, VALUE klass, VALUE recv, { rb_control_frame_t *reg_cfp = th->cfp; rb_control_frame_t *cfp = - push_frame(th, 0, FRAME_MAGIC_CFUNC, - recv, (VALUE)blockptr, 0, reg_cfp->sp, 0, 1); + vm_push_frame(th, 0, FRAME_MAGIC_CFUNC, + recv, (VALUE)blockptr, 0, reg_cfp->sp, 0, 1); cfp->method_id = id; cfp->method_klass = klass; @@ -926,7 +921,7 @@ th_call0(rb_thread_t *th, VALUE klass, VALUE recv, rb_bug("cfp consistency error - call0"); th->cfp = reg_cfp; } - pop_frame(th); + vm_pop_frame(th); } EXEC_EVENT_HOOK(th, RUBY_EVENT_C_RETURN, recv, id, klass); break; @@ -953,7 +948,7 @@ th_call0(rb_thread_t *th, VALUE klass, VALUE recv, break; } default: - rb_bug("unsupported: th_call0"); + rb_bug("unsupported: vm_call0"); } RUBY_VM_CHECK_INTS(); return val; @@ -979,7 +974,7 @@ search_super_klass(VALUE klass, VALUE recv) } static VALUE -th_call_super(rb_thread_t *th, int argc, const VALUE *argv) +vm_call_super(rb_thread_t *th, int argc, const VALUE *argv) { VALUE recv = th->cfp->self; VALUE klass; @@ -999,7 +994,7 @@ th_call_super(rb_thread_t *th, int argc, const VALUE *argv) id = cfp->method_id; } else { - rb_bug("th_call_super: should not be reached"); + rb_bug("vm_call_super: should not be reached"); } body = rb_method_node(klass, id); /* this returns NODE_METHOD */ @@ -1011,20 +1006,20 @@ th_call_super(rb_thread_t *th, int argc, const VALUE *argv) dp(recv); dp(klass); dpi(id); - rb_bug("th_call_super: not found"); + rb_bug("vm_call_super: not found"); } - return th_call0(th, klass, recv, id, id, argc, argv, body, nosuper); + return vm_call0(th, klass, recv, id, id, argc, argv, body, nosuper); } VALUE rb_call_super(int argc, const VALUE *argv) { - return th_call_super(GET_THREAD(), argc, argv); + return vm_call_super(GET_THREAD(), argc, argv); } static inline VALUE -th_yield_with_cfunc(rb_thread_t *th, rb_block_t *block, +vm_yield_with_cfunc(rb_thread_t *th, rb_block_t *block, VALUE self, int argc, VALUE *argv) { NODE *ifunc = (NODE *) block->iseq; @@ -1041,9 +1036,9 @@ th_yield_with_cfunc(rb_thread_t *th, rb_block_t *block, arg = rb_ary_new(); } - push_frame(th, 0, FRAME_MAGIC_IFUNC, - self, (VALUE)block->dfp, - 0, th->cfp->sp, block->lfp, 1); + vm_push_frame(th, 0, FRAME_MAGIC_IFUNC, + self, (VALUE)block->dfp, + 0, th->cfp->sp, block->lfp, 1); val = (*ifunc->nd_cfnc) (arg, ifunc->nd_tval, Qnil); @@ -1052,7 +1047,7 @@ th_yield_with_cfunc(rb_thread_t *th, rb_block_t *block, } static inline int -th_yield_setup_args(rb_thread_t *th, rb_iseq_t *iseq, +vm_yield_setup_args(rb_thread_t *th, rb_iseq_t *iseq, int argc, VALUE *argv, int lambda) { int i, arg_n = iseq->argc + (iseq->arg_rest == -1 ? 0 : 1); @@ -1149,7 +1144,7 @@ invoke_block(rb_thread_t *th, rb_block_t *block, VALUE self, int argc, VALUE *ar int magic = block_proc_is_lambda(block->proc) ? FRAME_MAGIC_LAMBDA : FRAME_MAGIC_BLOCK; - th_set_finish_env(th); + vm_set_finish_env(th); CHECK_STACK_OVERFLOW(th->cfp, argc); CHECK_STACK_OVERFLOW(th->cfp, iseq->stack_max); @@ -1158,14 +1153,14 @@ invoke_block(rb_thread_t *th, rb_block_t *block, VALUE self, int argc, VALUE *ar th->cfp->sp[i] = argv[i]; } - argc = th_yield_setup_args(th, iseq, argc, th->cfp->sp, magic == FRAME_MAGIC_LAMBDA); + argc = vm_yield_setup_args(th, iseq, argc, th->cfp->sp, magic == FRAME_MAGIC_LAMBDA); th->cfp->sp += argc; - push_frame(th, iseq, magic, - self, GC_GUARDED_PTR(block->dfp), - iseq->iseq_encoded, th->cfp->sp, block->lfp, - iseq->local_size - argc); - val = th_eval_body(th); + vm_push_frame(th, iseq, magic, + self, GC_GUARDED_PTR(block->dfp), + iseq->iseq_encoded, th->cfp->sp, block->lfp, + iseq->local_size - argc); + val = vm_eval_body(th); } else { if (((NODE*)block->iseq)->u3.state == 1) { @@ -1173,25 +1168,25 @@ invoke_block(rb_thread_t *th, rb_block_t *block, VALUE self, int argc, VALUE *ar argc = 1; argv = &args; } - val = th_yield_with_cfunc(th, block, block->self, argc, argv); + val = vm_yield_with_cfunc(th, block, block->self, argc, argv); } return val; } VALUE -th_yield(rb_thread_t *th, int argc, VALUE *argv) +vm_yield(rb_thread_t *th, int argc, VALUE *argv) { rb_block_t *block = GC_GUARDED_PTR_REF(th->cfp->lfp[0]); if (block == 0) { - th_localjump_error("no block given", Qnil, 0); + vm_localjump_error("no block given", Qnil, 0); } return invoke_block(th, block, block->self, argc, argv); } VALUE -th_invoke_proc(rb_thread_t *th, rb_proc_t *proc, +vm_invoke_proc(rb_thread_t *th, rb_proc_t *proc, VALUE self, int argc, VALUE *argv) { VALUE val = Qundef; @@ -1284,7 +1279,7 @@ lfp_svar(VALUE *lfp, int cnt) VALUE * -th_cfp_svar(rb_control_frame_t *cfp, int cnt) +vm_cfp_svar(rb_control_frame_t *cfp, int cnt) { while (cfp->pc == 0) { cfp++; @@ -1293,16 +1288,16 @@ th_cfp_svar(rb_control_frame_t *cfp, int cnt) } static VALUE * -th_svar(rb_thread_t *th, int cnt) +vm_svar(rb_thread_t *th, int cnt) { rb_control_frame_t *cfp = th->cfp; - return th_cfp_svar(cfp, cnt); + return vm_cfp_svar(cfp, cnt); } VALUE * rb_svar(int cnt) { - return th_svar(GET_THREAD(), cnt); + return vm_svar(GET_THREAD(), cnt); } VALUE @@ -1340,7 +1335,7 @@ rb_lastline_set(VALUE val) } int -th_get_sourceline(rb_control_frame_t *cfp) +vm_get_sourceline(rb_control_frame_t *cfp) { int line_no = 0; rb_iseq_t *iseq = cfp->iseq; @@ -1362,7 +1357,7 @@ th_get_sourceline(rb_control_frame_t *cfp) } static VALUE -th_backtrace_each(rb_thread_t *th, +vm_backtrace_each(rb_thread_t *th, rb_control_frame_t *limit_cfp, rb_control_frame_t *cfp, char *file, int line_no, VALUE ary) @@ -1375,7 +1370,7 @@ th_backtrace_each(rb_thread_t *th, if (cfp->pc != 0) { rb_iseq_t *iseq = cfp->iseq; - line_no = th_get_sourceline(cfp); + line_no = vm_get_sourceline(cfp); file = RSTRING_PTR(iseq->filename); str = rb_sprintf("%s:%d:in `%s'", file, line_no, RSTRING_PTR(iseq->name)); @@ -1394,7 +1389,7 @@ th_backtrace_each(rb_thread_t *th, } VALUE -th_backtrace(rb_thread_t *th, int lev) +vm_backtrace(rb_thread_t *th, int lev) { VALUE ary; rb_control_frame_t *cfp = th->cfp; @@ -1415,7 +1410,7 @@ th_backtrace(rb_thread_t *th, int lev) ary = rb_ary_new(); } - ary = th_backtrace_each(th, RUBY_VM_NEXT_CONTROL_FRAME(cfp), + ary = vm_backtrace_each(th, RUBY_VM_NEXT_CONTROL_FRAME(cfp), top_of_cfp, "", 0, ary); return ary; } @@ -1425,7 +1420,7 @@ thread_backtrace(VALUE self, int level) { rb_thread_t *th; GetThreadPtr(self, th); - return th_backtrace(th, level); + return vm_backtrace(th, level); } /* @@ -1484,7 +1479,7 @@ lfp_set_special_cref(VALUE *lfp, NODE * cref) } NODE * -th_set_special_cref(rb_thread_t *th, VALUE *lfp, NODE * cref_stack) +vm_set_special_cref(rb_thread_t *th, VALUE *lfp, NODE * cref_stack) { return lfp_set_special_cref(lfp, cref_stack); } @@ -1516,16 +1511,16 @@ get_cref(rb_iseq_t *iseq, VALUE *lfp) } NODE * -th_get_cref(rb_thread_t *th, rb_iseq_t *iseq, rb_control_frame_t *cfp) +vm_get_cref(rb_thread_t *th, rb_iseq_t *iseq, rb_control_frame_t *cfp) { return get_cref(iseq, cfp->lfp); } NODE * -th_cref_push(rb_thread_t *th, VALUE klass, int noex) +vm_cref_push(rb_thread_t *th, VALUE klass, int noex) { NODE *cref = NEW_BLOCK(klass); - rb_control_frame_t *cfp = th_get_ruby_level_cfp(th, th->cfp); + rb_control_frame_t *cfp = vm_get_ruby_level_cfp(th, th->cfp); cref->nd_file = 0; cref->nd_next = get_cref(cfp->iseq, cfp->lfp); @@ -1534,9 +1529,9 @@ th_cref_push(rb_thread_t *th, VALUE klass, int noex) } VALUE -th_get_cbase(rb_thread_t *th) +vm_get_cbase(rb_thread_t *th) { - rb_control_frame_t *cfp = th_get_ruby_level_cfp(th, th->cfp); + rb_control_frame_t *cfp = vm_get_ruby_level_cfp(th, th->cfp); NODE *cref = get_cref(cfp->iseq, cfp->lfp); VALUE klass = Qundef; @@ -1549,9 +1544,9 @@ th_get_cbase(rb_thread_t *th) return klass; } -EVALBODY_HELPER_FUNCTION VALUE -eval_get_ev_const(rb_thread_t *th, rb_iseq_t *iseq, - VALUE klass, ID id, int is_defined) +static inline VALUE +vm_get_ev_const(rb_thread_t *th, rb_iseq_t *iseq, + VALUE klass, ID id, int is_defined) { VALUE val; @@ -1620,8 +1615,8 @@ eval_get_ev_const(rb_thread_t *th, rb_iseq_t *iseq, } } -EVALBODY_HELPER_FUNCTION VALUE -eval_get_cvar_base(rb_thread_t *th, rb_iseq_t *iseq) +static inline VALUE +vm_get_cvar_base(rb_thread_t *th, rb_iseq_t *iseq) { NODE *cref = get_cref(iseq, th->cfp->lfp); VALUE klass = Qnil; @@ -1638,8 +1633,8 @@ eval_get_cvar_base(rb_thread_t *th, rb_iseq_t *iseq) return klass; } -EVALBODY_HELPER_FUNCTION void -eval_define_method(rb_thread_t *th, VALUE obj, +static inline void +vm_define_method(rb_thread_t *th, VALUE obj, ID id, rb_iseq_t *miseq, rb_num_t is_singleton, NODE *cref) { NODE *newbody; @@ -1674,8 +1669,8 @@ eval_define_method(rb_thread_t *th, VALUE obj, INC_VM_STATE_VERSION(); } -EVALBODY_HELPER_FUNCTION NODE * -eval_method_search(VALUE id, VALUE klass, IC ic) +static inline NODE * +vm_method_search(VALUE id, VALUE klass, IC ic) { NODE *mn; @@ -1698,12 +1693,6 @@ eval_method_search(VALUE id, VALUE klass, IC ic) return mn; } -static void -call_yarv_end_proc(VALUE data) -{ - rb_proc_call(data, rb_ary_new2(0)); -} - static inline int block_proc_is_lambda(VALUE procval) { @@ -1718,6 +1707,12 @@ block_proc_is_lambda(VALUE procval) } } +static void +call_yarv_end_proc(VALUE data) +{ + rb_proc_call(data, rb_ary_new2(0)); +} + /*********************************************************/ /*********************************************************/ @@ -1756,14 +1751,14 @@ make_localjump_error(const char *mesg, VALUE value, int reason) } void -th_localjump_error(const char *mesg, VALUE value, int reason) +vm_localjump_error(const char *mesg, VALUE value, int reason) { VALUE exc = make_localjump_error(mesg, value, reason); rb_exc_raise(exc); } VALUE -th_make_jump_tag_but_local_jump(int state, VALUE val) +vm_make_jump_tag_but_local_jump(int state, VALUE val) { VALUE result = Qnil; @@ -1794,9 +1789,9 @@ th_make_jump_tag_but_local_jump(int state, VALUE val) } void -th_jump_tag_but_local_jump(int state, VALUE val) +vm_jump_tag_but_local_jump(int state, VALUE val) { - VALUE exc = th_make_jump_tag_but_local_jump(state, val); + VALUE exc = vm_make_jump_tag_but_local_jump(state, val); if (val != Qnil) { rb_exc_raise(exc); } @@ -1804,7 +1799,7 @@ th_jump_tag_but_local_jump(int state, VALUE val) } void -th_iter_break(rb_thread_t *th) +vm_iter_break(rb_thread_t *th) { rb_control_frame_t *cfp = th->cfp; VALUE *dfp = GC_GUARDED_PTR_REF(*cfp->dfp); @@ -1987,7 +1982,7 @@ yarv_init_redefined_flag(void) VALUE -th_eval_body(rb_thread_t *th) +vm_eval_body(rb_thread_t *th) { int state; VALUE result, err; @@ -1996,7 +1991,7 @@ th_eval_body(rb_thread_t *th) TH_PUSH_TAG(th); if ((state = EXEC_TAG()) == 0) { vm_loop_start: - result = th_eval(th, initial); + result = vm_eval(th, initial); if ((state = th->state) != 0) { err = result; th->state = 0; @@ -2165,9 +2160,9 @@ th_eval_body(rb_thread_t *th) /* push block frame */ cfp->sp[0] = err; - push_frame(th, catch_iseq, FRAME_MAGIC_BLOCK, - cfp->self, (VALUE)cfp->dfp, catch_iseq->iseq_encoded, - cfp->sp + 1, cfp->lfp, catch_iseq->local_size - 1); + vm_push_frame(th, catch_iseq, FRAME_MAGIC_BLOCK, + cfp->self, (VALUE)cfp->dfp, catch_iseq->iseq_encoded, + cfp->sp + 1, cfp->lfp, catch_iseq->local_size - 1); state = 0; th->errinfo = Qnil; @@ -2179,7 +2174,7 @@ th_eval_body(rb_thread_t *th) goto exception_handler; } else { - pop_frame(th); + vm_pop_frame(th); th->errinfo = err; TH_POP_TAG2(); JUMP_TAG(state); @@ -2197,12 +2192,12 @@ rb_thread_eval(rb_thread_t *th, VALUE iseqval) VALUE val; volatile VALUE tmp; - th_set_top_stack(th, iseqval); + vm_set_top_stack(th, iseqval); if (!rb_const_defined(rb_cObject, rb_intern("TOPLEVEL_BINDING"))) { rb_define_global_const("TOPLEVEL_BINDING", rb_binding_new()); } - val = th_eval_body(th); + val = vm_eval_body(th); tmp = iseqval; /* prohibit tail call optimization */ return val; } @@ -2238,7 +2233,7 @@ rb_thread_current_status(rb_thread_t *th) if (cfp->iseq != 0) { if (cfp->pc != 0) { rb_iseq_t *iseq = cfp->iseq; - int line_no = th_get_sourceline(cfp); + int line_no = vm_get_sourceline(cfp); char *file = RSTRING_PTR(iseq->filename); str = rb_sprintf("%s:%d:in `%s'", file, line_no, RSTRING_PTR(iseq->name)); @@ -2261,9 +2256,9 @@ rb_vm_call_cfunc(VALUE recv, VALUE (*func)(VALUE), VALUE arg, rb_block_t *blockp volatile VALUE iseq = rb_iseq_new(0, filename, filename, 0, ISEQ_TYPE_TOP); VALUE val; - push_frame(th, DATA_PTR(iseq), FRAME_MAGIC_TOP, - recv, (VALUE)blockptr, 0, reg_cfp->sp, 0, 1); + vm_push_frame(th, DATA_PTR(iseq), FRAME_MAGIC_TOP, + recv, (VALUE)blockptr, 0, reg_cfp->sp, 0, 1); val = (*func)(arg); - pop_frame(th); + vm_pop_frame(th); return val; } diff --git a/vm_dump.c b/vm_dump.c index cd924f3c66..5030466b45 100644 --- a/vm_dump.c +++ b/vm_dump.c @@ -100,7 +100,7 @@ control_frame_dump(rb_thread_t *th, rb_control_frame_t *cfp) else { pc = cfp->pc - cfp->iseq->iseq_encoded; iseq_name = RSTRING_PTR(cfp->iseq->name); - line = th_get_sourceline(cfp); + line = vm_get_sourceline(cfp); if (line) { char fn[MAX_POSBUF+1]; snprintf(fn, MAX_POSBUF, "%s", RSTRING_PTR(cfp->iseq->filename)); @@ -141,12 +141,12 @@ control_frame_dump(rb_thread_t *th, rb_control_frame_t *cfp) void vm_stack_dump_raw(rb_thread_t *th, rb_control_frame_t *cfp) { +#if 0 VALUE *sp = cfp->sp, *bp = cfp->bp; VALUE *lfp = cfp->lfp; VALUE *dfp = cfp->dfp; VALUE *p, *st, *t; -#if 0 fprintf(stderr, "-- stack frame ------------\n"); for (p = st = th->stack; p < sp; p++) { fprintf(stderr, "%04ld (%p): %08lx", p - st, p, *p); @@ -166,6 +166,7 @@ vm_stack_dump_raw(rb_thread_t *th, rb_control_frame_t *cfp) fprintf(stderr, "\n"); } #endif + fprintf(stderr, "-- control frame ----------\n"); while ((void *)cfp < (void *)(th->stack + th->stack_size)) { control_frame_dump(th, cfp); @@ -587,7 +588,7 @@ yarv_bug(void) int i; SDR(); - bt = th_backtrace(th, 0); + bt = vm_backtrace(th, 0); if (TYPE(bt) == T_ARRAY) for (i = 0; i < RARRAY_LEN(bt); i++) { dp(RARRAY_PTR(bt)[i]); diff --git a/vm_evalbody.ci b/vm_evalbody.ci index d0c45b3a5b..a7c0f83262 100644 --- a/vm_evalbody.ci +++ b/vm_evalbody.ci @@ -30,7 +30,7 @@ typedef rb_iseq_t *ISEQ; #if !OPT_CALL_THREADED_CODE VALUE -th_eval(rb_thread_t *th, VALUE initial) +vm_eval(rb_thread_t *th, VALUE initial) { #if OPT_STACK_CACHING @@ -97,13 +97,13 @@ th_eval(rb_thread_t *th, VALUE initial) first: INSN_DISPATCH(); - /******************/ -#include "vm.inc" - /******************/ +/*****************/ + #include "vm.inc" +/*****************/ END_INSNS_DISPATCH(); /* unreachable */ - rb_bug("th_eval_iseq: unreachable"); + rb_bug("vm_eval: unreachable"); return Qundef; } @@ -119,7 +119,7 @@ get_insns_address_table() } VALUE -th_eval(rb_thread_t *th, VALUE initial) +vm_eval(rb_thread_t *th, VALUE initial) { register rb_control_frame_t *reg_cfp = th->cfp; SET_PC(reg_cfp->iseq->iseq_encoded); diff --git a/yarvcore.c b/yarvcore.c index 0fe43a7743..e297f69f5d 100644 --- a/yarvcore.c +++ b/yarvcore.c @@ -75,7 +75,6 @@ ID id__send_bang; rb_thread_t *ruby_current_thread = 0; rb_vm_t *ruby_current_vm = 0; -static VALUE ruby_vm_list = Qnil; RUBY_EXTERN int ruby_nerrs; @@ -99,7 +98,7 @@ yarvcore_eval_iseq(VALUE iseq) } static VALUE -th_compile_from_node(rb_thread_t *th, NODE * node, VALUE file) +vm_compile_from_node(rb_thread_t *th, NODE * node, VALUE file) { VALUE iseq; if (th->base_block) { @@ -117,16 +116,16 @@ th_compile_from_node(rb_thread_t *th, NODE * node, VALUE file) } VALUE -th_compile(rb_thread_t *th, VALUE str, VALUE file, VALUE line) +vm_compile(rb_thread_t *th, VALUE str, VALUE file, VALUE line) { NODE *node = (NODE *) compile_string(str, file, line); - return th_compile_from_node(th, (NODE *) node, file); + return vm_compile_from_node(th, (NODE *) node, file); } VALUE yarvcore_eval_parsed(NODE *node, VALUE file) { - VALUE iseq = th_compile_from_node(GET_THREAD(), node, file); + VALUE iseq = vm_compile_from_node(GET_THREAD(), node, file); return yarvcore_eval_iseq(iseq); } diff --git a/yarvcore.h b/yarvcore.h index c33163a570..054056c4fb 100644 --- a/yarvcore.h +++ b/yarvcore.h @@ -653,19 +653,19 @@ void rb_enable_interrupt(void); void rb_disable_interrupt(void); int rb_thread_method_id_and_klass(rb_thread_t *th, ID *idp, VALUE *klassp); -VALUE th_eval_body(rb_thread_t *th); -VALUE th_set_eval_stack(rb_thread_t *, VALUE iseq); -VALUE th_invoke_proc(rb_thread_t *th, rb_proc_t *proc, VALUE self, int argc, VALUE *argv); -VALUE th_make_proc(rb_thread_t *th, rb_control_frame_t *cfp, rb_block_t *block); -VALUE th_make_env_object(rb_thread_t *th, rb_control_frame_t *cfp); -VALUE th_backtrace(rb_thread_t *, int); +VALUE vm_eval_body(rb_thread_t *th); +VALUE vm_set_eval_stack(rb_thread_t *, VALUE iseq); +VALUE vm_invoke_proc(rb_thread_t *th, rb_proc_t *proc, VALUE self, int argc, VALUE *argv); +VALUE vm_make_proc(rb_thread_t *th, rb_control_frame_t *cfp, rb_block_t *block); +VALUE vm_make_env_object(rb_thread_t *th, rb_control_frame_t *cfp); +VALUE vm_backtrace(rb_thread_t *, int); -VALUE th_yield(rb_thread_t *th, int argc, VALUE *argv); -VALUE th_call0(rb_thread_t *th, VALUE klass, VALUE recv, +VALUE vm_yield(rb_thread_t *th, int argc, VALUE *argv); +VALUE vm_call0(rb_thread_t *th, VALUE klass, VALUE recv, VALUE id, ID oid, int argc, const VALUE *argv, NODE * body, int nosuper); -int th_get_sourceline(rb_control_frame_t *); +int vm_get_sourceline(rb_control_frame_t *); VALUE yarvcore_eval_parsed(NODE *node, VALUE file); VALUE yarvcore_eval(VALUE self, VALUE str, VALUE file, VALUE line);