Class: Carbon::Concrete::Build
- Inherits:
-
Object
- Object
- Carbon::Concrete::Build
- Defined in:
- lib/carbon/concrete/build.rb
Overview
Handles building requests. This is the step after all requests are determined from the dependency build stage. The entire purpose of this class is to consolidate state information for LLVM module building.
Instance Attribute Summary collapse
-
#index ⇒ Concrete::Index
readonly
The index associated with this build.
-
#items ⇒ {Concrete::Type => (Concrete::Item, ::LLVM::Value)}
readonly
The types that have been defined.
-
#module ⇒ ::LLVM::Module
readonly
The LLVM module that is being used for compilation.
Instance Method Summary collapse
-
#call ⇒ ::LLVM::Module
Performs the build process.
- #fetch(name, default = nil) ⇒ Object
-
#initialize(requests, index) ⇒ Build
constructor
Initialize the build process.
Constructor Details
#initialize(requests, index) ⇒ Build
Initialize the build process. This only initializes instance variables.
38 39 40 41 |
# File 'lib/carbon/concrete/build.rb', line 38 def initialize(requests, index) @requests = requests @index = index end |
Instance Attribute Details
#index ⇒ Concrete::Index (readonly)
The index associated with this build.
28 29 30 |
# File 'lib/carbon/concrete/build.rb', line 28 def index @index end |
#items ⇒ {Concrete::Type => (Concrete::Item, ::LLVM::Value)} (readonly)
18 19 20 |
# File 'lib/carbon/concrete/build.rb', line 18 def items @items end |
#module ⇒ ::LLVM::Module (readonly)
The LLVM module that is being used for compilation.
23 24 25 |
# File 'lib/carbon/concrete/build.rb', line 23 def module @module end |
Instance Method Details
#call ⇒ ::LLVM::Module
Performs the build process. Builds each request in order by calling Item::Base#call on each.
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/carbon/concrete/build.rb', line 56 def call @items = {} @module = ::LLVM::Module.new("__carbon_main") @requests.each do |request| item = @index.fetch(request).first generics = item.generics.map(&:name) .zip(request.generics.map(&:name)).to_h item.call(self, generics) end @module end |
#fetch(name, default = nil) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/carbon/concrete/build.rb', line 43 def fetch(name, default = nil) result = @items.find { |(k, _v)| k.match?(name) } return result[1] if result return default if default yield if block_given? fail ItemNotFoundError, "Could not find item with name #{name}" end |