ruby-changes:55059
From: mame <ko1@a...>
Date: Fri, 15 Mar 2019 14:20:00 +0900 (JST)
Subject: [ruby-changes:55059] mame:r67266 (trunk): node.h: introduce nd_brace to determine if a hash literal is a keyword
mame 2019-03-15 14:19:54 +0900 (Fri, 15 Mar 2019) New Revision: 67266 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=67266 Log: node.h: introduce nd_brace to determine if a hash literal is a keyword NODE_HASH#nd_brace is a flag that is 1 for `foo({ k: 1 })` and 0 for `foo(k: 1)`. nd_alen had been abused for the flag (and the implementation is completely the same), but an explicit name is better to read. Modified files: trunk/compile.c trunk/node.c trunk/node.h Index: node.c =================================================================== --- node.c (revision 67265) +++ node.c (revision 67266) @@ -557,7 +557,7 @@ dump_node(VALUE buf, VALUE indent, int c https://github.com/ruby/ruby/blob/trunk/node.c#L557 return; case NODE_HASH: - if (!node->nd_alen) { + if (!node->nd_brace) { ANN("keyword arguments"); ANN("format: nd_head"); ANN("example: a: 1, b: 2"); @@ -567,8 +567,8 @@ dump_node(VALUE buf, VALUE indent, int c https://github.com/ruby/ruby/blob/trunk/node.c#L567 ANN("format: { [nd_head] }"); ANN("example: { 1 => 2, 3 => 4 }"); } - F_CUSTOM1(nd_alen, "keyword arguments or hash literal") { - switch (node->nd_alen) { + F_CUSTOM1(nd_brace, "keyword arguments or hash literal") { + switch (node->nd_brace) { case 0: A("0 (keyword argument)"); break; case 1: A("1 (hash literal)"); break; } Index: compile.c =================================================================== --- compile.c (revision 67265) +++ compile.c (revision 67266) @@ -3801,7 +3801,7 @@ compile_keyword_arg(rb_iseq_t *iseq, LIN https://github.com/ruby/ruby/blob/trunk/compile.c#L3801 assert(nd_type(node) == NODE_ARRAY); if (!key_node) { - if (flag && !root_node->nd_alen) *flag |= VM_CALL_KW_SPLAT; + if (flag && !root_node->nd_brace) *flag |= VM_CALL_KW_SPLAT; return FALSE; } else if (nd_type(key_node) == NODE_LIT && RB_TYPE_P(key_node->nd_lit, T_SYMBOL)) { @@ -4785,7 +4785,7 @@ check_keyword(const NODE *node) https://github.com/ruby/ruby/blob/trunk/compile.c#L4785 node = node->nd_head; } - if (nd_type(node) == NODE_HASH && !node->nd_alen) return TRUE; + if (nd_type(node) == NODE_HASH && !node->nd_brace) return TRUE; return FALSE; } Index: node.h =================================================================== --- node.h (revision 67265) +++ node.h (revision 67266) @@ -266,6 +266,8 @@ typedef struct RNode { https://github.com/ruby/ruby/blob/trunk/node.h#L266 #define nd_orig u2.id #define nd_undef u2.node +#define nd_brace u2.argc + #define NEW_NODE(t,a0,a1,a2,loc) rb_node_newnode((t),(VALUE)(a0),(VALUE)(a1),(VALUE)(a2),loc) #define NEW_DEFN(i,a,d,loc) NEW_NODE(NODE_DEFN,0,i,NEW_SCOPE(a,d,loc),loc) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/