1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
mame 2018-01-04 12:47:22 +00:00
parent 3ec5c75594
commit 0947c2ba63
5 changed files with 17 additions and 5 deletions

View file

@ -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));

View file

@ -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);

7
node.c
View file

@ -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]");

2
node.h
View file

@ -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,

View file

@ -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;