class Ikra::Types::StructType
This type represents a C++ struct. It has fields, each of which has a type.
Attributes
fields[R]
Public Class Methods
identifier_from_hash(fields)
click to toggle source
Generates a unique type identifier based on the types of the struct fields.
# File lib/types/types/struct_type.rb, line 29 def identifier_from_hash(fields) identifier = "indexed_struct_#{fields.size}_lt_" type_parts = fields.map do |key, value| value.to_c_type end identifier = identifier + type_parts.join("_") return identifier + "_gt_t" end
new(fields)
click to toggle source
Ensure singleton per class
Calls superclass method
# File lib/types/types/struct_type.rb, line 16 def new(fields) if @cache == nil @cache = {} end if not @cache.include?(identifier_from_hash(fields)) @cache[identifier_from_hash(fields)] = super(fields) end @cache[identifier_from_hash(fields)] end
new(fields)
click to toggle source
# File lib/types/types/struct_type.rb, line 46 def initialize(fields) fields.each do |key, value| if not value.is_union_type? raise AssertionError.new("Union type expected for field #{key}") end end @fields = fields end
Public Instance Methods
==(other)
click to toggle source
# File lib/types/types/struct_type.rb, line 42 def ==(other) return other.class == self.class && other.fields == self.fields end
generate_definition()
click to toggle source
# File lib/translator/struct_type.rb, line 4 def generate_definition raise NotImplementedError.new("ZipStructType is the only implementation") end
to_c_type()
click to toggle source
# File lib/types/types/struct_type.rb, line 56 def to_c_type return StructType.identifier_from_hash(@fields) end
to_ffi_type()
click to toggle source
# File lib/types/types/struct_type.rb, line 60 def to_ffi_type # TODO: Support transfering zipped data back from GPU return to_ruby_type end
to_ruby_type()
click to toggle source
# File lib/types/types/struct_type.rb, line 65 def to_ruby_type # TODO: general structs raise NotImplementedError.new end