Class: WType
Constant Summary
collapse
- WASM_TYPE_MAP =
{
UI64: Type::UI64,
I64: Type::I64,
UI32: Type::UI32,
I32: Type::I32,
F64: Type::F64,
F32: Type::F32
}
- CAST_PRECEDENCE =
Implicit Type cast order in decreasing order of precedence Class types have precedence over default integer type because of pointer arithmetics
[:F64, :F32, :UI64, :I64, :Class, :UI32, :I32]
- DEFAULT =
self.new(WASM_TYPE_MAP.key(Type::DEFAULT))
- UNSIGNED_DEFAULT =
self.new(WASM_TYPE_MAP.key(Type::UNSIGNED_DEFAULT))
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Log
included, logger, #logger, logger=
Constructor Details
#initialize(name) ⇒ WType
Name is a symbol of the form :A or :“A::B” or :“A::B::C” or a string “A” or “A::B” or “A::B::C” or it can also be an array of symbols [:A], [:A, :B] or [:A, :B, :C] (It is not a class object)
53
54
55
56
57
58
59
60
61
62
63
64
|
# File 'lib/rlang/parser/wtype.rb', line 53
def initialize(name)
if name.is_a? Symbol
@name = name
elsif name.is_a? String
@name = name.to_sym
elsif name.is_a? Array
@name = name.map(&:to_s).join('::').to_sym
else
raise "Unknown type for WType name (got #{name}, class: #{name.class}"
end
raise "Invalid WType #{name.inspect}" unless self.valid?
end
|
Instance Attribute Details
Returns the value of attribute name.
34
35
36
|
# File 'lib/rlang/parser/wtype.rb', line 34
def name
@name
end
|
Class Method Details
.leading(wtypes) ⇒ Object
40
41
42
43
44
45
46
47
|
# File 'lib/rlang/parser/wtype.rb', line 40
def self.leading(wtypes)
logger.debug "wtypes: #{wtypes}"
leading_idx = wtypes.map {|wt| wt.class? ? :Class : wt.name}. \
map {|wtn| CAST_PRECEDENCE.index(wtn) }.compact.each_with_index.min.last
wtypes[leading_idx]
end
|
.legit?(name) ⇒ Boolean
36
37
38
|
# File 'lib/rlang/parser/wtype.rb', line 36
def self.legit?(name)
WASM_TYPE_MAP.has_key? name
end
|
Instance Method Details
#==(other) ⇒ Object
96
97
98
|
# File 'lib/rlang/parser/wtype.rb', line 96
def ==(other)
@name == other.name
end
|
#blank? ⇒ Boolean
87
88
89
|
# File 'lib/rlang/parser/wtype.rb', line 87
def blank?
@name == :none || @name == :nil
end
|
#class? ⇒ Boolean
91
92
93
94
|
# File 'lib/rlang/parser/wtype.rb', line 91
def class?
!self.native? && ('A'..'Z').include?(@name.to_s[0])
end
|
#class_path ⇒ Object
66
67
68
69
|
# File 'lib/rlang/parser/wtype.rb', line 66
def class_path
return [] if self.blank?
name.to_s.split('::').map(&:to_sym)
end
|
#default? ⇒ Boolean
71
72
73
|
# File 'lib/rlang/parser/wtype.rb', line 71
def default?
@name == WType::DEFAULT.name
end
|
131
132
133
|
# File 'lib/rlang/parser/wtype.rb', line 131
def inspect
self.to_s
end
|
#native? ⇒ Boolean
79
80
81
|
# File 'lib/rlang/parser/wtype.rb', line 79
def native?
WASM_TYPE_MAP.has_key? @name
end
|
#signed? ⇒ Boolean
83
84
85
|
# File 'lib/rlang/parser/wtype.rb', line 83
def signed?
self.native? && WASM_TYPE_MAP[@name].signed?
end
|
100
101
102
103
104
105
106
107
108
|
# File 'lib/rlang/parser/wtype.rb', line 100
def size
if self.blank?
0
elsif self.native?
WASM_TYPE_MAP[@name].size
else
Type::DEFAULT.size
end
end
|
127
128
129
|
# File 'lib/rlang/parser/wtype.rb', line 127
def to_s
":#{@name}"
end
|
#valid? ⇒ Boolean
75
76
77
|
# File 'lib/rlang/parser/wtype.rb', line 75
def valid?
self.blank? || self.native? || self.class?
end
|
#wasm_type ⇒ Object
returns a String with the proper WASM type that can be used for code generation
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# File 'lib/rlang/parser/wtype.rb', line 112
def wasm_type
if self.blank?
''
elsif self.native?
WASM_TYPE_MAP[@name].wasm_type
elsif self.class?
Type::DEFAULT.wasm_type
else
raise "Unknown WType #{self.inspect}"
end
end
|