Skip to content

Commit

Permalink
Showing 6 changed files with 28 additions and 16 deletions.
4 changes: 4 additions & 0 deletions kernel/common/capi.rb
Original file line number Diff line number Diff line change
@@ -186,5 +186,9 @@ def self.rb_integer_pack(value, words, numwords, wordsize, nails, flags)
return 1
end
end

def self.rb_block_proc(env)
Rubinius::Mirror::Proc.from_block ::Proc, env
end
end
end
2 changes: 1 addition & 1 deletion kernel/common/kernel.rb
Original file line number Diff line number Diff line change
@@ -481,7 +481,7 @@ def lambda

raise ArgumentError, "block required" unless env

prc = Proc.__from_block__(env)
prc = Rubinius::Mirror::Proc.from_block ::Proc, env

# Make a proc lambda only when passed an actual block (ie, not using the
# "&block" notation), otherwise don't modify it at all.
16 changes: 3 additions & 13 deletions kernel/common/proc.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,7 @@
class Proc

def self.__from_block__(env)
Rubinius.primitive :proc_from_env

if Rubinius::Type.object_kind_of? env, Rubinius::BlockEnvironment
raise PrimitiveFailure, "Proc.__from_block__ primitive failed to create Proc from BlockEnvironment"
else
begin
env.to_proc
rescue Exception
raise ArgumentError, "Unable to convert #{env.inspect} to a Proc"
end
end
# The compiler must be fixed before this method can be removed.
Rubinius::Mirror::Proc.from_block self, env
end

def self.new(*args)
@@ -35,7 +25,7 @@ def self.new(*args)
end
end

block = __from_block__(env)
block = Rubinius::Mirror::Proc.from_block self, env

if block.class != self
block = block.dup
17 changes: 17 additions & 0 deletions kernel/common/proc_mirror.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,23 @@
module Rubinius
class Mirror
class Proc < Mirror
def self.from_block(klass, env)
begin
return Rubinius.invoke_primitive :proc_from_env, env, klass
rescue Rubinius::Internal => exc
if Type.object_kind_of? env, BlockEnvironment
msg = "unable to create Proc from BlockEnvironment"
raise PrimitiveFailure, msg, exc
end
end

begin
env.to_proc
rescue Exception
raise ArgumentError, "Unable to convert #{env.inspect} to a Proc"
end
end

def curry(executable, args, arity)
args.freeze

2 changes: 1 addition & 1 deletion kernel/delta/rubinius.rb
Original file line number Diff line number Diff line change
@@ -359,7 +359,7 @@ def self.lambda

raise ArgumentError, "block required" unless env

prc = Proc.__from_block__(env)
prc = Rubinius::Mirror::Proc.from_block ::Proc, env

# Make a proc lambda only when passed an actual block (ie, not using the
# "&block" notation), otherwise don't modify it at all.
3 changes: 2 additions & 1 deletion vm/capi/kernel.cpp
Original file line number Diff line number Diff line change
@@ -250,7 +250,8 @@ extern "C" {

VALUE rb_block_proc() {
NativeMethodEnvironment* env = NativeMethodEnvironment::get();
return rb_funcall(rb_cProc, rb_intern("__from_block__"), 1, env->get_handle(env->block()));
return rb_funcall(rb_mCAPI, rb_intern("rb_block_proc"), 1,
env->get_handle(env->block()));
}

// Hoisted from 1.8.7

0 comments on commit 1857962

Please sign in to comment.