2014-08-23 09:25:55 +02:00
|
|
|
module Virtual
|
2014-08-21 16:46:12 +02:00
|
|
|
# This implements the send logic
|
|
|
|
# Send is so complicated that we actually code it in ruby and stick it in
|
2014-09-23 18:06:10 +02:00
|
|
|
# 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
|
2014-08-23 09:25:55 +02:00
|
|
|
class SendImplementation
|
2014-08-21 16:46:12 +02:00
|
|
|
def run block
|
|
|
|
block.codes.dup.each do |code|
|
2014-08-23 09:25:55 +02:00
|
|
|
next unless code.is_a? MessageSend
|
2014-09-23 18:06:10 +02:00
|
|
|
new_codes = [ ]
|
2014-09-15 11:08:37 +02:00
|
|
|
ref = code.me
|
|
|
|
raise "only refs implemented #{me.inspect}" unless ( ref.type == Reference)
|
2015-05-16 11:53:10 +02:00
|
|
|
# value known at compile time, got do something with it
|
2014-09-15 11:08:37 +02:00
|
|
|
if(ref.value)
|
|
|
|
me = ref.value
|
2015-05-16 11:53:10 +02:00
|
|
|
if( me.is_a? Parfait::Class )
|
2014-09-14 20:26:30 +02:00
|
|
|
raise "unimplemented #{code}"
|
2015-05-16 11:53:10 +02:00
|
|
|
elsif( me.is_a? Parfait::Object )
|
2014-09-15 11:08:37 +02:00
|
|
|
# get the function from my class. easy peasy
|
2015-05-16 11:53:10 +02:00
|
|
|
puts "Me is #{me.class}"
|
|
|
|
method = me.get_class.get_instance_method(code.name)
|
2015-05-23 11:15:06 +02:00
|
|
|
raise "Method not implemented #{me.class}.#{code.name}" unless method
|
2014-10-05 00:10:10 +02:00
|
|
|
new_codes << MethodCall.new( method )
|
2014-08-22 09:21:12 +02:00
|
|
|
else
|
2014-09-23 19:16:05 +02:00
|
|
|
# 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-16 19:16:49 +02:00
|
|
|
kernel = Virtual::Machine.instance.space.get_class_by_name("Kernel")
|
2014-09-24 17:25:18 +02:00
|
|
|
method = kernel.get_instance_method(:__send)
|
2014-10-05 00:10:10 +02:00
|
|
|
new_codes << MethodCall.new( method )
|
2015-05-16 11:53:10 +02:00
|
|
|
raise "unimplemented: \n#{code}"
|
2014-08-22 09:21:12 +02:00
|
|
|
end
|
2014-09-14 20:26:30 +02:00
|
|
|
else
|
2015-05-16 11:53:10 +02:00
|
|
|
# must defer send to run-time
|
|
|
|
# So inlining the code from message.send (in the future)
|
2014-09-23 18:06:10 +02:00
|
|
|
raise "not constant/ known object for send #{ref.inspect}"
|
2014-08-21 21:57:20 +02:00
|
|
|
end
|
2014-09-23 18:06:10 +02:00
|
|
|
block.replace(code , new_codes )
|
2014-08-21 16:46:12 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|