summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMasamitsu MURASE <[email protected]>2013-01-20 17:05:43 +0900
committerMasamitsu MURASE <[email protected]>2013-01-20 17:44:28 +0900
commit7195fb871665c8b286c76ae0935372c8f5d8f8bc (patch)
treeeb4c2f813ed168642ce5a76ddf9bcf65848e3020
parent583983385b81c21f82704b116eab52d606a609f4 (diff)
downloadmruby-7195fb871665c8b286c76ae0935372c8f5d8f8bc.tar.gz
mruby-7195fb871665c8b286c76ae0935372c8f5d8f8bc.zip
Modify handling of NODE_UNDEF to accept multiple arguments.
-rw-r--r--src/codegen.c17
-rw-r--r--src/parse.y25
2 files changed, 24 insertions, 18 deletions
diff --git a/src/codegen.c b/src/codegen.c
index e728da4ca..5c3614814 100644
--- a/src/codegen.c
+++ b/src/codegen.c
@@ -1938,16 +1938,21 @@ codegen(codegen_scope *s, node *tree, int val)
case NODE_UNDEF:
{
- int sym = new_msym(s, sym(tree));
int undef = new_msym(s, mrb_intern(s->mrb, "undef_method"));
+ int num = 0;
+ node *t = tree;
genop(s, MKOP_A(OP_TCLASS, cursp()));
push();
- genop(s, MKOP_ABx(OP_LOADSYM, cursp(), sym));
- push();
- genop(s, MKOP_A(OP_LOADNIL, cursp()));
- pop_n(2);
- genop(s, MKOP_ABC(OP_SEND, cursp(), undef, 2));
+ while (t) {
+ int symbol = new_msym(s, sym(t->car));
+ genop(s, MKOP_ABx(OP_LOADSYM, cursp(), symbol));
+ push();
+ t = t->cdr;
+ num++;
+ }
+ pop_n(num + 1);
+ genop(s, MKOP_ABC(OP_SEND, cursp(), undef, num));
if (val) {
push();
}
diff --git a/src/parse.y b/src/parse.y
index 403db1cc8..a2864b02c 100644
--- a/src/parse.y
+++ b/src/parse.y
@@ -570,7 +570,7 @@ new_const(parser_state *p, mrb_sym sym)
static node*
new_undef(parser_state *p, mrb_sym sym)
{
- return cons((node*)NODE_UNDEF, nsym(sym));
+ return list2((node*)NODE_UNDEF, nsym(sym));
}
// (:class class super body)
@@ -917,7 +917,7 @@ var_reference(parser_state *p, node *lhs)
%type <nd> assoc_list assocs assoc undef_list backref for_var
%type <nd> block_param opt_block_param block_param_def f_opt
%type <nd> bv_decls opt_bv_decl bvar f_larglist lambda_body
-%type <nd> brace_block cmd_brace_block do_block lhs none fitem f_bad_arg
+%type <nd> brace_block cmd_brace_block do_block lhs none f_bad_arg
%type <nd> mlhs mlhs_list mlhs_post mlhs_basic mlhs_item mlhs_node mlhs_inner
%type <id> fsym sym basic_symbol operation operation2 operation3
%type <id> cname fname op f_rest_arg f_block_arg opt_f_block_arg f_norm_arg
@@ -1485,19 +1485,13 @@ fsym : fname
| basic_symbol
;
-fitem : fsym
- {
- $$ = new_sym(p, $1);
- }
- ;
-
undef_list : fsym
{
$$ = new_undef(p, $1);
}
- | undef_list ',' {p->lstate = EXPR_FNAME;} fitem
+ | undef_list ',' {p->lstate = EXPR_FNAME;} fsym
{
- $$ = push($1, (node*)$4);
+ $$ = push($1, nsym($4));
}
;
@@ -5458,8 +5452,15 @@ parser_dump(mrb_state *mrb, node *tree, int offset)
break;
case NODE_UNDEF:
- printf("NODE_UNDEF %s:\n",
- mrb_sym2name(mrb, sym(tree)));
+ printf("NODE_UNDEF");
+ {
+ node *t = tree;
+ while (t) {
+ printf(" %s", mrb_sym2name(mrb, sym(t->car)));
+ t = t->cdr;
+ }
+ }
+ printf(":\n");
break;
case NODE_CLASS: