Skip to content

Commit

Permalink
Added mirror for Proc.__from_block__.
Browse files Browse the repository at this point in the history
  • Loading branch information
brixen committed May 25, 2015
1 parent 0ec240a commit 1857962
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 16 deletions.
4 changes: 4 additions & 0 deletions kernel/common/capi.rb
Expand Up @@ -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
Expand Up @@ -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.
Expand Down
16 changes: 3 additions & 13 deletions kernel/common/proc.rb
@@ -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)
Expand All @@ -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
Expand Down
17 changes: 17 additions & 0 deletions kernel/common/proc_mirror.rb
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion kernel/delta/rubinius.rb
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion vm/capi/kernel.cpp
Expand Up @@ -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
Expand Down

0 comments on commit 1857962

Please sign in to comment.