From 32a96472648fac55ae5651f404de4c75e697409c Mon Sep 17 00:00:00 2001 From: ko1 Date: Fri, 13 Nov 2015 20:02:19 +0000 Subject: * refactoring CREF related code. * eval_intern.h: remove unused setter functions. CREF_CLASS_SET() CREF_NEXT_SET() CREF_SCOPE_VISI_COPY() * eval_intern.h: rename flags: * NODE_FL_CREF_PUSHED_BY_EVAL_ -> CREF_FL_PUSHED_BY_EVAL * NODE_FL_CREF_OMOD_SHARED_ -> CREF_FL_OMOD_SHARED and use IMEMO_FL_USER1/2. * vm.c (vm_cref_new): accept push_by_eval parameter. * vm.c (vm_cref_new_use_prev): added for rb_vm_rewrite_cref(). * vm_insnhelper.c (vm_cref_push): accept pushed_by_eval parameter. * vm_insnhelper.h: remove unused macros: COPY_CREF_OMOD() and COPY_CREF(). * vm_eval.c, insns.def: catch up this fix. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52564 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- vm.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 6 deletions(-) (limited to 'vm.c') diff --git a/vm.c b/vm.c index 81de1a21e3..929144d6a8 100644 --- a/vm.c +++ b/vm.c @@ -86,25 +86,69 @@ rb_vm_control_frame_block_ptr(const rb_control_frame_t *cfp) } static rb_cref_t * -vm_cref_new(VALUE klass, rb_method_visibility_t visi, const rb_cref_t *prev_cref) +vm_cref_new0(VALUE klass, rb_method_visibility_t visi, int module_func, rb_cref_t *prev_cref, int pushed_by_eval, int use_prev_prev) { + VALUE refinements = Qnil; + int omod_shared = FALSE; + rb_cref_t *cref; + + /* scope */ union { rb_scope_visibility_t visi; VALUE value; } scope_visi; + scope_visi.visi.method_visi = visi; - scope_visi.visi.module_func = 0; + scope_visi.visi.module_func = module_func; + + /* refinements */ + if (prev_cref != NULL && prev_cref != (void *)1 /* TODO: why CREF_NEXT(cref) is 1? */) { + refinements = CREF_REFINEMENTS(prev_cref); + + if (!NIL_P(refinements)) { + omod_shared = TRUE; + CREF_OMOD_SHARED_SET(prev_cref); + } + } + + cref = (rb_cref_t *)rb_imemo_new(imemo_cref, klass, (VALUE)(use_prev_prev ? CREF_NEXT(prev_cref) : prev_cref), scope_visi.value, refinements); + + if (pushed_by_eval) CREF_PUSHED_BY_EVAL_SET(cref); + if (omod_shared) CREF_OMOD_SHARED_SET(cref); + + return cref; +} + +static rb_cref_t * +vm_cref_new(VALUE klass, rb_method_visibility_t visi, int module_func, rb_cref_t *prev_cref, int pushed_by_eval) +{ + return vm_cref_new0(klass, visi, module_func, prev_cref, pushed_by_eval, FALSE); +} + +static rb_cref_t * +vm_cref_new_use_prev(VALUE klass, rb_method_visibility_t visi, int module_func, rb_cref_t *prev_cref, int pushed_by_eval) +{ + return vm_cref_new0(klass, visi, module_func, prev_cref, pushed_by_eval, TRUE); +} + +static rb_cref_t * +vm_cref_dup(const rb_cref_t *cref) +{ + VALUE klass = CREF_CLASS(cref); + const rb_scope_visibility_t *visi = CREF_SCOPE_VISI(cref); + rb_cref_t *next_cref = CREF_NEXT(cref); + int pushed_by_eval = CREF_PUSHED_BY_EVAL(cref); - return (rb_cref_t *)rb_imemo_new(imemo_cref, klass, (VALUE)prev_cref, scope_visi.value, Qnil); + return vm_cref_new(klass, visi->method_visi, visi->module_func, next_cref, pushed_by_eval); } static rb_cref_t * vm_cref_new_toplevel(rb_thread_t *th) { - rb_cref_t *cref = vm_cref_new(rb_cObject, METHOD_VISI_PRIVATE /* toplevel visibility is private */, NULL); + rb_cref_t *cref = vm_cref_new(rb_cObject, METHOD_VISI_PRIVATE /* toplevel visibility is private */, FALSE, NULL, FALSE); if (th->top_wrapper) { - cref = vm_cref_new(th->top_wrapper, METHOD_VISI_PRIVATE, cref); + cref = vm_cref_new(th->top_wrapper, METHOD_VISI_PRIVATE, FALSE, cref, FALSE); } return cref; @@ -2844,7 +2888,7 @@ Init_VM(void) th->cfp->pc = iseq->body->iseq_encoded; th->cfp->self = th->top_self; - th->cfp->ep[-1] = (VALUE)vm_cref_new(rb_cObject, METHOD_VISI_PRIVATE, NULL); + th->cfp->ep[-1] = (VALUE)vm_cref_new(rb_cObject, METHOD_VISI_PRIVATE, FALSE, NULL, FALSE); /* * The Binding of the top level scope -- cgit v1.2.3