mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Change NODE layout for pattern matching
I prefer pconst to be the first element of NODE. Before: | ARYPTN | FNDPTN | HSHPTN ---+--------+--------+----------- u1 | imemo | imemo | pkwargs u2 | pconst | pconst | pconst u3 | apinfo | fpinfo | pkwrestarg After: | ARYPTN | FNDPTN | HSHPTN ---+--------+--------+----------- u1 | pconst | pconst | pconst u2 | imemo | imemo | pkwargs u3 | apinfo | fpinfo | pkwrestarg
This commit is contained in:
parent
305c79af2f
commit
e03e1982bd
3 changed files with 11 additions and 7 deletions
8
node.c
8
node.c
|
@ -1328,9 +1328,11 @@ mark_ast_value(void *ctx, NODE * node)
|
|||
case NODE_DXSTR:
|
||||
case NODE_DREGX:
|
||||
case NODE_DSYM:
|
||||
rb_gc_mark_movable(node->nd_lit);
|
||||
break;
|
||||
case NODE_ARYPTN:
|
||||
case NODE_FNDPTN:
|
||||
rb_gc_mark_movable(node->nd_lit);
|
||||
rb_gc_mark_movable(node->nd_rval);
|
||||
break;
|
||||
default:
|
||||
rb_bug("unreachable node %s", ruby_node_name(nd_type(node)));
|
||||
|
@ -1355,9 +1357,11 @@ update_ast_value(void *ctx, NODE * node)
|
|||
case NODE_DXSTR:
|
||||
case NODE_DREGX:
|
||||
case NODE_DSYM:
|
||||
node->nd_lit = rb_gc_location(node->nd_lit);
|
||||
break;
|
||||
case NODE_ARYPTN:
|
||||
case NODE_FNDPTN:
|
||||
node->nd_lit = rb_gc_location(node->nd_lit);
|
||||
node->nd_rval = rb_gc_location(node->nd_rval);
|
||||
break;
|
||||
default:
|
||||
rb_bug("unreachable");
|
||||
|
|
4
node.h
4
node.h
|
@ -273,8 +273,8 @@ typedef struct RNode {
|
|||
|
||||
#define nd_brace u2.argc
|
||||
|
||||
#define nd_pkwargs u1.node
|
||||
#define nd_pconst u2.node
|
||||
#define nd_pconst u1.node
|
||||
#define nd_pkwargs u2.node
|
||||
#define nd_pkwrestarg u3.node
|
||||
|
||||
#define nd_apinfo u3.apinfo
|
||||
|
|
6
parse.y
6
parse.y
|
@ -11606,7 +11606,7 @@ new_array_pattern_tail(struct parser_params *p, NODE *pre_args, int has_rest, ID
|
|||
VALUE tmpbuf = rb_imemo_tmpbuf_auto_free_pointer();
|
||||
struct rb_ary_pattern_info *apinfo = ZALLOC(struct rb_ary_pattern_info);
|
||||
rb_imemo_tmpbuf_set_ptr(tmpbuf, apinfo);
|
||||
node = NEW_NODE(NODE_ARYPTN, tmpbuf, 0, apinfo, loc);
|
||||
node = NEW_NODE(NODE_ARYPTN, 0, tmpbuf, apinfo, loc);
|
||||
RB_OBJ_WRITTEN(p->ast, Qnil, tmpbuf);
|
||||
|
||||
apinfo->pre_args = pre_args;
|
||||
|
@ -11645,7 +11645,7 @@ new_find_pattern_tail(struct parser_params *p, ID pre_rest_arg, NODE *args, ID p
|
|||
VALUE tmpbuf = rb_imemo_tmpbuf_auto_free_pointer();
|
||||
struct rb_fnd_pattern_info *fpinfo = ZALLOC(struct rb_fnd_pattern_info);
|
||||
rb_imemo_tmpbuf_set_ptr(tmpbuf, fpinfo);
|
||||
node = NEW_NODE(NODE_FNDPTN, tmpbuf, 0, fpinfo, loc);
|
||||
node = NEW_NODE(NODE_FNDPTN, 0, tmpbuf, fpinfo, loc);
|
||||
RB_OBJ_WRITTEN(p->ast, Qnil, tmpbuf);
|
||||
|
||||
fpinfo->pre_rest_arg = pre_rest_arg ? assignable(p, pre_rest_arg, 0, loc) : NODE_SPECIAL_NO_NAME_REST;
|
||||
|
@ -11679,7 +11679,7 @@ new_hash_pattern_tail(struct parser_params *p, NODE *kw_args, ID kw_rest_arg, co
|
|||
kw_rest_arg_node = NULL;
|
||||
}
|
||||
|
||||
node = NEW_NODE(NODE_HSHPTN, kw_args, 0, kw_rest_arg_node, loc);
|
||||
node = NEW_NODE(NODE_HSHPTN, 0, kw_args, kw_rest_arg_node, loc);
|
||||
|
||||
p->ruby_sourceline = saved_line;
|
||||
return node;
|
||||
|
|
Loading…
Reference in a new issue