diff options
-rw-r--r-- | bootstraptest/test_yjit.rb | 16 | ||||
-rw-r--r-- | yjit/bindgen/src/main.rs | 1 | ||||
-rw-r--r-- | yjit/src/codegen.rs | 32 | ||||
-rw-r--r-- | yjit/src/cruby_bindings.inc.rs | 1 |
4 files changed, 50 insertions, 0 deletions
diff --git a/bootstraptest/test_yjit.rb b/bootstraptest/test_yjit.rb index 2e190a5b9c..216594f6cc 100644 --- a/bootstraptest/test_yjit.rb +++ b/bootstraptest/test_yjit.rb @@ -4816,3 +4816,19 @@ assert_equal "abc", %q{ change_bytes(str, to_int_1, to_int_99) str } + +assert_equal '["raised", "Module", "Object"]', %q{ + def foo(obj) + obj.superclass.name + end + + ret = [] + + begin + foo(Class.allocate) + rescue TypeError + ret << 'raised' + end + + ret += [foo(Class), foo(Class.new)] +} diff --git a/yjit/bindgen/src/main.rs b/yjit/bindgen/src/main.rs index c58df7c377..c16617b3f0 100644 --- a/yjit/bindgen/src/main.rs +++ b/yjit/bindgen/src/main.rs @@ -174,6 +174,7 @@ fn main() { .allowlist_var("rb_cThread") .allowlist_var("rb_cArray") .allowlist_var("rb_cHash") + .allowlist_var("rb_cClass") // From include/ruby/internal/fl_type.h .allowlist_type("ruby_fl_type") diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs index a7bf2e06f6..a927aa9684 100644 --- a/yjit/src/codegen.rs +++ b/yjit/src/codegen.rs @@ -6060,6 +6060,36 @@ fn gen_block_given( asm.mov(out_opnd, block_given); } +// Codegen for rb_class_superclass() +fn jit_rb_class_superclass( + jit: &mut JITState, + asm: &mut Assembler, + _ocb: &mut OutlinedCb, + _ci: *const rb_callinfo, + cme: *const rb_callable_method_entry_t, + _block: Option<crate::codegen::BlockHandler>, + _argc: i32, + _known_recv_class: Option<VALUE>, +) -> bool { + extern "C" { + fn rb_class_superclass(klass: VALUE) -> VALUE; + } + + if !jit_prepare_lazy_frame_call(jit, asm, cme, StackOpnd(0)) { + return false; + } + + asm_comment!(asm, "Class#superclass"); + let recv_opnd = asm.stack_opnd(0); + let ret = asm.ccall(rb_class_superclass as *const u8, vec![recv_opnd]); + + asm.stack_pop(1); + let ret_opnd = asm.stack_push(Type::Unknown); + asm.mov(ret_opnd, ret); + + true +} + fn jit_thread_s_current( _jit: &mut JITState, asm: &mut Assembler, @@ -10072,6 +10102,8 @@ pub fn yjit_reg_method_codegen_fns() { yjit_reg_method(rb_mKernel, "respond_to?", jit_obj_respond_to); yjit_reg_method(rb_mKernel, "block_given?", jit_rb_f_block_given_p); + yjit_reg_method(rb_cClass, "superclass", jit_rb_class_superclass); + yjit_reg_method(rb_singleton_class(rb_cThread), "current", jit_thread_s_current); } } diff --git a/yjit/src/cruby_bindings.inc.rs b/yjit/src/cruby_bindings.inc.rs index 359227d60d..bdaee0534c 100644 --- a/yjit/src/cruby_bindings.inc.rs +++ b/yjit/src/cruby_bindings.inc.rs @@ -962,6 +962,7 @@ extern "C" { pub static mut rb_mKernel: VALUE; pub static mut rb_cBasicObject: VALUE; pub static mut rb_cArray: VALUE; + pub static mut rb_cClass: VALUE; pub static mut rb_cFalseClass: VALUE; pub static mut rb_cFloat: VALUE; pub static mut rb_cHash: VALUE; |