class RubyVM::RJIT::CPointer::BitField

Public Class Methods

define(width, offset) click to toggle source

@param width [Integer] @param offset [Integer]

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

@param addr [Integer] @param width [Integer] @param offset [Integer]

# File ruby_vm/rjit/c_pointer.rb, line 342
def initialize(addr, width, offset)
  @addr = addr
  @width = width
  @offset = offset
end

Public Instance Methods

*() click to toggle source

Dereference

# File ruby_vm/rjit/c_pointer.rb, line 349
def *
  byte = Fiddle::Pointer.new(@addr)[0, Fiddle::SIZEOF_CHAR].unpack('c').first
  if @width == 1
    bit = (1 & (byte >> @offset))
    bit == 1
  elsif @width <= 8 && @offset == 0
    bitmask = @width.times.map { |i| 1 << i }.sum
    byte & bitmask
  else
    raise NotImplementedError.new("not-implemented bit field access: width=#{@width} offset=#{@offset}")
  end
end