aboutsummaryrefslogtreecommitdiffstats
path: root/compile.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-17 12:05:32 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-17 12:05:32 +0000
commit8dc510b577e0e2ff7adf4e78cd61c76edc8fb677 (patch)
treebf7474efda955a35f1dca10ca08f619736dd63b2 /compile.c
parent1f5f136f3d662d72862cd1011fc05491584d69f6 (diff)
downloadruby-8dc510b577e0e2ff7adf4e78cd61c76edc8fb677.tar.gz
compile.c: compile_for
* compile.c (compile_for): extract from iseq_compile_each. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60200 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c63
1 files changed, 37 insertions, 26 deletions
diff --git a/compile.c b/compile.c
index 64859c555e..46a853709f 100644
--- a/compile.c
+++ b/compile.c
@@ -4575,6 +4575,41 @@ compile_iter(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int popped)
}
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_ANCHOR *const ret, NODE *node, int popp
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;