* defs/id.def (predefined): add idLASTLINE and idBACKREF for $~
  and $_ respectively.
* parse.y: use idLASTLINE and idBACKREF instead of rb_intern.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53856 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2016-02-17 12:42:00 +00:00
Родитель 5a6a502ef9
Коммит 0201900d76
3 изменённых файлов: 18 добавлений и 8 удалений

Просмотреть файл

@ -1,3 +1,10 @@
Wed Feb 17 21:41:29 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* defs/id.def (predefined): add idLASTLINE and idBACKREF for $~
and $_ respectively.
* parse.y: use idLASTLINE and idBACKREF instead of rb_intern.
Wed Feb 17 20:23:38 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (rb_str_init): fix segfault and memory leak, consider

Просмотреть файл

@ -62,6 +62,9 @@ firstline, predefined = __LINE__+1, %[\
core#hash_merge_kwd
- debug#created_info
$_ LASTLINE
$~ BACKREF
]
# VM ID OP Parser Token
@ -145,7 +148,7 @@ predefined.split(/^/).each_with_index do |line, num|
case name
when /\A[A-Z]\w*\z/; const_ids
when /\A(?!\d)\w+\z/; local_ids
when /\A\$(?:\d+|(?!\d)\w+)\z/; global_ids
when /\A\$(?:\d+|(?!\d)\w+|\W)\z/; global_ids
when /\A@@(?!\d)\w+\z/; class_ids
when /\A@(?!\d)\w+\z/; instance_ids
when /\A((?!\d)\w+)=\z/; attrset_ids

14
parse.y
Просмотреть файл

@ -9887,7 +9887,7 @@ cond0(struct parser_params *parser, NODE *node)
case NODE_DREGX:
case NODE_DREGX_ONCE:
warning_unless_e_option(parser, node, "regex literal in condition");
return NEW_MATCH2(node, NEW_GVAR(rb_intern("$_")));
return NEW_MATCH2(node, NEW_GVAR(idLASTLINE));
case NODE_AND:
case NODE_OR:
@ -10610,7 +10610,7 @@ reg_named_capture_assign_iter(const OnigUChar *name, const OnigUChar *name_end,
arg->succ_block = block_append(arg->succ_block,
newline_node(node_assign(assignable(var,0),
NEW_CALL(
gettable(rb_intern("$~")),
gettable(idBACKREF),
idAREF,
NEW_LIST(NEW_LIT(ID2SYM(var))))
)));
@ -10637,12 +10637,12 @@ reg_named_capture_assign_gen(struct parser_params* parser, VALUE regexp, NODE *m
return
block_append(
newline_node(match),
NEW_IF(gettable(rb_intern("$~")),
NEW_IF(gettable(idBACKREF),
block_append(
newline_node(arg.succ_block),
newline_node(
NEW_CALL(
gettable(rb_intern("$~")),
gettable(idBACKREF),
rb_intern("begin"),
NEW_LIST(NEW_LIT(INT2FIX(0)))))),
block_append(
@ -10712,7 +10712,7 @@ rb_parser_append_print(VALUE vparser, NODE *node)
node = block_append(node,
NEW_FCALL(rb_intern("print"),
NEW_ARRAY(NEW_GVAR(rb_intern("$_")))));
NEW_ARRAY(NEW_GVAR(idLASTLINE))));
if (prelude) {
prelude->nd_body = node;
scope->nd_body = prelude;
@ -10743,12 +10743,12 @@ rb_parser_while_loop(VALUE vparser, NODE *node, int chop, int split)
}
if (split) {
node = block_append(NEW_GASGN(rb_intern("$F"),
NEW_CALL(NEW_GVAR(rb_intern("$_")),
NEW_CALL(NEW_GVAR(idLASTLINE),
rb_intern("split"), 0)),
node);
}
if (chop) {
node = block_append(NEW_CALL(NEW_GVAR(rb_intern("$_")),
node = block_append(NEW_CALL(NEW_GVAR(idLASTLINE),
rb_intern("chop!"), 0), node);
}