class RubyVM::RJIT::CPointer::Immediate

公共类方法

define(fiddle_type) 点击以切换源代码

@param fiddle_type [Integer] Fiddle::TYPE_*

调用父类方法
# File ruby_vm/rjit/c_pointer.rb, line 207
def self.define(fiddle_type)
  size = Fiddle::PackInfo::SIZE_MAP.fetch(fiddle_type)
  pack = Fiddle::PackInfo::PACK_MAP.fetch(fiddle_type)

  Class.new(self) do
    define_method(:initialize) do |addr|
      super(addr, size, pack)
    end

    define_singleton_method(:size) do
      size
    end

    # Type-level []=: Used by struct fields
    define_singleton_method(:[]=) do |addr, value|
      Fiddle::Pointer.new(addr)[0, size] = [value].pack(pack)
    end
  end
end
new(addr, size, pack) 点击以切换源代码

@param addr [Integer] @param size [Integer] @param pack [String]

# File ruby_vm/rjit/c_pointer.rb, line 169
def initialize(addr, size, pack)
  @addr = addr
  @size = size
  @pack = pack
end

公共实例方法

*() 点击以切换源代码

解引用

# File ruby_vm/rjit/c_pointer.rb, line 186
def *
  self[0]
end
+(index) 点击以切换源代码

像数组一样移动 addr 到此指针的地址

# File ruby_vm/rjit/c_pointer.rb, line 181
def +(index)
  Immediate.new(@addr + index * @size, @size, @pack)
end
[](index) 点击以切换源代码

Array 访问

# File ruby_vm/rjit/c_pointer.rb, line 191
def [](index)
  return nil if @addr == 0
  Fiddle::Pointer.new(@addr + index * @size)[0, @size].unpack1(@pack)
end
[]=(index, value) 点击以切换源代码

Array 设置

# File ruby_vm/rjit/c_pointer.rb, line 197
def []=(index, value)
  Fiddle::Pointer.new(@addr + index * @size)[0, @size] = [value].pack(@pack)
end
to_i() 点击以切换源代码

获取原始地址

# File ruby_vm/rjit/c_pointer.rb, line 176
def to_i
  @addr
end
to_s() 点击以切换源代码

用于生成代码的序列化地址。用于嵌入诸如 body->iseq_encoded 之类的内容。

# File ruby_vm/rjit/c_pointer.rb, line 202
def to_s
  "0x#{Integer(@addr).to_s(16)}"
end