diff options
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | bootstraptest/test_method.rb | 19 | ||||
-rw-r--r-- | compile.c | 8 |
3 files changed, 34 insertions, 0 deletions
@@ -1,3 +1,10 @@ +Wed Jul 4 03:52:55 2007 Koichi Sasada <ko1@atdot.net> + + * compile.c (iseq_compile_each): support v[&b]= type method call. + [ruby-dev:31094] + + * bootstraptest/test_method.rb: add a test for above. + Wed Jul 4 03:43:29 2007 Koichi Sasada <ko1@atdot.net> * compile.c (compile_massign): fix massign compilation diff --git a/bootstraptest/test_method.rb b/bootstraptest/test_method.rb index faf3d4bc58..c95eec175e 100644 --- a/bootstraptest/test_method.rb +++ b/bootstraptest/test_method.rb @@ -318,6 +318,25 @@ assert_equal '1', %q( class C; def m() 7 end; private :m end assert_equal '1', %q( class C; def m() 1 end; private :m end C.new.funcall(:m) ) +# with block +assert_equal '[[:ok1, :foo], [:ok2, :foo, :bar]]', +%q{ + class C + def [](a) + $ary << [yield, a] + end + def []=(a, b) + $ary << [yield, a, b] + end + end + + $ary = [] + C.new[:foo, &lambda{:ok1}] + C.new[:foo, &lambda{:ok2}] = :bar + $ary +} + + # splat and block arguments assert_equal %q{[[[:x, :y, :z], NilClass], [[1, :x, :y, :z], NilClass], [[1, 2, :x, :y, :z], NilClass], [[:obj], NilClass], [[1, :obj], NilClass], [[1, 2, :obj], NilClass], [[], Proc], [[1], Proc], [[1, 2], Proc], [[], Proc], [[1], Proc], [[1, 2], Proc], [[:x, :y, :z], Proc], [[1, :x, :y, :z], Proc], [[1, 2, :x, :y, :z], Proc]]}, %q{ def m(*args, &b) @@ -4285,8 +4285,16 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) ADD_INSN(ret, nd_line(node), putnil); ADD_SEQ(ret, recv); ADD_SEQ(ret, args); + + if (flag & VM_CALL_ARGS_BLOCKARG_BIT) { + ADD_INSN1(ret, nd_line(node), topn, INT2FIX(1)); + ADD_INSN1(ret, nd_line(node), setn, INT2FIX(FIX2INT(argc) + 3)); + ADD_INSN (ret, nd_line(node), pop); + } + else { ADD_INSN1(ret, nd_line(node), setn, INT2FIX(FIX2INT(argc) + 1)); } + } else { ADD_SEQ(ret, recv); ADD_SEQ(ret, args); |