* 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:
parent
eccf9342c7
commit
2abf664151
14
ChangeLog
14
ChangeLog
@ -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>
|
Mon Mar 10 23:19:29 2003 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* file.c (rb_find_file): need world writable directory check for
|
* file.c (rb_find_file): need world writable directory check for
|
||||||
|
52
eval.c
52
eval.c
@ -2221,6 +2221,25 @@ svalue_to_avalue(v)
|
|||||||
return tmp;
|
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
|
static VALUE
|
||||||
class_prefix(self, cpath)
|
class_prefix(self, cpath)
|
||||||
VALUE self;
|
VALUE self;
|
||||||
@ -2978,7 +2997,7 @@ rb_eval(self, n)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case NODE_MASGN:
|
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);
|
result = massign(self, node, result, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -3910,7 +3929,9 @@ rb_yield_0(val, self, klass, pcall, avalue)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (nd_type(block->var) == NODE_MASGN) {
|
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);
|
massign(self, block->var, val, pcall);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -4024,42 +4045,21 @@ massign(self, node, val, pcall)
|
|||||||
int pcall;
|
int pcall;
|
||||||
{
|
{
|
||||||
NODE *list;
|
NODE *list;
|
||||||
VALUE tmp;
|
|
||||||
long i = 0, len;
|
long i = 0, len;
|
||||||
|
|
||||||
len = RARRAY(val)->len;
|
len = RARRAY(val)->len;
|
||||||
list = node->nd_head;
|
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++) {
|
for (; list && i<len; i++) {
|
||||||
assign(self, list->nd_head, RARRAY(val)->ptr[i], pcall);
|
assign(self, list->nd_head, RARRAY(val)->ptr[i], pcall);
|
||||||
list = list->nd_next;
|
list = list->nd_next;
|
||||||
}
|
}
|
||||||
tmp = val;
|
|
||||||
}
|
|
||||||
if (pcall && list) goto arg_error;
|
if (pcall && list) goto arg_error;
|
||||||
if (node->nd_args) {
|
if (node->nd_args) {
|
||||||
if (node->nd_args == (NODE*)-1) {
|
if (node->nd_args == (NODE*)-1) {
|
||||||
/* no check for mere `*' */
|
/* no check for mere `*' */
|
||||||
}
|
}
|
||||||
else if (!list && i<len) {
|
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 {
|
else {
|
||||||
assign(self, node->nd_args, rb_ary_new2(0), pcall);
|
assign(self, node->nd_args, rb_ary_new2(0), pcall);
|
||||||
@ -6691,7 +6691,6 @@ proc_invoke(proc, args, pcall, self)
|
|||||||
|
|
||||||
PUSH_ITER(ITER_CUR);
|
PUSH_ITER(ITER_CUR);
|
||||||
ruby_frame->iter = ITER_CUR;
|
ruby_frame->iter = ITER_CUR;
|
||||||
|
|
||||||
PUSH_TAG(PROT_NONE);
|
PUSH_TAG(PROT_NONE);
|
||||||
state = EXEC_TAG();
|
state = EXEC_TAG();
|
||||||
if (state == 0) {
|
if (state == 0) {
|
||||||
@ -6713,9 +6712,6 @@ proc_invoke(proc, args, pcall, self)
|
|||||||
case 0:
|
case 0:
|
||||||
break;
|
break;
|
||||||
case TAG_BREAK:
|
case TAG_BREAK:
|
||||||
if (!pcall && orphan) {
|
|
||||||
localjump_error("break from proc-closure", prot_tag->retval);
|
|
||||||
}
|
|
||||||
result = prot_tag->retval;
|
result = prot_tag->retval;
|
||||||
break;
|
break;
|
||||||
case TAG_RETRY:
|
case TAG_RETRY:
|
||||||
|
@ -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]]; 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,[]])
|
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; end; test_ok(a == nil)
|
||||||
a = loop do break nil; 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)
|
a = loop do break 1; end; test_ok(a == 1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user