2015-05-08 14:10:30 +02:00
|
|
|
module Virtual
|
|
|
|
module Compiler
|
2014-08-20 16:14:52 +02:00
|
|
|
# operators are really function calls
|
2014-07-25 10:48:06 +02:00
|
|
|
|
2015-05-04 13:22:22 +02:00
|
|
|
# call_site - attr_reader :name, :args , :receiver
|
|
|
|
|
2015-05-06 14:14:47 +02:00
|
|
|
def self.compile_callsite expession , method
|
|
|
|
me = Compiler.compile( expession.receiver , method )
|
2015-05-20 15:43:26 +02:00
|
|
|
method.info.add_code NewMessage.new
|
2015-06-21 12:29:27 +02:00
|
|
|
method.info.add_code Set.new( me , NextSelf.new(me.type))
|
|
|
|
method.info.add_code Set.new( expession.name.to_sym , NextMessageName.new())
|
2014-08-21 21:57:20 +02:00
|
|
|
compiled_args = []
|
2015-05-04 13:22:22 +02:00
|
|
|
expession.args.each_with_index do |arg , i|
|
2014-09-14 17:14:57 +02:00
|
|
|
#compile in the running method, ie before passing control
|
2015-05-06 14:14:47 +02:00
|
|
|
val = Compiler.compile( arg , method)
|
2014-09-14 17:14:57 +02:00
|
|
|
# move the compiled value to it's slot in the new message
|
2015-06-20 23:21:42 +02:00
|
|
|
to = NextMessageSlot.new(i ,val.type , val)
|
2014-09-14 17:14:57 +02:00
|
|
|
# (doing this immediately, not after the loop, so if it's a return it won't get overwritten)
|
2015-06-21 12:29:27 +02:00
|
|
|
method.info.add_code Set.new( val , to )
|
2014-09-23 18:06:10 +02:00
|
|
|
compiled_args << to
|
2014-08-20 16:14:52 +02:00
|
|
|
end
|
2015-05-20 15:43:26 +02:00
|
|
|
method.info.add_code MessageSend.new(expession.name , me , compiled_args) #and pass control
|
2014-09-14 17:14:57 +02:00
|
|
|
# the effect of the method is that the NewMessage Return slot will be filled, return it
|
|
|
|
# (this is what is moved _inside_ above loop for such expressions that are calls (or constants))
|
2015-05-20 15:43:26 +02:00
|
|
|
Return.new( method.info.return_type )
|
2014-07-13 15:00:48 +02:00
|
|
|
end
|
2015-05-08 14:10:30 +02:00
|
|
|
end
|
2015-05-04 13:22:22 +02:00
|
|
|
end
|