1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49935 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2015-03-11 12:27:34 +00:00
parent 734146a459
commit ac28b985bd
6 changed files with 48 additions and 24 deletions

View file

@ -1,3 +1,16 @@
Wed Mar 11 21:21:56 2015 Koichi Sasada <ko1@atdot.net>
* 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 <ko1@atdot.net> Wed Mar 11 19:35:46 2015 Koichi Sasada <ko1@atdot.net>
* include/ruby/ruby.h: introduce new type T_IMEMO. * include/ruby/ruby.h: introduce new type T_IMEMO.

9
gc.c
View file

@ -382,6 +382,7 @@ typedef struct RVALUE {
struct RComplex complex; struct RComplex complex;
union { union {
rb_cref_t cref; rb_cref_t cref;
struct vm_svar svar;
} imemo; } imemo;
struct { struct {
struct RBasic basic; 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, (VALUE)RANY(obj)->as.imemo.cref.next);
gc_mark(objspace, RANY(obj)->as.imemo.cref.refinements); gc_mark(objspace, RANY(obj)->as.imemo.cref.refinements);
return; 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: default:
rb_bug("unreachable"); rb_bug("T_IMEMO: unreachable");
} }
} }

View file

@ -532,6 +532,7 @@ struct RIMemo {
enum imemo_type { enum imemo_type {
imemo_none, imemo_none,
imemo_cref, imemo_cref,
imemo_svar,
imemo_mask = 0x07 imemo_mask = 0x07
}; };
@ -634,6 +635,16 @@ CREF_OMOD_SHARED_UNSET(rb_cref_t *cref)
cref->flags &= ~NODE_FL_CREF_OMOD_SHARED_; 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 */ /* MEMO */
struct MEMO { struct MEMO {

1
node.c
View file

@ -947,7 +947,6 @@ rb_gc_mark_node(NODE *obj)
{ {
switch (nd_type(obj)) { switch (nd_type(obj)) {
case NODE_IF: /* 1,2,3 */ case NODE_IF: /* 1,2,3 */
rb_gc_mark(CREF_REFINEMENTS((rb_cref_t *)obj)); /* use as SVAR */
case NODE_FOR: case NODE_FOR:
case NODE_ITER: case NODE_ITER:
case NODE_WHEN: case NODE_WHEN:

View file

@ -141,7 +141,7 @@ rb_error_arity(int argc, int min, int max)
/* svar */ /* svar */
static inline struct SVAR ** static inline struct vm_svar **
lep_svar_place(rb_thread_t *th, const VALUE *lep) lep_svar_place(rb_thread_t *th, const VALUE *lep)
{ {
const VALUE *svar; const VALUE *svar;
@ -153,14 +153,14 @@ lep_svar_place(rb_thread_t *th, const VALUE *lep)
svar = &th->root_svar; svar = &th->root_svar;
} }
return (struct SVAR **)svar; return (struct vm_svar **)svar;
} }
static VALUE static VALUE
lep_svar_get(rb_thread_t *th, const VALUE *lep, rb_num_t key) lep_svar_get(rb_thread_t *th, const VALUE *lep, rb_num_t key)
{ {
struct SVAR ** const svar_place = lep_svar_place(th, lep); struct vm_svar ** const svar_place = lep_svar_place(th, lep);
const struct SVAR *const svar = *svar_place; const struct vm_svar *const svar = *svar_place;
if (NIL_P((VALUE)svar)) return Qnil; if (NIL_P((VALUE)svar)) return Qnil;
if (RB_TYPE_P((VALUE)svar, T_IMEMO) && imemo_type((VALUE)svar) == imemo_cref) 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 static void
lep_svar_set(rb_thread_t *th, VALUE *lep, rb_num_t key, VALUE val) 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 vm_svar **svar_place = lep_svar_place(th, lep);
struct SVAR *svar = *svar_place; struct vm_svar *svar = *svar_place;
if (NIL_P((VALUE)svar)) { if (NIL_P((VALUE)svar)) {
svar = *svar_place = (struct SVAR *)NEW_IF(Qnil, Qnil, Qnil); svar = *svar_place = svar_new(NULL);
svar->cref = NULL;
} }
else if (RB_TYPE_P((VALUE)svar, T_IMEMO) && imemo_type((VALUE)svar) == imemo_cref) { else if (RB_TYPE_P((VALUE)svar, T_IMEMO) && imemo_type((VALUE)svar) == imemo_cref) {
const rb_cref_t *cref = (rb_cref_t *)svar; const rb_cref_t *cref = (rb_cref_t *)svar;
svar = *svar_place = (struct SVAR *)NEW_IF(Qnil, Qnil, Qnil); svar = *svar_place = svar_new(cref);
RB_OBJ_WRITE(svar, &svar->cref, (VALUE)cref);
} }
switch (key) { switch (key) {
@ -265,7 +269,7 @@ lep_cref(const VALUE *ep)
return (rb_cref_t *)svar; return (rb_cref_t *)svar;
} }
else { 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); COPY_CREF_OMOD(new_node, node);
node = CREF_NEXT(node); node = CREF_NEXT(node);
*new_cref_ptr = new_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; *new_cref_ptr = NULL;
} }

View file

@ -229,16 +229,6 @@ enum vm_regan_acttype {
static VALUE make_no_method_exception(VALUE exc, const char *format, static VALUE make_no_method_exception(VALUE exc, const char *format,
VALUE obj, int argc, const VALUE *argv); 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 { struct THROW_DATA {
VALUE flags; VALUE flags;
VALUE reserved; VALUE reserved;