ruby-changes:67524
From: Nobuyoshi <ko1@a...>
Date: Wed, 1 Sep 2021 16:17:24 +0900 (JST)
Subject: [ruby-changes:67524] a92fdc90da (master): Extract compile_yield from iseq_compile_each0
https://git.ruby-lang.org/ruby.git/commit/?id=a92fdc90da From a92fdc90da26be883b71e1f225034237991c5929 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Sun, 12 Mar 2017 19:31:28 +0900 Subject: Extract compile_yield from iseq_compile_each0 --- compile.c | 94 +++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 46 insertions(+), 48 deletions(-) diff --git a/compile.c b/compile.c index 6449b80..3e2f6ef 100644 --- a/compile.c +++ b/compile.c @@ -8617,6 +8617,50 @@ compile_super(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, i https://github.com/ruby/ruby/blob/trunk/compile.c#L8617 return COMPILE_OK; } +static int +compile_yield(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, int popped) +{ + DECL_ANCHOR(args); + VALUE argc; + unsigned int flag = 0; + struct rb_callinfo_kwarg *keywords = NULL; + + INIT_ANCHOR(args); + + switch (iseq->body->local_iseq->body->type) { + case ISEQ_TYPE_TOP: + case ISEQ_TYPE_MAIN: + case ISEQ_TYPE_CLASS: + COMPILE_ERROR(ERROR_ARGS "Invalid yield"); + return COMPILE_NG; + default: /* valid */; + } + + if (node->nd_head) { + argc = setup_args(iseq, args, node->nd_head, &flag, &keywords); + CHECK(!NIL_P(argc)); + } + else { + argc = INT2FIX(0); + } + + ADD_SEQ(ret, args); + ADD_INSN1(ret, node, invokeblock, new_callinfo(iseq, 0, FIX2INT(argc), flag, keywords, FALSE)); + + if (popped) { + ADD_INSN(ret, node, pop); + } + + int level = 0; + const rb_iseq_t *tmp_iseq = iseq; + for (; tmp_iseq != iseq->body->local_iseq; level++ ) { + tmp_iseq = tmp_iseq->body->parent_iseq; + } + if (level > 0) access_outer_variables(iseq, level, rb_intern("yield"), true); + + return COMPILE_OK; +} + static int iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, int popped); /** compile each node @@ -8642,19 +8686,6 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, const NODE *node, int poppe https://github.com/ruby/ruby/blob/trunk/compile.c#L8686 } static int -check_yield_place(const rb_iseq_t *iseq) -{ - switch (iseq->body->local_iseq->body->type) { - case ISEQ_TYPE_TOP: - case ISEQ_TYPE_MAIN: - case ISEQ_TYPE_CLASS: - return FALSE; - default: - return TRUE; - } -} - -static int iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, int popped) { const int line = (int)nd_line(node); @@ -8897,42 +8928,9 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const no https://github.com/ruby/ruby/blob/trunk/compile.c#L8928 case NODE_RETURN: CHECK(compile_return(iseq, ret, node, popped)); break; - case NODE_YIELD:{ - DECL_ANCHOR(args); - VALUE argc; - unsigned int flag = 0; - struct rb_callinfo_kwarg *keywords = NULL; - - INIT_ANCHOR(args); - - if (check_yield_place(iseq) == FALSE) { - COMPILE_ERROR(ERROR_ARGS "Invalid yield"); - goto ng; - } - - if (node->nd_head) { - argc = setup_args(iseq, args, node->nd_head, &flag, &keywords); - CHECK(!NIL_P(argc)); - } - else { - argc = INT2FIX(0); - } - - ADD_SEQ(ret, args); - ADD_INSN1(ret, node, invokeblock, new_callinfo(iseq, 0, FIX2INT(argc), flag, keywords, FALSE)); - - if (popped) { - ADD_INSN(ret, node, pop); - } - - int level = 0; - const rb_iseq_t *tmp_iseq = iseq; - for (; tmp_iseq != iseq->body->local_iseq; level++ ) { - tmp_iseq = tmp_iseq->body->parent_iseq; - } - if (level > 0) access_outer_variables(iseq, level, rb_intern("yield"), true); + case NODE_YIELD: + CHECK(compile_yield(iseq, ret, node, popped)); break; - } case NODE_LVAR:{ if (!popped) { compile_lvar(iseq, ret, node, node->nd_vid); -- cgit v1.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/