diff --git a/ChangeLog b/ChangeLog index aab9e3f24f..00eceef6d0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +Wed Mar 11 21:21:56 2015 Koichi Sasada + + * vm_insnhelper.c: use T_IMEMO to create SVAR. + + * internal.h, vm_insnhelper.h: move definition `struct SVAR' + from vm_insnhelper.h to internal.h. And rename it to strcut vm_svar. + + new imemo_type imemo_svar is added. + + * gc.c (gc_mark_children): mark imemo_svar. + + * node.c (rb_gc_mark_node): remove useless marking. + Wed Mar 11 19:35:46 2015 Koichi Sasada * include/ruby/ruby.h: introduce new type T_IMEMO. diff --git a/gc.c b/gc.c index a37923baeb..a7b2c6a0f0 100644 --- a/gc.c +++ b/gc.c @@ -382,6 +382,7 @@ typedef struct RVALUE { struct RComplex complex; union { rb_cref_t cref; + struct vm_svar svar; } imemo; struct { struct RBasic basic; @@ -4156,8 +4157,14 @@ gc_mark_children(rb_objspace_t *objspace, VALUE obj) gc_mark(objspace, (VALUE)RANY(obj)->as.imemo.cref.next); gc_mark(objspace, RANY(obj)->as.imemo.cref.refinements); return; + case imemo_svar: + gc_mark(objspace, (VALUE)RANY(obj)->as.imemo.svar.cref); + gc_mark(objspace, RANY(obj)->as.imemo.svar.lastline); + gc_mark(objspace, RANY(obj)->as.imemo.svar.backref); + gc_mark(objspace, RANY(obj)->as.imemo.svar.others); + return; default: - rb_bug("unreachable"); + rb_bug("T_IMEMO: unreachable"); } } diff --git a/internal.h b/internal.h index 9172fb1892..0a4bcba5fa 100644 --- a/internal.h +++ b/internal.h @@ -532,6 +532,7 @@ struct RIMemo { enum imemo_type { imemo_none, imemo_cref, + imemo_svar, imemo_mask = 0x07 }; @@ -634,6 +635,16 @@ CREF_OMOD_SHARED_UNSET(rb_cref_t *cref) cref->flags &= ~NODE_FL_CREF_OMOD_SHARED_; } +/* SVAR */ + +struct vm_svar { + VALUE flags; + const rb_cref_t * const cref; + const VALUE lastline; + const VALUE backref; + const VALUE others; +}; + /* MEMO */ struct MEMO { diff --git a/node.c b/node.c index bd20f2d913..79f65ec684 100644 --- a/node.c +++ b/node.c @@ -947,7 +947,6 @@ rb_gc_mark_node(NODE *obj) { switch (nd_type(obj)) { case NODE_IF: /* 1,2,3 */ - rb_gc_mark(CREF_REFINEMENTS((rb_cref_t *)obj)); /* use as SVAR */ case NODE_FOR: case NODE_ITER: case NODE_WHEN: diff --git a/vm_insnhelper.c b/vm_insnhelper.c index b2481834de..9a30986275 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -141,7 +141,7 @@ rb_error_arity(int argc, int min, int max) /* svar */ -static inline struct SVAR ** +static inline struct vm_svar ** lep_svar_place(rb_thread_t *th, const VALUE *lep) { const VALUE *svar; @@ -153,14 +153,14 @@ lep_svar_place(rb_thread_t *th, const VALUE *lep) svar = &th->root_svar; } - return (struct SVAR **)svar; + return (struct vm_svar **)svar; } static VALUE lep_svar_get(rb_thread_t *th, const VALUE *lep, rb_num_t key) { - struct SVAR ** const svar_place = lep_svar_place(th, lep); - const struct SVAR *const svar = *svar_place; + struct vm_svar ** const svar_place = lep_svar_place(th, lep); + const struct vm_svar *const svar = *svar_place; if (NIL_P((VALUE)svar)) return Qnil; if (RB_TYPE_P((VALUE)svar, T_IMEMO) && imemo_type((VALUE)svar) == imemo_cref) return Qnil; @@ -183,20 +183,24 @@ lep_svar_get(rb_thread_t *th, const VALUE *lep, rb_num_t key) } } +static struct vm_svar * +svar_new(const rb_cref_t *cref) +{ + return (struct vm_svar *)rb_imemo_new(imemo_svar, Qnil, Qnil, Qnil, (VALUE)cref); +} + static void lep_svar_set(rb_thread_t *th, VALUE *lep, rb_num_t key, VALUE val) { - struct SVAR **svar_place = lep_svar_place(th, lep); - struct SVAR *svar = *svar_place; + struct vm_svar **svar_place = lep_svar_place(th, lep); + struct vm_svar *svar = *svar_place; if (NIL_P((VALUE)svar)) { - svar = *svar_place = (struct SVAR *)NEW_IF(Qnil, Qnil, Qnil); - svar->cref = NULL; + svar = *svar_place = svar_new(NULL); } else if (RB_TYPE_P((VALUE)svar, T_IMEMO) && imemo_type((VALUE)svar) == imemo_cref) { const rb_cref_t *cref = (rb_cref_t *)svar; - svar = *svar_place = (struct SVAR *)NEW_IF(Qnil, Qnil, Qnil); - RB_OBJ_WRITE(svar, &svar->cref, (VALUE)cref); + svar = *svar_place = svar_new(cref); } switch (key) { @@ -265,7 +269,7 @@ lep_cref(const VALUE *ep) return (rb_cref_t *)svar; } else { - return (rb_cref_t *)((struct SVAR *)svar)->cref; + return (rb_cref_t *)((struct vm_svar *)svar)->cref; } } @@ -310,7 +314,7 @@ rb_vm_rewrite_cref_stack(rb_cref_t *node, VALUE old_klass, VALUE new_klass, rb_c COPY_CREF_OMOD(new_node, node); node = CREF_NEXT(node); *new_cref_ptr = new_node; - new_cref_ptr = &new_node->next; + new_cref_ptr = (rb_cref_t **)&new_node->next; } *new_cref_ptr = NULL; } diff --git a/vm_insnhelper.h b/vm_insnhelper.h index b94b777606..9a3a2b1564 100644 --- a/vm_insnhelper.h +++ b/vm_insnhelper.h @@ -229,16 +229,6 @@ enum vm_regan_acttype { static VALUE make_no_method_exception(VALUE exc, const char *format, VALUE obj, int argc, const VALUE *argv); -/* SVAR */ - -struct SVAR { - VALUE flags; - const rb_cref_t *cref; - VALUE lastline; - VALUE backref; - VALUE others; -}; - struct THROW_DATA { VALUE flags; VALUE reserved;