start a new ruby layer to do the to_vool conversion
the "normalization" is getting more and more complicated and is not tested And it seems i really don't like working with the untyped ast
This commit is contained in:
22
lib/ruby/normalizer.rb
Normal file
22
lib/ruby/normalizer.rb
Normal file
@ -0,0 +1,22 @@
|
||||
module Ruby
|
||||
module Normalizer
|
||||
# given a something, determine if it is a Name
|
||||
#
|
||||
# Return a Name, and a possible rest that has a hoisted part of the statement
|
||||
#
|
||||
# eg if( @var % 5) is not normalized
|
||||
# but if(tmp_123) is with tmp_123 = @var % 5 hoisted above the if
|
||||
#
|
||||
# also constants count, though they may not be so useful in ifs, but returns
|
||||
def normalize_name( condition )
|
||||
if( condition.is_a?(ScopeStatement) and condition.single?)
|
||||
condition = condition.first
|
||||
end
|
||||
return [condition] if condition.is_a?(Named) or condition.is_a?(Constant)
|
||||
condition = condition.normalize
|
||||
local = "tmp_#{object_id}".to_sym
|
||||
assign = Statements.new [LocalAssignment.new( local , condition)]
|
||||
[LocalVariable.new(local) , assign]
|
||||
end
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user