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,39 +1,13 @@
module Ruby
class YieldStatement < Statement
attr_reader :arguments
class YieldStatement < Callable
def initialize(arguments )
@arguments = arguments
@arguments ||= []
end
def to_vool
statements = Statements.new([])
arguments = []
@arguments.each_with_index do |arg , index |
normalize_arg(arg , arguments , statements)
end
if statements.empty?
return YieldStatement.new(@name, @receiver , @arguments)
else
statements << YieldStatement.new(@name, @receiver , arguments)
return statements
end
end
def to_vool_arg(arg , arguments , statements)
if arg.respond_to?(:slot_definition) and !arg.is_a?(YieldStatement)
arguments << arg
return
end
assign = LocalAssignment.new( "tmp_#{arg.object_id}".to_sym, arg.to_vool)
statements << assign
arguments << LocalVariable.new(assign.name)
def initialize(arguments)
super("yield_#{object_id}".to_sym , SelfExpression.new , arguments)
end
def to_s
"#{receiver}.#{name}(#{arguments.join(', ')})"
"yield(#{arguments.join(', ')})"
end
end
end