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
# also throw errors if violation
def normalize
def normalize(method)
return self
end

View File

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

View File

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

View File

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