Class: MilkTea::Types::Vector

Inherits:
Base
  • Object
show all
Defined in:
lib/milk_tea/core/types.rb

Constant Summary collapse

FIELD_NAMES =
%w[x y z w].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#accept, #bitwise?, #boolean?, #children, #field_c_name, #float?, #integer?, #sendable?, #void?

Constructor Details

#initialize(name, element_type:, width:) ⇒ Vector

Returns a new instance of Vector.



1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
# File 'lib/milk_tea/core/types.rb', line 1388

def initialize(name, element_type:, width:)
  @name = name
  @element_type = element_type
  @width = width
  @module_name = nil
  @fields = FIELD_NAMES.first(width).each_with_object({}) do |fname, h|
    h[fname] = element_type
  end.freeze
  @hash = [self.class, name, element_type].hash
  freeze
end

Instance Attribute Details

#element_typeObject (readonly)

Returns the value of attribute element_type.



1384
1385
1386
# File 'lib/milk_tea/core/types.rb', line 1384

def element_type
  @element_type
end

#hashObject (readonly)

Returns the value of attribute hash.



1406
1407
1408
# File 'lib/milk_tea/core/types.rb', line 1406

def hash
  @hash
end

#module_nameObject (readonly)

Returns the value of attribute module_name.



1384
1385
1386
# File 'lib/milk_tea/core/types.rb', line 1384

def module_name
  @module_name
end

#nameObject (readonly)

Returns the value of attribute name.



1384
1385
1386
# File 'lib/milk_tea/core/types.rb', line 1384

def name
  @name
end

#widthObject (readonly)

Returns the value of attribute width.



1384
1385
1386
# File 'lib/milk_tea/core/types.rb', line 1384

def width
  @width
end

Instance Method Details

#eql?(other) ⇒ Boolean Also known as: ==

Returns:

  • (Boolean)


1400
1401
1402
# File 'lib/milk_tea/core/types.rb', line 1400

def eql?(other)
  other.is_a?(Vector) && other.name == name && other.element_type == element_type
end

#field(name) ⇒ Object



1412
1413
1414
# File 'lib/milk_tea/core/types.rb', line 1412

def field(name)
  @fields[name]
end

#fieldsObject



1408
1409
1410
# File 'lib/milk_tea/core/types.rb', line 1408

def fields
  @fields
end

#numeric?Boolean

Returns:

  • (Boolean)


1416
1417
1418
# File 'lib/milk_tea/core/types.rb', line 1416

def numeric?
  true
end

#to_sObject



1421
1422
1423
# File 'lib/milk_tea/core/types.rb', line 1421

def to_s
  name
end