MJIT: Use the built-in PACK_MAP

106744107b made this possible.
This commit is contained in:
Takashi Kokubun 2022-09-11 15:39:32 +09:00
Родитель 106744107b
Коммит 472e7b8518
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 6FFC433B12EE23DD
1 изменённых файлов: 4 добавлений и 12 удалений

Просмотреть файл

@ -2,14 +2,6 @@ module RubyVM::MJIT
# Every class under this namespace is a pointer. Even if the type is # Every class under this namespace is a pointer. Even if the type is
# immediate, it shouldn't be dereferenced until `*` is called. # immediate, it shouldn't be dereferenced until `*` is called.
module CPointer module CPointer
# Patched PACK_MAP to support unsigned operations
PACK_MAP = Fiddle::PackInfo::PACK_MAP.dup
PACK_MAP.keys.each do |type|
if type.negative? || type == Fiddle::TYPE_VOIDP
PACK_MAP[type] = PACK_MAP[type].upcase
end
end
# Note: We'd like to avoid alphabetic method names to avoid a conflict # Note: We'd like to avoid alphabetic method names to avoid a conflict
# with member methods. to_i and to_s are considered an exception. # with member methods. to_i and to_s are considered an exception.
class Struct class Struct
@ -188,7 +180,7 @@ module RubyVM::MJIT
# @param fiddle_type [Integer] Fiddle::TYPE_* # @param fiddle_type [Integer] Fiddle::TYPE_*
def self.define(fiddle_type) def self.define(fiddle_type)
size = Fiddle::PackInfo::SIZE_MAP.fetch(fiddle_type) size = Fiddle::PackInfo::SIZE_MAP.fetch(fiddle_type)
pack = PACK_MAP.fetch(fiddle_type) pack = Fiddle::PackInfo::PACK_MAP.fetch(fiddle_type)
Class.new(self) do Class.new(self) do
define_method(:initialize) do |addr| define_method(:initialize) do |addr|
@ -252,13 +244,13 @@ module RubyVM::MJIT
# @param value [Integer, RubyVM::MJIT::CPointer::Struct] an address itself or an object that return an address with to_i # @param value [Integer, RubyVM::MJIT::CPointer::Struct] an address itself or an object that return an address with to_i
def []=(index, value) def []=(index, value)
Fiddle::Pointer.new(@addr + index * Fiddle::SIZEOF_VOIDP)[0, Fiddle::SIZEOF_VOIDP] = Fiddle::Pointer.new(@addr + index * Fiddle::SIZEOF_VOIDP)[0, Fiddle::SIZEOF_VOIDP] =
[value.to_i].pack(PACK_MAP[Fiddle::TYPE_VOIDP]) [value.to_i].pack(Fiddle::PackInfo::PACK_MAP[Fiddle::TYPE_VOIDP])
end end
private private
def dest_addr def dest_addr
Fiddle::Pointer.new(@addr)[0, Fiddle::SIZEOF_VOIDP].unpack1(PACK_MAP[Fiddle::TYPE_VOIDP]) Fiddle::Pointer.new(@addr)[0, Fiddle::SIZEOF_VOIDP].unpack1(Fiddle::PackInfo::PACK_MAP[Fiddle::TYPE_VOIDP])
end end
def self.define(block) def self.define(block)
@ -272,7 +264,7 @@ module RubyVM::MJIT
# @param value [Integer, RubyVM::MJIT::CPointer::Struct] an address itself, or an object that return an address with to_i # @param value [Integer, RubyVM::MJIT::CPointer::Struct] an address itself, or an object that return an address with to_i
define_singleton_method(:[]=) do |addr, value| define_singleton_method(:[]=) do |addr, value|
value = value.to_i value = value.to_i
Fiddle::Pointer.new(addr)[0, Fiddle::SIZEOF_VOIDP] = [value].pack(PACK_MAP[Fiddle::TYPE_VOIDP]) Fiddle::Pointer.new(addr)[0, Fiddle::SIZEOF_VOIDP] = [value].pack(Fiddle::PackInfo::PACK_MAP[Fiddle::TYPE_VOIDP])
end end
end end
end end