should splat and iterate elements when "*ary" speficied in the case-when clause; close #1627

parent 2122cf48
...@@ -1111,6 +1111,22 @@ mrb_ary_eql(mrb_state *mrb, mrb_value ary1) ...@@ -1111,6 +1111,22 @@ mrb_ary_eql(mrb_state *mrb, mrb_value ary1)
return mrb_true_value(); return mrb_true_value();
} }
static mrb_value
mrb_ary_ceqq(mrb_state *mrb, mrb_value ary)
{
mrb_value v;
mrb_int i, len;
mrb_sym eqq = mrb_intern_lit(mrb, "===");
mrb_get_args(mrb, "o", &v);
len = RARRAY_LEN(ary);
for (i=0; i<len; i++) {
mrb_value c = mrb_funcall_argv(mrb, ary_elt(ary, i), eqq, 1, &v);
if (mrb_test(c)) return mrb_true_value();
}
return mrb_false_value();
}
void void
mrb_init_array(mrb_state *mrb) mrb_init_array(mrb_state *mrb)
{ {
...@@ -1153,4 +1169,5 @@ mrb_init_array(mrb_state *mrb) ...@@ -1153,4 +1169,5 @@ mrb_init_array(mrb_state *mrb)
mrb_define_method(mrb, a, "==", mrb_ary_equal, MRB_ARGS_REQ(1)); /* 15.2.12.5.33 (x) */ mrb_define_method(mrb, a, "==", mrb_ary_equal, MRB_ARGS_REQ(1)); /* 15.2.12.5.33 (x) */
mrb_define_method(mrb, a, "eql?", mrb_ary_eql, MRB_ARGS_REQ(1)); /* 15.2.12.5.34 (x) */ mrb_define_method(mrb, a, "eql?", mrb_ary_eql, MRB_ARGS_REQ(1)); /* 15.2.12.5.34 (x) */
mrb_define_method(mrb, a, "<=>", mrb_ary_cmp, MRB_ARGS_REQ(1)); /* 15.2.12.5.36 (x) */ mrb_define_method(mrb, a, "<=>", mrb_ary_cmp, MRB_ARGS_REQ(1)); /* 15.2.12.5.36 (x) */
mrb_define_method(mrb, a, "__case_eqq", mrb_ary_ceqq, MRB_ARGS_REQ(1)); /* internal */
} }
...@@ -1386,7 +1386,12 @@ codegen(codegen_scope *s, node *tree, int val) ...@@ -1386,7 +1386,12 @@ codegen(codegen_scope *s, node *tree, int val)
if (head) { if (head) {
genop(s, MKOP_AB(OP_MOVE, cursp(), head)); genop(s, MKOP_AB(OP_MOVE, cursp(), head));
pop(); pop();
genop(s, MKOP_ABC(OP_SEND, cursp(), new_msym(s, mrb_intern_lit(s->mrb, "===")), 1)); if ((intptr_t)n->car->car == NODE_SPLAT) {
genop(s, MKOP_ABC(OP_SEND, cursp(), new_msym(s, mrb_intern_lit(s->mrb, "__case_eqq")), 1));
}
else {
genop(s, MKOP_ABC(OP_SEND, cursp(), new_msym(s, mrb_intern_lit(s->mrb, "===")), 1));
}
} }
else { else {
pop(); pop();
...@@ -1510,7 +1515,14 @@ codegen(codegen_scope *s, node *tree, int val) ...@@ -1510,7 +1515,14 @@ codegen(codegen_scope *s, node *tree, int val)
break; break;
case NODE_SPLAT: case NODE_SPLAT:
codegen(s, tree, VAL); {
int idx = new_msym(s, mrb_intern_lit(s->mrb, "to_a"));
codegen(s, tree, VAL);
pop();
genop(s, MKOP_ABC(OP_SEND, cursp(), idx, 0));
push();
}
break; break;
case NODE_ASGN: case NODE_ASGN:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment