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

ruby-changes:47194

From: nobu <ko1@a...>
Date: Mon, 10 Jul 2017 20:42:13 +0900 (JST)
Subject: [ruby-changes:47194] nobu:r59309 (trunk): compile.c: simplify defined_expr0

nobu	2017-07-10 20:42:07 +0900 (Mon, 10 Jul 2017)

  New Revision: 59309

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

  Log:
    compile.c: simplify defined_expr0
    
    * compile.c (defined_expr0): exapnd defined_expr macro.
    
    * compile.c (defined_expr0): reduce duplicate code.

  Modified files:
    trunk/compile.c
Index: compile.c
===================================================================
--- compile.c	(revision 59308)
+++ compile.c	(revision 59309)
@@ -3611,11 +3611,13 @@ compile_cpath(LINK_ANCHOR *const ret, rb https://github.com/ruby/ruby/blob/trunk/compile.c#L3611
 }
 
 #define private_recv_p(node) (nd_type((node)->nd_recv) == NODE_SELF)
-
-#define defined_expr defined_expr0
 static int
 defined_expr(rb_iseq_t *iseq, LINK_ANCHOR *const ret,
-	     NODE *node, LABEL **lfinish, VALUE needstr)
+	     NODE *node, LABEL **lfinish, VALUE needstr);
+
+static int
+defined_expr0(rb_iseq_t *iseq, LINK_ANCHOR *const ret,
+	      NODE *node, LABEL **lfinish, VALUE needstr)
 {
     enum defined_type expr_type = 0;
     enum node_type type;
@@ -3640,7 +3642,7 @@ defined_expr(rb_iseq_t *iseq, LINK_ANCHO https://github.com/ruby/ruby/blob/trunk/compile.c#L3642
 	NODE *vals = node;
 
 	do {
-	    defined_expr(iseq, ret, vals->nd_head, lfinish, Qfalse);
+	    defined_expr0(iseq, ret, vals->nd_head, lfinish, Qfalse);
 
 	    if (!lfinish[1]) {
 		lfinish[1] = NEW_LABEL(nd_line(node));
@@ -3690,19 +3692,14 @@ defined_expr(rb_iseq_t *iseq, LINK_ANCHO https://github.com/ruby/ruby/blob/trunk/compile.c#L3692
 	if (!lfinish[1]) {
 	    lfinish[1] = NEW_LABEL(nd_line(node));
 	}
-	defined_expr(iseq, ret, node->nd_head, lfinish, Qfalse);
+	defined_expr0(iseq, ret, node->nd_head, lfinish, Qfalse);
 	ADD_INSNL(ret, nd_line(node), branchunless, lfinish[1]);
+	COMPILE(ret, "defined/colon2#nd_head", node->nd_head);
 
-	if (rb_is_const_id(node->nd_mid)) {
-	    COMPILE(ret, "defined/colon2#nd_head", node->nd_head);
-	    ADD_INSN3(ret, nd_line(node), defined, INT2FIX(DEFINED_CONST),
-		      ID2SYM(node->nd_mid), needstr);
-	}
-	else {
-	    COMPILE(ret, "defined/colon2#nd_head", node->nd_head);
-	    ADD_INSN3(ret, nd_line(node), defined, INT2FIX(DEFINED_METHOD),
-		      ID2SYM(node->nd_mid), needstr);
-	}
+	ADD_INSN3(ret, nd_line(node), defined,
+		  (rb_is_const_id(node->nd_mid) ?
+		   INT2FIX(DEFINED_CONST) : INT2FIX(DEFINED_METHOD)),
+		  ID2SYM(node->nd_mid), needstr);
 	return 1;
       case NODE_COLON3:
 	ADD_INSN1(ret, nd_line(node), putobject, rb_cObject);
@@ -3724,11 +3721,11 @@ defined_expr(rb_iseq_t *iseq, LINK_ANCHO https://github.com/ruby/ruby/blob/trunk/compile.c#L3721
 	    lfinish[1] = NEW_LABEL(nd_line(node));
 	}
 	if (node->nd_args) {
-	    defined_expr(iseq, ret, node->nd_args, lfinish, Qfalse);
+	    defined_expr0(iseq, ret, node->nd_args, lfinish, Qfalse);
 	    ADD_INSNL(ret, nd_line(node), branchunless, lfinish[1]);
 	}
 	if (explicit_receiver) {
-	    defined_expr(iseq, ret, node->nd_recv, lfinish, Qfalse);
+	    defined_expr0(iseq, ret, node->nd_recv, lfinish, Qfalse);
 	    ADD_INSNL(ret, nd_line(node), branchunless, lfinish[1]);
 	    COMPILE(ret, "defined/recv", node->nd_recv);
 	    ADD_INSN3(ret, nd_line(node), defined, INT2FIX(DEFINED_METHOD),
@@ -3792,7 +3789,6 @@ defined_expr(rb_iseq_t *iseq, LINK_ANCHO https://github.com/ruby/ruby/blob/trunk/compile.c#L3789
     }
     return 0;
 }
-#undef defined_expr
 
 static int
 defined_expr(rb_iseq_t *iseq, LINK_ANCHOR *const ret,

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

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