Implement non-embedded ivars

This commit is contained in:
Takashi Kokubun 2023-02-07 23:25:33 -08:00
parent 5a1cee1d96
commit d11f960fb0
2 changed files with 14 additions and 9 deletions

View File

@ -135,12 +135,13 @@ module RubyVM::MJIT
define_singleton_method(:sizeof) { sizeof } define_singleton_method(:sizeof) { sizeof }
# Part of Struct's offsetof implementation # Part of Struct's offsetof implementation
define_singleton_method(:offsetof) do |*fields| define_singleton_method(:offsetof) do |field, *fields|
if fields.size == 1 member = members.fetch(field)
0 offset = 0
else unless fields.empty?
raise NotImplementedError offset += member.offsetof(*fields)
end end
offset
end end
define_method(:initialize) do |addr| define_method(:initialize) do |addr|

View File

@ -575,7 +575,7 @@ module RubyVM::MJIT
case C.BUILTIN_TYPE(comptime_obj) case C.BUILTIN_TYPE(comptime_obj)
when C.T_OBJECT when C.T_OBJECT
# This is the only supported case for now # This is the only supported case for now (ROBJECT_IVPTR)
else else
asm.incr_counter(:getivar_not_t_object) asm.incr_counter(:getivar_not_t_object)
return CantCompile return CantCompile
@ -593,13 +593,17 @@ module RubyVM::MJIT
index = C.rb_shape_get_iv_index(shape_id, ivar_id) index = C.rb_shape_get_iv_index(shape_id, ivar_id)
if index if index
# See ROBJECT_IVPTR
if C.FL_TEST_RAW(comptime_obj, C.ROBJECT_EMBED) if C.FL_TEST_RAW(comptime_obj, C.ROBJECT_EMBED)
# Access embedded array
asm.mov(:rax, [:rax, C.RObject.offsetof(:as, :ary) + (index * C.VALUE.size)]) asm.mov(:rax, [:rax, C.RObject.offsetof(:as, :ary) + (index * C.VALUE.size)])
val_opnd = :rax
else else
asm.incr_counter(:getivar_too_complex) # Pull out an ivar table on heap
return CantCompile asm.mov(:rax, [:rax, C.RObject.offsetof(:as, :heap, :ivptr)])
# Read the table
asm.mov(:rax, [:rax, index * C.VALUE.size])
end end
val_opnd = :rax
else else
val_opnd = Qnil val_opnd = Qnil
end end