summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2023-03-03 21:41:35 -0800
committerTakashi Kokubun <takashikkbn@gmail.com>2023-03-05 23:28:59 -0800
commit3b38fe028035a024095dedffb4c8a1efc4f320ce (patch)
tree7f377624d7c843fb32362ad09ca55ab581216bef
parent7456b10c33ef984a685d174d7ff4ed418001923f (diff)
Implement getclassvariable
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/7448
-rw-r--r--lib/ruby_vm/mjit/insn_compiler.rb24
-rw-r--r--mjit_c.rb7
2 files changed, 28 insertions, 3 deletions
diff --git a/lib/ruby_vm/mjit/insn_compiler.rb b/lib/ruby_vm/mjit/insn_compiler.rb
index 5c0ad97966..dc7683078d 100644
--- a/lib/ruby_vm/mjit/insn_compiler.rb
+++ b/lib/ruby_vm/mjit/insn_compiler.rb
@@ -24,7 +24,7 @@ module RubyVM::MJIT
asm.incr_counter(:mjit_insns_count)
asm.comment("Insn: #{insn.name}")
- # 64/101
+ # 65/101
case insn.name
when :nop then nop(jit, ctx, asm)
when :getlocal then getlocal(jit, ctx, asm)
@@ -36,7 +36,7 @@ module RubyVM::MJIT
# setspecial
when :getinstancevariable then getinstancevariable(jit, ctx, asm)
when :setinstancevariable then setinstancevariable(jit, ctx, asm)
- # getclassvariable
+ when :getclassvariable then getclassvariable(jit, ctx, asm)
# setclassvariable
when :opt_getconstant_path then opt_getconstant_path(jit, ctx, asm)
# getconstant
@@ -408,7 +408,25 @@ module RubyVM::MJIT
KeepCompiling
end
- # getclassvariable
+ # @param jit [RubyVM::MJIT::JITState]
+ # @param ctx [RubyVM::MJIT::Context]
+ # @param asm [RubyVM::MJIT::Assembler]
+ def getclassvariable(jit, ctx, asm)
+ # rb_vm_getclassvariable 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], jit.operand(1))
+ asm.call(C.rb_vm_getclassvariable)
+
+ top = ctx.stack_push
+ asm.mov(top, C_RET)
+
+ KeepCompiling
+ end
+
# setclassvariable
# @param jit [RubyVM::MJIT::JITState]
diff --git a/mjit_c.rb b/mjit_c.rb
index b95b9f0c32..0a75ed1650 100644
--- a/mjit_c.rb
+++ b/mjit_c.rb
@@ -329,6 +329,13 @@ module RubyVM::MJIT # :nodoc: all
Primitive.cexpr! 'SIZET2NUM((size_t)rb_ivar_get)'
end
+ def rb_vm_getclassvariable
+ Primitive.cstmt! %{
+ extern VALUE rb_vm_getclassvariable(const rb_iseq_t *iseq, const rb_control_frame_t *cfp, ID id, ICVARC ic);
+ return SIZET2NUM((size_t)rb_vm_getclassvariable);
+ }
+ end
+
#========================================================================================
#
# Old stuff