Module: BOAST::TypeTransition
- Included in:
- BOAST, CKernel, Expression
- Defined in:
- lib/BOAST/Transitions.rb
Constant Summary collapse
- @@transitions =
Hash::new { |hash, key| hash[key] = Hash::new }
Instance Method Summary collapse
- #get_transition(type1, type2, operator) ⇒ Object
- #set_transition(type1, type2, operator, return_type) ⇒ Object
- #transition(var1, var2, operator) ⇒ Object
Instance Method Details
#get_transition(type1, type2, operator) ⇒ Object
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/BOAST/Transitions.rb', line 7 def get_transition(type1, type2, operator) #STDERR.puts @@transitions.inspect ops = @@transitions[[type1,type2]] raise "Types #{[type1,type2]} have no relation!" if not ops t = ops[operator] return [t,operator] if t t = ops[:default] return [t,operator] if t raise "Unresolvable transition!" end |
#set_transition(type1, type2, operator, return_type) ⇒ Object
18 19 20 |
# File 'lib/BOAST/Transitions.rb', line 18 def set_transition(type1, type2, operator, return_type) @@transitions[[type1,type2]][operator] = return_type end |
#transition(var1, var2, operator) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/BOAST/Transitions.rb', line 22 def transition(var1, var2, operator) signed = false size = nil vector_length = 1 t1 = var1.type.class t2 = var2.type.class t1 = var1.type.name if t1 == CustomType t2 = var2.type.name if t2 == CustomType return_type, operator = get_transition(t1, t2, operator) #STDERR.puts "#{return_type} : #{var1.type.class} #{operator} #{var2.type.class}" if t1 == return_type and t2 == return_type then signed = (signed or var1.type.signed) signed = (signed or var2.type.signed) size = [var1.type.size, var2.type.size].max vector_length = [var1.type.vector_length, var2.type.vector_length].max [Variable::new("dummy", return_type, :size => size, :signed => signed, :vector_length => vector_length), operator] elsif var1.type.class == return_type then return [var1, operator] else # var2.type.class == return_type then return [var2, operator] end end |