diff --git a/lib/arm/passes/syscall_implementation.rb b/lib/arm/passes/syscall_implementation.rb index 5e5354db..5c2879c6 100644 --- a/lib/arm/passes/syscall_implementation.rb +++ b/lib/arm/passes/syscall_implementation.rb @@ -15,7 +15,7 @@ module Arm def putstring int_code , codes codes << ArmMachine.mov( :r1 , 20 ) # String length, obvious TODO - codes << ArmMachine.ldr( :r0 , Virtual::Slot::MESSAGE_REGISTER, Virtual::SELF_INDEX) + codes << ArmMachine.ldr( :r0 , Register::RegisterReference.message_reg, Virtual::SELF_INDEX) syscall(int_code , codes ) end diff --git a/lib/register/builtin/kernel.rb b/lib/register/builtin/kernel.rb index a9deb549..6dddceca 100644 --- a/lib/register/builtin/kernel.rb +++ b/lib/register/builtin/kernel.rb @@ -12,10 +12,12 @@ module Builtin function.info.blocks.last.codes.pop # no Method return #Set up the Space as self upon init space = Parfait::Space.object_space - function.info.add_code Register::LoadConstant.new( space , Virtual::Slot::SELF_REGISTER) + function.info.add_code Register::LoadConstant.new( space , Register::RegisterReference.self_reg) message_ind = space.get_layout().index_of( :next_message ) # Load the message to message register (0) - function.info.add_code Register::GetSlot.new( Virtual::Slot::SELF_REGISTER , message_ind , Virtual::Slot::MESSAGE_REGISTER) + function.info.add_code Register::GetSlot.new( Register::RegisterReference.self_reg , message_ind , Register::RegisterReference.new_message_reg) + # And store the space as the new self (so the call can move it back as self) + function.info.add_code Register::SetSlot.new( Register::RegisterReference.self_reg , Register::RegisterReference.new_message_reg , Virtual::SELF_INDEX) # now we are set up to issue a call to the main function.info.add_code Virtual::MethodCall.new(Virtual.machine.space.get_main) emit_syscall( function , :exit ) @@ -56,22 +58,22 @@ module Builtin ind = Parfait::Space.object_space.get_layout().index_of( :syscall_message ) raise "index not found for :syscall_message" unless ind function.info.add_code Register::LoadConstant.new( Parfait::Space.object_space , space_tmp) - function.info.add_code Register::SetSlot.new( Virtual::Slot::MESSAGE_REGISTER , space_tmp , ind) + function.info.add_code Register::SetSlot.new( Register::RegisterReference.message_reg , space_tmp , ind) end def restore_message(function) # get the sys return out of the way return_tmp = Register::RegisterReference.tmp_reg # load the space into the base register - function.info.add_code Register::RegisterTransfer.new( return_tmp , Virtual::Slot::MESSAGE_REGISTER ) + function.info.add_code Register::RegisterTransfer.new( return_tmp , Register::RegisterReference.message_reg ) slot = Virtual::Slot # find the stored message ind = Parfait::Space.object_space.get_layout().index_of( :syscall_message ) raise "index not found for #{kind}.#{kind.class}" unless ind # and load it into the base RegisterMachine - function.info.add_code Register::GetSlot.new( slot::MESSAGE_REGISTER , ind , slot::MESSAGE_REGISTER ) + function.info.add_code Register::GetSlot.new( Register::RegisterReference.message_reg , ind , Register::RegisterReference.message_reg ) # and "unroll" self and frame - function.info.add_code Register::GetSlot.new( slot::MESSAGE_REGISTER , Virtual::SELF_INDEX, slot::SELF_REGISTER ) - function.info.add_code Register::GetSlot.new( slot::MESSAGE_REGISTER , Virtual::FRAME_INDEX, slot::FRAME_REGISTER ) + function.info.add_code Register::GetSlot.new( Register::RegisterReference.message_reg , Virtual::SELF_INDEX, Register::RegisterReference.self_reg ) + function.info.add_code Register::GetSlot.new( Register::RegisterReference.message_reg , Virtual::FRAME_INDEX, Register::RegisterReference.frame_reg ) end end extend ClassMethods diff --git a/lib/register/passes/call_implementation.rb b/lib/register/passes/call_implementation.rb index 021ac3b1..ea6af3e2 100644 --- a/lib/register/passes/call_implementation.rb +++ b/lib/register/passes/call_implementation.rb @@ -14,9 +14,9 @@ module Register new_codes = [] slot = Virtual::Slot # move the current new_message to message - new_codes << RegisterTransfer.new( slot::NEW_MESSAGE_REGISTER , slot::MESSAGE_REGISTER ) + new_codes << RegisterTransfer.new( RegisterReference.new_message_reg , RegisterReference.message_reg ) # "roll out" self into its register - new_codes << GetSlot.new( slot::MESSAGE_REGISTER , Virtual::SELF_INDEX, slot::SELF_REGISTER ) + new_codes << GetSlot.new( RegisterReference.message_reg , Virtual::SELF_INDEX, RegisterReference.self_reg ) # 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 0c898867..e17fe94d 100644 --- a/lib/register/passes/return_implementation.rb +++ b/lib/register/passes/return_implementation.rb @@ -6,14 +6,14 @@ module Register next unless code.is_a? Virtual::MethodReturn new_codes = [] # move the current message to new_message - new_codes << RegisterTransfer.new( slot::MESSAGE_REGISTER , slot::NEW_MESSAGE_REGISTER ) + new_codes << RegisterTransfer.new( RegisterReference.message_reg , RegisterReference.new_message_reg ) # and restore the message from saved value in new_message - new_codes << GetSlot.new( slot::NEW_MESSAGE_REGISTER , Virtual::CALLER_INDEX , slot::MESSAGE_REGISTER) + new_codes << GetSlot.new( RegisterReference.new_message_reg , Virtual::CALLER_INDEX , RegisterReference.message_reg) # "roll out" self and frame into their registers - 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 ) + new_codes << GetSlot.new( RegisterReference.message_reg , Virtual::SELF_INDEX , RegisterReference.self_reg ) + new_codes << GetSlot.new( RegisterReference.message_reg , Virtual::FRAME_INDEX , RegisterReference.frame_reg ) #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::RETURN_INDEX ) + new_codes << FunctionReturn.new( RegisterReference.message_reg , Virtual::RETURN_INDEX ) block.replace(code , new_codes ) end end diff --git a/lib/register/register_reference.rb b/lib/register/register_reference.rb index a2794c48..d6c9ee83 100644 --- a/lib/register/register_reference.rb +++ b/lib/register/register_reference.rb @@ -48,27 +48,27 @@ module Register RegisterReference.new( sym ) end - SELF_REG = :r0 - MESSAGE_REG = :r1 - FRAME_REG = :r2 - NEW_MESSAGE_REG = :r3 + MESSAGE_REGISTER = :r0 + SELF_REGISTER = :r1 + FRAME_REGISTER = :r2 + NEW_MESSAGE_REGISTER = :r3 - TMP_REG = :r4 + TMP_REGISTER = :r4 def self.self_reg - new SELF_REG + new SELF_REGISTER end def self.message_reg - new MESSAGE_REG + new MESSAGE_REGISTER end def self.frame_reg - new FRAME_REG + new FRAME_REGISTER end def self.new_message_reg - new NEW_MESSAGE_REG + new NEW_MESSAGE_REGISTER end def self.tmp_reg - new TMP_REG + new TMP_REGISTER end def sof_reference_name diff --git a/lib/virtual/compiled_method_info.rb b/lib/virtual/compiled_method_info.rb index 619dcdc7..4c4dbc9f 100644 --- a/lib/virtual/compiled_method_info.rb +++ b/lib/virtual/compiled_method_info.rb @@ -70,7 +70,7 @@ module Virtual def locals_at l_block used =[] # call assigns the return register, but as it is in l_block, it is not asked. - assigned = [ RegisterReference.new(Virtual::RegisterMachine.instance.return_register) ] + assigned = [ Register::RegisterReference.new(Virtual::RegisterMachine.instance.return_register) ] l_block.reachable.each do |b| b.uses.each {|u| (used << u) unless assigned.include?(u) diff --git a/lib/virtual/compiler/function_expression.rb b/lib/virtual/compiler/function_expression.rb index 86746468..1a1c0477 100644 --- a/lib/virtual/compiler/function_expression.rb +++ b/lib/virtual/compiler/function_expression.rb @@ -36,7 +36,7 @@ module Virtual locals = {} expression.params.each_with_index do |param , index| arg = param.name - register = RegisterReference.new(RegisterMachine.instance.receiver_register).next_reg_use(index + 1) + register = Register::RegisterReference.new(RegisterMachine.instance.receiver_register).next_reg_use(index + 1) arg_value = Integer.new(register) locals[arg] = arg_value args << arg_value diff --git a/lib/virtual/message.rb b/lib/virtual/message.rb index 72f6a97c..9ee002d6 100644 --- a/lib/virtual/message.rb +++ b/lib/virtual/message.rb @@ -23,13 +23,6 @@ module Virtual class Message - SELF_REG = :r0 - MESSAGE_REG = :r1 - FRAME_REG = :r2 - NEW_MESSAGE_REG = :r3 - - TMP_REG = :r4 - def initialize me , normal , exceptional @me = me @next_normal = normal diff --git a/lib/virtual/passes/enter_implementation.rb b/lib/virtual/passes/enter_implementation.rb index 355d05fc..72e51c8a 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::RETURN_INDEX ) + new_codes << Register::SaveReturn.new( Register::RegisterReference.message_reg , Virtual::RETURN_INDEX ) new_codes << Virtual::NewFrame.new block.replace(code , new_codes ) end diff --git a/lib/virtual/slots/slot.rb b/lib/virtual/slots/slot.rb index 28599da0..19bee9e5 100644 --- a/lib/virtual/slots/slot.rb +++ b/lib/virtual/slots/slot.rb @@ -16,10 +16,6 @@ module Virtual # Names for the slots avoid indexes class Slot < Object - MESSAGE_REGISTER = :r0 - SELF_REGISTER = :r1 - FRAME_REGISTER = :r2 - NEW_MESSAGE_REGISTER = :r3 attr_accessor :index , :type , :value