diff options
author | Takashi Kokubun <[email protected]> | 2023-02-28 22:45:59 -0800 |
---|---|---|
committer | Takashi Kokubun <[email protected]> | 2023-03-05 23:28:59 -0800 |
commit | 8b84c68d77f4697cc647860c168c2b85b8f6e84d (patch) | |
tree | b381ae1843bbe6ca90c6a83c20dce0b298a1bdce /lib | |
parent | 536d8cc51b065315ff463594b5135abb5f1340da (diff) |
Implement defined
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/7448
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ruby_vm/mjit/insn_compiler.rb | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/lib/ruby_vm/mjit/insn_compiler.rb b/lib/ruby_vm/mjit/insn_compiler.rb index a266c11665..963d03a0bd 100644 --- a/lib/ruby_vm/mjit/insn_compiler.rb +++ b/lib/ruby_vm/mjit/insn_compiler.rb @@ -22,7 +22,7 @@ module RubyVM::MJIT asm.incr_counter(:mjit_insns_count) asm.comment("Insn: #{insn.name}") - # 59/101 + # 60/101 case insn.name when :nop then nop(jit, ctx, asm) when :getlocal then getlocal(jit, ctx, asm) @@ -67,7 +67,7 @@ module RubyVM::MJIT when :topn then topn(jit, ctx, asm) when :setn then setn(jit, ctx, asm) when :adjuststack then adjuststack(jit, ctx, asm) - # defined + when :defined then defined(jit, ctx, asm) # checkmatch # checkkeyword # checktype @@ -617,7 +617,41 @@ module RubyVM::MJIT KeepCompiling end - # defined + # @param jit [RubyVM::MJIT::JITState] + # @param ctx [RubyVM::MJIT::Context] + # @param asm [RubyVM::MJIT::Assembler] + def defined(jit, ctx, asm) + op_type = jit.operand(0) + obj = jit.operand(1, ruby: true) + pushval = jit.operand(2, ruby: true) + + # Save the PC and SP because the callee may allocate + # Note that this modifies REG_SP, which is why we do it first + jit_prepare_routine_call(jit, ctx, asm) + + # Get the operands from the stack + v_opnd = ctx.stack_pop(1) + + # Call vm_defined(ec, reg_cfp, op_type, obj, v) + asm.mov(C_ARGS[0], EC) + asm.mov(C_ARGS[1], CFP) + asm.mov(C_ARGS[2], op_type) + asm.mov(C_ARGS[3], to_value(obj)) + asm.mov(C_ARGS[4], v_opnd) + asm.call(C.rb_vm_defined) + + asm.test(C_RET, 255) + asm.mov(:rax, Qnil) + asm.mov(:rcx, to_value(pushval)) + asm.cmovnz(:rax, :rcx) + + # Push the return value onto the stack + stack_ret = ctx.stack_push + asm.mov(stack_ret, :rax) + + KeepCompiling + end + # checkmatch # checkkeyword # checktype |