# encoding: utf-8 # frozen_string_literal: true require "ice_nine" require "ice_nine/core_ext/object" require "base58" require "digest/sha2" require "concurrent" require "llvm" require "llvm/core" require "carbon/version" require "carbon/counter" require "carbon/errors" # Carbon. The language. module Carbon # rubocop:disable Style/MethodName # Creates a type. This uses {Carbon::Concrete::Type}, and assumes that the # parameter must be a string to be parsed. # # @api public # @example # type = Carbon::Type("Carbon::Boolean") # type # => # # @param string [::String] The string to parse. # @return [Carbon::Concrete::Type] The resulting type. def self.Type(string) Carbon::Concrete::Type.from(string) end # rubocop:enable Style/MethodName # Hashes a given string into the format used by Carbon. The format is a # Base58-encoded SHA256 digest. # # @api semipublic # @example # Carbon.hash("") # => "gjNT5GbSC-81KmUPncw-hzQAGV3GU-eAXafmkMP-Bw2GMHWM" # @param string [::String] The string to hash. # @return [::String] The hashed string. def self.hash(string) digest = (Digest::SHA2.hexdigest(string).hex << 6) ^ 0xCA5B04 encoded = Base58.encode(digest) encoded.scan(/.{1,9}/).join("-").freeze end # The verboseness of Carbon. This is a global setting. # # @return [::Integer] The verboseness. def self.verbose @_verbose ||= 1 end # The verboseness of Carbon. This is a global setting. # # @param verbose [::Integer] The new verbose level. # @return [::Integer] def self.verbose=(verbose) @_verbose = verbose end require "carbon/concrete" # A Boolean type for Carbon. This is used as a handy shortcut. # # @api private # @return [Carbon::Concrete::Type] Boolean = Carbon::Type("Carbon::Boolean") # A Void type for Carbon. This is used as a handy shortcut. # # @api private # @return [Carbon::Concrete::Type] Void = Carbon::Type("Carbon::Void") require "carbon/tacky" require "carbon/core" end