callable as base for yield and send

more yield tests
This commit is contained in:
Torsten Ruger
2018-07-21 14:34:39 +03:00
parent 84a6fb1aba
commit b6c85cd4a4
7 changed files with 95 additions and 66 deletions

View File

@ -1,37 +1,6 @@
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.is_a?(Constant) and !arg.is_a?(SendStatement)
arguments << arg.to_vool
return
end
assign = Vool::LocalAssignment.new( "tmp_#{arg.object_id}".to_sym, arg.to_vool)
statements << assign
arguments << Vool::LocalVariable.new(assign.name)
end
class SendStatement < Callable
def to_s
"#{receiver}.#{name}(#{arguments.join(', ')})"
end