class RubyVM::RJIT::CPointer::Immediate

Public Class Methods

define(fiddle_type) click to toggle source

@param fiddle_type [Integer] Fiddle::TYPE_*

Calls superclass method
# 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) click to toggle source

@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

Public Instance Methods

*() click to toggle source

Dereference

# File ruby_vm/rjit/c_pointer.rb, line 186
def *
  self[0]
end
+(index) click to toggle source

Move addr to addess this pointer like an array

# File ruby_vm/rjit/c_pointer.rb, line 181
def +(index)
  Immediate.new(@addr + index * @size, @size, @pack)
end
[](index) click to toggle source

Array access

# 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) click to toggle source

Array set

# 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() click to toggle source

Get a raw address

# File ruby_vm/rjit/c_pointer.rb, line 176
def to_i
  @addr
end
to_s() click to toggle source

Serialized address for generated code. Used for embedding things like body->iseq_encoded.

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