rubyx/lib/virtual/passes/send_implementation.rb

46 lines
2.0 KiB
Ruby
Raw Normal View History

module Virtual
# This implements the send logic
# Send is so complicated that we actually code it in ruby and stick it in
# That off course opens up an endless loop possibility that we stop by
# implementing Class and Module methods
# Note: I find it slightly unsemetrical that the NewMessage object needs to be created before this instruction
# This is because all expressions create a (return) value and that return value is overwritten by the next
# expression unless saved. And since the message is the place to save it it needs to exist. qed
class SendImplementation
def run block
block.codes.dup.each do |code|
next unless code.is_a? MessageSend
new_codes = [ ]
ref = code.me
raise "only refs implemented #{me.inspect}" unless ( ref.type == Reference)
# value known at compile time, got do something with it
if(ref.value)
me = ref.value
if( me.is_a? Parfait::Class )
raise "unimplemented #{code}"
elsif( me.is_a? Parfait::Object )
# get the function from my class. easy peasy
puts "Me is #{me.class}"
method = me.get_class.get_instance_method(code.name)
raise "Method not implemented #{clazz.name}.#{code.name}" unless method
new_codes << MethodCall.new( method )
else
# note: this is the current view: call internal send, even the method name says else
# but send is "special" and accesses the internal method name and resolves.
2015-05-13 11:15:14 +02:00
kernel = Virtual::Machine.instance.space.get_or_create_class(:Kernel)
method = kernel.get_instance_method(:__send)
new_codes << MethodCall.new( method )
raise "unimplemented: \n#{code}"
end
else
# must defer send to run-time
# So inlining the code from message.send (in the future)
raise "not constant/ known object for send #{ref.inspect}"
end
block.replace(code , new_codes )
end
end
end
end