Class: JIT::Array::Instance
Overview
An abstraction for an instance of a fixed-length array.
Instance Attribute Summary collapse
-
#array_type ⇒ Object
readonly
Returns the value of attribute array_type.
-
#ptr ⇒ Object
readonly
A pointer to the first element of the array.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.wrap(array_type, ptr) ⇒ Object
Wrap an existing array.
Instance Method Summary collapse
-
#[](index) ⇒ Object
Generate JIT code to retrieve the element at the given
index. -
#[]=(index, value) ⇒ Object
Generate JIT code to assign to the element at the given
index.
Methods inherited from Value
#%, #&, #*, #+, #-, #-@, #/, #<, #<<, #<=, #==, #>, #>=, #>>, #^, #address, #addressable=, #addressable?, #coerce, #constant?, #function, #inspect, #local?, #neq, new, new_value, #set_volatile, #store, #temporary?, #to_s, #valid?, #volatile?, #|, #~
Instance Attribute Details
#array_type ⇒ Object (readonly)
Returns the value of attribute array_type.
79 80 81 |
# File 'lib/jit/array.rb', line 79 def array_type @array_type end |
#ptr ⇒ Object (readonly)
A pointer to the first element of the array. Note that this differs from address, which returns the address of a pointer to the array.
85 86 87 |
# File 'lib/jit/array.rb', line 85 def ptr @ptr end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
80 81 82 |
# File 'lib/jit/array.rb', line 80 def type @type end |
Class Method Details
.wrap(array_type, ptr) ⇒ Object
Wrap an existing array.
array_type-
The JIT::Array type to wrap.
ptr-
A pointer to the first element in the array.
95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/jit/array.rb', line 95 def self.wrap(array_type, ptr) pointer_type = JIT::Type.create_pointer(array_type) value = self.new_value(ptr.function, pointer_type) value.store(ptr) value.instance_eval do @array_type = array_type @type = array_type.type @function = ptr.function @ptr = ptr end return value end |
Instance Method Details
#[](index) ⇒ Object
Generate JIT code to retrieve the element at the given index.
index-
The index of the desired element. The value of the index must be known at compile-time.
113 114 115 116 117 118 |
# File 'lib/jit/array.rb', line 113 def [](index) @function.insn_load_relative( @ptr, @array_type.offset_of(index), @array_type.type_of(index)) end |
#[]=(index, value) ⇒ Object
Generate JIT code to assign to the element at the given index.
index-
The index of the desired element. The value of the index must be known at compile-time.
value-
The JIT::Value to assign to the element.
126 127 128 129 130 131 |
# File 'lib/jit/array.rb', line 126 def []=(index, value) @function.insn_store_relative( @ptr, @array_type.offset_of(index), value) end |