summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-04 12:47:22 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-01-04 12:47:22 +0000
commit0947c2ba63d6f0da53a181edb98c0cde77142670 (patch)
treecd6912441ff0f62bb1a5dcface427b83c68a4d3e
parent3ec5c75594720a0b4ddb515a301c1fbc29539541 (diff)
node.h: add NODE_ONCE instead of reuse of NODE_SCOPE
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61597 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--compile.c8
-rw-r--r--ext/objspace/objspace.c1
-rw-r--r--node.c7
-rw-r--r--node.h2
-rw-r--r--parse.y4
5 files changed, 17 insertions, 5 deletions
diff --git a/compile.c b/compile.c
index 9f79a727b5..b876d9ab98 100644
--- a/compile.c
+++ b/compile.c
@@ -6619,10 +6619,12 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, in
}
break;
}
- case NODE_SCOPE:{
+ case NODE_ONCE:{
int ic_index = iseq->body->is_size++;
- const rb_iseq_t *block_iseq = NEW_CHILD_ISEQ(node, make_name_for_block(iseq),
- ISEQ_TYPE_ONCE_GUARD, line);
+ NODE tmp_node;
+ const rb_iseq_t *block_iseq;
+ rb_node_init(&tmp_node, NODE_SCOPE, 0, (VALUE)node->nd_body, 0);
+ block_iseq = NEW_CHILD_ISEQ(&tmp_node, make_name_for_block(iseq), ISEQ_TYPE_ONCE_GUARD, line);
ADD_INSN2(ret, line, once, block_iseq, INT2FIX(ic_index));
diff --git a/ext/objspace/objspace.c b/ext/objspace/objspace.c
index d5e86353f1..490ff714d0 100644
--- a/ext/objspace/objspace.c
+++ b/ext/objspace/objspace.c
@@ -436,6 +436,7 @@ count_nodes(int argc, VALUE *argv, VALUE os)
COUNT_NODE(NODE_DXSTR);
COUNT_NODE(NODE_EVSTR);
COUNT_NODE(NODE_DREGX);
+ COUNT_NODE(NODE_ONCE);
COUNT_NODE(NODE_ARGS);
COUNT_NODE(NODE_ARGS_AUX);
COUNT_NODE(NODE_OPT_ARG);
diff --git a/node.c b/node.c
index 23b15c2dbc..dfbfc9eb44 100644
--- a/node.c
+++ b/node.c
@@ -716,6 +716,13 @@ dump_node(VALUE buf, VALUE indent, int comment, NODE *node)
F_LIT(nd_lit, "literal");
return;
+ case NODE_ONCE:
+ ANN("once evaluation");
+ ANN("format: [nd_body]");
+ ANN("example: /foo#{ bar }baz/o");
+ LAST_NODE;
+ F_NODE(nd_body, "body");
+ return;
case NODE_DSTR:
ANN("string literal with interpolation");
ANN("format: [nd_lit]");
diff --git a/node.h b/node.h
index 9730edeea2..12f4d423a8 100644
--- a/node.h
+++ b/node.h
@@ -150,6 +150,8 @@ enum node_type {
#define NODE_EVSTR NODE_EVSTR
NODE_DREGX,
#define NODE_DREGX NODE_DREGX
+ NODE_ONCE,
+#define NODE_ONCE NODE_ONCE
NODE_ARGS,
#define NODE_ARGS NODE_ARGS
NODE_ARGS_AUX,
diff --git a/parse.y b/parse.y
index d6477fe5f1..6e168e72f1 100644
--- a/parse.y
+++ b/parse.y
@@ -9322,7 +9322,7 @@ new_qcall_gen(struct parser_params* parser, ID atype, NODE *recv, ID mid, NODE *
return qcall;
}
-#define nd_once_body(node) (nd_type(node) == NODE_SCOPE ? (node)->nd_body : node)
+#define nd_once_body(node) (nd_type(node) == NODE_ONCE ? (node)->nd_body : node)
static NODE*
match_op_gen(struct parser_params *parser, NODE *node1, NODE *node2, const YYLTYPE *op_loc, const YYLTYPE *location)
{
@@ -9564,7 +9564,7 @@ new_regexp_gen(struct parser_params *parser, NODE *node, int options, const YYLT
add_mark_object(node->nd_lit = reg_compile(src, options));
}
if (options & RE_OPTION_ONCE) {
- node = NEW_NODE(NODE_SCOPE, 0, node, 0);
+ node = NEW_NODE(NODE_ONCE, 0, node, 0);
nd_set_loc(node, location);
}
break;