Permalink
Browse files

Don't change a given proc to lambda when shouldn't

  • Loading branch information...
ryoqun committed Feb 24, 2013
1 parent 50e0ebb commit ffc41aaba95cf7b6c938c6a7be089ee9aeb0f350
Showing with 37 additions and 15 deletions.
  1. +0 −8 kernel/common/kernel.rb
  2. +7 −0 kernel/common/kernel18.rb
  3. +29 −6 kernel/common/kernel19.rb
  4. +1 −1 kernel/common/module.rb
View
@@ -155,14 +155,6 @@ def block_given?
alias_method :iterator?, :block_given?
module_function :iterator?
- def lambda(&prc)
- raise ArgumentError, "block required" unless prc
- prc.lambda_style!
- return prc
- end
-
- module_function :lambda
-
def caller(start=1, exclude_kernel=true)
# The + 1 is to skip this frame
Rubinius.mri_backtrace(start + 1).map do |tup|
@@ -93,6 +93,13 @@ def open(path, *rest, &block)
end
module_function :open
+ def lambda(&prc)
+ raise ArgumentError, "block required" unless prc
+ prc.lambda_style!
+ return prc
+ end
+
+ module_function :lambda
alias_method :proc, :lambda
module_function :proc
View
@@ -140,12 +140,6 @@ def object_id
raise PrimitiveFailure, "Kernel#object_id primitive failed"
end
- def proc(&prc)
- raise ArgumentError, "block required" unless prc
- return prc
- end
- module_function :proc
-
def open(obj, *rest, &block)
if obj.respond_to?(:to_open)
obj = obj.to_open(*rest)
@@ -177,6 +171,35 @@ def require_relative(name)
end
module_function :require_relative
+ def lambda
+ env = nil
+
+ Rubinius.asm do
+ push_block
+ # assign a pushed block to the above local variable "env"
+ # Note that "env" is indexed at 0.
+ set_local 0
+ end
+
+ raise ArgumentError, "block required" unless env
+
+ prc = Proc.__from_block__(env)
+
+ # Make a proc lambda only when passed an actual block (ie, not using the
+ # "&block" notation), otherwise don't modify it at all.
+ prc.lambda_style! if env.is_a?(Rubinius::BlockEnvironment)
+
+ return prc
+ end
+
+ module_function :lambda
+
+ def proc(&prc)
+ raise ArgumentError, "block required" unless prc
+ return prc
+ end
+ module_function :proc
+
def String(obj)
return obj if obj.kind_of? String
View
@@ -277,7 +277,7 @@ def define_method(name, meth = undefined, &prc)
be = meth.block.dup
be.change_name name
code = Rubinius::BlockEnvironment::AsMethod.new(be)
- meth = lambda(&meth)
+ meth.lambda_style!
end
when Method
exec = meth.executable

0 comments on commit ffc41aa

Please sign in to comment.