ruby-changes:23979
From: ko1 <ko1@a...>
Date: Mon, 11 Jun 2012 12:15:12 +0900 (JST)
Subject: [ruby-changes:23979] ko1:r36030 (trunk): * vm_core.h: remove lfp (local frame pointer) and rename
ko1 2012-06-11 12:14:59 +0900 (Mon, 11 Jun 2012) New Revision: 36030 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36030 Log: * vm_core.h: remove lfp (local frame pointer) and rename dfp (dynamic frame pointer) to ep (environment pointer). This change make VM `normal' (similar to other interpreters). Before this commit: Each frame has two env pointers lfp and dfp. lfp points local environment which is method/class/toplevel frame. lfp[0] is block pointer. dfp is block local frame. dfp[0] points previous (parent) environment pointer. lfp == dfp when frame is method/class/toplevel. You can get lfp from dfp by traversing previous environment pointers. After this commit: Each frame has only `ep' to point respective enviornoment. If there is parent environment, then ep[0] points parent envioenment (as dfp). If there are no more environment, then ep[0] points block pointer (as lfp). We call such ep as `LEP' (local EP). We add some macros to get LEP and to detect LEP or not. In short, we replace dfp and lfp with ep and LEP. rb_block_t and rb_binding_t member `lfp' and `dfp' are removed and member `ep' is added. rename rb_thread_t's member `local_lfp' and `local_svar' to `root_lep' and `root_svar'. (VM_EP_PREV_EP(ep)): get previous environment pointer. This macro assume that ep is not LEP. (VM_EP_BLOCK_PTR(ep)): get block pointer. This macro assume that ep is LEP. (VM_EP_LEP_P(ep)): detect ep is LEP or not. (VM_ENVVAL_BLOCK_PTR(ptr)): make block pointer. (VM_ENVVAL_BLOCK_PTR_P(v)): detect v is block pointer. (VM_ENVVAL_PREV_EP_PTR(ptr)): make prev environment pointer. (VM_ENVVAL_PREV_EP_PTR_P(v)): detect v is prev env pointer. * vm.c: apply above changes. (VM_EP_LEP(ep)): get LEP. (VM_CF_LEP(cfp)): get LEP of cfp->ep. (VM_CF_PREV_EP(cfp)): utility function VM_EP_PREV_EP(cfp->ep). (VM_CF_BLOCK_PTR(cfp)): utility function VM_EP_BLOCK_PTR(cfp->ep). * vm.c, vm_eval.c, vm_insnhelper.c, vm_insnhelper.h, insns.def: apply above changes. * cont.c: ditto. * eval.c, eval_intern.h: ditto. * proc.c: ditto. * thread.c: ditto. * vm_dump.c: ditto. * vm_exec.h: fix function name (on vm debug mode). Modified files: trunk/ChangeLog trunk/cont.c trunk/eval.c trunk/eval_intern.h trunk/insns.def trunk/proc.c trunk/thread.c trunk/vm.c trunk/vm_core.h trunk/vm_dump.c trunk/vm_eval.c trunk/vm_exec.h trunk/vm_insnhelper.c trunk/vm_insnhelper.h Index: eval_intern.h =================================================================== --- eval_intern.h (revision 36029) +++ eval_intern.h (revision 36030) @@ -5,7 +5,7 @@ #include "vm_core.h" #define PASS_PASSED_BLOCK_TH(th) do { \ - (th)->passed_block = GC_GUARDED_PTR_REF((rb_block_t *)(th)->cfp->lfp[0]); \ + (th)->passed_block = rb_vm_control_frame_block_ptr(th->cfp); \ (th)->cfp->flag |= VM_FRAME_FLAG_PASSED; \ } while (0) Index: ChangeLog =================================================================== --- ChangeLog (revision 36029) +++ ChangeLog (revision 36030) @@ -1,3 +1,60 @@ +Mon Jun 11 12:14:37 2012 Koichi Sasada <ko1@a...> + + * vm_core.h: remove lfp (local frame pointer) and rename + dfp (dynamic frame pointer) to ep (environment pointer). + This change make VM `normal' (similar to other interpreters). + Before this commit: + Each frame has two env pointers lfp and dfp. lfp points + local environment which is method/class/toplevel frame. + lfp[0] is block pointer. + dfp is block local frame. dfp[0] points previous (parent) + environment pointer. + lfp == dfp when frame is method/class/toplevel. + You can get lfp from dfp by traversing previous environment + pointers. + After this commit: + Each frame has only `ep' to point respective enviornoment. + If there is parent environment, then ep[0] points parent + envioenment (as dfp). If there are no more environment, + then ep[0] points block pointer (as lfp). We call such ep + as `LEP' (local EP). We add some macros to get LEP and to + detect LEP or not. + In short, we replace dfp and lfp with ep and LEP. + rb_block_t and rb_binding_t member `lfp' and `dfp' are removed + and member `ep' is added. + rename rb_thread_t's member `local_lfp' and `local_svar' to + `root_lep' and `root_svar'. + (VM_EP_PREV_EP(ep)): get previous environment pointer. This macro + assume that ep is not LEP. + (VM_EP_BLOCK_PTR(ep)): get block pointer. This macro assume + that ep is LEP. + (VM_EP_LEP_P(ep)): detect ep is LEP or not. + (VM_ENVVAL_BLOCK_PTR(ptr)): make block pointer. + (VM_ENVVAL_BLOCK_PTR_P(v)): detect v is block pointer. + (VM_ENVVAL_PREV_EP_PTR(ptr)): make prev environment pointer. + (VM_ENVVAL_PREV_EP_PTR_P(v)): detect v is prev env pointer. + + * vm.c: apply above changes. + (VM_EP_LEP(ep)): get LEP. + (VM_CF_LEP(cfp)): get LEP of cfp->ep. + (VM_CF_PREV_EP(cfp)): utility function VM_EP_PREV_EP(cfp->ep). + (VM_CF_BLOCK_PTR(cfp)): utility function VM_EP_BLOCK_PTR(cfp->ep). + + * vm.c, vm_eval.c, vm_insnhelper.c, vm_insnhelper.h, insns.def: + apply above changes. + + * cont.c: ditto. + + * eval.c, eval_intern.h: ditto. + + * proc.c: ditto. + + * thread.c: ditto. + + * vm_dump.c: ditto. + + * vm_exec.h: fix function name (on vm debug mode). + Mon Jun 11 11:52:18 2012 URABE Shyouhei <shyouhei@r...> * compile.c (iseq_set_sequence): nonstatic initializer of an Index: insns.def =================================================================== --- insns.def (revision 36029) +++ insns.def (revision 36030) @@ -55,7 +55,7 @@ () (VALUE val) { - val = *(GET_LFP() - idx); + val = *(GET_LEP() - idx); } /** @@ -69,7 +69,7 @@ (VALUE val) () { - (*(GET_LFP() - idx)) = val; + *(GET_LEP() - idx) = val; } /** @@ -83,7 +83,7 @@ () (VALUE val) { - val = vm_getspecial(th, GET_LFP(), key, type); + val = vm_getspecial(th, GET_LEP(), key, type); } /** @@ -97,7 +97,7 @@ (VALUE obj) () { - lfp_svar_set(th, GET_LFP(), key, obj); + lep_svar_set(th, GET_LEP(), key, obj); } /** @@ -114,11 +114,11 @@ (VALUE val) { rb_num_t i; - VALUE *dfp2 = GET_DFP(); + VALUE *ep = GET_EP(); for (i = 0; i < level; i++) { - dfp2 = GET_PREV_DFP(dfp2); + ep = GET_PREV_EP(ep); } - val = *(dfp2 - idx); + val = *(ep - idx); } /** @@ -135,11 +135,11 @@ () { rb_num_t i; - VALUE *dfp2 = GET_DFP(); + VALUE *ep = GET_EP(); for (i = 0; i < level; i++) { - dfp2 = GET_PREV_DFP(dfp2); + ep = GET_PREV_EP(ep); } - *(dfp2 - idx) = val; + *(ep - idx) = val; } /** @@ -183,7 +183,7 @@ () (VALUE val) { - NODE * const cref = vm_get_cref(GET_ISEQ(), GET_LFP(), GET_DFP()); + NODE *cref = vm_get_cref(GET_ISEQ(), GET_EP()); val = rb_cvar_get(vm_get_cvar_base(cref), id); } @@ -198,7 +198,7 @@ (VALUE val) () { - NODE * const cref = vm_get_cref(GET_ISEQ(), GET_LFP(), GET_DFP()); + NODE *cref = vm_get_cref(GET_ISEQ(), GET_EP()); rb_cvar_set(vm_get_cvar_base(cref), id, val); } @@ -343,10 +343,10 @@ val = rb_mRubyVMFrozenCore; break; case VM_SPECIAL_OBJECT_CBASE: - val = vm_get_cbase(GET_ISEQ(), GET_LFP(), GET_DFP()); + val = vm_get_cbase(GET_ISEQ(), GET_EP()); break; case VM_SPECIAL_OBJECT_CONST_BASE: - val = vm_get_const_base(GET_ISEQ(), GET_LFP(), GET_DFP()); + val = vm_get_const_base(GET_ISEQ(), GET_EP()); break; default: rb_bug("putspecialobject insn: unknown value_type"); @@ -768,7 +768,7 @@ } break; case DEFINED_IVAR2: - klass = vm_get_cbase(GET_ISEQ(), GET_LFP(), GET_DFP()); + klass = vm_get_cbase(GET_ISEQ(), GET_EP()); break; case DEFINED_GVAR: if (rb_gvar_defined(rb_global_entry(SYM2ID(obj)))) { @@ -777,7 +777,7 @@ break; case DEFINED_CVAR: { - NODE *cref = vm_get_cref(GET_ISEQ(), GET_LFP(), GET_DFP()); + NODE *cref = vm_get_cref(GET_ISEQ(), GET_EP()); klass = vm_get_cvar_base(cref); if (rb_cvar_defined(klass, SYM2ID(obj))) { expr_type = "class variable"; @@ -842,7 +842,7 @@ break; } case DEFINED_REF:{ - val = vm_getspecial(th, GET_LFP(), Qfalse, FIX2INT(obj)); + val = vm_getspecial(th, GET_LEP(), Qfalse, FIX2INT(obj)); if (val != Qnil) { expr_type = "global-variable"; } @@ -971,9 +971,9 @@ COPY_CREF(class_iseq->cref_stack, vm_cref_push(th, klass, NOEX_PUBLIC, NULL)); /* enter scope */ - vm_push_frame(th, class_iseq, - VM_FRAME_MAGIC_CLASS, klass, (VALUE) GET_BLOCK_PTR(), - class_iseq->iseq_encoded, GET_SP(), 0, + vm_push_frame(th, class_iseq, VM_FRAME_MAGIC_CLASS, + klass, VM_ENVVAL_BLOCK_PTR(GET_BLOCK_PTR()), + class_iseq->iseq_encoded, GET_SP(), class_iseq->local_size); RESTORE_REGS(); @@ -1315,11 +1315,11 @@ () () { - if (GET_CFP()->bp != GET_DFP() + 1) { - VALUE *new_dfp = GET_CFP()->bp - 1; + if (GET_CFP()->bp != GET_EP() + 1) { + VALUE *ep = GET_CFP()->bp - 1; /* TODO: copy env and clean stack at creating env? */ - *new_dfp = *GET_DFP(); - SET_DFP(new_dfp); + *ep = *GET_EP(); + SET_EP(ep); } } Index: vm_core.h =================================================================== --- vm_core.h (revision 36029) +++ vm_core.h (revision 36030) @@ -349,17 +349,15 @@ rb_iseq_t *iseq; /* cfp[3] */ VALUE flag; /* cfp[4] */ VALUE self; /* cfp[5] / block[0] */ - VALUE *lfp; /* cfp[6] / block[1] */ - VALUE *dfp; /* cfp[7] / block[2] */ - rb_iseq_t *block_iseq; /* cfp[8] / block[3] */ - VALUE proc; /* cfp[9] / block[4] */ - const rb_method_entry_t *me;/* cfp[10] */ + VALUE *ep; /* cfp[6] / block[1] */ + rb_iseq_t *block_iseq; /* cfp[7] / block[2] */ + VALUE proc; /* cfp[8] / block[3] */ + const rb_method_entry_t *me;/* cfp[9] */ } rb_control_frame_t; typedef struct rb_block_struct { VALUE self; /* share with method frame if it's only block */ - VALUE *lfp; /* share with method frame if it's only block */ - VALUE *dfp; /* share with method frame if it's only block */ + VALUE *ep; /* share with method frame if it's only block */ rb_iseq_t *iseq; VALUE proc; } rb_block_t; @@ -434,8 +432,8 @@ /* eval env */ rb_block_t *base_block; - VALUE *local_lfp; - VALUE local_svar; + VALUE *root_lep; + VALUE root_svar; /* thread control */ rb_thread_id_t thread_id; @@ -622,8 +620,28 @@ #define GC_GUARDED_PTR_REF(p) ((void *)(((VALUE)(p)) & ~0x03)) #define GC_GUARDED_PTR_P(p) (((VALUE)(p)) & 0x01) -#define RUBY_VM_GET_BLOCK_PTR(cfp) ((rb_block_t *)(GC_GUARDED_PTR_REF((cfp)->lfp[0]))) +/* + * block frame: + * ep[ 0]: prev frame + * ep[-1]: CREF (for *_eval) + * + * method frame: + * ep[ 0]: block pointer (ptr | VM_ENVVAL_BLOCK_PTR_FLAG) + */ +#define VM_ENVVAL_BLOCK_PTR_FLAG 0x02 +#define VM_ENVVAL_BLOCK_PTR(v) (GC_GUARDED_PTR(v) | VM_ENVVAL_BLOCK_PTR_FLAG) +#define VM_ENVVAL_BLOCK_PTR_P(v) ((v) & VM_ENVVAL_BLOCK_PTR_FLAG) +#define VM_ENVVAL_PREV_EP_PTR(v) ((VALUE)GC_GUARDED_PTR(v)) +#define VM_ENVVAL_PREV_EP_PTR_P(v) (!(VM_ENVVAL_BLOCK_PTR_P(v))) + +#define VM_EP_PREV_EP(ep) ((VALUE *)GC_GUARDED_PTR_REF((ep)[0])) +#define VM_EP_BLOCK_PTR(ep) ((rb_block_t *)GC_GUARDED_PTR_REF((ep)[0])) +#define VM_EP_LEP_P(ep) VM_ENVVAL_BLOCK_PTR_P((ep)[0]) + +VALUE *rb_vm_ep_local_ep(VALUE *ep); +rb_block_t *rb_vm_control_frame_block_ptr(rb_control_frame_t *cfp); + #define RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp) ((cfp)+1) #define RUBY_VM_NEXT_CONTROL_FRAME(cfp) ((cfp)-1) #define RUBY_VM_END_CONTROL_FRAME(th) \ @@ -647,6 +665,9 @@ /* for debug */ extern void rb_vmdebug_stack_dump_raw(rb_thread_t *, rb_control_frame_t *); +extern void rb_vmdebug_debug_print_pre(rb_thread_t *th, rb_control_frame_t *cfp); +extern void rb_vmdebug_debug_print_post(rb_thread_t *th, rb_control_frame_t *cfp); + #define SDR() rb_vmdebug_stack_dump_raw(GET_THREAD(), GET_THREAD()->cfp) #define SDR2(cfp) rb_vmdebug_stack_dump_raw(GET_THREAD(), (cfp)) void rb_vm_bugreport(void); @@ -666,7 +687,7 @@ int argc, const VALUE *argv, const rb_block_t *blockptr); VALUE rb_vm_make_proc(rb_thread_t *th, const rb_block_t *block, VALUE klass); VALUE rb_vm_make_env_object(rb_thread_t *th, rb_control_frame_t *cfp); -void rb_vm_rewrite_dfp_in_errinfo(rb_thread_t *th, rb_control_frame_t *cfp); +void rb_vm_rewrite_ep_in_errinfo(rb_thread_t *th, rb_control_frame_t *cfp); void rb_vm_inc_const_missing_count(void); void rb_vm_gvl_destroy(rb_vm_t *vm); VALUE rb_vm_call(rb_thread_t *th, VALUE recv, VALUE id, int argc, Index: vm_eval.c =================================================================== --- vm_eval.c (revision 36029) +++ vm_eval.c (revision 36030) @@ -74,7 +74,7 @@ rb_control_frame_t *reg_cfp = th->cfp; rb_control_frame_t *cfp = vm_push_frame(th, 0, VM_FRAME_MAGIC_CFUNC, - recv, (VALUE)blockptr, 0, reg_cfp->sp, 0, 1); + recv, VM_ENVVAL_BLOCK_PTR(blockptr), 0, reg_cfp->sp, 1); cfp->me = me; val = call_cfunc(def->body.cfunc.func, recv, def->body.cfunc.argc, argc, argv); @@ -896,7 +896,7 @@ blockptr->proc = 0; } else { - blockptr = GC_GUARDED_PTR_REF(th->cfp->lfp[0]); + blockptr = VM_CF_BLOCK_PTR(th->cfp); } th->passed_block = blockptr; } @@ -905,10 +905,10 @@ else { VALUE err = th->errinfo; if (state == TAG_BREAK) { - VALUE *escape_dfp = GET_THROWOBJ_CATCH_POINT(err); - VALUE *cdfp = cfp->dfp; + VALUE *escape_ep = GET_THROWOBJ_CATCH_POINT(err); + VALUE *cep = cfp->ep; - if (cdfp == escape_dfp) { + if (cep == escape_ep) { state = 0; th->state = 0; th->errinfo = Qnil; @@ -932,10 +932,10 @@ } } else if (state == TAG_RETRY) { - VALUE *escape_dfp = GET_THROWOBJ_CATCH_POINT(err); - VALUE *cdfp = cfp->dfp; + VALUE *escape_ep = GET_THROWOBJ_CATCH_POINT(err); + VALUE *cep = cfp->ep; - if (cdfp == escape_dfp) { + if (cep == escape_ep) { state = 0; th->state = 0; th->errinfo = Qnil; @@ -1247,10 +1247,10 @@ rb_block_t block, *blockptr; NODE *cref; - if ((blockptr = GC_GUARDED_PTR_REF(th->cfp->lfp[0])) != 0) { + if ((blockptr = VM_CF_BLOCK_PTR(th->cfp)) != 0) { block = *blockptr; block.self = self; - th->cfp->lfp[0] = GC_GUARDED_PTR(&block); + VM_CF_LEP(th->cfp)[0] = VM_ENVVAL_BLOCK_PTR(&block); } cref = vm_cref_push(th, under, NOEX_PUBLIC, blockptr); cref->flags |= NODE_FL_CREF_PUSHED_BY_EVAL; @@ -1611,15 +1611,15 @@ } } } - if (cfp->lfp != cfp->dfp) { + if (!VM_EP_LEP_P(cfp->ep)) { /* block */ - VALUE *dfp = GC_GUARDED_PTR_REF(cfp->dfp[0]); + VALUE *ep = VM_CF_PREV_EP(cfp); - if (vm_collect_local_variables_in_heap(th, dfp, ary)) { + if (vm_collect_local_variables_in_heap(th, ep, ary)) { break; } else { - while (cfp->dfp != dfp) { + while (cfp->ep != ep) { cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp); } } @@ -1660,7 +1660,7 @@ rb_control_frame_t *cfp = th->cfp; cfp = vm_get_ruby_level_caller_cfp(th, RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp)); - if (cfp != 0 && RUBY_VM_GET_BLOCK_PTR(cfp)) { + if (cfp != 0 && VM_CF_BLOCK_PTR(cfp)) { return Qtrue; } else { Index: proc.c =================================================================== --- proc.c (revision 36029) +++ proc.c (revision 36030) @@ -383,17 +383,13 @@ rb_control_frame_t *cfp = th->cfp; rb_block_t *block; - if ((GC_GUARDED_PTR_REF(cfp->lfp[0])) != 0) { - - block = GC_GUARDED_PTR_REF(cfp->lfp[0]); + if ((block = rb_vm_control_frame_block_ptr(cfp)) != 0) { + /* block found */ } else { cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp); - if ((GC_GUARDED_PTR_REF(cfp->lfp[0])) != 0) { - - block = GC_GUARDED_PTR_REF(cfp->lfp[0]); - + if ((block = rb_vm_control_frame_block_ptr(cfp)) != 0) { if (is_lambda) { rb_warn("tried to create Proc object without a block"); } @@ -418,7 +414,7 @@ } procval = rb_vm_make_proc(th, block, klass); - rb_vm_rewrite_dfp_in_errinfo(th, cfp); + rb_vm_rewrite_ep_in_errinfo(th, cfp); if (is_lambda) { rb_proc_t *proc; @@ -801,7 +797,7 @@ GetProcPtr(prc, proc); hash = rb_hash_uint(hash, (st_index_t)proc->block.iseq); hash = rb_hash_uint(hash, (st_index_t)proc->envval); - return rb_hash_uint(hash, (st_index_t)proc->block.lfp >> 16); + return rb_hash_uint(hash, (st_index_t)proc->block.ep >> 16); } /* Index: thread.c =================================================================== --- thread.c (revision 36029) +++ thread.c (revision 36030) @@ -454,8 +454,8 @@ if (!th->first_func) { GetProcPtr(th->first_proc, proc); th->errinfo = Qnil; - th->local_lfp = proc->block.lfp; - th->local_svar = Qnil; + th->root_lep = rb_vm_ep_local_ep(proc->block.ep); + th->root_svar = Qnil; th->value = rb_vm_invoke_proc(th, proc, proc->block.self, (int)RARRAY_LEN(args), RARRAY_PTR(args), 0); } Index: eval.c =================================================================== --- eval.c (revision 36029) +++ eval.c (revision 36030) @@ -604,7 +604,7 @@ { rb_thread_t *th = GET_THREAD(); - if (RUBY_VM_GET_BLOCK_PTR(th->cfp)) { + if (rb_vm_control_frame_block_ptr(th->cfp)) { return TRUE; } else { @@ -1054,12 +1054,12 @@ while (RUBY_VM_VALID_CONTROL_FRAME_P(cfp, end_cfp)) { if (RUBY_VM_NORMAL_ISEQ_P(cfp->iseq)) { if (cfp->iseq->type == ISEQ_TYPE_RESCUE) { - return &cfp->dfp[-2]; + return &cfp->ep[-2]; } else if (cfp->iseq->type == ISEQ_TYPE_ENSURE && - !RB_TYPE_P(cfp->dfp[-2], T_NODE) && - !FIXNUM_P(cfp->dfp[-2])) { - return &cfp->dfp[-2]; + !RB_TYPE_P(cfp->ep[-2], T_NODE) && + !FIXNUM_P(cfp->ep[-2])) { + return &cfp->ep[-2]; } } cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp); Index: vm_exec.h =================================================================== --- vm_exec.h (revision 36029) +++ vm_exec.h (revision 36030) @@ -38,7 +38,7 @@ #if VMDEBUG > 0 #define debugs printf #define DEBUG_ENTER_INSN(insn) \ - debug_print_pre(th, GET_CFP()); + rb_vmdebug_debug_print_pre(th, GET_CFP()); #if OPT_STACK_CACHING #define SC_REGS() , reg_a, reg_b @@ -47,7 +47,7 @@ #endif #define DEBUG_END_INSN() \ - debug_print_post(th, GET_CFP() SC_REGS()); + rb_vmdebug_debug_print_post(th, GET_CFP() SC_REGS()); #else Index: cont.c =================================================================== --- cont.c (revision 36029) +++ cont.c (revision 36030) @@ -1059,9 +1059,8 @@ th->cfp->pc = 0; th->cfp->sp = th->stack + 1; th->cfp->bp = 0; - th->cfp->lfp = th->stack; - *th->cfp->lfp = 0; - th->cfp->dfp = th->stack; + th->cfp->ep = th->stack; + *th->cfp->ep = VM_ENVVAL_BLOCK_PTR(0); th->cfp->self = Qnil; th->cfp->flag = 0; th->cfp->iseq = 0; @@ -1155,8 +1154,8 @@ argv = (argc = cont->argc) > 1 ? RARRAY_PTR(args) : &args; cont->value = Qnil; th->errinfo = Qnil; - th->local_lfp = proc->block.lfp; - th->local_svar = Qnil; + th->root_lep = rb_vm_ep_local_ep(proc->block.ep); + th->root_svar = Qnil; fib->status = RUNNING; cont->value = rb_vm_invoke_proc(th, proc, proc->block.self, argc, argv, 0); Index: vm.c =================================================================== --- vm.c (revision 36029) +++ vm.c (revision 36030) @@ -19,6 +19,48 @@ #include "iseq.h" #include "eval_intern.h" +static inline VALUE * +VM_EP_LEP(VALUE *ep) +{ + while (1) { + if (VM_EP_LEP_P(ep)) { + return ep; + } + ep = VM_EP_PREV_EP(ep); + } +} + +VALUE * +rb_vm_ep_local_ep(VALUE *ep) +{ + return VM_EP_LEP(ep); +} + +static inline VALUE * +VM_CF_LEP(rb_control_frame_t *cfp) +{ + return VM_EP_LEP(cfp->ep); +} + +static inline VALUE * +VM_CF_PREV_EP(rb_control_frame_t * cfp) +{ + return VM_EP_PREV_EP((cfp)->ep); +} + +static inline rb_block_t * +VM_CF_BLOCK_PTR(rb_control_frame_t *cfp) +{ + VALUE *ep = VM_CF_LEP(cfp); + return VM_EP_BLOCK_PTR(ep); +} + +rb_block_t * +rb_vm_control_frame_block_ptr(rb_control_frame_t *cfp) +{ + return VM_CF_BLOCK_PTR(cfp); +} + #include "vm_insnhelper.h" #include "vm_insnhelper.c" #include "vm_exec.h" @@ -85,8 +127,8 @@ rb_vm_set_finish_env(rb_thread_t * th) { vm_push_frame(th, 0, VM_FRAME_MAGIC_FINISH, - Qnil, th->cfp->lfp[0], 0, - th->cfp->sp, 0, 1); + Qnil, VM_ENVVAL_BLOCK_PTR(VM_CF_BLOCK_PTR(th->cfp)), 0, + th->cfp->sp, 1); th->cfp->pc = (VALUE *)&finish_insn_seq[0]; return Qtrue; } @@ -106,8 +148,8 @@ CHECK_STACK_OVERFLOW(th->cfp, iseq->local_size + iseq->stack_max); vm_push_frame(th, iseq, VM_FRAME_MAGIC_TOP, - th->top_self, 0, iseq->iseq_encoded, - th->cfp->sp, 0, iseq->local_size); + th->top_self, VM_ENVVAL_BLOCK_PTR(0), iseq->iseq_encoded, + th->cfp->sp, iseq->local_size); } static void @@ -122,11 +164,11 @@ CHECK_STACK_OVERFLOW(th->cfp, iseq->local_size + iseq->stack_max); vm_push_frame(th, iseq, VM_FRAME_MAGIC_EVAL, block->self, - GC_GUARDED_PTR(block->dfp), iseq->iseq_encoded, - th->cfp->sp, block->lfp, iseq->local_size); + VM_ENVVAL_PREV_EP_PTR(block->ep), iseq->iseq_encoded, + th->cfp->sp, iseq->local_size); if (cref) { - th->cfp->dfp[-1] = (VALUE)cref; + th->cfp->ep[-1] = (VALUE)cref; } } @@ -298,11 +340,10 @@ check_env(rb_env_t * const env) { fprintf(stderr, "---\n"); - fprintf(stderr, "envptr: %p\n", (void *)&env->block.dfp[0]); - fprintf(stderr, "envval: %10p ", (void *)env->block.dfp[1]); - dp(env->block.dfp[1]); - fprintf(stderr, "lfp: %10p\n", (void *)env->block.lfp); - fprintf(stderr, "dfp: %10p\n", (void *)env->block.dfp); + fprintf(stderr, "envptr: %p\n", (void *)&env->block.ep[0]); + fprintf(stderr, "envval: %10p ", (void *)env->block.ep[1]); + dp(env->block.ep[1]); + fprintf(stderr, "ep: %10p\n", (void *)env->block.ep); if (env->prev_envval) { fprintf(stderr, ">>\n"); check_env_value(env->prev_envval); @@ -345,16 +386,15 @@ penvval = ENV_VAL(penvptr); } else { - while (pcfp->dfp != penvptr) { + while (pcfp->ep != penvptr) { pcfp++; - if (pcfp->dfp == 0) { + if (pcfp->ep == 0) { SDR(); - rb_bug("invalid dfp"); + rb_bug("invalid ep"); } } penvval = vm_make_env_each(th, pcfp, penvptr, endptr); - cfp->lfp = pcfp->lfp; (... truncated) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/