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
|
|
|
|
# That off course opens up an endless loop possibility that we stop by reducing to Class and Module methods
|
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-15 11:08:37 +02:00
|
|
|
ref = code.me
|
|
|
|
raise "only refs implemented #{me.inspect}" unless ( ref.type == Reference)
|
|
|
|
if(ref.value)
|
|
|
|
me = ref.value
|
2014-08-23 23:25:15 +02:00
|
|
|
if( me.is_a? BootClass )
|
2014-09-14 20:26:30 +02:00
|
|
|
raise "unimplemented #{code}"
|
2014-08-23 09:25:55 +02:00
|
|
|
elsif( me.is_a? ObjectConstant )
|
2014-09-15 11:08:37 +02:00
|
|
|
# get the function from my class. easy peasy
|
|
|
|
method = me.clazz.get_instance_method(code.name)
|
2014-08-22 09:21:12 +02:00
|
|
|
raise "Method not implemented #{clazz.name}.#{code.name}" unless method
|
2014-08-23 09:25:55 +02:00
|
|
|
call = FunctionCall.new( method )
|
2014-08-30 15:57:56 +02:00
|
|
|
block.replace(code , call )
|
2014-08-22 09:21:12 +02:00
|
|
|
else
|
2014-09-14 20:26:30 +02:00
|
|
|
raise "unimplemented #{code}"
|
2014-08-22 09:21:12 +02:00
|
|
|
end
|
2014-09-14 20:26:30 +02:00
|
|
|
else
|
2014-09-15 11:08:37 +02:00
|
|
|
raise "not constant/ known object for send #{me.inspect}"
|
2014-08-21 21:57:20 +02:00
|
|
|
end
|
2014-08-21 16:46:12 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|