[前][次][番号順一覧][スレッド一覧]

ruby-changes:37854

From: ko1 <ko1@a...>
Date: Wed, 11 Mar 2015 21:27:55 +0900 (JST)
Subject: [ruby-changes:37854] ko1:r49935 (trunk): * vm_insnhelper.c: use T_IMEMO to create SVAR.

ko1	2015-03-11 21:27:34 +0900 (Wed, 11 Mar 2015)

  New Revision: 49935

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=49935

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

  Modified files:
    trunk/ChangeLog
    trunk/gc.c
    trunk/internal.h
    trunk/node.c
    trunk/vm_insnhelper.c
    trunk/vm_insnhelper.h
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 49934)
+++ ChangeLog	(revision 49935)
@@ -1,3 +1,16 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Mar 11 21:21:56 2015  Koichi Sasada  <ko1@a...>
+
+	* 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@a...>
 
 	* include/ruby/ruby.h: introduce new type T_IMEMO.
Index: gc.c
===================================================================
--- gc.c	(revision 49934)
+++ gc.c	(revision 49935)
@@ -382,6 +382,7 @@ typedef struct RVALUE { https://github.com/ruby/ruby/blob/trunk/gc.c#L382
 	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 https://github.com/ruby/ruby/blob/trunk/gc.c#L4157
 	    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");
 	}
     }
 
Index: internal.h
===================================================================
--- internal.h	(revision 49934)
+++ internal.h	(revision 49935)
@@ -532,6 +532,7 @@ struct RIMemo { https://github.com/ruby/ruby/blob/trunk/internal.h#L532
 enum imemo_type {
     imemo_none,
     imemo_cref,
+    imemo_svar,
     imemo_mask = 0x07
 };
 
@@ -634,6 +635,16 @@ CREF_OMOD_SHARED_UNSET(rb_cref_t *cref) https://github.com/ruby/ruby/blob/trunk/internal.h#L635
     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 {
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 49934)
+++ vm_insnhelper.c	(revision 49935)
@@ -141,7 +141,7 @@ rb_error_arity(int argc, int min, int ma https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L141
 
 /* 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 VA https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L153
 	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 VALU https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L183
     }
 }
 
+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) https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L269
 	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 https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L314
 	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;
 }
Index: vm_insnhelper.h
===================================================================
--- vm_insnhelper.h	(revision 49934)
+++ vm_insnhelper.h	(revision 49935)
@@ -229,16 +229,6 @@ enum vm_regan_acttype { https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.h#L229
 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;
Index: node.c
===================================================================
--- node.c	(revision 49934)
+++ node.c	(revision 49935)
@@ -947,7 +947,6 @@ rb_gc_mark_node(NODE *obj) https://github.com/ruby/ruby/blob/trunk/node.c#L947
 {
     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:

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]