# 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 Core::Integer.define_integer Core::Pointer.define_pointer index end def self.find if PATH.exist? Concrete.load(PATH.read) else @index = Concrete::Index.new finalize.tap { |i| PATH.write(Concrete.dump(i)) } end end require "carbon/core/int" require "carbon/core/integer" require "carbon/core/pointer" end end