Class: RubyVM::RJIT::CPointer::Pointer
- Inherits:
-
Object
- Object
- RubyVM::RJIT::CPointer::Pointer
- Defined in:
- lib/ruby_vm/rjit/c_pointer.rb
Instance Attribute Summary collapse
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
Instance Method Summary collapse
-
#* ⇒ Object
Dereference.
-
#+(index) ⇒ Object
Move addr to addess this pointer like an array.
-
#[](index) ⇒ Object
Array access.
-
#[]=(index, value) ⇒ Object
Array set.
-
#initialize(addr, type) ⇒ Pointer
constructor
A new instance of Pointer.
-
#to_i ⇒ Object
Get a raw address.
Constructor Details
#initialize(addr, type) ⇒ Pointer
Returns a new instance of Pointer.
280 281 282 283 |
# File 'lib/ruby_vm/rjit/c_pointer.rb', line 280 def initialize(addr, type) @addr = addr @type = type end |
Instance Attribute Details
#type ⇒ Object (readonly)
Returns the value of attribute type.
276 277 278 |
# File 'lib/ruby_vm/rjit/c_pointer.rb', line 276 def type @type end |
Class Method Details
.define(block) ⇒ Object
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 |
# File 'lib/ruby_vm/rjit/c_pointer.rb', line 321 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::RJIT::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 |
Instance Method Details
#* ⇒ Object
Dereference
292 293 294 295 |
# File 'lib/ruby_vm/rjit/c_pointer.rb', line 292 def * return nil if dest_addr == 0 @type.new(dest_addr) end |
#+(index) ⇒ Object
Move addr to addess this pointer like an array
286 287 288 289 |
# File 'lib/ruby_vm/rjit/c_pointer.rb', line 286 def +(index) raise ArgumentError unless index.is_a?(Integer) Pointer.new(@addr + index * Fiddle::SIZEOF_VOIDP, @type) end |
#[](index) ⇒ Object
Array access
298 299 300 |
# File 'lib/ruby_vm/rjit/c_pointer.rb', line 298 def [](index) (self + index).* end |
#[]=(index, value) ⇒ Object
Array set
305 306 307 308 |
# File 'lib/ruby_vm/rjit/c_pointer.rb', line 305 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 |
#to_i ⇒ Object
Get a raw address
311 312 313 |
# File 'lib/ruby_vm/rjit/c_pointer.rb', line 311 def to_i @addr end |