class RubyVM::MJIT::CPointer::Immediate

Public Class Methods

define(fiddle_type) click to toggle source

@param fiddle_type [Integer] Fiddle::TYPE_*

Calls superclass method
# File lib/mjit/c_pointer.rb, line 181
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 lib/mjit/c_pointer.rb, line 143
def initialize(addr, size, pack)
  @addr = addr
  @size = size
  @pack = pack
end

Public Instance Methods

*() click to toggle source

Dereference

# File lib/mjit/c_pointer.rb, line 160
def *
  self[0]
end
+(index) click to toggle source

Move addr to addess this pointer like an array

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

Array access

# File lib/mjit/c_pointer.rb, line 165
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 lib/mjit/c_pointer.rb, line 171
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 lib/mjit/c_pointer.rb, line 150
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 lib/mjit/c_pointer.rb, line 176
def to_s
  "0x#{Integer(@addr).to_s(16)}"
end