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

ruby-changes:55420

From: ktsj <ko1@a...>
Date: Sat, 20 Apr 2019 12:37:29 +0900 (JST)
Subject: [ruby-changes:55420] ktsj:r67629 (trunk): Avoid usage of the dummy empty BEGIN node

ktsj	2019-04-20 12:37:22 +0900 (Sat, 20 Apr 2019)

  New Revision: 67629

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

  Log:
    Avoid usage of the dummy empty BEGIN node
    
    Use NODE_SPECIAL_NO_NAME_REST instead.

  Modified files:
    trunk/ast.c
    trunk/compile.c
    trunk/node.c
    trunk/parse.y
Index: compile.c
===================================================================
--- compile.c	(revision 67628)
+++ compile.c	(revision 67629)
@@ -5305,8 +5305,8 @@ iseq_compile_pattern_each(rb_iseq_t *ise https://github.com/ruby/ruby/blob/trunk/compile.c#L5305
         const int post_args_num = apinfo->post_args ? rb_long2int(apinfo->post_args->nd_alen) : 0;
 
         const int min_argc = pre_args_num + post_args_num;
-        const int use_rest_num = apinfo->rest_arg && ((nd_type(apinfo->rest_arg) != NODE_BEGIN) ||
-                                                      (nd_type(apinfo->rest_arg) == NODE_BEGIN && post_args_num > 0));
+        const int use_rest_num = apinfo->rest_arg && (NODE_NAMED_REST_P(apinfo->rest_arg) ||
+                                                      (!NODE_NAMED_REST_P(apinfo->rest_arg) && post_args_num > 0));
 
         LABEL *match_failed, *type_error, *fin;
         int i;
@@ -5354,17 +5354,7 @@ iseq_compile_pattern_each(rb_iseq_t *ise https://github.com/ruby/ruby/blob/trunk/compile.c#L5354
         }
 
         if (apinfo->rest_arg) {
-            if (nd_type(apinfo->rest_arg) == NODE_BEGIN) {
-                if (post_args_num > 0) {
-                    ADD_INSN(ret, line, dup);
-                    ADD_SEND(ret, line, idLength, INT2FIX(0));
-                    ADD_INSN1(ret, line, putobject, INT2FIX(min_argc));
-                    ADD_SEND(ret, line, idMINUS, INT2FIX(1));
-                    ADD_INSN1(ret, line, setn, INT2FIX(2));
-                    ADD_INSN(ret, line, pop);
-                }
-            }
-            else {
+            if (NODE_NAMED_REST_P(apinfo->rest_arg)) {
                 ADD_INSN(ret, line, dup);
                 ADD_INSN1(ret, line, putobject, INT2FIX(pre_args_num));
                 ADD_INSN1(ret, line, topn, INT2FIX(1));
@@ -5377,6 +5367,16 @@ iseq_compile_pattern_each(rb_iseq_t *ise https://github.com/ruby/ruby/blob/trunk/compile.c#L5367
                 iseq_compile_pattern_each(iseq, ret, apinfo->rest_arg, in_alt_pattern);
                 ADD_INSNL(ret, line, branchunless, match_failed);
             }
+            else {
+                if (post_args_num > 0) {
+                    ADD_INSN(ret, line, dup);
+                    ADD_SEND(ret, line, idLength, INT2FIX(0));
+                    ADD_INSN1(ret, line, putobject, INT2FIX(min_argc));
+                    ADD_SEND(ret, line, idMINUS, INT2FIX(1));
+                    ADD_INSN1(ret, line, setn, INT2FIX(2));
+                    ADD_INSN(ret, line, pop);
+                }
+            }
         }
 
         args = apinfo->post_args;
Index: parse.y
===================================================================
--- parse.y	(revision 67628)
+++ parse.y	(revision 67629)
@@ -11037,7 +11037,7 @@ new_array_pattern_tail(struct parser_par https://github.com/ruby/ruby/blob/trunk/parse.y#L11037
 	if (rest_arg) {
 	    apinfo->rest_arg = assignable(p, rest_arg, 0, loc);
 	} else {
-	    apinfo->rest_arg = NEW_BEGIN(0, loc);
+	    apinfo->rest_arg = NODE_SPECIAL_NO_NAME_REST;
 	}
     } else {
 	apinfo->rest_arg = NULL;
Index: node.c
===================================================================
--- node.c	(revision 67628)
+++ node.c	(revision 67629)
@@ -1040,7 +1040,12 @@ dump_node(VALUE buf, VALUE indent, int c https://github.com/ruby/ruby/blob/trunk/node.c#L1040
         ANN("format: [nd_pconst]([pre_args], ..., *[rest_arg], [post_args], ...)");
         F_NODE(nd_pconst, "constant");
         F_NODE(nd_apinfo->pre_args, "pre arguments");
-        F_NODE(nd_apinfo->rest_arg, "rest argument");
+        if (NODE_NAMED_REST_P(node->nd_apinfo->rest_arg)) {
+            F_NODE(nd_apinfo->rest_arg, "rest argument");
+        }
+        else {
+            F_MSG(nd_apinfo->rest_arg, "rest argument", "NODE_SPECIAL_NO_NAME_REST (rest argument without name)");
+        }
         LAST_NODE;
         F_NODE(nd_apinfo->post_args, "post arguments");
         return;
Index: ast.c
===================================================================
--- ast.c	(revision 67628)
+++ ast.c	(revision 67629)
@@ -634,10 +634,12 @@ node_children(rb_ast_t *ast, NODE *node) https://github.com/ruby/ruby/blob/trunk/ast.c#L634
       case NODE_ARYPTN:
         {
             struct rb_ary_pattern_info *apinfo = node->nd_apinfo;
+            VALUE rest = NODE_NAMED_REST_P(apinfo->rest_arg) ? NEW_CHILD(ast, apinfo->rest_arg) :
+                                                               ID2SYM(rb_intern("NODE_SPECIAL_NO_NAME_REST"));
             return rb_ary_new_from_args(4,
                                         NEW_CHILD(ast, node->nd_pconst),
                                         NEW_CHILD(ast, apinfo->pre_args),
-                                        NEW_CHILD(ast, apinfo->rest_arg),
+                                        rest,
                                         NEW_CHILD(ast, apinfo->post_args));
         }
       case NODE_HSHPTN:

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

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