From 9c21f4274dbf9afd3f16034e26901c28aa6516a6 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 21 Jun 2015 21:09:15 +0300 Subject: [PATCH] better names for index constants --- lib/register/passes/call_implementation.rb | 2 +- lib/register/passes/return_implementation.rb | 8 +++--- lib/virtual/passes/enter_implementation.rb | 2 +- lib/virtual/slots/message_slot.rb | 30 +++++++++++--------- lib/virtual/slots/next_message_slot.rb | 10 +++---- 5 files changed, 28 insertions(+), 24 deletions(-) diff --git a/lib/register/passes/call_implementation.rb b/lib/register/passes/call_implementation.rb index 7dc35571..ff535f11 100644 --- a/lib/register/passes/call_implementation.rb +++ b/lib/register/passes/call_implementation.rb @@ -16,7 +16,7 @@ module Register # move the current new_message to message new_codes << RegisterTransfer.new( slot::NEW_MESSAGE_REGISTER , slot::MESSAGE_REGISTER ) # "roll out" self into its register - new_codes << GetSlot.new( slot::SELF_REGISTER ,slot::MESSAGE_REGISTER , Virtual::MESSAGE_SELF ) + new_codes << GetSlot.new( slot::SELF_REGISTER ,slot::MESSAGE_REGISTER , Virtual::SELF_INDEX ) # do the register call new_codes << FunctionCall.new( code.method ) block.replace(code , new_codes ) diff --git a/lib/register/passes/return_implementation.rb b/lib/register/passes/return_implementation.rb index 07d69183..0c898867 100644 --- a/lib/register/passes/return_implementation.rb +++ b/lib/register/passes/return_implementation.rb @@ -8,12 +8,12 @@ module Register # move the current message to new_message new_codes << RegisterTransfer.new( slot::MESSAGE_REGISTER , slot::NEW_MESSAGE_REGISTER ) # and restore the message from saved value in new_message - new_codes << GetSlot.new( slot::NEW_MESSAGE_REGISTER , Virtual::MESSAGE_CALLER , slot::MESSAGE_REGISTER) + new_codes << GetSlot.new( slot::NEW_MESSAGE_REGISTER , Virtual::CALLER_INDEX , slot::MESSAGE_REGISTER) # "roll out" self and frame into their registers - new_codes << GetSlot.new( slot::MESSAGE_REGISTER , Virtual::MESSAGE_SELF , slot::SELF_REGISTER ) - new_codes << GetSlot.new( slot::MESSAGE_REGISTER , Virtual::MESSAGE_FRAME , slot::FRAME_REGISTER ) + new_codes << GetSlot.new( slot::MESSAGE_REGISTER , Virtual::SELF_INDEX , slot::SELF_REGISTER ) + new_codes << GetSlot.new( slot::MESSAGE_REGISTER , Virtual::FRAME_INDEX , slot::FRAME_REGISTER ) #load the return address into pc, affecting return. (other cpus have commands for this, but not arm) - new_codes << FunctionReturn.new( slot::MESSAGE_REGISTER , Virtual::MESSAGE_RETURN_ADDRESS ) + new_codes << FunctionReturn.new( slot::MESSAGE_REGISTER , Virtual::RETURN_INDEX ) block.replace(code , new_codes ) end end diff --git a/lib/virtual/passes/enter_implementation.rb b/lib/virtual/passes/enter_implementation.rb index 6cc2da7b..355d05fc 100644 --- a/lib/virtual/passes/enter_implementation.rb +++ b/lib/virtual/passes/enter_implementation.rb @@ -7,7 +7,7 @@ module Virtual new_codes = [] # save return register and create a new frame # lr is link register, ie where arm stores the return address when call is issued - new_codes << Register::SaveReturn.new( Virtual::Slot::MESSAGE_REGISTER , Virtual::MESSAGE_RETURN_ADDRESS ) + new_codes << Register::SaveReturn.new( Virtual::Slot::MESSAGE_REGISTER , Virtual::RETURN_INDEX ) new_codes << Virtual::NewFrame.new block.replace(code , new_codes ) end diff --git a/lib/virtual/slots/message_slot.rb b/lib/virtual/slots/message_slot.rb index 647bb26e..13a001a0 100644 --- a/lib/virtual/slots/message_slot.rb +++ b/lib/virtual/slots/message_slot.rb @@ -1,13 +1,17 @@ module Virtual - MESSAGE_CALLER = 0 - MESSAGE_RETURN_ADDRESS = 1 - MESSAGE_EXCEPTION_ADDRESS = 2 - MESSAGE_SELF = 3 - MESSAGE_NAME = 4 - MESSAGE_RETURN_VALUE = 5 - MESSAGE_FRAME = 6 - MESSAGE_PAYLOAD = 7 + #TODO : this constant approach is a bit old, from before PArfait adapter + # nowadays these are unneccessary as we can resolve the names by using the + # layout of the class. (get Class from space) + TYPE_INDEX = 0 + LAYOUT_INDEX = 1 + CALLER_INDEX = 2 + RETURN_INDEX = 3 + EXCEPTION_INDEX = 4 + SELF_INDEX = 5 + NAME_INDEX = 6 + FRAME_INDEX = 7 + ARGUMENT_START = 8 # The current Message is one of four objects the virtual machine knows # @@ -23,24 +27,24 @@ module Virtual # named classes exist for slots that often accessed - # Return is the MessageSlot(MESSAGE_RETURN_VALUE) + # Return is the MessageSlot(RETURN_INDEX) class Return < MessageSlot def initialize type = Unknown, value = nil - super( MESSAGE_RETURN_VALUE , type , value ) + super( RETURN_INDEX , type , value ) end end - # Self is the MessageSlot(MESSAGE_SELF) + # Self is the MessageSlot(SELF_INDEX) class Self < MessageSlot def initialize type = Unknown, value = nil - super( MESSAGE_SELF , type , value ) + super( SELF_INDEX , type , value ) end end # MessageName of the current message class MessageName < MessageSlot def initialize type = Unknown, value = nil - super( MESSAGE_NAME , type , value ) + super( NAME_INDEX , type , value ) end end end diff --git a/lib/virtual/slots/next_message_slot.rb b/lib/virtual/slots/next_message_slot.rb index 07c30f48..3e0aa217 100644 --- a/lib/virtual/slots/next_message_slot.rb +++ b/lib/virtual/slots/next_message_slot.rb @@ -14,24 +14,24 @@ module Virtual # named classes exist for slots that often accessed - # NextReturn is the NextMessageSlot(MESSAGE_RETURN_VALUE) + # NextReturn is the NextMessageSlot(RETURN_INDEX) class NextReturn < NextMessageSlot def initialize type = Unknown, value = nil - super( MESSAGE_RETURN_VALUE, type , value ) + super( RETURN_INDEX, type , value ) end end - # NextSelf is the NextMessageSlot(MESSAGE_SELF) + # NextSelf is the NextMessageSlot(SELF_INDEX) class NextSelf < NextMessageSlot def initialize type = Unknown, value = nil - super( MESSAGE_SELF , type , value ) + super( SELF_INDEX , type , value ) end end # NextMessageName of the next message class NextMessageName < NextMessageSlot def initialize type = Unknown, value = nil - super( MESSAGE_NAME, type , value ) + super( NAME_INDEX, type , value ) end end end