Class: Ikra::Types::PrimitiveType

Inherits:
Object
  • Object
show all
Includes:
RubyType
Defined in:
lib/types/types/primitive_type.rb

Constant Summary collapse

Int =
self.new("int", Fixnum, 4, :int, 1)
Float =
self.new("float", Float, 4, :float, 2)
Bool =
self.new("bool", TrueClass, 1, :bool, 3)
Void =
self.new("void", nil, 0, :void, 4)
Nil =
self.new("int", NilClass, 4, :int, 5)

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RubyType

#eql?, #hash, #inspect, #is_union_type?, #should_generate_self_arg?, #to_array_type, #to_str, #to_union_type

Constructor Details

#initialize(c_type, ruby_type, c_size, ffi_type, class_id) ⇒ PrimitiveType

Returns a new instance of PrimitiveType.



11
12
13
14
15
16
17
# File 'lib/types/types/primitive_type.rb', line 11

def initialize(c_type, ruby_type, c_size, ffi_type, class_id)
    @c_type = c_type
    @ruby_type = ruby_type
    @c_size = c_size
    @ffi_type = ffi_type
    @class_id = class_id
end

Instance Attribute Details

#c_sizeObject (readonly)

Returns the value of attribute c_size.



8
9
10
# File 'lib/types/types/primitive_type.rb', line 8

def c_size
  @c_size
end

#class_idObject (readonly)

Returns the value of attribute class_id.



9
10
11
# File 'lib/types/types/primitive_type.rb', line 9

def class_id
  @class_id
end

Instance Method Details

#==(other) ⇒ Object



25
26
27
# File 'lib/types/types/primitive_type.rb', line 25

def ==(other)
    return other.is_a?(PrimitiveType) && other.class_id == class_id
end

#is_primitive?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/types/types/primitive_type.rb', line 41

def is_primitive?
    true
end

#to_c_typeObject



33
34
35
# File 'lib/types/types/primitive_type.rb', line 33

def to_c_type
    @c_type
end

#to_ffi_typeObject



37
38
39
# File 'lib/types/types/primitive_type.rb', line 37

def to_ffi_type
    @ffi_type
end

#to_ruby_typeObject



29
30
31
# File 'lib/types/types/primitive_type.rb', line 29

def to_ruby_type
    @ruby_type
end

#to_sObject



45
46
47
# File 'lib/types/types/primitive_type.rb', line 45

def to_s
    "<primitive: #{@c_type}>"
end