Compile a real return value

This commit is contained in:
Takashi Kokubun 2022-12-15 22:20:43 -08:00
parent 3fa4d41460
commit 6fc336fedc
3 changed files with 51 additions and 22 deletions

View file

@ -19,15 +19,29 @@ class RubyVM::MJIT::Compiler
# @param iseq [RubyVM::MJIT::CPointer::Struct]
def compile(iseq)
return if iseq.body.location.label == '<main>'
iseq.body.jit_func = write_addr
asm = Assembler.new
asm.mov(:eax, Qundef)
asm.ret
asm.compile(self)
iseq.body.jit_func = compile_iseq(iseq)
end
def write_addr
@mem_block + @write_pos
end
private
# ec -> RDI, cfp -> RSI
def compile_iseq(iseq)
addr = write_addr
asm = Assembler.new
# pop the current frame (ec->cfp++)
asm.add(:rsi, C.rb_control_frame_t.size)
asm.mov([:rdi, C.rb_execution_context_t.offsetof(:cfp)], :rsi)
# return a value
asm.mov(:rax, 7)
asm.ret
asm.compile(self)
addr
end
end