small refactor and rename

This commit is contained in:
Torsten Ruger 2016-12-28 18:16:39 +02:00
parent 184f129107
commit 4412eda105
8 changed files with 25 additions and 28 deletions

View File

@ -146,7 +146,7 @@ module Arm
end end
def exit int_code def exit int_code
codes = ArmMachine.ldr( :r0 , :r0 , arm_index(Register.resolve_index(:Message , :return_value)) ) codes = ArmMachine.ldr( :r0 , :r0 , arm_index(Register.resolve_to_index(:Message , :return_value)) )
syscall int_code , codes syscall int_code , codes
end end

View File

@ -14,7 +14,7 @@ module Register
space = Parfait::Space.object_space space = Parfait::Space.object_space
space_reg = compiler.use_reg(:Space) #Set up the Space as self upon init space_reg = compiler.use_reg(:Space) #Set up the Space as self upon init
compiler.add_code LoadConstant.new("__init__ load Space", space , space_reg) compiler.add_code LoadConstant.new("__init__ load Space", space , space_reg)
message_ind = Register.resolve_index( :space , :first_message ) message_ind = Register.resolve_to_index( :space , :first_message )
compiler.add_code Register.slot_to_reg( "__init__ load 1st message" , space_reg , message_ind , :message) compiler.add_code Register.slot_to_reg( "__init__ load 1st message" , space_reg , message_ind , :message)
compiler.add_code Register.reg_to_slot( "__init__ store Space in message", space_reg , :message , :receiver) compiler.add_code Register.reg_to_slot( "__init__ store Space in message", space_reg , :message , :receiver)
exit_label = Label.new("_exit_label for __init__" , "#{compiler.type.object_class.name}.#{compiler.method.name}" ) exit_label = Label.new("_exit_label for __init__" , "#{compiler.type.object_class.name}.#{compiler.method.name}" )

View File

@ -13,7 +13,7 @@ module Register
# but index is left as is. # but index is left as is.
# def self.reg_to_byte source , from , to , index # def self.reg_to_byte source , from , to , index
# from = resolve_to_register from # from = resolve_to_register from
# index = resolve_index( to , index) # index = resolve_to_index( to , index)
# to = resolve_to_register to # to = resolve_to_register to
# RegToByte.new( source, from , to , index) # RegToByte.new( source, from , to , index)
# end # end

View File

@ -15,10 +15,10 @@ module Register
# Produce a RegToSlot instruction. # Produce a RegToSlot instruction.
# From and to are registers or symbols that can be transformed to a register by resolve_to_register # From and to are registers or symbols that can be transformed to a register by resolve_to_register
# index resolves with resolve_index. # index resolves with resolve_to_index.
def self.reg_to_slot source , from , to , index def self.reg_to_slot source , from , to , index
from = resolve_to_register from from = resolve_to_register from
index = resolve_index( to , index) index = resolve_to_index( to , index)
to = resolve_to_register to to = resolve_to_register to
RegToSlot.new( source, from , to , index) RegToSlot.new( source, from , to , index)
end end

View File

@ -15,11 +15,11 @@ module Register
# Produce a SlotToReg instruction. # Produce a SlotToReg instruction.
# Array and to are registers or symbols that can be transformed to a register by resolve_to_register # Array and to are registers or symbols that can be transformed to a register by resolve_to_register
# index resolves with resolve_index. # index resolves with resolve_to_index.
def self.slot_to_reg source , array , index , to def self.slot_to_reg source , array , index , to
index = resolve_index( array , index) index = resolve_to_index( array , index)
array = resolve_to_register array array = resolve_to_register( array )
to = resolve_to_register to to = resolve_to_register( to )
SlotToReg.new( source , array , index , to) SlotToReg.new( source , array , index , to)
end end
end end

View File

@ -79,7 +79,7 @@ module Register
# The first scratch register. There is a next_reg_use to get a next and next. # The first scratch register. There is a next_reg_use to get a next and next.
# Current thinking is that scratch is schatch between instructions # Current thinking is that scratch is schatch between instructions
def self.tmp_reg type , value = nil def self.tmp_reg( type , value = nil)
RegisterValue.new :r2 , type , value RegisterValue.new :r2 , type , value
end end
@ -87,7 +87,7 @@ module Register
# By looking up the class and the type for that class, we can resolve the instance # By looking up the class and the type for that class, we can resolve the instance
# variable name to an index. # variable name to an index.
# The class can be mapped to a register, and so we get a memory address (reg+index) # The class can be mapped to a register, and so we get a memory address (reg+index)
def self.resolve_index( clazz_name , instance_name ) def self.resolve_to_index( clazz_name , instance_name )
return instance_name unless instance_name.is_a? Symbol return instance_name unless instance_name.is_a? Symbol
real_name = clazz_name.to_s.split('_').last.capitalize.to_sym real_name = clazz_name.to_s.split('_').last.capitalize.to_sym
clazz = Parfait::Space.object_space.get_class_by_name(real_name) clazz = Parfait::Space.object_space.get_class_by_name(real_name)
@ -97,24 +97,21 @@ module Register
return index # the type word is at index 0, but type is a list and starts at 1 == type return index # the type word is at index 0, but type is a list and starts at 1 == type
end end
# if a symbol is given, it may be one of the four objects that the vm knows. # if a symbol is given, it may be the message or the new_message.
# These are mapped to register references. # These are mapped to register references.
# The valid symbols (:message, :self,:locals,:new_message) are the same that are returned # The valid symbols (:message,:new_message) are the same that are returned
# by the slots. All data (at any time) is in one of the instance variables of these four # by the slots. All data (at any time) is in one of the instance variables of these two
# objects. Register defines module methods with the same names (and _reg) # objects. Register defines module methods with the same names (and _reg)
def self.resolve_to_register reference def self.resolve_to_register( reference )
register = reference return reference if reference.is_a?(RegisterValue)
if reference.is_a? Symbol case reference
case reference when :message
when :message return message_reg
register = message_reg when :new_message
when :new_message return new_message_reg
register = new_message_reg else
else raise "not recognized register reference #{reference}"
raise "not recognized register reference #{reference}"
end
end end
return register
end end
end end

View File

@ -137,7 +137,7 @@ module Typed
@current = enter = method.instructions @current = enter = method.instructions
add_code Register::Label.new( source, "return #{name}") add_code Register::Label.new( source, "return #{name}")
#load the return address into pc, affecting return. (other cpus have commands for this, but not arm) #load the return address into pc, affecting return. (other cpus have commands for this, but not arm)
add_code Register::FunctionReturn.new( source , Register.message_reg , Register.resolve_index(:message , :return_address) ) add_code Register::FunctionReturn.new( source , Register.message_reg , Register.resolve_to_index(:message , :return_address) )
@current = enter @current = enter
self self
end end

View File

@ -51,7 +51,7 @@ class BasicType < MiniTest::Test
# not really parfait test, but related and no other place currently # not really parfait test, but related and no other place currently
def test_reg_index def test_reg_index
message_ind = Register.resolve_index( :message , :receiver ) message_ind = Register.resolve_to_index( :message , :receiver )
assert_equal 3 , message_ind assert_equal 3 , message_ind
@mess.receiver = 55 @mess.receiver = 55
assert_equal 55 , @mess.get_internal_word(message_ind) assert_equal 55 , @mess.get_internal_word(message_ind)