Sha256: d981f2522edbe966de1603dc815ad5df6a6e595a6f1fa1244b4868df6e63d8c4

Contents?: true

Size: 1.77 KB

Versions: 2

Compression:

Stored size: 1.77 KB

Contents

# encoding: utf-8
# frozen_string_literal: true

require "pathname"

module Carbon
  # The Carbon Core library.  This is the library that is loaded for every
  # program, and contains definitions that cannot be defined from within
  # Carbon.  The Carbon Core library is required for any Carbon program
  # to function.
  #
  # @api private
  module Core
    PATH = Pathname.new(File.expand_path("../core/core.clib", __FILE__))
    # The core index.  This can either be loaded from a core library file or
    # from the definitions in this library.
    #
    # @return [Concrete::Index] The Carbon Core library index.
    def self.index
      @index ||= find
    end

    # Defines an item on the core index.
    #
    # @see .index
    # @see Concrete::Index#define
    # @api semipublic
    # @example (see Concrete::Index#define)
    # @param (see Concrete::Index#define)
    # @yield (see Concrete::Index#define)
    # @yieldparam (see Concrete::Index#define)
    # @raise (see Concrete::Index#define)
    # @return (see Concrete::Index#define)
    def self.define(*options, &block)
      index.define(*options, &block)
    end

    # Finalizes the index by defining all of the types on it.
    #
    # @api private
    # @return [void]
    def self.finalize
      @index = Concrete::Index.new
      Core::Integer.define_integer
      Core::Pointer.define_pointer
      index.finalize
    end

    def self.define_main(build, pass)
      Core::Main.define_main_function(build.module, build.index, pass)
    end

    def self.find
      if PATH.exist?
        Concrete.load(PATH.read)
      else
        finalize.tap { |i| PATH.write(Concrete.dump(i)) }
      end
    end

    require "carbon/core/int"
    require "carbon/core/integer"
    require "carbon/core/pointer"
    require "carbon/core/main"
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
carbon-core-0.2.1 lib/carbon/core.rb
carbon-core-0.2.0 lib/carbon/core.rb