diff --git a/lib/ruby_vm/rjit/insn_compiler.rb b/lib/ruby_vm/rjit/insn_compiler.rb index 347319dd35..47e842e00e 100644 --- a/lib/ruby_vm/rjit/insn_compiler.rb +++ b/lib/ruby_vm/rjit/insn_compiler.rb @@ -18,7 +18,7 @@ module RubyVM::RJIT asm.incr_counter(:rjit_insns_count) asm.comment("Insn: #{insn.name}") - # 82/102 + # 83/102 case insn.name when :nop then nop(jit, ctx, asm) when :getlocal then getlocal(jit, ctx, asm) @@ -31,7 +31,7 @@ module RubyVM::RJIT when :getinstancevariable then getinstancevariable(jit, ctx, asm) when :setinstancevariable then setinstancevariable(jit, ctx, asm) when :getclassvariable then getclassvariable(jit, ctx, asm) - # setclassvariable + when :setclassvariable then setclassvariable(jit, ctx, asm) when :opt_getconstant_path then opt_getconstant_path(jit, ctx, asm) when :getconstant then getconstant(jit, ctx, asm) # setconstant @@ -556,7 +556,22 @@ module RubyVM::RJIT KeepCompiling end - # setclassvariable + # @param jit [RubyVM::RJIT::JITState] + # @param ctx [RubyVM::RJIT::Context] + # @param asm [RubyVM::RJIT::Assembler] + def setclassvariable(jit, ctx, asm) + # rb_vm_setclassvariable can raise exceptions. + jit_prepare_routine_call(jit, ctx, asm) + + asm.mov(C_ARGS[0], [CFP, C.rb_control_frame_t.offsetof(:iseq)]) + asm.mov(C_ARGS[1], CFP) + asm.mov(C_ARGS[2], jit.operand(0)) + asm.mov(C_ARGS[3], ctx.stack_pop(1)) + asm.mov(C_ARGS[4], jit.operand(1)) + asm.call(C.rb_vm_setclassvariable) + + KeepCompiling + end # @param jit [RubyVM::RJIT::JITState] # @param ctx [RubyVM::RJIT::Context] @@ -1251,6 +1266,9 @@ module RubyVM::RJIT # checkmatch + # @param jit [RubyVM::RJIT::JITState] + # @param ctx [RubyVM::RJIT::Context] + # @param asm [RubyVM::RJIT::Assembler] def checkkeyword(jit, ctx, asm) # When a keyword is unspecified past index 32, a hash will be used # instead. This can only happen in iseqs taking more than 32 keywords. diff --git a/rjit_c.c b/rjit_c.c index 3d4d22742e..1a2aa0b1b1 100644 --- a/rjit_c.c +++ b/rjit_c.c @@ -496,6 +496,7 @@ extern rb_event_flag_t rb_rjit_global_events; extern void rb_vm_setinstancevariable(const rb_iseq_t *iseq, VALUE obj, ID id, VALUE val, IVC ic); extern VALUE rb_vm_throw(const rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, rb_num_t throw_state, VALUE throwobj); extern VALUE rb_reg_new_ary(VALUE ary, int opt); +extern void rb_vm_setclassvariable(const rb_iseq_t *iseq, const rb_control_frame_t *cfp, ID id, VALUE val, ICVARC ic); #include "rjit_c.rbinc" diff --git a/rjit_c.rb b/rjit_c.rb index a582fd80ba..17aa6754f0 100644 --- a/rjit_c.rb +++ b/rjit_c.rb @@ -625,6 +625,10 @@ module RubyVM::RJIT # :nodoc: all Primitive.cexpr! %q{ SIZET2NUM((size_t)rb_vm_opt_newarray_min) } end + def C.rb_vm_setclassvariable + Primitive.cexpr! %q{ SIZET2NUM((size_t)rb_vm_setclassvariable) } + end + def C.rb_vm_setinstancevariable Primitive.cexpr! %q{ SIZET2NUM((size_t)rb_vm_setinstancevariable) } end diff --git a/tool/rjit/bindgen.rb b/tool/rjit/bindgen.rb index 9c1cbdfcc9..2e472a411b 100755 --- a/tool/rjit/bindgen.rb +++ b/tool/rjit/bindgen.rb @@ -542,6 +542,7 @@ generator = BindingGenerator.new( rb_reg_new_ary rb_ary_clear rb_str_intern + rb_vm_setclassvariable ], types: %w[ CALL_DATA