Class: Carbon::Concrete::Item::Internal Private
- Inherits:
-
Object
- Object
- Carbon::Concrete::Item::Internal
- Includes:
- Data
- Defined in:
- lib/carbon/concrete/item/internal.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
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.
An internal data type. In most cases, this is just integers and pointers that can't be easily serialized because of links to LLVM and FFI.
Constant Summary collapse
- TYPE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Retreives the LLVM type information for the given integer size. This cannot be serialized by marshal or any other serialization library.
proc { |size| LLVM.const_get("Int#{size}").type }
Instance Attribute Summary
Attributes included from Data
Attributes included from Base
#dependencies, #generics, #name, #type
Class Method Summary collapse
-
.from(type) ⇒ {::Symbol => ::Object}
private
Creates a hash from a given Type that can be used to intialize an instance of this object.
Instance Method Summary collapse
-
#call(build, generics) ⇒ void
private
Performs compilation for the item.
-
#initialize(data) ⇒ Internal
constructor
private
Initialize the internal data type.
Methods included from Base
#==, #corrected_dependencies, #define, #hash
Constructor Details
#initialize(data) ⇒ Internal
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Initialize the internal data type. Internal data types may not have generic information, and have no dependencies, but can still implement traits.
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/carbon/concrete/item/internal.rb', line 48 def initialize(data) @type = data.fetch(:type) @kind = data.fetch(:kind).to_s @size = data.fetch(:size, 8) @extern = data[:extern] @generics = @type.generics @implements = Set.new(data.fetch(:implements, [])) @dependencies = Set.new(@generics.map(&:name)) @name = @module.to_s deep_freeze! end |
Class Method Details
.from(type) ⇒ {::Symbol => ::Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a hash from a given Type that can be used to intialize an instance of this object. This is mostly used for Carbon::Concrete::Index#define and shouldn't be used anywhere else.
28 29 30 |
# File 'lib/carbon/concrete/item/internal.rb', line 28 def self.from(type) { type: type, implements: [] } end |
Instance Method Details
#call(build, generics) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Performs compilation for the item. This converts the item into an
LLVM-based value or type, to be used for compiling. If
unimplemented, it raises a NotImplementedError
.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/carbon/concrete/item/internal.rb', line 63 def call(build, generics) full = @type.sub(generics) value = case @kind.to_s when "integer" then TYPE.call(@size) when "void" then ::LLVM::Type.void when "opaque" ::LLVM::Type.struct([], false, @extern || full.to_s) when "pointer" type = build.fetch(generics.fetch(Carbon::Type("T"))) type.last.pointer else fail ArgumentError, "Unknown kind #{@kind}" end build.items[@type.sub(generics)] = [self, value] end |