Class: RubyVM::RJIT::CPointer::BitField
- Inherits:
-
Object
- Object
- RubyVM::RJIT::CPointer::BitField
- Defined in:
- lib/ruby_vm/rjit/c_pointer.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#* ⇒ Object
Dereference.
-
#initialize(addr, width, offset) ⇒ BitField
constructor
A new instance of BitField.
Constructor Details
#initialize(addr, width, offset) ⇒ BitField
Returns a new instance of BitField.
342 343 344 345 346 |
# File 'lib/ruby_vm/rjit/c_pointer.rb', line 342 def initialize(addr, width, offset) @addr = addr @width = width @offset = offset end |
Class Method Details
.define(width, offset) ⇒ Object
364 365 366 367 368 369 370 |
# File 'lib/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 |
Instance Method Details
#* ⇒ Object
Dereference
349 350 351 352 353 354 355 356 357 358 359 360 |
# File 'lib/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 |