[前][次][番号順一覧][スレッド一覧]

ruby-changes:67529

From: Nobuyoshi <ko1@a...>
Date: Wed, 1 Sep 2021 16:17:26 +0900 (JST)
Subject: [ruby-changes:67529] aac2b0fc6b (master): Extract compile_kw_arg from iseq_compile_each0

https://git.ruby-lang.org/ruby.git/commit/?id=aac2b0fc6b

From aac2b0fc6b6262d083c791bc333e0b1919f24b7a Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
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(-)

diff --git a/compile.c b/compile.c
index ee2507d..19add8b 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, https://github.com/ruby/ruby/blob/trunk/compile.c#L8830
     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 https://github.com/ruby/ruby/blob/trunk/compile.c#L9549
 	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.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]