ruby-changes:47551
From: nobu <ko1@a...>
Date: Mon, 28 Aug 2017 01:04:32 +0900 (JST)
Subject: [ruby-changes:47551] nobu:r59667 (trunk): compile.c: compile_rescue
nobu 2017-08-28 01:04:26 +0900 (Mon, 28 Aug 2017) New Revision: 59667 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59667 Log: compile.c: compile_rescue * compile.c (compile_rescue): extract from iseq_compile_each. Modified files: trunk/compile.c Index: compile.c =================================================================== --- compile.c (revision 59666) +++ compile.c (revision 59667) @@ -4623,6 +4623,39 @@ compile_retry(rb_iseq_t *iseq, LINK_ANCH https://github.com/ruby/ruby/blob/trunk/compile.c#L4623 return COMPILE_OK; } +static int +compile_rescue(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int popped) +{ + const int line = nd_line(node); + LABEL *lstart = NEW_LABEL(line); + LABEL *lend = NEW_LABEL(line); + LABEL *lcont = NEW_LABEL(line); + const rb_iseq_t *rescue = NEW_CHILD_ISEQ(node->nd_resq, + rb_str_concat(rb_str_new2("rescue in "), iseq->body->location.label), + ISEQ_TYPE_RESCUE, line); + + lstart->rescued = LABEL_RESCUE_BEG; + lend->rescued = LABEL_RESCUE_END; + ADD_LABEL(ret, lstart); + CHECK(COMPILE(ret, "rescue head", node->nd_head)); + ADD_LABEL(ret, lend); + if (node->nd_else) { + ADD_INSN(ret, line, pop); + CHECK(COMPILE(ret, "rescue else", node->nd_else)); + } + ADD_INSN(ret, line, nop); + ADD_LABEL(ret, lcont); + + if (popped) { + ADD_INSN(ret, line, pop); + } + + /* register catch entry */ + ADD_CATCH_ENTRY(CATCH_TYPE_RESCUE, lstart, lend, rescue, lcont); + ADD_CATCH_ENTRY(CATCH_TYPE_RETRY, lend, lcont, NULL, lstart); + return COMPILE_OK; +} + static int iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int popped); /** compile each node @@ -4804,35 +4837,9 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L4837 CHECK(COMPILE_(ret, "NODE_BEGIN", node->nd_body, popped)); break; } - case NODE_RESCUE:{ - LABEL *lstart = NEW_LABEL(line); - LABEL *lend = NEW_LABEL(line); - LABEL *lcont = NEW_LABEL(line); - const rb_iseq_t *rescue = NEW_CHILD_ISEQ(node->nd_resq, - rb_str_concat(rb_str_new2("rescue in "), iseq->body->location.label), - ISEQ_TYPE_RESCUE, line); - - lstart->rescued = LABEL_RESCUE_BEG; - lend->rescued = LABEL_RESCUE_END; - ADD_LABEL(ret, lstart); - CHECK(COMPILE(ret, "rescue head", node->nd_head)); - ADD_LABEL(ret, lend); - if (node->nd_else) { - ADD_INSN(ret, line, pop); - CHECK(COMPILE(ret, "rescue else", node->nd_else)); - } - ADD_INSN(ret, line, nop); - ADD_LABEL(ret, lcont); - - if (popped) { - ADD_INSN(ret, line, pop); - } - - /* register catch entry */ - ADD_CATCH_ENTRY(CATCH_TYPE_RESCUE, lstart, lend, rescue, lcont); - ADD_CATCH_ENTRY(CATCH_TYPE_RETRY, lend, lcont, NULL, lstart); + case NODE_RESCUE: + CHECK(compile_rescue(iseq, ret, node, popped)); break; - } case NODE_RESBODY:{ NODE *resq = node; NODE *narg; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/