rubyx/lib/vool/statements/normalizer.rb
Torsten Ruger 3702411043 first propper hoisting test
had to change course, normalising and object creation is not possible
in one go
have to now generate random tmp vars  that will have to be picked up
later (sorted by tmp_ prefix?)
2018-03-15 12:46:56 +05:30

17 lines
540 B
Ruby

module Vool
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 hoited above the if
def normalize_name( condition )
return [condition] if condition.is_a?(Named)
local = "tmp_#{object_id}"
assign = Statements.new [LocalAssignment.new( local , condition)]
[LocalVariable.new(local) , assign]
end
end
end