Skip to content

Commit

Permalink
RJIT: Implement definedivar
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Mar 13, 2023
1 parent 3938efa commit 330086d
Showing 1 changed file with 36 additions and 1 deletion.
37 changes: 36 additions & 1 deletion lib/ruby_vm/rjit/insn_compiler.rb
Expand Up @@ -18,7 +18,7 @@ def compile(jit, ctx, asm, insn)
asm.incr_counter(:rjit_insns_count)
asm.comment("Insn: #{insn.name}")

# 72/101
# 73/102
case insn.name
when :nop then nop(jit, ctx, asm)
when :getlocal then getlocal(jit, ctx, asm)
Expand Down Expand Up @@ -64,6 +64,7 @@ def compile(jit, ctx, asm, insn)
when :setn then setn(jit, ctx, asm)
when :adjuststack then adjuststack(jit, ctx, asm)
when :defined then defined(jit, ctx, asm)
when :definedvar then definedivar(jit, ctx, asm)
# checkmatch
# checkkeyword
# checktype
Expand Down Expand Up @@ -1038,6 +1039,40 @@ def defined(jit, ctx, asm)
KeepCompiling
end

# @param jit [RubyVM::RJIT::JITState]
# @param ctx [RubyVM::RJIT::Context]
# @param asm [RubyVM::RJIT::Assembler]
def definedivar(jit, ctx, asm)
ivar_name = jit.operand(0)
pushval = jit.operand(2)

# Get the receiver
asm.mov(:rcx, [CFP, C.rb_control_frame_t.offsetof(:self)])

# 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) # clobbers :rax

# Call rb_ivar_defined(recv, ivar_name)
asm.mov(C_ARGS[0], :rcx)
asm.mov(C_ARGS[1], ivar_name)
asm.call(C.rb_ivar_defined)

# if (rb_ivar_defined(recv, ivar_name)) {
# val = pushval;
# }
asm.test(C_RET, 255)
asm.mov(:rax, Qnil)
asm.mov(:rcx, 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
Expand Down

0 comments on commit 330086d

Please sign in to comment.