class RubyVM::MJIT::CPointer::Pointer

Attributes

type[R]

Public Class Methods

new(addr, type) click to toggle source

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

# File lib/mjit/c_pointer.rb, line 220
def initialize(addr, type)
  @addr = addr
  @type = type
end

Private Class Methods

define(block) click to toggle source
Calls superclass method
# File lib/mjit/c_pointer.rb, line 256
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::MJIT::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 lib/mjit/c_pointer.rb, line 232
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 lib/mjit/c_pointer.rb, line 226
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 lib/mjit/c_pointer.rb, line 238
def [](index)
  (self + index).*
end
[]=(index, value) click to toggle source

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

# File lib/mjit/c_pointer.rb, line 245
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

Private Instance Methods

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