Class: RLTK::CG::ConstantStruct

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

Overview

A constant struct value.

Instance Attribute Summary

Attributes included from BindingClass

#ptr

Instance Method Summary collapse

Methods inherited from ConstantAggregate

#extract, #insert

Methods inherited from Constant

#addr_space_cast, #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(size_or_values, packed = false, context = nil, &block) {|index| ... } ⇒ ConstantStruct

Create a new constant struct value.

Examples:

Using array of values:

ConstantStruct.new([Int32.new(0), Int64.new(1), Int32.new(2), Int64.new(3)])

Using size:

ConstantStruct.new(4) { |i| if i % 2 == 0 then Int32.new(i) else Int64.new(i) end }

Parameters:

  • size_or_values (Array<Value>, Integer)

    Number of values or array of values.

  • packed (Boolean) (defaults to: false)

    Are the types packed already, or should they be re-arranged to save space?

  • context (Context, nil) (defaults to: nil)

    Context in which to create the value.

  • block (Proc)

    Block evaluated if size is specified.

Yield Parameters:

  • index (Integer)

    Index of the value in the struct.



463
464
465
466
467
468
469
470
471
472
473
# File 'lib/rltk/cg/value.rb', line 463

def initialize(size_or_values, packed = false, context = nil, &block)
	vals_ptr = make_ptr_to_elements(size_or_values, &block)

	@ptr =
	if context
		Bindings.const_struct_in_context(check_type(context, Context, 'context'),
		                                 vals_ptr, vals_ptr.size / vals_ptr.type_size, packed.to_i)
	else
		Bindings.const_struct(vals_ptr, vals_ptr.size / vals_ptr.type_size, packed.to_i)
	end
end