1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* parse.y, compile.c (set_arguments): fix to support in-paren

parameter (ex: def foo((a, b))).



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12287 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2007-05-17 04:25:18 +00:00
parent 8206839659
commit ebaec402a7
3 changed files with 40 additions and 16 deletions

View file

@ -1,3 +1,8 @@
Thu May 17 13:23:38 2007 Koichi Sasada <ko1@atdot.net>
* parse.y, compile.c (set_arguments): fix to support in-paren
parameter (ex: def foo((a, b))).
Thu May 17 13:01:52 2007 Koichi Sasada <ko1@atdot.net> Thu May 17 13:01:52 2007 Koichi Sasada <ko1@atdot.net>
* iseq.c (ruby_iseq_disasm): fix to show post arg info. * iseq.c (ruby_iseq_disasm): fix to show post arg info.

View file

@ -789,9 +789,21 @@ set_arguments(rb_iseq_t *iseq, LINK_ANCHOR *optargs, NODE *node_args)
int d = iseq->local_size - iseq->local_table_size; int d = iseq->local_size - iseq->local_table_size;
if (nd_type(node_args) != NODE_ARGS) { if (nd_type(node_args) != NODE_ARGS) {
rb_bug("set_arguments: NODE_ARGS is expected, but %s", ruby_node_name(nd_type(node_args))); rb_bug("set_arguments: NODE_ARGS is expected, but %s",
ruby_node_name(nd_type(node_args)));
} }
/*
* new argument infromation:
* NODE_ARGS [m: int, o: NODE_OPT_ARG, ->]
* NODE_ARGS_AUX [r: ID, b: ID, ->]
* NODE_ARGS_AUX [Pst: id, Plen: int, init: NODE*]
* optarg information:
* NODE_OPT_ARGS [idx, expr, ->]
* init arg:
* NODE_AND(m_init, p_init)
*/
iseq->argc = node_args->nd_frml; iseq->argc = node_args->nd_frml;
debugs(" - argc: %d\n", iseq->argc); debugs(" - argc: %d\n", iseq->argc);
@ -807,10 +819,6 @@ set_arguments(rb_iseq_t *iseq, LINK_ANCHOR *optargs, NODE *node_args)
} }
} }
if (node_init) {
COMPILE_POPED(optargs, "init arguments", node_init);
}
if (node_opt) { if (node_opt) {
NODE *node = node_opt; NODE *node = node_opt;
LABEL *label; LABEL *label;
@ -843,6 +851,15 @@ set_arguments(rb_iseq_t *iseq, LINK_ANCHOR *optargs, NODE *node_args)
iseq->arg_opts = 0; iseq->arg_opts = 0;
} }
if (node_init) {
if (node_init->nd_1st) { /* m_init */
COMPILE_POPED(optargs, "init arguments (m)", node_init->nd_1st);
}
if (node_init->nd_2nd) { /* p_init */
COMPILE_POPED(optargs, "init arguments (p)", node_init->nd_2nd);
}
}
if (rest_id) { if (rest_id) {
iseq->arg_rest = get_dyna_var_idx_at_raw(iseq, rest_id) + d; iseq->arg_rest = get_dyna_var_idx_at_raw(iseq, rest_id) + d;
@ -920,7 +937,7 @@ set_arguments(rb_iseq_t *iseq, LINK_ANCHOR *optargs, NODE *node_args)
ADD_SEND (optargs, nd_line(node_args), ID2SYM(rb_intern("pop")), ADD_SEND (optargs, nd_line(node_args), ID2SYM(rb_intern("pop")),
INT2FIX(0)); INT2FIX(0));
SET_LOCAL(iseq->arg_rest + i + 1); SET_LOCAL(iseq->arg_rest + i + 1);
} }
iseq->arg_post_len = post_len; iseq->arg_post_len = post_len;
} }

22
parse.y
View file

@ -2689,16 +2689,11 @@ primary : literal
/*%%%*/ /*%%%*/
ID id = internal_id(); ID id = internal_id();
ID *tbl = ALLOC_N(ID, 2); ID *tbl = ALLOC_N(ID, 2);
NODE *args = NEW_ARGS(1 /* m */, 0 /* o */); NODE *args =new_args(NEW_NODE(NODE_ARGS_AUX, 0, 1 /* nd_plen */,
NODE *init; node_assign($2, NEW_DVAR(id))),
0, 0, 0, 0);
NODE *scope = NEW_NODE(NODE_SCOPE, tbl, $8, args); NODE *scope = NEW_NODE(NODE_SCOPE, tbl, $8, args);
tbl[0] = 1; tbl[1] = id; tbl[0] = 1; tbl[1] = id;
init = node_assign($2, NEW_DVAR(id));
args->nd_next = NEW_ARGS_AUX(0, 0);
args->nd_next->nd_next = NEW_ARGS_AUX(0, 0);
args->nd_next->nd_next->nd_next = init;
$$ = NEW_FOR(0, $5, scope); $$ = NEW_FOR(0, $5, scope);
fixpos($$, $2); fixpos($$, $2);
/*% /*%
@ -4114,7 +4109,12 @@ f_arg_item : f_norm_arg
/*%%%*/ /*%%%*/
ID tid = internal_id(); ID tid = internal_id();
arg_var(tid); arg_var(tid);
$2->nd_value = NEW_DVAR(tid); if (dyna_in_block()) {
$2->nd_value = NEW_DVAR(tid);
}
else {
$2->nd_value = NEW_LVAR(tid);
}
$$ = NEW_ARGS_AUX(tid, 1); $$ = NEW_ARGS_AUX(tid, 1);
$$->nd_next = $2; $$->nd_next = $2;
/*% /*%
@ -4128,11 +4128,12 @@ f_arg : f_arg_item
/*%c /*%c
{ {
$$ = rb_ary_new3(1, $1); $$ = rb_ary_new3(1, $1);
} n }
c%*/ c%*/
| f_arg ',' f_arg_item | f_arg ',' f_arg_item
{ {
/*%%%*/ /*%%%*/
$$ = $1;
$$->nd_plen++; $$->nd_plen++;
$$->nd_next = block_append($$->nd_next, $3->nd_next); $$->nd_next = block_append($$->nd_next, $3->nd_next);
rb_gc_force_recycle((VALUE)$3); rb_gc_force_recycle((VALUE)$3);
@ -7928,6 +7929,7 @@ new_args_gen(struct parser_params *parser, NODE *m, NODE *o, ID r, NODE *p, ID b
node = NEW_ARGS(m ? m->nd_plen : 0, o); node = NEW_ARGS(m ? m->nd_plen : 0, o);
i1 = m ? m->nd_next : 0; i1 = m ? m->nd_next : 0;
node->nd_next = NEW_ARGS_AUX(r, b); node->nd_next = NEW_ARGS_AUX(r, b);
if (p) { if (p) {
i2 = p->nd_next; i2 = p->nd_next;
node->nd_next->nd_next = NEW_ARGS_AUX(p->nd_pid, p->nd_plen); node->nd_next->nd_next = NEW_ARGS_AUX(p->nd_pid, p->nd_plen);