Class: JIT::Array
Overview
An abstraction for a fixed-length array type.
Example usage:
array_type = JIT::Array.new(JIT::Type::INT, 4)
JIT::Context.build do |context|
signature = JIT::Type.create_signature(
JIT::ABI::CDECL, JIT::Type::INT, [ ])
function = JIT::Function.compile(context, signature) do |f|
array_instance = array_type.create(f)
array_instance[0] = f.const(JIT::Type::INT, 42)
f.insn_return(array_instance[0])
end
end
Defined Under Namespace
Classes: Instance
Constant Summary
Constants inherited from Type
Type::FLOAT32, Type::FLOAT64, Type::FUNCTION_PTR, Type::ID, Type::INT, Type::LONG, Type::NFLOAT, Type::NINT, Type::NUINT, Type::OBJECT, Type::RUBY_VARARG_SIGNATURE, Type::SBYTE, Type::SHORT, Type::UBYTE, Type::UINT, Type::ULONG, Type::USHORT, Type::VOID, Type::VOID_PTR
Instance Attribute Summary collapse
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
Class Method Summary collapse
-
.new(type, length) ⇒ Object
Create a new JIT array type.
Instance Method Summary collapse
-
#create(function) ⇒ Object
Create a new array.
-
#offset_of(index) ⇒ Object
Return the offset (in bytes) of the element at the given
index. -
#type_of(index) ⇒ Object
Return the type of the element at the given
index. -
#wrap(ptr) ⇒ Object
Wrap an existing array.
Methods inherited from Type
_create_signature, create_pointer, create_signature, create_struct, #get_offset, #set_offset, #size
Instance Attribute Details
#length ⇒ Object (readonly)
Returns the value of attribute length.
26 27 28 |
# File 'lib/jit/array.rb', line 26 def length @length end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
25 26 27 |
# File 'lib/jit/array.rb', line 25 def type @type end |
Class Method Details
.new(type, length) ⇒ Object
Create a new JIT array type.
type-
The type of the elements in the array.
length-
The number of elements in the array.
33 34 35 36 37 38 39 40 |
# File 'lib/jit/array.rb', line 33 def self.new(type, length) array = self.create_struct([ type ] * length) array.instance_eval do @type = type @length = length end return array end |
Instance Method Details
#create(function) ⇒ Object
Create a new array.
function-
The JIT::Function this array will be used in.
54 55 56 57 58 |
# File 'lib/jit/array.rb', line 54 def create(function) instance = function.value(self) ptr = function.insn_address_of(instance) return wrap(ptr) end |
#offset_of(index) ⇒ Object
Return the offset (in bytes) of the element at the given index.
index-
The index of the desired element.
64 65 66 |
# File 'lib/jit/array.rb', line 64 def offset_of(index) return self.get_offset(index) end |
#type_of(index) ⇒ Object
Return the type of the element at the given index.
index-
The index of the desired element.
72 73 74 |
# File 'lib/jit/array.rb', line 72 def type_of(index) return @type end |