small refactor and rename
This commit is contained in:
parent
184f129107
commit
4412eda105
@ -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
|
||||
|
||||
|
@ -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}" )
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
def self.resolve_to_register( reference )
|
||||
return reference if reference.is_a?(RegisterValue)
|
||||
case reference
|
||||
when :message
|
||||
register = message_reg
|
||||
return message_reg
|
||||
when :new_message
|
||||
register = new_message_reg
|
||||
return new_message_reg
|
||||
else
|
||||
raise "not recognized register reference #{reference}"
|
||||
end
|
||||
end
|
||||
return register
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user