summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Kokubun <takashikkbn@gmail.com>2023-03-03 22:49:31 -0800
committerTakashi Kokubun <takashikkbn@gmail.com>2023-03-05 23:28:59 -0800
commit481615418a26568c3972daefaed7d583815e7191 (patch)
tree5f2827b7f1e3cb11776b08c1f8f351d41a61c0d3
parentf2ef352ee0bfa65cef8242740ab7ba5a831d1934 (diff)
Implement getconstant
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/7448
-rw-r--r--lib/ruby_vm/mjit/insn_compiler.rb29
-rw-r--r--mjit_c.rb7
2 files changed, 33 insertions, 3 deletions
diff --git a/lib/ruby_vm/mjit/insn_compiler.rb b/lib/ruby_vm/mjit/insn_compiler.rb
index d245ff2ce2..8dca11e4cf 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}")
- # 70/101
+ # 71/101
case insn.name
when :nop then nop(jit, ctx, asm)
when :getlocal then getlocal(jit, ctx, asm)
@@ -39,7 +39,7 @@ module RubyVM::MJIT
when :getclassvariable then getclassvariable(jit, ctx, asm)
# setclassvariable
when :opt_getconstant_path then opt_getconstant_path(jit, ctx, asm)
- # getconstant
+ when :getconstant then getconstant(jit, ctx, asm)
# setconstant
# getglobal
# setglobal
@@ -495,7 +495,30 @@ module RubyVM::MJIT
EndBlock
end
- # getconstant
+ # @param jit [RubyVM::MJIT::JITState]
+ # @param ctx [RubyVM::MJIT::Context]
+ # @param asm [RubyVM::MJIT::Assembler]
+ def getconstant(jit, ctx, asm)
+ id = jit.operand(0)
+
+ # vm_get_ev_const can raise exceptions.
+ jit_prepare_routine_call(jit, ctx, asm)
+
+ allow_nil_opnd = ctx.stack_pop(1)
+ klass_opnd = ctx.stack_pop(1)
+
+ asm.mov(C_ARGS[0], EC)
+ asm.mov(C_ARGS[1], klass_opnd)
+ asm.mov(C_ARGS[2], id)
+ asm.mov(C_ARGS[3], allow_nil_opnd)
+ asm.call(C.rb_vm_get_ev_const)
+
+ top = ctx.stack_push
+ asm.mov(top, C_RET)
+
+ KeepCompiling
+ end
+
# setconstant
# getglobal
# setglobal
diff --git a/mjit_c.rb b/mjit_c.rb
index de5c421714..b2b924248c 100644
--- a/mjit_c.rb
+++ b/mjit_c.rb
@@ -366,6 +366,13 @@ module RubyVM::MJIT # :nodoc: all
Primitive.cexpr! 'rb_class_attached_object(klass)'
end
+ def rb_vm_get_ev_const
+ Primitive.cstmt! %{
+ extern VALUE rb_vm_get_ev_const(rb_execution_context_t *ec, VALUE orig_klass, ID id, VALUE allow_nil);
+ return SIZET2NUM((size_t)rb_vm_get_ev_const);
+ }
+ end
+
#========================================================================================
#
# Old stuff