Skip to content

Commit 1857962

Browse files
committedMay 25, 2015
Added mirror for Proc.__from_block__.
1 parent 0ec240a commit 1857962

File tree

6 files changed

+28
-16
lines changed

6 files changed

+28
-16
lines changed
 

Diff for: ‎kernel/common/capi.rb

+4
Original file line numberDiff line numberDiff line change
@@ -186,5 +186,9 @@ def self.rb_integer_pack(value, words, numwords, wordsize, nails, flags)
186186
return 1
187187
end
188188
end
189+
190+
def self.rb_block_proc(env)
191+
Rubinius::Mirror::Proc.from_block ::Proc, env
192+
end
189193
end
190194
end

Diff for: ‎kernel/common/kernel.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ def lambda
481481

482482
raise ArgumentError, "block required" unless env
483483

484-
prc = Proc.__from_block__(env)
484+
prc = Rubinius::Mirror::Proc.from_block ::Proc, env
485485

486486
# Make a proc lambda only when passed an actual block (ie, not using the
487487
# "&block" notation), otherwise don't modify it at all.

Diff for: ‎kernel/common/proc.rb

+3-13
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,7 @@
11
class Proc
2-
32
def self.__from_block__(env)
4-
Rubinius.primitive :proc_from_env
5-
6-
if Rubinius::Type.object_kind_of? env, Rubinius::BlockEnvironment
7-
raise PrimitiveFailure, "Proc.__from_block__ primitive failed to create Proc from BlockEnvironment"
8-
else
9-
begin
10-
env.to_proc
11-
rescue Exception
12-
raise ArgumentError, "Unable to convert #{env.inspect} to a Proc"
13-
end
14-
end
3+
# The compiler must be fixed before this method can be removed.
4+
Rubinius::Mirror::Proc.from_block self, env
155
end
166

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

38-
block = __from_block__(env)
28+
block = Rubinius::Mirror::Proc.from_block self, env
3929

4030
if block.class != self
4131
block = block.dup

Diff for: ‎kernel/common/proc_mirror.rb

+17
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,23 @@
11
module Rubinius
22
class Mirror
33
class Proc < Mirror
4+
def self.from_block(klass, env)
5+
begin
6+
return Rubinius.invoke_primitive :proc_from_env, env, klass
7+
rescue Rubinius::Internal => exc
8+
if Type.object_kind_of? env, BlockEnvironment
9+
msg = "unable to create Proc from BlockEnvironment"
10+
raise PrimitiveFailure, msg, exc
11+
end
12+
end
13+
14+
begin
15+
env.to_proc
16+
rescue Exception
17+
raise ArgumentError, "Unable to convert #{env.inspect} to a Proc"
18+
end
19+
end
20+
421
def curry(executable, args, arity)
522
args.freeze
623

Diff for: ‎kernel/delta/rubinius.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ def self.lambda
359359

360360
raise ArgumentError, "block required" unless env
361361

362-
prc = Proc.__from_block__(env)
362+
prc = Rubinius::Mirror::Proc.from_block ::Proc, env
363363

364364
# Make a proc lambda only when passed an actual block (ie, not using the
365365
# "&block" notation), otherwise don't modify it at all.

Diff for: ‎vm/capi/kernel.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ extern "C" {
250250

251251
VALUE rb_block_proc() {
252252
NativeMethodEnvironment* env = NativeMethodEnvironment::get();
253-
return rb_funcall(rb_cProc, rb_intern("__from_block__"), 1, env->get_handle(env->block()));
253+
return rb_funcall(rb_mCAPI, rb_intern("rb_block_proc"), 1,
254+
env->get_handle(env->block()));
254255
}
255256

256257
// Hoisted from 1.8.7

0 commit comments

Comments
 (0)
Please sign in to comment.