Class: RLTK::CG::ConstantArray

Inherits:
ConstantAggregate show all
Defined in:
lib/rltk/cg/value.rb

Overview

A constant array value.

Direct Known Subclasses

ConstantString

Instance Attribute Summary

Attributes included from BindingClass

#ptr

Instance Method Summary collapse

Methods inherited from ConstantAggregate

#extract, #insert

Methods included from AbstractClass

included

Methods inherited from Constant

#bitcast_to, #get_element_ptr, #get_element_ptr_in_bounds

Methods inherited from User

#operands

Methods inherited from Value

#==, #attributes, #bitcast, #constant?, #dump, #hash, #name, #name=, #null?, #print, #trunc, #trunc_or_bitcast, #type, #undefined?, #zextend, #zextend_or_bitcast

Methods included from BindingClass

#==

Constructor Details

#initialize(element_type, size_or_values, &block) {|index| ... } ⇒ ConstantArray

Create a new constant array value.

Examples:

Using array of values:

ConstantArray.new(Int32Type, [Int32.new(0), Int32.new(1)])

Using size:

ConstantArray.new(Int32Type, 2) { |i| Int32.new(i) }

Parameters:

  • element_type (Type)

    Type of values in this aggregate.

  • size_or_values (Array<Value>, Integer)

    Number of values or array of values.

  • block (Proc)

    Block evaluated if size is specified.

Yield Parameters:

  • index (Integer)

    Index of the value in the array.



420
421
422
423
424
# File 'lib/rltk/cg/value.rb', line 420

def initialize(element_type, size_or_values, &block)
	vals_ptr	= make_ptr_to_elements(size_or_values, &block)
	@type	= ArrayType.new(element_type = check_cg_type(element_type, Type, 'element_type'))
	@ptr		= Bindings.const_array(element_type, vals_ptr, vals_ptr.size / vals_ptr.type_size)
end