Sha256: 0a5aefc5b9ec1ef0e58de8b59adaf991d972aa2a7966447beb812d910d708466

Contents?: true

Size: 854 Bytes

Versions: 3

Compression:

Stored size: 854 Bytes

Contents

# encoding: utf-8
# frozen_string_literal: true

module Carbon
  module Tacky
    Typed = Struct.new(:value, :type) do
      INT32 = Carbon::Type("Carbon::Int32")
      STRING = Carbon::Type("Carbon::String")
      FLOAT = Carbon::Type("Carbon::Float")

      def self.from(value)
        case value
        when Concrete::Type, Tacky::Typed then value
        when Tacky::Parameter             then new(value, value.type)
        when Tacky::Reference             then fail NotImplementedError
        when Tacky::Block                 then nil
        when ::Integer                    then new(value, INT32)
        when ::Float                      then new(value, FLOAT)
        when ::String, ::Symbol           then new(value, STRING)
        else fail ArgumentError, "Cannot guess type for #{value.class}"
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
carbon-core-0.2.1 lib/carbon/tacky/typed.rb
carbon-core-0.2.0 lib/carbon/tacky/typed.rb
carbon-core-0.1.1 lib/carbon/tacky/typed.rb