From aac2b0fc6b6262d083c791bc333e0b1919f24b7a Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Mon, 13 Mar 2017 00:07:10 +0900 Subject: Extract compile_kw_arg from iseq_compile_each0 --- compile.c | 69 ++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 37 insertions(+), 32 deletions(-) (limited to 'compile.c') diff --git a/compile.c b/compile.c index ee2507d898..19add8b7ff 100644 --- a/compile.c +++ b/compile.c @@ -8830,6 +8830,41 @@ compile_errinfo(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, return COMPILE_OK; } +static int +compile_kw_arg(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node, int popped) +{ + struct rb_iseq_constant_body *const body = iseq->body; + LABEL *end_label = NEW_LABEL(nd_line(node)); + const NODE *default_value = node->nd_body->nd_value; + + if (default_value == NODE_SPECIAL_REQUIRED_KEYWORD) { + /* required argument. do nothing */ + COMPILE_ERROR(ERROR_ARGS "unreachable"); + return COMPILE_NG; + } + else if (nd_type(default_value) == NODE_LIT || + nd_type(default_value) == NODE_NIL || + nd_type(default_value) == NODE_TRUE || + nd_type(default_value) == NODE_FALSE) { + COMPILE_ERROR(ERROR_ARGS "unreachable"); + return COMPILE_NG; + } + else { + /* if keywordcheck(_kw_bits, nth_keyword) + * kw = default_value + * end + */ + int kw_bits_idx = body->local_table_size - body->param.keyword->bits_start; + int keyword_idx = body->param.keyword->num; + + ADD_INSN2(ret, node, checkkeyword, INT2FIX(kw_bits_idx + VM_ENV_DATA_SIZE - 1), INT2FIX(keyword_idx)); + ADD_INSNL(ret, node, branchif, end_label); + CHECK(COMPILE_POPPED(ret, "keyword default argument", node->nd_body)); + ADD_LABEL(ret, end_label); + } + 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 @@ -9514,38 +9549,8 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const no break; } case NODE_KW_ARG: - { - LABEL *end_label = NEW_LABEL(nd_line(node)); - const NODE *default_value = node->nd_body->nd_value; - - if (default_value == NODE_SPECIAL_REQUIRED_KEYWORD) { - /* required argument. do nothing */ - COMPILE_ERROR(ERROR_ARGS "unreachable"); - goto ng; - } - else if (nd_type(default_value) == NODE_LIT || - nd_type(default_value) == NODE_NIL || - nd_type(default_value) == NODE_TRUE || - nd_type(default_value) == NODE_FALSE) { - COMPILE_ERROR(ERROR_ARGS "unreachable"); - goto ng; - } - else { - /* if keywordcheck(_kw_bits, nth_keyword) - * kw = default_value - * end - */ - int kw_bits_idx = body->local_table_size - body->param.keyword->bits_start; - int keyword_idx = body->param.keyword->num; - - ADD_INSN2(ret, node, checkkeyword, INT2FIX(kw_bits_idx + VM_ENV_DATA_SIZE - 1), INT2FIX(keyword_idx)); - ADD_INSNL(ret, node, branchif, end_label); - CHECK(COMPILE_POPPED(ret, "keyword default argument", node->nd_body)); - ADD_LABEL(ret, end_label); - } - - break; - } + CHECK(compile_kw_arg(iseq, ret, node, popped)); + break; case NODE_DSYM:{ compile_dstr(iseq, ret, node); if (!popped) { -- cgit v1.2.3