Module: Carbon

Defined in:
lib/carbon.rb,
lib/carbon/core.rb,
lib/carbon/tacky.rb,
lib/carbon/errors.rb,
lib/carbon/counter.rb,
lib/carbon/version.rb,
lib/carbon/concrete.rb,
lib/carbon/core/int.rb,
lib/carbon/core/main.rb,
lib/carbon/core/void.rb,
lib/carbon/tacky/block.rb,
lib/carbon/tacky/typed.rb,
lib/carbon/tacky/value.rb,
lib/carbon/core/integer.rb,
lib/carbon/core/pointer.rb,
lib/carbon/concrete/item.rb,
lib/carbon/concrete/type.rb,
lib/carbon/tacky/builder.rb,
lib/carbon/tacky/context.rb,
lib/carbon/concrete/build.rb,
lib/carbon/concrete/index.rb,
lib/carbon/tacky/function.rb,
lib/carbon/tacky/parameter.rb,
lib/carbon/tacky/reference.rb,
lib/carbon/core/integer/cast.rb,
lib/carbon/core/integer/math.rb,
lib/carbon/core/integer/misc.rb,
lib/carbon/core/integer/pole.rb,
lib/carbon/core/integer/ship.rb,
lib/carbon/core/integer/sign.rb,
lib/carbon/core/integer/type.rb,
lib/carbon/core/integer/zero.rb,
lib/carbon/core/pointer/cast.rb,
lib/carbon/core/pointer/math.rb,
lib/carbon/core/pointer/type.rb,
lib/carbon/tacky/instruction.rb,
lib/carbon/concrete/item/base.rb,
lib/carbon/concrete/item/data.rb,
lib/carbon/concrete/type/name.rb,
lib/carbon/concrete/type/part.rb,
lib/carbon/concrete/item/class.rb,
lib/carbon/concrete/item/trait.rb,
lib/carbon/concrete/type/parse.rb,
lib/carbon/core/pointer/access.rb,
lib/carbon/core/pointer/memory.rb,
lib/carbon/concrete/item/struct.rb,
lib/carbon/concrete/type/generic.rb,
lib/carbon/concrete/item/function.rb,
lib/carbon/concrete/item/internal.rb,
lib/carbon/concrete/type/function.rb,
lib/carbon/concrete/item/class/element.rb,
lib/carbon/concrete/item/struct/element.rb,
lib/carbon/tacky/instruction/generation.rb,
lib/carbon/concrete/item/trait/expectation.rb

Overview

rubocop:disable Metrics/LineLength

Defined Under Namespace

Modules: Concrete, Core, Tacky Classes: Counter, Error, ItemNotFoundError, TooManyItemsError

Constant Summary collapse

Boolean =

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.

A Boolean type for Carbon. This is used as a handy shortcut.

Carbon::Type("Carbon::Boolean")
Void =

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.

A Void type for Carbon. This is used as a handy shortcut.

Carbon::Type("Carbon::Void")
VERSION =

The version of Carbon.

Returns:

  • (::String)
"0.2.1".freeze

Class Method Summary collapse

Class Method Details

.hash(string) ⇒ ::String

Hashes a given string into the format used by Carbon. The format is a Base58-encoded SHA256 digest.

Examples:

Carbon.hash("") # => "gjNT5GbSC-81KmUPncw-hzQAGV3GU-eAXafmkMP-Bw2GMHWM"

Parameters:

  • string (::String)

    The string to hash.

Returns:

  • (::String)

    The hashed string.



41
42
43
44
45
# File 'lib/carbon.rb', line 41

def self.hash(string)
  digest = (Digest::SHA2.hexdigest(string).hex << 6) ^ 0xCA5B04
  encoded = Base58.encode(digest)
  encoded.scan(/.{1,9}/).join("-").freeze
end

.Type(string) ⇒ Carbon::Concrete::Type

Creates a type. This uses Carbon::Concrete::Type, and assumes that the parameter must be a string to be parsed.

Examples:

type = Carbon::Type("Carbon::Boolean")
type # => #<Carbon::Concrete::Type Carbon::Boolean>

Parameters:

  • string (::String)

    The string to parse.

Returns:



28
29
30
# File 'lib/carbon.rb', line 28

def self.Type(string)
  Carbon::Concrete::Type.from(string)
end

.verbose::Integer

The verboseness of Carbon. This is a global setting.

Returns:

  • (::Integer)

    The verboseness.



50
51
52
# File 'lib/carbon.rb', line 50

def self.verbose
  @_verbose ||= 1
end

.verbose=(verbose) ⇒ ::Integer

The verboseness of Carbon. This is a global setting.

Parameters:

  • verbose (::Integer)

    The new verbose level.

Returns:

  • (::Integer)


58
59
60
# File 'lib/carbon.rb', line 58

def self.verbose=(verbose)
  @_verbose = verbose
end