rubyx/lib/ruby/send_statement.rb
Torsten Ruger e536a7ac88 fixing send to_vool
was hoisting unneccessarily, because not respecting basics
2018-07-20 13:15:16 +03:00

40 lines
1.1 KiB
Ruby

module Ruby
class SendStatement < Statement
attr_reader :name , :receiver , :arguments
def initialize(name , receiver , arguments )
@name , @receiver , @arguments = name , receiver , arguments
@arguments ||= []
end
def to_vool
statements = Vool::Statements.new([])
arguments = []
@arguments.each_with_index do |arg , index |
normalize_arg(arg , arguments , statements)
end
if statements.empty?
return Vool::SendStatement.new(@name, @receiver.to_vool , arguments)
else
statements << Vool::SendStatement.new(@name, @receiver.to_vool , arguments)
return statements
end
end
def normalize_arg(arg , arguments , statements)
if arg.respond_to?(:ct_type) and !arg.is_a?(SendStatement)
arguments << arg.to_vool
return
end
assign = Vool::LocalAssignment.new( "tmp_#{arg.object_id}".to_sym, arg)
statements << assign
arguments << Vool::LocalVariable.new(assign.name)
end
def to_s
"#{receiver}.#{name}(#{arguments.join(', ')})"
end
end
end