This commit is contained in:
Torsten Ruger 2018-03-15 11:32:32 +05:30
parent 78ef1368de
commit 9ddcb3224c
18 changed files with 6 additions and 5 deletions

View File

@ -27,7 +27,7 @@ module Vool
# after creation vool normalizes to ensure valid syntax and simplify # after creation vool normalizes to ensure valid syntax and simplify
# also throw errors if violation # also throw errors if violation
def normalize def normalize(method)
return self return self
end end

View File

@ -13,7 +13,7 @@ module Vool
end end
def normalize(method) def normalize(method)
cond , rest = *normalize_name(@condition) cond , rest = *normalize_name(@condition, method)
fals = @if_false ? @if_false.normalize(method) : nil fals = @if_false ? @if_false.normalize(method) : nil
me = IfStatement.new(cond , @if_true.normalize(method), fals) me = IfStatement.new(cond , @if_true.normalize(method), fals)
return me unless rest return me unless rest

View File

@ -6,10 +6,10 @@ module Vool
# #
# eg if( @var % 5) is not normalized # eg if( @var % 5) is not normalized
# but if(tmp_123) is with tmp_123 = @var % 5 hoited above the if # but if(tmp_123) is with tmp_123 = @var % 5 hoited above the if
def normalize_name( method ) def normalize_name( condition , method )
return [@condition] if @condition.is_a?(Named) return [condition] if condition.is_a?(Named)
local = method.create_tmp local = method.create_tmp
assign = LocalAssignment.new( local , @condition) assign = LocalAssignment.new( local , condition)
[LocalVariable.new(local) , assign] [LocalVariable.new(local) , assign]
end end
end end

View File

@ -5,6 +5,7 @@ module Vool
def self.ruby_to_vool( ruby_source ) def self.ruby_to_vool( ruby_source )
statements = RubyCompiler.compile( ruby_source ) statements = RubyCompiler.compile( ruby_source )
statements = statements.normalize(nil)
statements.create_objects statements.create_objects
statements statements
end end