class RubyVM::MJIT::CPointer::BitField

Public Class Methods

define(width, offset) click to toggle source

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

Calls superclass method
# File lib/mjit/c_pointer.rb, line 299
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 lib/mjit/c_pointer.rb, line 277
def initialize(addr, width, offset)
  @addr = addr
  @width = width
  @offset = offset
end

Public Instance Methods

*() click to toggle source

Dereference

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