diff options
Diffstat (limited to 'lib/ruby_vm/rjit/c_pointer.rb')
-rw-r--r-- | lib/ruby_vm/rjit/c_pointer.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/lib/ruby_vm/rjit/c_pointer.rb b/lib/ruby_vm/rjit/c_pointer.rb index 1a84896822..db00c4cd11 100644 --- a/lib/ruby_vm/rjit/c_pointer.rb +++ b/lib/ruby_vm/rjit/c_pointer.rb @@ -238,6 +238,40 @@ module RubyVM::RJIT end end + # Basically Immediate but without #* to skip auto-dereference of structs. + class Array + attr_reader :type + + # @param addr [Integer] + # @param type [Class] RubyVM::RJIT::CType::* + def initialize(addr, type) + @addr = addr + @type = type + end + + # Array access + def [](index) + @type.new(@addr)[index] + end + + # Array set + # @param index [Integer] + # @param value [Integer, RubyVM::RJIT::CPointer::Struct] an address itself or an object that return an address with to_i + def []=(index, value) + @type.new(@addr)[index] = value + end + + private + + def self.define(block) + Class.new(self) do + define_method(:initialize) do |addr| + super(addr, block.call) + end + end + end + end + class Pointer attr_reader :type |