2018-07-19 13:46:51 +02:00
|
|
|
module Ruby
|
|
|
|
|
|
|
|
class SendStatement < Statement
|
|
|
|
attr_reader :name , :receiver , :arguments
|
|
|
|
|
|
|
|
def initialize(name , receiver , arguments )
|
|
|
|
@name , @receiver , @arguments = name , receiver , arguments
|
|
|
|
@arguments ||= []
|
|
|
|
end
|
|
|
|
|
2018-07-19 13:59:10 +02:00
|
|
|
def to_vool
|
2018-07-20 09:05:11 +02:00
|
|
|
statements = Vool::Statements.new([])
|
2018-07-19 13:46:51 +02:00
|
|
|
arguments = []
|
|
|
|
@arguments.each_with_index do |arg , index |
|
|
|
|
normalize_arg(arg , arguments , statements)
|
|
|
|
end
|
|
|
|
if statements.empty?
|
2018-07-20 09:05:11 +02:00
|
|
|
return Vool::SendStatement.new(@name, @receiver.to_vool , @arguments)
|
2018-07-19 13:46:51 +02:00
|
|
|
else
|
2018-07-20 09:05:11 +02:00
|
|
|
statements << Vool::SendStatement.new(@name, @receiver.to_vool , arguments)
|
2018-07-19 13:46:51 +02:00
|
|
|
return statements
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-07-20 09:05:11 +02:00
|
|
|
def normalize_arg(arg , arguments , statements)
|
2018-07-19 13:46:51 +02:00
|
|
|
if arg.respond_to?(:slot_definition) and !arg.is_a?(SendStatement)
|
|
|
|
arguments << arg
|
|
|
|
return
|
|
|
|
end
|
2018-07-20 09:05:11 +02:00
|
|
|
assign = Vool::LocalAssignment.new( "tmp_#{arg.object_id}".to_sym, arg)
|
2018-07-19 13:46:51 +02:00
|
|
|
statements << assign
|
2018-07-20 09:05:11 +02:00
|
|
|
arguments << Vool::LocalVariable.new(assign.name)
|
2018-07-19 13:46:51 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
|
|
|
"#{receiver}.#{name}(#{arguments.join(', ')})"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|