2014-08-26 11:05:49 +02:00
|
|
|
module Register
|
|
|
|
class ReturnImplementation
|
|
|
|
def run block
|
|
|
|
block.codes.dup.each do |code|
|
|
|
|
next unless code.is_a? Virtual::MethodReturn
|
2014-09-23 18:20:55 +02:00
|
|
|
new_codes = []
|
2014-09-25 19:29:05 +02:00
|
|
|
machine = RegisterMachine.instance
|
|
|
|
slot = Virtual::Slot
|
2014-09-23 18:20:55 +02:00
|
|
|
# move the current message to new_message
|
2014-09-25 19:29:05 +02:00
|
|
|
new_codes << machine.mov( slot::MESSAGE_REGISTER , slot::NEW_MESSAGE_REGISTER )
|
2014-09-23 18:20:55 +02:00
|
|
|
# and restore the message from saved value in new_message
|
2014-09-25 19:29:05 +02:00
|
|
|
new_codes << machine.ldr( slot::MESSAGE_REGISTER ,slot::NEW_MESSAGE_REGISTER , slot::MESSAGE_CALLER )
|
2014-09-23 18:20:55 +02:00
|
|
|
# "roll out" self and frame into their registers
|
2014-09-25 19:29:05 +02:00
|
|
|
new_codes << machine.ldr( slot::SELF_REGISTER ,slot::MESSAGE_REGISTER , slot::MESSAGE_SELF )
|
|
|
|
new_codes << machine.ldr( slot::FRAME_REGISTER ,slot::MESSAGE_REGISTER , slot::MESSAGE_FRAME )
|
2014-09-11 18:00:14 +02:00
|
|
|
#load the return address into pc, affecting return. (other cpus have commands for this, but not arm)
|
2014-09-25 19:29:05 +02:00
|
|
|
new_codes << machine.ldr( :pc ,slot::MESSAGE_REGISTER , slot::MESSAGE_RETURN_ADDRESS )
|
2014-09-23 18:20:55 +02:00
|
|
|
block.replace(code , new_codes )
|
2014-08-26 11:05:49 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
Virtual::BootSpace.space.add_pass_after ReturnImplementation , CallImplementation
|
|
|
|
end
|