diff options
author | Takashi Kokubun <[email protected]> | 2022-12-15 22:20:43 -0800 |
---|---|---|
committer | Takashi Kokubun <[email protected]> | 2023-03-05 22:11:20 -0800 |
commit | 6fc336fedcbf58cceedd272ecf1ac2f725662f73 (patch) | |
tree | 11f64e23cc60e21833a9b3febf4dedc4c8207020 /lib/ruby_vm/mjit | |
parent | 3fa4d41460f67791d08d9bec2f8add9dd15f0f07 (diff) |
Compile a real return value
Diffstat (limited to 'lib/ruby_vm/mjit')
-rw-r--r-- | lib/ruby_vm/mjit/c_pointer.rb | 13 | ||||
-rw-r--r-- | lib/ruby_vm/mjit/compiler.rb | 26 |
2 files changed, 28 insertions, 11 deletions
diff --git a/lib/ruby_vm/mjit/c_pointer.rb b/lib/ruby_vm/mjit/c_pointer.rb index 743003f230..f0f34e949e 100644 --- a/lib/ruby_vm/mjit/c_pointer.rb +++ b/lib/ruby_vm/mjit/c_pointer.rb @@ -47,12 +47,15 @@ module RubyVM::MJIT # :nodoc: all type[@addr + offset / 8] = value end - # @param sizeof [Integer] + # @param size [Integer] # @param members [Hash{ Symbol => [Integer, RubyVM::MJIT::CType::*] }] - def self.define(sizeof, members) + def self.define(size, members) Class.new(self) do # Return the size of this type - define_singleton_method(:sizeof) { sizeof } + define_singleton_method(:size) { size } + + # Return the offset to a field + define_singleton_method(:offsetof) { |field| members.fetch(field).last / 8 } # Get the offset of a member named +name+ define_singleton_method(:offsetof) { |name| @@ -62,9 +65,9 @@ module RubyVM::MJIT # :nodoc: all define_method(:initialize) do |addr = nil| if addr.nil? # TODO: get rid of this feature later - addr = Fiddle.malloc(sizeof) + addr = Fiddle.malloc(size) end - super(addr, sizeof, members) + super(addr, size, members) end members.each do |member, (type, offset, to_ruby)| diff --git a/lib/ruby_vm/mjit/compiler.rb b/lib/ruby_vm/mjit/compiler.rb index c42f75bf4d..4b980c1400 100644 --- a/lib/ruby_vm/mjit/compiler.rb +++ b/lib/ruby_vm/mjit/compiler.rb @@ -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 |