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

ruby-changes:34280

From: nobu <ko1@a...>
Date: Fri, 6 Jun 2014 15:05:31 +0900 (JST)
Subject: [ruby-changes:34280] nobu:r46361 (trunk): node.h: NODE_PRIVATE_RECV

nobu	2014-06-06 15:05:19 +0900 (Fri, 06 Jun 2014)

  New Revision: 46361

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

  Log:
    node.h: NODE_PRIVATE_RECV
    
    * node.h (NODE_PRIVATE_RECV): name a magic number, `self` as the
      receiver of a setter method call.
    
    * compile.c (private_recv_p), parse.y (attr_receiver): use the
      named macro.

  Modified files:
    trunk/compile.c
    trunk/node.h
    trunk/parse.y
Index: compile.c
===================================================================
--- compile.c	(revision 46360)
+++ compile.c	(revision 46361)
@@ -2786,6 +2786,8 @@ compile_cpath(LINK_ANCHOR *ret, rb_iseq_ https://github.com/ruby/ruby/blob/trunk/compile.c#L2786
     }
 }
 
+#define private_recv_p(node) ((node)->nd_recv == NODE_PRIVATE_RECV)
+
 #define defined_expr defined_expr0
 static int
 defined_expr(rb_iseq_t *iseq, LINK_ANCHOR *ret,
@@ -2893,7 +2895,7 @@ defined_expr(rb_iseq_t *iseq, LINK_ANCHO https://github.com/ruby/ruby/blob/trunk/compile.c#L2895
 
 	switch (type) {
 	  case NODE_ATTRASGN:
-	    if (node->nd_recv == (NODE *)1) break;
+	    if (private_recv_p(node)) break;
 	  case NODE_CALL:
 	    self = FALSE;
 	    break;
@@ -4335,7 +4337,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ https://github.com/ruby/ruby/blob/trunk/compile.c#L4337
 	/* optimization shortcut
 	 *   obj["literal"] -> opt_aref_with(obj, "literal")
 	 */
-	if (node->nd_mid == idAREF && node->nd_recv != (NODE *)1 && node->nd_args &&
+	if (node->nd_mid == idAREF && !private_recv_p(node) && node->nd_args &&
 	    nd_type(node->nd_args) == NODE_ARRAY && node->nd_args->nd_alen == 1 &&
 	    nd_type(node->nd_args->nd_head) == NODE_STR)
 	{
@@ -5322,7 +5324,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ https://github.com/ruby/ruby/blob/trunk/compile.c#L5324
 	/* optimization shortcut
 	 *   obj["literal"] = value -> opt_aset_with(obj, "literal", value)
 	 */
-	if (node->nd_mid == idASET && node->nd_recv != (NODE *)1 && node->nd_args &&
+	if (node->nd_mid == idASET && !private_recv_p(node) && node->nd_args &&
 	    nd_type(node->nd_args) == NODE_ARRAY && node->nd_args->nd_alen == 2 &&
 	    nd_type(node->nd_args->nd_head) == NODE_STR)
 	{
@@ -5345,7 +5347,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ https://github.com/ruby/ruby/blob/trunk/compile.c#L5347
 	INIT_ANCHOR(args);
 	argc = setup_args(iseq, args, node->nd_args, &flag);
 
-	if (node->nd_recv == (NODE *) 1) {
+	if (private_recv_p(node)) {
 	    flag |= VM_CALL_FCALL;
 	    ADD_INSN(recv, line, putself);
 	}
Index: parse.y
===================================================================
--- parse.y	(revision 46360)
+++ parse.y	(revision 46361)
@@ -8895,11 +8895,18 @@ rb_id_attrget(ID id) https://github.com/ruby/ruby/blob/trunk/parse.y#L8895
     return attrsetname_to_attr(rb_id2str(id));
 }
 
+static inline NODE *
+attr_receiver(NODE *recv)
+{
+    if (recv && nd_type(recv) == NODE_SELF)
+	recv = NODE_PRIVATE_RECV;
+    return recv;
+}
+
 static NODE *
 attrset_gen(struct parser_params *parser, NODE *recv, ID id)
 {
-    if (recv && nd_type(recv) == NODE_SELF)
-	recv = (NODE *)1;
+    recv = attr_receiver(recv);
     return NEW_ATTRASGN(recv, rb_id_attrset(id), 0);
 }
 
Index: node.h
===================================================================
--- node.h	(revision 46360)
+++ node.h	(revision 46361)
@@ -465,6 +465,8 @@ typedef struct RNode { https://github.com/ruby/ruby/blob/trunk/node.h#L465
 #define NEW_PRELUDE(p,b) NEW_NODE(NODE_PRELUDE,p,b,0)
 #define NEW_MEMO(a,b,c) NEW_NODE(NODE_MEMO,a,b,c)
 
+#define NODE_PRIVATE_RECV ((NODE *)1)
+
 #define roomof(x, y) ((sizeof(x) + sizeof(y) - 1) / sizeof(y))
 #define MEMO_FOR(type, value) ((type *)RARRAY_PTR(value))
 #define NEW_MEMO_FOR(type, value) \

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

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