ruby-changes:49482
From: mame <ko1@a...>
Date: Thu, 4 Jan 2018 21:47:34 +0900 (JST)
Subject: [ruby-changes:49482] mame:r61597 (trunk): node.h: add NODE_ONCE instead of reuse of NODE_SCOPE
mame 2018-01-04 21:47:22 +0900 (Thu, 04 Jan 2018) New Revision: 61597 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61597 Log: node.h: add NODE_ONCE instead of reuse of NODE_SCOPE Modified files: trunk/compile.c trunk/ext/objspace/objspace.c trunk/node.c trunk/node.h trunk/parse.y Index: compile.c =================================================================== --- compile.c (revision 61596) +++ compile.c (revision 61597) @@ -6619,10 +6619,12 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK https://github.com/ruby/ruby/blob/trunk/compile.c#L6619 } 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)); Index: parse.y =================================================================== --- parse.y (revision 61596) +++ parse.y (revision 61597) @@ -9322,7 +9322,7 @@ new_qcall_gen(struct parser_params* pars https://github.com/ruby/ruby/blob/trunk/parse.y#L9322 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 *par https://github.com/ruby/ruby/blob/trunk/parse.y#L9564 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; Index: ext/objspace/objspace.c =================================================================== --- ext/objspace/objspace.c (revision 61596) +++ ext/objspace/objspace.c (revision 61597) @@ -436,6 +436,7 @@ count_nodes(int argc, VALUE *argv, VALUE https://github.com/ruby/ruby/blob/trunk/ext/objspace/objspace.c#L436 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); Index: node.c =================================================================== --- node.c (revision 61596) +++ node.c (revision 61597) @@ -716,6 +716,13 @@ dump_node(VALUE buf, VALUE indent, int c https://github.com/ruby/ruby/blob/trunk/node.c#L716 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]"); Index: node.h =================================================================== --- node.h (revision 61596) +++ node.h (revision 61597) @@ -150,6 +150,8 @@ enum node_type { https://github.com/ruby/ruby/blob/trunk/node.h#L150 #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, -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/