diff options
-rw-r--r-- | kernel.rb | 6 | ||||
-rw-r--r-- | object.c | 6 | ||||
-rw-r--r-- | yjit/src/codegen.rs | 31 |
3 files changed, 34 insertions, 9 deletions
@@ -118,7 +118,7 @@ module Kernel # 2.then.detect(&:odd?) # => nil # def then - unless Primitive.block_given_p + unless block_given? return Primitive.cexpr! 'SIZED_ENUMERATOR(self, 0, 0, rb_obj_size)' end yield(self) @@ -142,7 +142,7 @@ module Kernel # then {|response| JSON.parse(response) } # def yield_self - unless Primitive.block_given_p + unless block_given? return Primitive.cexpr! 'SIZED_ENUMERATOR(self, 0, 0, rb_obj_size)' end yield(self) @@ -178,7 +178,7 @@ module Kernel # puts enum.next # } #=> :ok def loop - unless Primitive.block_given_p + unless block_given? return enum_for(:loop) { Float::INFINITY } end @@ -569,12 +569,6 @@ rb_obj_size(VALUE self, VALUE args, VALUE obj) return LONG2FIX(1); } -static VALUE -block_given_p(rb_execution_context_t *ec, VALUE self) -{ - return RBOOL(rb_block_given_p()); -} - /** * :nodoc: *-- diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs index b7a2d0199b..27ef30e410 100644 --- a/yjit/src/codegen.rs +++ b/yjit/src/codegen.rs @@ -4380,6 +4380,36 @@ fn jit_obj_respond_to( true } +fn jit_rb_f_block_given_p( + jit: &mut JITState, + ctx: &mut Context, + asm: &mut Assembler, + _ocb: &mut OutlinedCb, + _ci: *const rb_callinfo, + _cme: *const rb_callable_method_entry_t, + _block: Option<IseqPtr>, + _argc: i32, + _known_recv_class: *const VALUE, +) -> bool { + asm.comment("block_given?"); + + // Same as rb_vm_frame_block_handler + let ep_opnd = gen_get_lep(jit, asm); + let block_handler = asm.load( + Opnd::mem(64, ep_opnd, SIZEOF_VALUE_I32 * VM_ENV_DATA_INDEX_SPECVAL) + ); + + ctx.stack_pop(1); + let out_opnd = ctx.stack_push(Type::UnknownImm); + + // Return `block_handler != VM_BLOCK_HANDLER_NONE` + asm.cmp(block_handler, VM_BLOCK_HANDLER_NONE.into()); + let block_given = asm.csel_ne(Qtrue.into(), Qfalse.into()); + asm.mov(out_opnd, block_given); + + true +} + fn jit_thread_s_current( _jit: &mut JITState, ctx: &mut Context, @@ -7513,6 +7543,7 @@ impl CodegenGlobals { self.yjit_reg_method(rb_cString, "+@", jit_rb_str_uplus); self.yjit_reg_method(rb_mKernel, "respond_to?", jit_obj_respond_to); + self.yjit_reg_method(rb_mKernel, "block_given?", jit_rb_f_block_given_p); // Thread.current self.yjit_reg_method( |