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:
parent
3ec5c75594
commit
0947c2ba63
5 changed files with 17 additions and 5 deletions
|
@ -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));
|
||||
|
||||
|
|
|
@ -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
7
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]");
|
||||
|
|
2
node.h
2
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,
|
||||
|
|
4
parse.y
4
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;
|
||||
|
|
Loading…
Reference in a new issue