class RubyVM::RJIT::CPointer::Pointer

Attributes

type[R]

Public Class Methods

new(addr, type) click to toggle source

@param addr [Integer] @param type [Class] RubyVM::RJIT::CType::*

# File ruby_vm/rjit/c_pointer.rb, line 246
def initialize(addr, type)
  @addr = addr
  @type = type
end

Private Class Methods

define(block) click to toggle source
Calls superclass method
# File ruby_vm/rjit/c_pointer.rb, line 287
def self.define(block)
  Class.new(self) do
    define_method(:initialize) do |addr|
      super(addr, block.call)
    end

    # Type-level []=: Used by struct fields
    # @param addr [Integer]
    # @param value [Integer, RubyVM::RJIT::CPointer::Struct] an address itself, or an object that return an address with to_i
    define_singleton_method(:[]=) do |addr, value|
      value = value.to_i
      Fiddle::Pointer.new(addr)[0, Fiddle::SIZEOF_VOIDP] = [value].pack(Fiddle::PackInfo::PACK_MAP[Fiddle::TYPE_VOIDP])
    end
  end
end

Public Instance Methods

*() click to toggle source

Dereference

# File ruby_vm/rjit/c_pointer.rb, line 258
def *
  return nil if dest_addr == 0
  @type.new(dest_addr)
end
+(index) click to toggle source

Move addr to addess this pointer like an array

# File ruby_vm/rjit/c_pointer.rb, line 252
def +(index)
  raise ArgumentError unless index.is_a?(Integer)
  Pointer.new(@addr + index * Fiddle::SIZEOF_VOIDP, @type)
end
[](index) click to toggle source

Array access

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

Array set @param index [Integer] @param value [Integer, RubyVM::RJIT::CPointer::Struct] an address itself or an object that return an address with to_i

# File ruby_vm/rjit/c_pointer.rb, line 271
def []=(index, value)
  Fiddle::Pointer.new(@addr + index * Fiddle::SIZEOF_VOIDP)[0, Fiddle::SIZEOF_VOIDP] =
    [value.to_i].pack(Fiddle::PackInfo::PACK_MAP[Fiddle::TYPE_VOIDP])
end
to_i() click to toggle source

Get a raw address

# File ruby_vm/rjit/c_pointer.rb, line 277
def to_i
  @addr
end

Private Instance Methods

dest_addr() click to toggle source
# File ruby_vm/rjit/c_pointer.rb, line 283
def dest_addr
  Fiddle::Pointer.new(@addr)[0, Fiddle::SIZEOF_VOIDP].unpack1(Fiddle::PackInfo::PACK_MAP[Fiddle::TYPE_VOIDP])
end