class Carbon::Concrete::Item::Class
A struct data type. This is normally a sequence of elements that are stored sequentially in memory. Each element has a name, to reference which position, and a type. All references to this data type in memory are through pointers.
@api private @note
**This class is frozen upon initialization.** This means that any attempt to modify it will result in an error. In most cases, the attributes on this class will also be frozen, as well.
Public Class Methods
from(type)
click to toggle source
(see Item::Base.from
)
# File lib/carbon/concrete/item/class.rb, line 23 def self.from(type) { type: type, implements: [], elements: [] } end
new(data)
click to toggle source
Initialize the struct with the given data.
@param data [::Hash] The data to initialize with. @option data [Type] :module The name of the struct. @option data [<::String, Type>] :elements The elements of
the struct.
@option data [<Type>] :implements The traits that this
data type implements.
# File lib/carbon/concrete/item/class.rb, line 35 def initialize(data) @type = data.fetch(:type) @generics = @type.generics @name = @type.to_s @extern = data[:extern] @implements = Set.new(data.fetch(:implements)) @dependencies = Set.new derive_elements(data.fetch(:elements)) derive_dependencies deep_freeze! end
Public Instance Methods
call(build, generics)
click to toggle source
(see Base#call
)
# File lib/carbon/concrete/item/class.rb, line 50 def call(build, generics) full = @type.sub(generics) elements = @elements.map(&:type).map { |t| t.sub(generics) } .map { |t| build.fetch(t).last } name = @extern || full.to_s build.items[full] = [self, ::LLVM::Type.struct(elements, false, name).pointer] end
Private Instance Methods
derive_dependencies()
click to toggle source
# File lib/carbon/concrete/item/class.rb, line 65 def derive_dependencies @dependencies.merge(@elements.map(&:type)) end
derive_elements(elements)
click to toggle source
# File lib/carbon/concrete/item/class.rb, line 61 def derive_elements(elements) @elements = elements.map { |e| Element.new(*e) } end