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; break;
} }
case NODE_SCOPE:{ case NODE_ONCE:{
int ic_index = iseq->body->is_size++; int ic_index = iseq->body->is_size++;
const rb_iseq_t *block_iseq = NEW_CHILD_ISEQ(node, make_name_for_block(iseq), NODE tmp_node;
ISEQ_TYPE_ONCE_GUARD, line); 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)); 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_DXSTR);
COUNT_NODE(NODE_EVSTR); COUNT_NODE(NODE_EVSTR);
COUNT_NODE(NODE_DREGX); COUNT_NODE(NODE_DREGX);
COUNT_NODE(NODE_ONCE);
COUNT_NODE(NODE_ARGS); COUNT_NODE(NODE_ARGS);
COUNT_NODE(NODE_ARGS_AUX); COUNT_NODE(NODE_ARGS_AUX);
COUNT_NODE(NODE_OPT_ARG); 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"); F_LIT(nd_lit, "literal");
return; 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: case NODE_DSTR:
ANN("string literal with interpolation"); ANN("string literal with interpolation");
ANN("format: [nd_lit]"); ANN("format: [nd_lit]");

2
node.h
View File

@ -150,6 +150,8 @@ enum node_type {
#define NODE_EVSTR NODE_EVSTR #define NODE_EVSTR NODE_EVSTR
NODE_DREGX, NODE_DREGX,
#define NODE_DREGX NODE_DREGX #define NODE_DREGX NODE_DREGX
NODE_ONCE,
#define NODE_ONCE NODE_ONCE
NODE_ARGS, NODE_ARGS,
#define NODE_ARGS NODE_ARGS #define NODE_ARGS NODE_ARGS
NODE_ARGS_AUX, 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; 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* static NODE*
match_op_gen(struct parser_params *parser, NODE *node1, NODE *node2, const YYLTYPE *op_loc, const YYLTYPE *location) 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)); add_mark_object(node->nd_lit = reg_compile(src, options));
} }
if (options & RE_OPTION_ONCE) { 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); nd_set_loc(node, location);
} }
break; break;