From e0ef514a35586b91957b52f18d696fcaa535fc60 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 17 Oct 2017 12:05:30 +0000 Subject: 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 --- compile.c | 70 ++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 38 insertions(+), 32 deletions(-) (limited to 'compile.c') diff --git a/compile.c b/compile.c index f92eabaa13..64859c555e 100644 --- a/compile.c +++ b/compile.c @@ -4538,6 +4538,42 @@ compile_loop(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int popped, co return COMPILE_OK; } +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) { @@ -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; -- cgit v1.2.3