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

* parse.y (block_param): do not use multiple assignment for a sole

block parameter.  [ruby-dev:28710]

* eval.c (rb_yield_0): pass a raw yielded value to a sole block
  parameter if a value is passed by yield.

* eval.c (proc_invoke): args may not be an array.

* eval.c (rb_proc_yield): pass original value without wrapping
  it in an array.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10356 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2006-06-21 08:08:36 +00:00
parent ad5f0fc6cc
commit 2ca2a4a43b
6 changed files with 60 additions and 38 deletions

View file

@ -1,3 +1,16 @@
Wed Jun 21 14:35:06 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* parse.y (block_param): do not use multiple assignment for a sole
block parameter. [ruby-dev:28710]
* eval.c (rb_yield_0): pass a raw yielded value to a sole block
parameter if a value is passed by yield.
* eval.c (proc_invoke): args may not be an array.
* eval.c (rb_proc_yield): pass original value without wrapping
it in an array.
Wed Jun 21 14:06:47 2006 Yukihiro Matsumoto <matz@ruby-lang.org>
* parse.y (method_call): remove (fn)(args) style lambda

15
eval.c
View file

@ -4739,6 +4739,9 @@ rb_yield_0(VALUE val, VALUE self, VALUE klass /* OK */, int flags)
massign(self, var, val, pcall);
}
else {
if (pcall) {
val = RARRAY(val)->ptr[0];
}
assign(self, var, val, pcall);
}
if (bvar) {
@ -8367,7 +8370,7 @@ proc_invoke(VALUE proc, VALUE args /* OK */, VALUE self, VALUE klass, int call)
_block.block_obj = bvar;
if (self != Qundef) _block.frame.self = self;
if (klass) _block.frame.this_class = klass;
_block.frame.argc = RARRAY(args)->len;
_block.frame.argc = call ? RARRAY(args)->len : 1;
_block.frame.flags = ruby_frame->flags;
if (_block.frame.argc && (ruby_frame->flags & FRAME_DMETH)) {
NEWOBJ(scope, struct SCOPE);
@ -8473,10 +8476,14 @@ rb_proc_call(VALUE proc, VALUE args /* OK */)
VALUE
rb_proc_yield(int argc, VALUE *argv, VALUE proc)
{
if (argc == 1)
return proc_invoke(proc, svalue_to_avalue(argv[0]), Qundef, 0, 0);
else
switch (argc) {
case 0:
return proc_invoke(proc, Qnil, Qundef, 0, 0);
case 1:
return proc_invoke(proc, argv[0], Qundef, 0, 0);
default:
return proc_invoke(proc, rb_ary_new4(argc, argv), Qundef, 0, 0);
}
}
/* :nodoc: */

View file

@ -213,14 +213,10 @@ def parse_args()
opts = nil
$optparser ||= OptionParser.new do |opts|
opts.on('-n') {$dryrun = true}
opts.on('--[no-]extension [EXTS]', Array) do |*v|
v.compact!
v = v[0] if v.size == 1 and !v[0]
opts.on('--[no-]extension [EXTS]', Array) do |v|
$extension = (v == false ? [] : v)
end
opts.on('--[no-]extstatic [STATIC]', Array) do |*v|
v.compact!
v = v[0] if v.size == 1 and !v[0]
opts.on('--[no-]extstatic [STATIC]', Array) do |v|
if ($extstatic = v) == false
$extstatic = []
elsif v
@ -237,7 +233,7 @@ def parse_args()
opts.on('--make=MAKE') do |v|
$make = v || 'make'
end
opts.on('--make-flags=FLAGS', '--mflags', Shellwords) do |*v|
opts.on('--make-flags=FLAGS', '--mflags', Shellwords) do |v|
v.grep(/\A([-\w]+)=(.*)/) {$configure_args["--#{$1}"] = $2}
if arg = v.first
arg.insert(0, '-') if /\A[^-][^=]*\Z/ =~ arg
@ -358,7 +354,7 @@ end unless $extstatic
ext_prefix = "#{$top_srcdir}/ext"
exts = $static_ext.sort_by {|t, i| i}.collect {|t, i| t}
if $extension && $extension.size > 0
if $extension
exts |= $extension.select {|d| File.directory?("#{ext_prefix}/#{d}")}
else
withes, withouts = %w[--with --without].collect {|w|

View file

@ -352,12 +352,12 @@ class OptionParser
# : (({block}))
# (({yields})) at semi-error condition, instead of raises exception.
#
def conv_arg(arg, val = [])
def conv_arg(arg, val = nil)
if block
if conv
val = conv.yield(*val)
val = conv.yield(val)
else
val = val[0]
val = *val
end
return arg, block, val
else
@ -453,12 +453,12 @@ class OptionParser
#
# Raises an exception if argument is not present.
#
def parse(arg, argv)
def parse(arg, argv, &error)
unless arg
raise MissingArgument if argv.empty?
arg = argv.shift
end
conv_arg(*parse_arg(arg) {|*exc| raise(*exc)})
conv_arg(*parse_arg(arg), &error)
end
end
@ -622,7 +622,7 @@ class OptionParser
if list = __send__(id)
val = list.fetch(key) {return nil}
return val unless block_given?
yield(*val)
yield(val)
end
end
@ -700,7 +700,7 @@ class OptionParser
# Completion for hash key.
#
def match(key)
return key, fetch(key) {
return key, *fetch(key) {
raise AmbiguousArgument, catch(:ambiguous) {return complete(key)}
}
end
@ -1495,9 +1495,9 @@ class OptionParser
yielded with the found value when succeeded.
=end #'#"#`#
def search(id, key)
visit(:search, id, key) do |*k|
visit(:search, id, key) do |k|
return k unless block_given?
return yield(*k)
return yield(k)
end
end
private :search

View file

@ -2900,7 +2900,13 @@ block_param0 : mlhs_item
block_param : block_param0
{
/*%%%*/
$$ = NEW_MASGN($1, 0);
if ($1->nd_alen == 1) {
$$ = $1->nd_head;
rb_gc_force_recycle((VALUE)$1);
}
else {
$$ = NEW_MASGN($1, 0);
}
/*%
$$ = blockvar_new($1);
%*/

View file

@ -127,13 +127,13 @@ a,b,*c = *[*[1,2]]; test_ok([a,b,c] == [1,2,[]])
def f; yield nil; end; f {|a| test_ok(a == nil)}
def f; yield 1; end; f {|a| test_ok(a == 1)}
def f; yield *[]; end; f {|a| test_ok(a == nil)}
def f; yield *[1]; end; f {|a| test_ok(a == 1)}
def f; yield *[nil]; end; f {|a| test_ok(a == nil)}
def f; yield *[[]]; end; f {|a| test_ok(a == [])}
def f; yield *[*[]]; end; f {|a| test_ok(a == nil)}
def f; yield *[*[1]]; end; f {|a| test_ok(a == 1)}
def f; yield *[*[1,2]]; end; f {|a| test_ok(a == 1)}
def f; yield *[]; end; f {|a| test_ok(a == [])}
def f; yield *[1]; end; f {|a| test_ok(a == [1])}
def f; yield *[nil]; end; f {|a| test_ok(a == [nil])}
def f; yield *[[]]; end; f {|a| test_ok(a == [[]])}
def f; yield *[*[]]; end; f {|a| test_ok(a == [])}
def f; yield *[*[1]]; end; f {|a| test_ok(a == [1])}
def f; yield *[*[1,2]]; end; f {|a| test_ok(a == [1,2])}
def f; yield; end; f {|a,| test_ok(a == nil)}
def f; yield nil; end; f {|a,| test_ok(a == nil)}
@ -957,23 +957,23 @@ IterTest.new([1]).each1 {|x| test_ok(x == 1)}
IterTest.new([2]).each2 {|x| test_ok(x == [2])}
#IterTest.new([3]).each3 {|x| test_ok(x == 3)}
IterTest.new([4]).each4 {|x| test_ok(x == 4)}
IterTest.new([5]).each5 {|x| test_ok(x == 5)}
IterTest.new([6]).each6 {|x| test_ok(x == 6)}
IterTest.new([5]).each5 {|x| test_ok(x == [5])}
IterTest.new([6]).each6 {|x| test_ok(x == [6])}
#IterTest.new([7]).each7 {|x| test_ok(x == 7)}
IterTest.new([8]).each8 {|x| test_ok(x == 8)}
IterTest.new([[0]]).each0 {|x| test_ok(x == 0)}
IterTest.new([[0]]).each0 {|x| test_ok(x == [0])}
IterTest.new([[1]]).each1 {|x| test_ok(x == 1)}
IterTest.new([[2]]).each2 {|x| test_ok(x == [2])}
IterTest.new([[3]]).each3 {|x| test_ok(x == 3)}
IterTest.new([[4]]).each4 {|x| test_ok(x == 4)}
IterTest.new([[5]]).each5 {|x| test_ok(x == 5)}
IterTest.new([[6]]).each6 {|x| test_ok(x == 6)}
IterTest.new([[7]]).each7 {|x| test_ok(x == 7)}
IterTest.new([[8]]).each8 {|x| test_ok(x == 8)}
IterTest.new([[4]]).each4 {|x| test_ok(x == [4])}
IterTest.new([[5]]).each5 {|x| test_ok(x == [5])}
IterTest.new([[6]]).each6 {|x| test_ok(x == [6])}
IterTest.new([[7]]).each7 {|x| test_ok(x == [7])}
IterTest.new([[8]]).each8 {|x| test_ok(x == [8])}
IterTest.new([[0,0]]).each0 {|*x| test_ok(x == [0,0])}
IterTest.new([[8,8]]).each8 {|*x| test_ok(x == [8])}
IterTest.new([[8,8]]).each8 {|*x| test_ok(x == [8,8])}
def m0(v)
v