diff options
-rw-r--r-- | ChangeLog | 14 | ||||
-rw-r--r-- | eval.c | 58 | ||||
-rw-r--r-- | sample/test.rb | 11 |
3 files changed, 52 insertions, 31 deletions
@@ -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 @@ -2222,6 +2222,25 @@ svalue_to_avalue(v) } 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; NODE *cpath; @@ -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: diff --git a/sample/test.rb b/sample/test.rb index 141575bc90..247518c75e 100644 --- a/sample/test.rb +++ b/sample/test.rb @@ -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) |