Skip to content

Commit

Permalink
* node.h, node.c, parse.y: implement a parser part for keyword argume…
Browse files Browse the repository at this point in the history
…nts. This is a preparation for keyword argument (see [ruby-core:40290]).

* gc.c (gc_mark_children): bookkeeping.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34135 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
mame committed Dec 26, 2011
1 parent afb10c6 commit 1ab3974
Show file tree
Hide file tree
Showing 5 changed files with 650 additions and 75 deletions.
8 changes: 8 additions & 0 deletions ChangeLog
@@ -1,3 +1,11 @@
Mon Dec 26 22:00:17 2011 Yusuke Endoh <mame@tsg.ne.jp>

* node.h, node.c, parse.y: implement a parser part for keyword
arguments.
This is a preparation for keyword argument (see [ruby-core:40290]).

* gc.c (gc_mark_children): bookkeeping.

Mon Dec 26 21:03:18 2011 Yusuke Endoh <mame@tsg.ne.jp>

* node.h, parse.y (new_args_gen), compile.c (iseq_set_arguments): use
Expand Down
8 changes: 5 additions & 3 deletions gc.c
Expand Up @@ -1791,9 +1791,11 @@ gc_mark_children(rb_objspace_t *objspace, VALUE ptr, int lev)
{
struct rb_args_info *args = obj->as.node.u3.args;
if (args) {
if (args->pre_init) gc_mark(objspace, (VALUE)args->pre_init, lev);
if (args->post_init) gc_mark(objspace, (VALUE)args->post_init, lev);
if (args->opt_args) gc_mark(objspace, (VALUE)args->opt_args, lev);
if (args->pre_init) gc_mark(objspace, (VALUE)args->pre_init, lev);
if (args->post_init) gc_mark(objspace, (VALUE)args->post_init, lev);
if (args->opt_args) gc_mark(objspace, (VALUE)args->opt_args, lev);
if (args->kw_args) gc_mark(objspace, (VALUE)args->kw_args, lev);
if (args->kw_rest_arg) gc_mark(objspace, (VALUE)args->kw_rest_arg, lev);
}
}
ptr = (VALUE)obj->as.node.u2.node;
Expand Down
11 changes: 11 additions & 0 deletions node.c
Expand Up @@ -823,6 +823,15 @@ dump_node(VALUE buf, VALUE indent, int comment, NODE *node)
F_NODE(nd_next, "next");
break;

case NODE_KW_ARG:
ANN("keyword arguments");
ANN("format: def method_name([nd_body=some], [nd_next..])");
ANN("example: def foo(a:1, b:2); end");
F_NODE(nd_body, "body");
LAST_NODE;
F_NODE(nd_next, "next");
break;

case NODE_POSTARG:
ANN("post arguments");
ANN("format: *[nd_1st], [nd_2nd..] = ..");
Expand All @@ -849,6 +858,8 @@ dump_node(VALUE buf, VALUE indent, int comment, NODE *node)
F_ID(nd_ainfo->rest_arg, "rest argument");
F_ID(nd_ainfo->block_arg, "block argument");
F_NODE(nd_ainfo->opt_args, "optional arguments");
LAST_NODE;
F_NODE(nd_ainfo->kw_args, "keyword arguments");
break;

case NODE_SCOPE:
Expand Down
6 changes: 6 additions & 0 deletions node.h
Expand Up @@ -154,6 +154,8 @@ enum node_type {
#define NODE_ARGS_AUX NODE_ARGS_AUX
NODE_OPT_ARG,
#define NODE_OPT_ARG NODE_OPT_ARG
NODE_KW_ARG,
#define NODE_KW_ARG NODE_KW_ARG
NODE_POSTARG,
#define NODE_POSTARG NODE_POSTARG
NODE_ARGSCAT,
Expand Down Expand Up @@ -419,6 +421,7 @@ typedef struct RNode {
#define NEW_ZSUPER() NEW_NODE(NODE_ZSUPER,0,0,0)
#define NEW_ARGS_AUX(r,b) NEW_NODE(NODE_ARGS_AUX,r,b,0)
#define NEW_OPT_ARG(i,v) NEW_NODE(NODE_OPT_ARG,i,v,0)
#define NEW_KW_ARG(i,v) NEW_NODE(NODE_KW_ARG,i,v,0)
#define NEW_POSTARG(i,v) NEW_NODE(NODE_POSTARG,i,v,0)
#define NEW_ARGSCAT(a,b) NEW_NODE(NODE_ARGSCAT,a,b,0)
#define NEW_ARGSPUSH(a,b) NEW_NODE(NODE_ARGSPUSH,a,b,0)
Expand Down Expand Up @@ -495,6 +498,9 @@ struct rb_args_info {
ID rest_arg;
ID block_arg;

NODE *kw_args;
NODE *kw_rest_arg;

NODE *opt_args;
};

Expand Down

0 comments on commit 1ab3974

Please sign in to comment.