summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKazuki Tsujimoto <kazuki@callcc.net>2020-11-01 16:19:07 +0900
committerKazuki Tsujimoto <kazuki@callcc.net>2020-11-01 16:19:07 +0900
commite03e1982bdc2d815298b211d44534908d79aec4e (patch)
treeedb06eabeb1365fb33cdd7702fcf59499df26fa2
parent305c79af2f3358f3c330b00c6a883634894bc35c (diff)
downloadruby-e03e1982bdc2d815298b211d44534908d79aec4e.tar.gz
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
-rw-r--r--node.c8
-rw-r--r--node.h4
-rw-r--r--parse.y6
3 files changed, 11 insertions, 7 deletions
diff --git a/node.c b/node.c
index b68d9c1cfe..9b4255bf4a 100644
--- a/node.c
+++ b/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");
diff --git a/node.h b/node.h
index 3b8b3313f2..d9dfaa5c2d 100644
--- a/node.h
+++ b/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
diff --git a/parse.y b/parse.y
index 98fd4ae921..87ec408b26 100644
--- a/parse.y
+++ b/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;