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

* eval.c (massign): remove unnecessary array unpacking; it should

be handled before massign() by svalue_to_mrhs().

* eval.c (svalue_to_mrhs): '*a = v' value conversion to avalue
  (i.e. [1] => [[1]], [1,2] => [1,2]).

* eval.c (rb_eval): use svalue_to_mrhs.

* eval.c (rb_yield_0): ditto.

* eval.c (proc_invoke): break from "Proc#yield" is legal.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3573 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2003-03-10 23:03:06 +00:00
parent eccf9342c7
commit 2abf664151
3 changed files with 52 additions and 31 deletions

View file

@ -1,3 +1,17 @@
Tue Mar 11 04:30:12 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* eval.c (massign): remove unnecessary array unpacking; it should
be handled before massign() by svalue_to_mrhs().
* eval.c (svalue_to_mrhs): '*a = v' value conversion to avalue
(i.e. [1] => [[1]], [1,2] => [1,2]).
* eval.c (rb_eval): use svalue_to_mrhs.
* eval.c (rb_yield_0): ditto.
* eval.c (proc_invoke): break from "Proc#yield" is legal.
Mon Mar 10 23:19:29 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
* file.c (rb_find_file): need world writable directory check for

58
eval.c
View file

@ -2221,6 +2221,25 @@ svalue_to_avalue(v)
return tmp;
}
static VALUE
svalue_to_mrhs(v, lhs)
VALUE v;
NODE *lhs;
{
VALUE tmp;
if (v == Qundef) return rb_ary_new2(0);
tmp = rb_check_array_type(v);
if (NIL_P(tmp)) {
return rb_ary_new3(1, v);
}
if (!lhs && RARRAY(tmp)->len <= 1) {
return rb_ary_new3(1, tmp);
}
return tmp;
}
static VALUE
class_prefix(self, cpath)
VALUE self;
@ -2978,7 +2997,7 @@ rb_eval(self, n)
break;
case NODE_MASGN:
result = svalue_to_avalue(rb_eval(self, node->nd_value));
result = svalue_to_mrhs(rb_eval(self, node->nd_value), node->nd_head);
result = massign(self, node, result, 0);
break;
@ -3910,7 +3929,9 @@ rb_yield_0(val, self, klass, pcall, avalue)
}
}
else if (nd_type(block->var) == NODE_MASGN) {
if (!avalue) val = svalue_to_avalue(val);
if (!avalue) {
val = svalue_to_mrhs(val, block->var->nd_head);
}
massign(self, block->var, val, pcall);
}
else {
@ -4024,34 +4045,13 @@ massign(self, node, val, pcall)
int pcall;
{
NODE *list;
VALUE tmp;
long i = 0, len;
len = RARRAY(val)->len;
list = node->nd_head;
if (len == 1 && list) {
VALUE v = RARRAY(val)->ptr[0];
tmp = rb_check_array_type(v);
if (NIL_P(tmp)) {
assign(self, list->nd_head, v, pcall);
list = list->nd_next;
i = 1;
}
else {
len = RARRAY(tmp)->len;
for (i=0; list && i<len; i++) {
assign(self, list->nd_head, RARRAY(tmp)->ptr[i], pcall);
list = list->nd_next;
}
}
}
else {
for (; list && i<len; i++) {
assign(self, list->nd_head, RARRAY(val)->ptr[i], pcall);
list = list->nd_next;
}
tmp = val;
for (; list && i<len; i++) {
assign(self, list->nd_head, RARRAY(val)->ptr[i], pcall);
list = list->nd_next;
}
if (pcall && list) goto arg_error;
if (node->nd_args) {
@ -4059,7 +4059,7 @@ massign(self, node, val, pcall)
/* no check for mere `*' */
}
else if (!list && i<len) {
assign(self, node->nd_args, rb_ary_new4(len-i, RARRAY(tmp)->ptr+i), pcall);
assign(self, node->nd_args, rb_ary_new4(len-i, RARRAY(val)->ptr+i), pcall);
}
else {
assign(self, node->nd_args, rb_ary_new2(0), pcall);
@ -6691,7 +6691,6 @@ proc_invoke(proc, args, pcall, self)
PUSH_ITER(ITER_CUR);
ruby_frame->iter = ITER_CUR;
PUSH_TAG(PROT_NONE);
state = EXEC_TAG();
if (state == 0) {
@ -6713,9 +6712,6 @@ proc_invoke(proc, args, pcall, self)
case 0:
break;
case TAG_BREAK:
if (!pcall && orphan) {
localjump_error("break from proc-closure", prot_tag->retval);
}
result = prot_tag->retval;
break;
case TAG_RETRY:

View file

@ -240,6 +240,17 @@ def r; return *[*[]]; end; a,b,*c = r(); test_ok([a,b,c] == [nil,nil,[]])
def r; return *[*[1]]; end; a,b,*c = r(); test_ok([a,b,c] == [1,nil,[]])
def r; return *[*[1,2]]; end; a,b,*c = r(); test_ok([a,b,c] == [1,2,[]])
f = lambda {|r,| test_ok([] == r)}
f.call([], *[])
f.yield([], *[])
f = lambda {|r,*l| test_ok([] == r); test_ok([1] == l)}
f.call([], *[1])
f.yield([], *[1])
a,=*[1]
test_ok(a == 1)
a = loop do break; end; test_ok(a == nil)
a = loop do break nil; end; test_ok(a == nil)
a = loop do break 1; end; test_ok(a == 1)