rubyx/lib/register/return_implementation.rb

22 lines
1.3 KiB
Ruby
Raw Normal View History

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 = []
# move the current message to new_message
2014-09-23 18:23:52 +02:00
new_codes << RegisterMachine.instance.mov( Virtual::Slot::MESSAGE_REGISTER , Virtual::Slot::NEW_MESSAGE_REGISTER )
2014-09-23 18:20:55 +02:00
# and restore the message from saved value in new_message
2014-09-23 18:23:52 +02:00
new_codes << RegisterMachine.instance.ldr( Virtual::Slot::MESSAGE_REGISTER ,Virtual::Slot::NEW_MESSAGE_REGISTER , Virtual::Slot::MESSAGE_CALLER )
2014-09-23 18:20:55 +02:00
# "roll out" self and frame into their registers
2014-09-23 18:23:52 +02:00
new_codes << RegisterMachine.instance.ldr( Virtual::Slot::SELF_REGISTER ,Virtual::Slot::MESSAGE_REGISTER , Virtual::Slot::MESSAGE_SELF )
new_codes << RegisterMachine.instance.ldr( Virtual::Slot::FRAME_REGISTER ,Virtual::Slot::MESSAGE_REGISTER , Virtual::Slot::MESSAGE_FRAME )
#load the return address into pc, affecting return. (other cpus have commands for this, but not arm)
2014-09-23 18:23:52 +02:00
new_codes << RegisterMachine.instance.ldr( :pc ,Virtual::Slot::MESSAGE_REGISTER , Virtual::Slot::MESSAGE_RETURN_ADDRESS )
2014-09-23 18:20:55 +02:00
block.replace(code , new_codes )
end
end
end
Virtual::BootSpace.space.add_pass_after ReturnImplementation , CallImplementation
end