aboutsummaryrefslogtreecommitdiffstats
path: root/compile.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-17 12:05:30 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-17 12:05:30 +0000
commit1f5f136f3d662d72862cd1011fc05491584d69f6 (patch)
treee91f171f1d8ea5bf79898963de52e36204b9057d /compile.c
parent6737bd5e344c5c85bb3bf37c270edd57927523bb (diff)
downloadruby-1f5f136f3d662d72862cd1011fc05491584d69f6.tar.gz
compile.c: compile_iter
* compile.c (compile_iter): extract from iseq_compile_each. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60199 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c70
1 files changed, 38 insertions, 32 deletions
diff --git a/compile.c b/compile.c
index f92eabaa13..64859c555e 100644
--- a/compile.c
+++ b/compile.c
@@ -4539,6 +4539,42 @@ compile_loop(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int popped, co
}
static int
+compile_iter(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int popped)
+{
+ const int line = nd_line(node);
+ const rb_iseq_t *prevblock = ISEQ_COMPILE_DATA(iseq)->current_block;
+ LABEL *retry_label = NEW_LABEL(line);
+ LABEL *retry_end_l = NEW_LABEL(line);
+ const rb_iseq_t *child_iseq;
+
+ ADD_LABEL(ret, retry_label);
+ if (nd_type(node) == NODE_FOR) {
+ CHECK(COMPILE(ret, "iter caller (for)", node->nd_iter));
+
+ ISEQ_COMPILE_DATA(iseq)->current_block = child_iseq =
+ NEW_CHILD_ISEQ(node->nd_body, make_name_for_block(iseq),
+ ISEQ_TYPE_BLOCK, line);
+ ADD_SEND_WITH_BLOCK(ret, line, idEach, INT2FIX(0), child_iseq);
+ }
+ else {
+ ISEQ_COMPILE_DATA(iseq)->current_block = child_iseq =
+ NEW_CHILD_ISEQ(node->nd_body, make_name_for_block(iseq),
+ ISEQ_TYPE_BLOCK, line);
+ CHECK(COMPILE(ret, "iter caller", node->nd_iter));
+ }
+ ADD_LABEL(ret, retry_end_l);
+
+ if (popped) {
+ ADD_INSN(ret, line, pop);
+ }
+
+ ISEQ_COMPILE_DATA(iseq)->current_block = prevblock;
+
+ ADD_CATCH_ENTRY(CATCH_TYPE_BREAK, retry_label, retry_end_l, child_iseq, retry_end_l);
+ return COMPILE_OK;
+}
+
+static int
compile_break(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int popped)
{
const int line = nd_line(node);
@@ -5016,39 +5052,9 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int popp
ADD_LABEL(ret, not_single);
break;
}
- case NODE_ITER:{
- const rb_iseq_t *prevblock = ISEQ_COMPILE_DATA(iseq)->current_block;
- LABEL *retry_label = NEW_LABEL(line);
- LABEL *retry_end_l = NEW_LABEL(line);
- const rb_iseq_t *child_iseq;
-
- ADD_LABEL(ret, retry_label);
- if (nd_type(node) == NODE_FOR) {
- CHECK(COMPILE(ret, "iter caller (for)", node->nd_iter));
-
- ISEQ_COMPILE_DATA(iseq)->current_block = child_iseq =
- NEW_CHILD_ISEQ(node->nd_body, make_name_for_block(iseq),
- ISEQ_TYPE_BLOCK, line);
- ADD_SEND_WITH_BLOCK(ret, line, idEach, INT2FIX(0), child_iseq);
- }
- else {
- ISEQ_COMPILE_DATA(iseq)->current_block = child_iseq =
- NEW_CHILD_ISEQ(node->nd_body, make_name_for_block(iseq),
- ISEQ_TYPE_BLOCK, line);
- CHECK(COMPILE(ret, "iter caller", node->nd_iter));
- }
- ADD_LABEL(ret, retry_end_l);
-
- if (popped) {
- ADD_INSN(ret, line, pop);
- }
-
- ISEQ_COMPILE_DATA(iseq)->current_block = prevblock;
-
- ADD_CATCH_ENTRY(CATCH_TYPE_BREAK, retry_label, retry_end_l, child_iseq, retry_end_l);
-
+ case NODE_ITER:
+ CHECK(compile_iter(iseq, ret, node, popped));
break;
- }
case NODE_BREAK:
CHECK(compile_break(iseq, ret, node, popped));
break;