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

ruby-changes:48086

From: nobu <ko1@a...>
Date: Tue, 17 Oct 2017 21:05:36 +0900 (JST)
Subject: [ruby-changes:48086] nobu:r60200 (trunk): compile.c: compile_for

nobu	2017-10-17 21:05:32 +0900 (Tue, 17 Oct 2017)

  New Revision: 60200

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

  Log:
    compile.c: compile_for
    
    * compile.c (compile_for): extract from iseq_compile_each.

  Modified files:
    trunk/compile.c
Index: compile.c
===================================================================
--- compile.c	(revision 60199)
+++ compile.c	(revision 60200)
@@ -4575,6 +4575,41 @@ compile_iter(rb_iseq_t *iseq, LINK_ANCHO https://github.com/ruby/ruby/blob/trunk/compile.c#L4575
 }
 
 static int
+compile_for(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int popped)
+{
+    const int line = nd_line(node);
+    if (node->nd_var) {
+	/* massign to var in "for"
+	 * args.length == 1 && Array === (tmp = args[0]) ? tmp : args
+	 */
+	NODE *var = node->nd_var;
+	LABEL *not_single = NEW_LABEL(nd_line(var));
+	LABEL *not_ary = NEW_LABEL(nd_line(var));
+	CHECK(COMPILE(ret, "for var", var));
+	ADD_INSN(ret, line, dup);
+	ADD_CALL(ret, line, idLength, INT2FIX(0));
+	ADD_INSN1(ret, line, putobject, INT2FIX(1));
+	ADD_CALL(ret, line, idEq, INT2FIX(1));
+	ADD_INSNL(ret, line, branchunless, not_single);
+	ADD_INSN(ret, line, dup);
+	ADD_INSN1(ret, line, putobject, INT2FIX(0));
+	ADD_CALL(ret, line, idAREF, INT2FIX(1));
+	ADD_INSN1(ret, line, putobject, rb_cArray);
+	ADD_INSN1(ret, line, topn, INT2FIX(1));
+	ADD_CALL(ret, line, idEqq, INT2FIX(1));
+	ADD_INSNL(ret, line, branchunless, not_ary);
+	ADD_INSN(ret, line, swap);
+	ADD_LABEL(ret, not_ary);
+	ADD_INSN(ret, line, pop);
+	ADD_LABEL(ret, not_single);
+	return COMPILE_OK;
+    }
+    else {
+	return compile_iter(iseq, ret, node, popped);
+    }
+}
+
+static int
 compile_break(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int popped)
 {
     const int line = nd_line(node);
@@ -5026,32 +5061,8 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L5061
 	CHECK(compile_loop(iseq, ret, node, popped, type));
 	break;
       case NODE_FOR:
-	if (node->nd_var) {
-	    /* massign to var in "for"
-	     * args.length == 1 && Array === (tmp = args[0]) ? tmp : args
-	     */
-	    NODE *var = node->nd_var;
-	    LABEL *not_single = NEW_LABEL(nd_line(var));
-	    LABEL *not_ary = NEW_LABEL(nd_line(var));
-	    CHECK(COMPILE(ret, "for var", var));
-	    ADD_INSN(ret, line, dup);
-	    ADD_CALL(ret, line, idLength, INT2FIX(0));
-	    ADD_INSN1(ret, line, putobject, INT2FIX(1));
-	    ADD_CALL(ret, line, idEq, INT2FIX(1));
-	    ADD_INSNL(ret, line, branchunless, not_single);
-	    ADD_INSN(ret, line, dup);
-	    ADD_INSN1(ret, line, putobject, INT2FIX(0));
-	    ADD_CALL(ret, line, idAREF, INT2FIX(1));
-	    ADD_INSN1(ret, line, putobject, rb_cArray);
-	    ADD_INSN1(ret, line, topn, INT2FIX(1));
-	    ADD_CALL(ret, line, idEqq, INT2FIX(1));
-	    ADD_INSNL(ret, line, branchunless, not_ary);
-	    ADD_INSN(ret, line, swap);
-	    ADD_LABEL(ret, not_ary);
-	    ADD_INSN(ret, line, pop);
-	    ADD_LABEL(ret, not_single);
-	    break;
-	}
+	CHECK(compile_for(iseq, ret, node, popped));
+	break;
       case NODE_ITER:
 	CHECK(compile_iter(iseq, ret, node, popped));
 	break;

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

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