mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* vm.c (th_yield_setup_args): |v| should work as |v,|.
ex) def m;yield 1, 2; end; m{|v| p v} #=> 1 * parse.y: apply above change for "for" statement. * test/ruby/test_assignment.rb: ditto * test/ruby/test_basicinstructions.rb: ditto. * test/ruby/test_iterator.rb: ditto. * test/ruby/test_yield.rb: ditto. * compile.c (iseq_compile_each): fix debug. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12544 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
70df6311af
commit
7567fbf080
8 changed files with 75 additions and 34 deletions
17
ChangeLog
17
ChangeLog
|
@ -1,3 +1,20 @@
|
|||
Fri Jun 15 12:25:33 2007 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* vm.c (th_yield_setup_args): |v| should work as |v,|.
|
||||
ex) def m;yield 1, 2; end; m{|v| p v} #=> 1
|
||||
|
||||
* parse.y: apply above change for "for" statement.
|
||||
|
||||
* test/ruby/test_assignment.rb: ditto
|
||||
|
||||
* test/ruby/test_basicinstructions.rb: ditto.
|
||||
|
||||
* test/ruby/test_iterator.rb: ditto.
|
||||
|
||||
* test/ruby/test_yield.rb: ditto.
|
||||
|
||||
* compile.c (iseq_compile_each): fix debug.
|
||||
|
||||
Fri Jun 15 12:22:10 2007 Koichi Sasada <ko1@atdot.net>
|
||||
|
||||
* eval.c (ruby_finalize_1): rb_thread_t#errinfo should be clear with
|
||||
|
|
|
@ -3232,7 +3232,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
|
|||
case NODE_DASGN_CURR:{
|
||||
int idx, lv, ls;
|
||||
COMPILE(ret, "dvalue", node->nd_value);
|
||||
debugp_param("dassn id", rb_str_new2(rb_id2name(node->nd_vid)));
|
||||
debugp_param("dassn id", rb_str_new2(rb_id2name(node->nd_vid) ? rb_id2name(node->nd_vid) : "*"));
|
||||
|
||||
if (!poped) {
|
||||
ADD_INSN(ret, nd_line(node), dup);
|
||||
|
|
42
parse.y
42
parse.y
|
@ -2691,12 +2691,46 @@ primary : literal
|
|||
keyword_end
|
||||
{
|
||||
/*%%%*/
|
||||
/*
|
||||
* for a, b, c in e
|
||||
* #=>
|
||||
* e.each{|*x| a, b, c = x
|
||||
*
|
||||
* for a in e
|
||||
* #=>
|
||||
* e.each{|x| a, = x}
|
||||
*/
|
||||
ID id = internal_id();
|
||||
ID *tbl = ALLOC_N(ID, 2);
|
||||
NODE *args =new_args(NEW_NODE(NODE_ARGS_AUX, 0, 1 /* nd_plen */,
|
||||
node_assign($2, NEW_DVAR(id))),
|
||||
0, 0, 0, 0);
|
||||
NODE *scope = NEW_NODE(NODE_SCOPE, tbl, $8, args);
|
||||
NODE *m = NEW_ARGS_AUX(0, 0);
|
||||
NODE *args, *scope;
|
||||
|
||||
if (nd_type($2) == NODE_MASGN) {
|
||||
/* if args.length == 1 && args[0].kind_of?(Array)
|
||||
* args = args[0]
|
||||
* end
|
||||
*/
|
||||
NODE *one = NEW_LIST(NEW_LIT(INT2FIX(1)));
|
||||
NODE *zero = NEW_LIST(NEW_LIT(INT2FIX(0)));
|
||||
m->nd_next = block_append(
|
||||
NEW_IF(cond(
|
||||
NEW_NODE(NODE_AND,
|
||||
NEW_CALL(NEW_CALL(NEW_DVAR(id), rb_intern("length"), 0),
|
||||
rb_intern("=="), one),
|
||||
NEW_CALL(NEW_CALL(NEW_DVAR(id), rb_intern("[]"), zero),
|
||||
rb_intern("kind_of?"), NEW_LIST(NEW_LIT(rb_cArray))),
|
||||
0)),
|
||||
NEW_DASGN_CURR(id,
|
||||
NEW_CALL(NEW_DVAR(id), rb_intern("[]"), zero)),
|
||||
0),
|
||||
node_assign($2, NEW_DVAR(id)));
|
||||
}
|
||||
else {
|
||||
m->nd_next = node_assign(NEW_MASGN(NEW_LIST($2), 0), NEW_DVAR(id));
|
||||
}
|
||||
|
||||
args = new_args(m, 0, id, 0, 0);
|
||||
scope = NEW_NODE(NODE_SCOPE, tbl, $8, args);
|
||||
tbl[0] = 1; tbl[1] = id;
|
||||
$$ = NEW_FOR(0, $5, scope);
|
||||
fixpos($$, $2);
|
||||
|
|
|
@ -90,22 +90,22 @@ class TestAssignment < Test::Unit::TestCase
|
|||
def f; yield([*[1]]); end; f {|a| assert_equal([1], a)}; undef f
|
||||
def f; yield([*[1,2]]); end; f {|a| assert_equal([1,2], a)}; undef f
|
||||
|
||||
def f; yield(*[1]); end; f {|a| assert_equal([1], a)}; undef f
|
||||
def f; yield(*[nil]); end; f {|a| assert_equal([nil], a)}; undef f
|
||||
def f; yield(*[[]]); end; f {|a| assert_equal([[]], a)}; undef f
|
||||
def f; yield(*[*[1]]); end; f {|a| assert_equal([1], a)}; undef f
|
||||
def f; yield(*[1]); end; f {|a| assert_equal(1, a)}; undef f
|
||||
def f; yield(*[nil]); end; f {|a| assert_equal(nil, a)}; undef f
|
||||
def f; yield(*[[]]); end; f {|a| assert_equal([], a)}; undef f
|
||||
def f; yield(*[*[1]]); end; f {|a| assert_equal(1, a)}; undef f
|
||||
|
||||
def f; yield; end; f {|*a| assert_equal([], a)}; undef f
|
||||
def f; yield(nil); end; f {|*a| assert_equal([nil], a)}; undef f
|
||||
def f; yield(1); end; f {|*a| assert_equal([1], a)}; undef f
|
||||
def f; yield([]); end; f {|*a| assert_equal([], a)}; undef f
|
||||
def f; yield([1]); end; f {|*a| assert_equal([1], a)}; undef f
|
||||
def f; yield([nil]); end; f {|*a| assert_equal([nil], a)}; undef f
|
||||
def f; yield([[]]); end; f {|*a| assert_equal([[]], a)}; undef f
|
||||
def f; yield([1,2]); end; f {|*a| assert_equal([1,2], a)}; undef f
|
||||
def f; yield([*[]]); end; f {|*a| assert_equal([], a)}; undef f
|
||||
def f; yield([*[1]]); end; f {|*a| assert_equal([1], a)}; undef f
|
||||
def f; yield([*[1,2]]); end; f {|*a| assert_equal([1,2], a)}; undef f
|
||||
def f; yield([]); end; f {|*a| assert_equal([[]], a)}; undef f
|
||||
def f; yield([1]); end; f {|*a| assert_equal([[1]], a)}; undef f
|
||||
def f; yield([nil]); end; f {|*a| assert_equal([[nil]], a)}; undef f
|
||||
def f; yield([[]]); end; f {|*a| assert_equal([[[]]], a)}; undef f
|
||||
def f; yield([1,2]); end; f {|*a| assert_equal([[1,2]], a)}; undef f
|
||||
def f; yield([*[]]); end; f {|*a| assert_equal([[]], a)}; undef f
|
||||
def f; yield([*[1]]); end; f {|*a| assert_equal([[1]], a)}; undef f
|
||||
def f; yield([*[1,2]]); end; f {|*a| assert_equal([[1,2]], a)}; undef f
|
||||
|
||||
def f; yield(*[]); end; f {|*a| assert_equal([], a)}; undef f
|
||||
def f; yield(*[1]); end; f {|*a| assert_equal([1], a)}; undef f
|
||||
|
@ -129,7 +129,7 @@ class TestAssignment < Test::Unit::TestCase
|
|||
def f; yield(*[]); end; f {|a,b,*c| assert_equal([nil,nil,[]], [a,b,c])}; undef f
|
||||
def f; yield(*[1]); end; f {|a,b,*c| assert_equal([1,nil,[]], [a,b,c])}; undef f
|
||||
def f; yield(*[nil]); end; f {|a,b,*c| assert_equal([nil,nil,[]], [a,b,c])}; undef f
|
||||
def f; yield(*[[]]); end; f {|a,b,*c| assert_equal([[],nil,[]], [a,b,c])}; undef f
|
||||
def f; yield(*[[]]); end; f {|a,b,*c| assert_equal([nil,nil,[]], [a,b,c])}; undef f
|
||||
def f; yield(*[*[]]); end; f {|a,b,*c| assert_equal([nil,nil,[]], [a,b,c])}; undef f
|
||||
def f; yield(*[*[1]]); end; f {|a,b,*c| assert_equal([1,nil,[]], [a,b,c])}; undef f
|
||||
def f; yield(*[*[1,2]]); end; f {|a,b,*c| assert_equal([1,2,[]], [a,b,c])}; undef f
|
||||
|
|
|
@ -621,8 +621,8 @@ class TestBasicInstructions < Test::Unit::TestCase
|
|||
assert_equal [1, 2, 3], [1, *a]
|
||||
|
||||
a = nil
|
||||
assert_equal [nil], [*a] # FIXME: []? [nil]? error?
|
||||
assert_equal [1], [1, *a] # FIXME: [1, nil]? error?
|
||||
assert_equal [], [*a]
|
||||
assert_equal [1], [1, *a]
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -365,7 +365,7 @@ class TestIterator < Test::Unit::TestCase
|
|||
|
||||
def test_assoc_yield
|
||||
[{:key=>:value}, H.new].each {|h|
|
||||
h.each{|a| assert_equal([:key, :value], a)}
|
||||
h.each{|a| assert_equal(:key, a)} # changed at 1.9
|
||||
h.each{|*a| assert_equal([:key, :value], a)}
|
||||
h.each{|k,v| assert_equal([:key, :value], [k,v])}
|
||||
}
|
||||
|
@ -480,3 +480,4 @@ class TestIterator < Test::Unit::TestCase
|
|||
assert_equal(["b"], ["a", "b", "c"].grep(IterString.new("b")) {|s| s})
|
||||
end
|
||||
end
|
||||
GC.stress=true
|
||||
|
|
|
@ -16,8 +16,8 @@ class TestRubyYield < Test::Unit::TestCase
|
|||
assert_equal :a, k
|
||||
assert_equal 1, v
|
||||
end
|
||||
h.each do |kv|
|
||||
assert_equal [:a, 1], kv
|
||||
h.each do |k|
|
||||
assert_equal :a, k # changed at 1.9
|
||||
end
|
||||
end
|
||||
|
||||
|
|
11
vm.c
11
vm.c
|
@ -718,17 +718,6 @@ th_yield_setup_args(rb_thread_t *th, rb_iseq_t *iseq,
|
|||
}
|
||||
|
||||
if (iseq->arg_rest == -1) {
|
||||
if (lambda == 0 && iseq->argc == 1) {
|
||||
if (argc > 1) {
|
||||
/* yield 1, 2, 3 for iter{|a| ...}
|
||||
*
|
||||
* ruby 1.8 warns on this timing.
|
||||
* rb_warn("multiple values for a block parameter (%d for %d)", argc, iseq->argc);
|
||||
*/
|
||||
argv[0] = rb_ary_new4(argc, argv);
|
||||
th->mark_stack_len = argc = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (iseq->argc < argc) {
|
||||
if (lambda) {
|
||||
|
|
Loading…
Reference in a new issue