Class: MilkTea::Types::Vector

Inherits:
Base
  • Object
show all
Defined in:
lib/milk_tea/core/types/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.



1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
# File 'lib/milk_tea/core/types/types.rb', line 1399

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.



1395
1396
1397
# File 'lib/milk_tea/core/types/types.rb', line 1395

def element_type
  @element_type
end

#hashObject (readonly)

Returns the value of attribute hash.



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

def hash
  @hash
end

#module_nameObject (readonly)

Returns the value of attribute module_name.



1395
1396
1397
# File 'lib/milk_tea/core/types/types.rb', line 1395

def module_name
  @module_name
end

#nameObject (readonly)

Returns the value of attribute name.



1395
1396
1397
# File 'lib/milk_tea/core/types/types.rb', line 1395

def name
  @name
end

#widthObject (readonly)

Returns the value of attribute width.



1395
1396
1397
# File 'lib/milk_tea/core/types/types.rb', line 1395

def width
  @width
end

Instance Method Details

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

Returns:

  • (Boolean)


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

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

#field(name) ⇒ Object



1423
1424
1425
# File 'lib/milk_tea/core/types/types.rb', line 1423

def field(name)
  @fields[name]
end

#fieldsObject



1419
1420
1421
# File 'lib/milk_tea/core/types/types.rb', line 1419

def fields
  @fields
end

#numeric?Boolean

Returns:

  • (Boolean)


1427
1428
1429
# File 'lib/milk_tea/core/types/types.rb', line 1427

def numeric?
  true
end

#to_sObject



1432
1433
1434
# File 'lib/milk_tea/core/types/types.rb', line 1432

def to_s
  name
end