diff --git a/lib/arm/translator.rb b/lib/arm/translator.rb index 1ff60adf..e374ff42 100644 --- a/lib/arm/translator.rb +++ b/lib/arm/translator.rb @@ -146,7 +146,7 @@ module Arm end 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 end diff --git a/lib/register/builtin/kernel.rb b/lib/register/builtin/kernel.rb index 6b2f3cba..69e5e62f 100644 --- a/lib/register/builtin/kernel.rb +++ b/lib/register/builtin/kernel.rb @@ -14,7 +14,7 @@ module Register space = Parfait::Space.object_space 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) - 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.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}" ) diff --git a/lib/register/instructions/reg_to_byte.rb b/lib/register/instructions/reg_to_byte.rb index 1d4df493..b092ee97 100644 --- a/lib/register/instructions/reg_to_byte.rb +++ b/lib/register/instructions/reg_to_byte.rb @@ -13,7 +13,7 @@ module Register # but index is left as is. # def self.reg_to_byte source , from , to , index # from = resolve_to_register from - # index = resolve_index( to , index) + # index = resolve_to_index( to , index) # to = resolve_to_register to # RegToByte.new( source, from , to , index) # end diff --git a/lib/register/instructions/reg_to_slot.rb b/lib/register/instructions/reg_to_slot.rb index 1cd72afc..91d3cdae 100644 --- a/lib/register/instructions/reg_to_slot.rb +++ b/lib/register/instructions/reg_to_slot.rb @@ -15,10 +15,10 @@ module Register # Produce a RegToSlot instruction. # 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 from = resolve_to_register from - index = resolve_index( to , index) + index = resolve_to_index( to , index) to = resolve_to_register to RegToSlot.new( source, from , to , index) end diff --git a/lib/register/instructions/slot_to_reg.rb b/lib/register/instructions/slot_to_reg.rb index 6c1bc3c5..13fce0b6 100644 --- a/lib/register/instructions/slot_to_reg.rb +++ b/lib/register/instructions/slot_to_reg.rb @@ -15,11 +15,11 @@ module Register # Produce a SlotToReg instruction. # 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 - index = resolve_index( array , index) - array = resolve_to_register array - to = resolve_to_register to + index = resolve_to_index( array , index) + array = resolve_to_register( array ) + to = resolve_to_register( to ) SlotToReg.new( source , array , index , to) end end diff --git a/lib/register/register_value.rb b/lib/register/register_value.rb index e8af1d47..d18502c7 100644 --- a/lib/register/register_value.rb +++ b/lib/register/register_value.rb @@ -79,7 +79,7 @@ module Register # 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 - def self.tmp_reg type , value = nil + def self.tmp_reg( type , value = nil) RegisterValue.new :r2 , type , value end @@ -87,7 +87,7 @@ module Register # By looking up the class and the type for that class, we can resolve the instance # variable name to an 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 real_name = clazz_name.to_s.split('_').last.capitalize.to_sym 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 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. - # The valid symbols (:message, :self,:locals,: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 + # 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 two # objects. Register defines module methods with the same names (and _reg) - def self.resolve_to_register reference - register = reference - if reference.is_a? Symbol - case reference - when :message - register = message_reg - when :new_message - register = new_message_reg - else - raise "not recognized register reference #{reference}" - end + def self.resolve_to_register( reference ) + return reference if reference.is_a?(RegisterValue) + case reference + when :message + return message_reg + when :new_message + return new_message_reg + else + raise "not recognized register reference #{reference}" end - return register end end diff --git a/lib/typed/method_compiler.rb b/lib/typed/method_compiler.rb index fade9473..2e8df0e8 100644 --- a/lib/typed/method_compiler.rb +++ b/lib/typed/method_compiler.rb @@ -137,7 +137,7 @@ module Typed @current = enter = method.instructions 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) - 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 self end diff --git a/test/typed/type/test_basic.rb b/test/typed/type/test_basic.rb index 56e2f951..4569ee58 100644 --- a/test/typed/type/test_basic.rb +++ b/test/typed/type/test_basic.rb @@ -51,7 +51,7 @@ class BasicType < MiniTest::Test # not really parfait test, but related and no other place currently def test_reg_index - message_ind = Register.resolve_index( :message , :receiver ) + message_ind = Register.resolve_to_index( :message , :receiver ) assert_equal 3 , message_ind @mess.receiver = 55 assert_equal 55 , @mess.get_internal_word(message_ind)