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

ruby-changes:37857

From: ko1 <ko1@a...>
Date: Wed, 11 Mar 2015 22:31:34 +0900 (JST)
Subject: [ruby-changes:37857] ko1:r49938 (trunk): * node.h: remove NODE_IFUNC, NEW_IFUNC.

ko1	2015-03-11 22:31:11 +0900 (Wed, 11 Mar 2015)

  New Revision: 49938

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

  Log:
    * node.h: remove NODE_IFUNC, NEW_IFUNC.
    * internal.h: use T_IMEMO for IFUNC.
      rename `struct IFUNC' to `struct vm_ifunc' and move the definition
      from vm_insnhelper.h. Add imemo_ifunc.
    * gc.c (gc_mark_children): mark imemo_ifunc type T_IMEMO object.
    * compile.c: catch up these changes.
    * proc.c: ditto.
    * vm_core.h (RUBY_VM_IFUNC_P): ditto.
    * vm_eval.c (rb_iterate): ditto.
    * vm_insnhelper.c: ditto.
    * ext/objspace/objspace.c: ditto.

  Modified files:
    trunk/ChangeLog
    trunk/compile.c
    trunk/ext/objspace/objspace.c
    trunk/gc.c
    trunk/internal.h
    trunk/node.h
    trunk/proc.c
    trunk/vm_core.h
    trunk/vm_eval.c
    trunk/vm_insnhelper.c
    trunk/vm_insnhelper.h
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 49937)
+++ ChangeLog	(revision 49938)
@@ -1,3 +1,26 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Mar 11 22:27:05 2015  Koichi Sasada  <ko1@a...>
+
+	* node.h: remove NODE_IFUNC, NEW_IFUNC.
+
+	* internal.h: use T_IMEMO for IFUNC.
+
+	  rename `struct IFUNC' to `struct vm_ifunc' and move the definition
+	  from vm_insnhelper.h. Add imemo_ifunc.
+
+	* gc.c (gc_mark_children): mark imemo_ifunc type T_IMEMO object.
+
+	* compile.c: catch up these changes.
+
+	* proc.c: ditto.
+
+	* vm_core.h (RUBY_VM_IFUNC_P): ditto.
+
+	* vm_eval.c (rb_iterate): ditto.
+
+	* vm_insnhelper.c: ditto.
+
+	* ext/objspace/objspace.c: ditto.
+
 Wed Mar 11 21:53:43 2015  Koichi Sasada  <ko1@a...>
 
 	* internal.h, eval_intern.h: move CREF accessors.
Index: vm_core.h
===================================================================
--- vm_core.h	(revision 49937)
+++ vm_core.h	(revision 49938)
@@ -910,7 +910,7 @@ rb_block_t *rb_vm_control_frame_block_pt https://github.com/ruby/ruby/blob/trunk/vm_core.h#L910
 #define RUBY_VM_CONTROL_FRAME_STACK_OVERFLOW_P(th, cfp) \
   (!RUBY_VM_VALID_CONTROL_FRAME_P((cfp), RUBY_VM_END_CONTROL_FRAME(th)))
 
-#define RUBY_VM_IFUNC_P(ptr)        RB_TYPE_P((VALUE)(ptr), T_NODE)
+#define RUBY_VM_IFUNC_P(ptr)        RB_TYPE_P((VALUE)(ptr), T_IMEMO)
 #define RUBY_VM_NORMAL_ISEQ_P(ptr) \
   ((ptr) && !RUBY_VM_IFUNC_P(ptr))
 
Index: compile.c
===================================================================
--- compile.c	(revision 49937)
+++ compile.c	(revision 49938)
@@ -520,9 +520,10 @@ rb_iseq_compile_node(VALUE self, NODE *n https://github.com/ruby/ruby/blob/trunk/compile.c#L520
 	  }
 	}
     }
-    else if (nd_type(node) == NODE_IFUNC) {
+    else if (RB_TYPE_P((VALUE)node, T_IMEMO)) {
+	const struct vm_ifunc *ifunc = (struct vm_ifunc *)node;
 	/* user callback */
-	(*node->nd_cfnc)(iseq, ret, node->nd_tval);
+	(*ifunc->func)(iseq, ret, ifunc->data);
     }
     else {
 	switch (iseq->type) {
@@ -5396,7 +5397,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ https://github.com/ruby/ruby/blob/trunk/compile.c#L5397
 	 */
 	int is_index = iseq->is_size++;
 	VALUE once_iseq = NEW_CHILD_ISEQVAL(
-	    NEW_IFUNC(build_postexe_iseq, node->nd_body),
+	    (NODE *)IFUNC_NEW(build_postexe_iseq, node->nd_body),
 	    make_name_for_block(iseq), ISEQ_TYPE_BLOCK, line);
 
 	ADD_INSN2(ret, line, once, once_iseq, INT2FIX(is_index));
@@ -6314,7 +6315,7 @@ method_for_self(VALUE name, VALUE arg, r https://github.com/ruby/ruby/blob/trunk/compile.c#L6315
     acc.arg = arg;
     acc.func = func;
     acc.line = caller_location(&path, &absolute_path);
-    return rb_iseq_new_with_opt(NEW_IFUNC(build, (VALUE)&acc),
+    return rb_iseq_new_with_opt((NODE *)IFUNC_NEW(build, (VALUE)&acc),
 				rb_sym2str(name), path, absolute_path,
 				INT2FIX(acc.line), 0, ISEQ_TYPE_METHOD, 0);
 }
Index: vm_eval.c
===================================================================
--- vm_eval.c	(revision 49937)
+++ vm_eval.c	(revision 49938)
@@ -1105,7 +1105,7 @@ rb_iterate(VALUE (* it_proc) (VALUE), VA https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L1105
 {
     int state;
     volatile VALUE retval = Qnil;
-    struct IFUNC *ifunc = (struct IFUNC *)NEW_IFUNC(bl_proc, data2);
+    struct vm_ifunc *ifunc = IFUNC_NEW(bl_proc, data2);
     rb_thread_t *th = GET_THREAD();
     rb_control_frame_t *volatile cfp = th->cfp;
 
Index: proc.c
===================================================================
--- proc.c	(revision 49937)
+++ proc.c	(revision 49938)
@@ -37,7 +37,7 @@ static int method_min_max_arity(VALUE, i https://github.com/ruby/ruby/blob/trunk/proc.c#L37
 
 /* Proc */
 
-#define IS_METHOD_PROC_NODE(node) (nd_type(node) == NODE_IFUNC && (node)->nd_cfnc == bmcall)
+#define IS_METHOD_PROC_ISEQ(iseq) (RB_TYPE_P((VALUE)(iseq), T_IMEMO) && ((struct vm_ifunc *)(iseq))->func == bmcall)
 
 static void
 proc_mark(void *ptr)
@@ -850,10 +850,10 @@ rb_block_min_max_arity(rb_block_t *block https://github.com/ruby/ruby/blob/trunk/proc.c#L850
 	    return rb_iseq_min_max_arity(iseq, max);
 	}
 	else {
-	    NODE *node = (NODE *)iseq;
-	    if (IS_METHOD_PROC_NODE(node)) {
+	    if (IS_METHOD_PROC_ISEQ(iseq)) {
+		const struct vm_ifunc *ifunc = (struct vm_ifunc *)iseq;
 		/* e.g. method(:foo).to_proc.arity */
-		return method_min_max_arity(node->nd_tval, max);
+		return method_min_max_arity((VALUE)ifunc->data, max);
 	    }
 	}
     }
@@ -919,11 +919,11 @@ rb_proc_get_iseq(VALUE self, int *is_pro https://github.com/ruby/ruby/blob/trunk/proc.c#L919
     iseq = proc->block.iseq;
     if (is_proc) *is_proc = !proc->is_lambda;
     if (!RUBY_VM_NORMAL_ISEQ_P(iseq)) {
-	NODE *node = (NODE *)iseq;
+	const struct vm_ifunc *ifunc = (struct vm_ifunc *)iseq;
 	iseq = 0;
-	if (IS_METHOD_PROC_NODE(node)) {
+	if (IS_METHOD_PROC_ISEQ(ifunc)) {
 	    /* method(:foo).to_proc */
-	    iseq = rb_method_get_iseq(node->nd_tval);
+	    iseq = rb_method_get_iseq((VALUE)ifunc->data);
 	    if (is_proc) *is_proc = 0;
 	}
     }
@@ -2465,10 +2465,10 @@ proc_binding(VALUE self) https://github.com/ruby/ruby/blob/trunk/proc.c#L2465
     GetProcPtr(self, proc);
     iseq = proc->block.iseq;
     if (RUBY_VM_IFUNC_P(iseq)) {
-	if (!IS_METHOD_PROC_NODE((NODE *)iseq)) {
+	if (!IS_METHOD_PROC_ISEQ(iseq)) {
 	    rb_raise(rb_eArgError, "Can't create Binding from C level Proc");
 	}
-	iseq = rb_method_get_iseq(RNODE(iseq)->u2.value);
+	iseq = rb_method_get_iseq((VALUE)((struct vm_ifunc *)iseq)->data);
     }
 
     bindval = rb_binding_alloc(rb_cBinding);
Index: gc.c
===================================================================
--- gc.c	(revision 49937)
+++ gc.c	(revision 49938)
@@ -384,6 +384,7 @@ typedef struct RVALUE { https://github.com/ruby/ruby/blob/trunk/gc.c#L384
 	    rb_cref_t cref;
 	    struct vm_svar svar;
 	    struct vm_throw_data throw_data;
+	    struct vm_ifunc ifunc;
 	} imemo;
 	struct {
 	    struct RBasic basic;
@@ -4167,6 +4168,9 @@ gc_mark_children(rb_objspace_t *objspace https://github.com/ruby/ruby/blob/trunk/gc.c#L4168
 	  case imemo_throw_data:
 	    gc_mark(objspace, RANY(obj)->as.imemo.throw_data.throw_obj);
 	    return;
+	  case imemo_ifunc:
+	    gc_mark_maybe(objspace, (VALUE)RANY(obj)->as.imemo.ifunc.data);
+	    return;
 	  default:
 	    rb_bug("T_IMEMO: unreachable");
 	}
Index: ext/objspace/objspace.c
===================================================================
--- ext/objspace/objspace.c	(revision 49937)
+++ ext/objspace/objspace.c	(revision 49938)
@@ -406,7 +406,6 @@ count_nodes(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace.c#L406
 		COUNT_NODE(NODE_ALLOCA);
 		COUNT_NODE(NODE_BMETHOD);
 		COUNT_NODE(NODE_MEMO);
-		COUNT_NODE(NODE_IFUNC);
 		COUNT_NODE(NODE_DSYM);
 		COUNT_NODE(NODE_ATTRASGN);
 		COUNT_NODE(NODE_PRELUDE);
Index: internal.h
===================================================================
--- internal.h	(revision 49937)
+++ internal.h	(revision 49938)
@@ -534,6 +534,7 @@ enum imemo_type { https://github.com/ruby/ruby/blob/trunk/internal.h#L534
     imemo_cref,
     imemo_svar,
     imemo_throw_data,
+    imemo_ifunc,
     imemo_mask = 0x07
 };
 
@@ -577,6 +578,18 @@ struct vm_throw_data { https://github.com/ruby/ruby/blob/trunk/internal.h#L578
 
 #define THROW_DATA_P(err) RB_TYPE_P((err), T_IMEMO)
 
+/* IFUNC */
+
+struct vm_ifunc {
+    VALUE flags;
+    VALUE reserved;
+    VALUE (*func)(ANYARGS);
+    const void *data;
+    ID id;
+};
+
+#define IFUNC_NEW(a, b) ((struct vm_ifunc *)rb_imemo_new(imemo_ifunc, (VALUE)(a), (VALUE)(b), 0, 0))
+
 /* MEMO */
 
 struct MEMO {
Index: vm_insnhelper.c
===================================================================
--- vm_insnhelper.c	(revision 49937)
+++ vm_insnhelper.c	(revision 49938)
@@ -2044,7 +2044,7 @@ vm_yield_with_cfunc(rb_thread_t *th, con https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L2044
 		    int argc, const VALUE *argv,
 		    const rb_block_t *blockargptr)
 {
-    struct IFUNC *ifunc = (struct IFUNC *)block->iseq;
+    const struct vm_ifunc *ifunc = (struct vm_ifunc *)block->iseq;
     VALUE val, arg, blockarg;
     int lambda = block_proc_is_lambda(block->proc);
 
Index: vm_insnhelper.h
===================================================================
--- vm_insnhelper.h	(revision 49937)
+++ vm_insnhelper.h	(revision 49938)
@@ -265,12 +265,4 @@ THROW_DATA_STATE(const struct vm_throw_d https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.h#L265
     return (int)obj->throw_state;
 }
 
-struct IFUNC {
-    VALUE flags;
-    VALUE reserved;
-    VALUE (*func)(ANYARGS);
-    void *data;
-    ID id;
-};
-
 #endif /* RUBY_INSNHELPER_H */
Index: node.h
===================================================================
--- node.h	(revision 49937)
+++ node.h	(revision 49938)
@@ -220,8 +220,6 @@ enum node_type { https://github.com/ruby/ruby/blob/trunk/node.h#L220
 #define NODE_BMETHOD     NODE_BMETHOD
     NODE_MEMO,
 #define NODE_MEMO        NODE_MEMO
-    NODE_IFUNC,
-#define NODE_IFUNC       NODE_IFUNC
     NODE_DSYM,
 #define NODE_DSYM        NODE_DSYM
     NODE_ATTRASGN,
@@ -361,7 +359,6 @@ typedef struct RNode { https://github.com/ruby/ruby/blob/trunk/node.h#L359
 
 #define NEW_DEFN(i,a,d,p) NEW_NODE(NODE_DEFN,0,i,NEW_SCOPE(a,d))
 #define NEW_DEFS(r,i,a,d) NEW_NODE(NODE_DEFS,r,i,NEW_SCOPE(a,d))
-#define NEW_IFUNC(f,c) NEW_NODE(NODE_IFUNC,f,c,0)
 #define NEW_SCOPE(a,b) NEW_NODE(NODE_SCOPE,local_tbl(),b,a)
 #define NEW_BLOCK(a) NEW_NODE(NODE_BLOCK,a,0,0)
 #define NEW_IF(c,t,e) NEW_NODE(NODE_IF,c,t,e)

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

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