2018-06-28 19:15:24 +02:00
|
|
|
module Vool
|
|
|
|
|
|
|
|
class YieldStatement < Statement
|
|
|
|
attr_reader :arguments
|
|
|
|
|
|
|
|
def initialize(arguments )
|
|
|
|
@arguments = arguments
|
|
|
|
@arguments ||= []
|
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
2018-07-03 18:15:36 +02:00
|
|
|
"#{receiver}.#{name}(#{arguments.join(', ')})"
|
2018-06-28 19:15:24 +02:00
|
|
|
end
|
|
|
|
def each(&block)
|
|
|
|
block.call(self)
|
|
|
|
block.call(@receiver)
|
|
|
|
@arguments.each do |arg|
|
|
|
|
block.call(arg)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# A Send breaks down to 2 steps:
|
|
|
|
# - Setting up the next message, with receiver, arguments, and (importantly) return address
|
|
|
|
# - a SimpleCall,
|
2018-07-05 13:02:38 +02:00
|
|
|
def to_mom( compiler )
|
|
|
|
@parfait_block = @block.to_mom(compiler) if @block
|
2018-07-06 19:01:17 +02:00
|
|
|
@receiver = SelfExpression.new(compiler.self_type) if @receiver.is_a?(SelfExpression)
|
2018-06-28 19:15:24 +02:00
|
|
|
if(@receiver.ct_type)
|
2018-07-05 13:02:38 +02:00
|
|
|
simple_call(compiler)
|
2018-06-28 19:15:24 +02:00
|
|
|
else
|
|
|
|
raise "ERROR"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# When used as right hand side, this tells what data to move to get the result into
|
|
|
|
# a varaible. It is (off course) the return value of the message
|
2018-07-05 13:02:38 +02:00
|
|
|
def slot_definition(compiler)
|
2018-06-28 19:15:24 +02:00
|
|
|
Mom::SlotDefinition.new(:message ,[ :return_value])
|
|
|
|
end
|
|
|
|
|
|
|
|
def message_setup(in_method,called_method)
|
|
|
|
setup = Mom::MessageSetup.new( called_method )
|
2018-07-05 13:02:38 +02:00
|
|
|
mom_receive = @receiver.slot_definition(compiler)
|
2018-06-28 19:15:24 +02:00
|
|
|
arg_target = [:message , :next_message , :arguments]
|
|
|
|
args = []
|
|
|
|
@arguments.each_with_index do |arg , index| # +1 because of type
|
2018-07-05 13:02:38 +02:00
|
|
|
args << Mom::SlotLoad.new( arg_target + [index + 1] , arg.slot_definition(compiler))
|
2018-06-28 19:15:24 +02:00
|
|
|
end
|
|
|
|
setup << Mom::ArgumentTransfer.new( mom_receive , args )
|
|
|
|
end
|
|
|
|
|
|
|
|
def simple_call(in_method)
|
|
|
|
type = @receiver.ct_type
|
|
|
|
called_method = type.resolve_method(@name)
|
|
|
|
raise "No method #{@name} for #{type}" unless called_method
|
|
|
|
message_setup(in_method,called_method) << Mom::SimpleCall.new(called_method)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|