rubyx/lib/virtual/compiler/callsite_expression.rb

31 lines
1.3 KiB
Ruby
Raw Normal View History

module Virtual
module Compiler
# operators are really function calls
2014-07-25 10:48:06 +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 )
method.info.add_code NewMessage.new
2015-06-29 19:55:45 +02:00
method.info.add_code Set.new( me , NewSelf.new(me.type))
method.info.add_code Set.new( expession.name.to_sym , NewMessageName.new())
compiled_args = []
expession.args.each_with_index do |arg , i|
#compile in the running method, ie before passing control
2015-05-06 14:14:47 +02:00
val = Compiler.compile( arg , method)
# move the compiled value to it's slot in the new message
2015-07-01 08:48:20 +02:00
# + 1 as this is a ruby 0-start , but 0 is the last message ivar.
# so the next free is +1
2015-07-01 08:48:20 +02:00
to = NewArgSlot.new(i + 1 ,val.type , val)
# (doing this immediately, not after the loop, so if it's a return it won't get overwritten)
method.info.add_code Set.new( val , to )
compiled_args << to
end
method.info.add_code MessageSend.new(expession.name , me , compiled_args) #and pass control
# 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))
Return.new( method.info.return_type )
2014-07-13 15:00:48 +02:00
end
end
end