remove Risc.resolve_to_index
mostly by using better typed registers, which cleans up the code where it was used
This commit is contained in:
parent
29363e7f72
commit
4cc04787e9
@ -32,15 +32,14 @@ module Mom
|
|||||||
# a target (not a label)
|
# a target (not a label)
|
||||||
def to_risc(compiler)
|
def to_risc(compiler)
|
||||||
compiler.add_constant( @cache_entry )
|
compiler.add_constant( @cache_entry )
|
||||||
reg = compiler.use_reg( :Object )
|
entry = compiler.use_reg( :CacheEntry )
|
||||||
return_label = Risc.label(self, "continue_#{object_id}")
|
return_label = Risc.label(self, "continue_#{object_id}")
|
||||||
save_return = SlotLoad.new([:message,:next_message,:return_address],[return_label],self)
|
save_return = SlotLoad.new([:message,:next_message,:return_address],[return_label],self)
|
||||||
moves = save_return.to_risc(compiler)
|
moves = save_return.to_risc(compiler)
|
||||||
moves << Risc.slot_to_reg(self, Risc.message_reg , :next_message , Risc.message_reg)
|
moves << Risc.slot_to_reg(self, Risc.message_reg , :next_message , Risc.message_reg)
|
||||||
moves << Risc.load_constant( self , @cache_entry , reg )
|
moves << Risc.load_constant( self , @cache_entry , entry )
|
||||||
method_index = Risc.resolve_to_index(:cache_entry , :cached_method)
|
moves << Risc.slot_to_reg( self , entry ,:cached_method , entry)
|
||||||
moves << Risc::SlotToReg.new( self , reg ,method_index, reg)
|
moves << Risc::DynamicJump.new(self, entry )
|
||||||
moves << Risc::DynamicJump.new(self, reg )
|
|
||||||
moves << return_label
|
moves << return_label
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -22,13 +22,12 @@ module Mom
|
|||||||
def to_risc(compiler)
|
def to_risc(compiler)
|
||||||
return_move = SlotLoad.new( [:message , :caller,:return_value] , [:message , :return_value],self)
|
return_move = SlotLoad.new( [:message , :caller,:return_value] , [:message , :return_value],self)
|
||||||
moves = return_move.to_risc(compiler)
|
moves = return_move.to_risc(compiler)
|
||||||
return_address = compiler.use_reg(:Object)
|
|
||||||
compiler.reset_regs
|
compiler.reset_regs
|
||||||
caller_index = Risc.resolve_to_index(:message , :caller)
|
return_address = compiler.use_reg(:ReturnAddress)
|
||||||
return_index = Risc.resolve_to_index(:message , :return_address)
|
message = Risc.message_reg
|
||||||
moves << Risc::SlotToReg.new(self, Risc.message_reg, return_index , return_address)
|
moves << Risc.slot_to_reg(self,message, :return_address , return_address)
|
||||||
moves << Risc::SlotToReg.new( self , return_address , Parfait::Integer.integer_index , return_address)
|
moves << Risc.slot_to_reg(self,return_address , Parfait::Integer.integer_index , return_address)
|
||||||
moves << Risc::SlotToReg.new(self, Risc.message_reg , caller_index , Risc.message_reg)
|
moves << Risc.slot_to_reg(self,message , :caller , message)
|
||||||
moves << Risc::FunctionReturn.new(self, return_address)
|
moves << Risc::FunctionReturn.new(self, return_address)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -46,7 +46,13 @@ module Mom
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
def to_register(compiler, source)
|
def to_register(compiler, source)
|
||||||
type = known_object.respond_to?(:ct_type) ? known_object.ct_type : :Object
|
if known_object.respond_to?(:ct_type)
|
||||||
|
type = known_object.ct_type
|
||||||
|
elsif(known_object.respond_to?(:get_type))
|
||||||
|
type = known_object.get_type
|
||||||
|
else
|
||||||
|
type = :Object
|
||||||
|
end
|
||||||
right = compiler.use_reg( type )
|
right = compiler.use_reg( type )
|
||||||
case known_object
|
case known_object
|
||||||
when Constant
|
when Constant
|
||||||
@ -57,8 +63,7 @@ module Mom
|
|||||||
const = Risc.load_constant(source, known_object , right)
|
const = Risc.load_constant(source, known_object , right)
|
||||||
if slots.length > 0
|
if slots.length > 0
|
||||||
# desctructively replace the existing value to be loaded if more slots
|
# desctructively replace the existing value to be loaded if more slots
|
||||||
index = Risc.resolve_to_index(known_object , slots[0] ,compiler)
|
const << Risc.slot_to_reg( source , right ,slots[0], right)
|
||||||
const << Risc::SlotToReg.new( source , right ,index, right)
|
|
||||||
end
|
end
|
||||||
when Symbol
|
when Symbol
|
||||||
return sym_to_risc(compiler , source)
|
return sym_to_risc(compiler , source)
|
||||||
|
@ -46,10 +46,9 @@ module Mom
|
|||||||
when Symbol
|
when Symbol
|
||||||
sym_to_risc(compiler , const)
|
sym_to_risc(compiler , const)
|
||||||
when Parfait::CacheEntry
|
when Parfait::CacheEntry
|
||||||
left = compiler.use_reg( :Object )
|
left = compiler.use_reg( :CacheEntry )
|
||||||
const << Risc.load_constant(original_source, @left.known_object , left)
|
const << Risc.load_constant(original_source, @left.known_object , left)
|
||||||
left_index = Risc.resolve_to_index(:cache_entry , left_slots.first)
|
const << Risc.reg_to_slot(original_source, const.register , left, left_slots.first)
|
||||||
const << Risc.reg_to_slot(original_source, const.register , left, left_index)
|
|
||||||
else
|
else
|
||||||
raise "We have left #{@left.known_object}"
|
raise "We have left #{@left.known_object}"
|
||||||
end
|
end
|
||||||
|
@ -7,12 +7,15 @@
|
|||||||
#
|
#
|
||||||
module Parfait
|
module Parfait
|
||||||
class CacheEntry < Object
|
class CacheEntry < Object
|
||||||
|
|
||||||
attr :cached_type
|
attr :cached_type
|
||||||
attr :cached_method
|
attr :cached_method
|
||||||
|
|
||||||
def initialize(type , method)
|
def initialize(type , method)
|
||||||
@cached_type = type
|
@cached_type = type
|
||||||
@cached_method = method
|
@cached_method = method
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
"CacheEntry" + "#{cached_method&.name}"
|
"CacheEntry" + "#{cached_method&.name}"
|
||||||
end
|
end
|
||||||
|
@ -89,10 +89,10 @@ module Risc
|
|||||||
source += "add_new_int "
|
source += "add_new_int "
|
||||||
space = compiler.use_reg(:Space)
|
space = compiler.use_reg(:Space)
|
||||||
int = compiler.use_reg(:Integer)
|
int = compiler.use_reg(:Integer)
|
||||||
space_i = Risc.resolve_to_index(:Space, :next_integer)
|
space_i = space.resolve_index(:next_integer)
|
||||||
add_load_constant( source + "space" , Parfait.object_space , space )
|
add_load_constant( source + "space" , Parfait.object_space , space )
|
||||||
add_slot_to_reg( source + "next_i1" , space , space_i , to)
|
add_slot_to_reg( source + "next_i1" , space , space_i , to)
|
||||||
add_slot_to_reg( source + "next_i2" , to , Risc.resolve_to_index(:Integer, :next_integer) , int)
|
add_slot_to_reg( source + "next_i2" , to , int.resolve_index(:next_integer) , int)
|
||||||
add_reg_to_slot( source + "store link" , int , space , space_i )
|
add_reg_to_slot( source + "store link" , int , space , space_i )
|
||||||
add_reg_to_slot( source + "store value" , from , to , Parfait::Integer.integer_index)
|
add_reg_to_slot( source + "store value" , from , to , Parfait::Integer.integer_index)
|
||||||
end
|
end
|
||||||
@ -209,7 +209,7 @@ module Risc
|
|||||||
# 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)
|
||||||
# Third arg, compiler, is only needed to resolve receiver/arguments/frame
|
# Third arg, compiler, is only needed to resolve receiver/arguments/frame
|
||||||
def self.resolve_to_index(object , variable_name ,compiler = nil)
|
def self.old_resolve_to_index(object , variable_name , compiler)
|
||||||
return variable_name if variable_name.is_a?(Integer) or variable_name.is_a?(RegisterValue)
|
return variable_name if variable_name.is_a?(Integer) or variable_name.is_a?(RegisterValue)
|
||||||
case object
|
case object
|
||||||
when :frame
|
when :frame
|
||||||
|
@ -12,9 +12,8 @@ module Risc
|
|||||||
# from and to are translated (from symbol to register if neccessary)
|
# from and to are translated (from symbol to register if neccessary)
|
||||||
# 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
|
raise "Not register #{to}" unless RegisterValue.look_like_reg(to)
|
||||||
index = resolve_to_index( to , index)
|
index = to.resolve_index(index) if index.is_a?(Symbol)
|
||||||
to = resolve_to_register to
|
|
||||||
RegToByte.new( source, from , to , index)
|
RegToByte.new( source, from , to , index)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -56,14 +56,6 @@ module Parfait
|
|||||||
assert_equal 55 , @mess.receiver
|
assert_equal 55 , @mess.receiver
|
||||||
end
|
end
|
||||||
|
|
||||||
# not really parfait test, but related and no other place currently
|
|
||||||
def test_reg_index
|
|
||||||
message_ind = Risc.resolve_to_index( :message , :receiver )
|
|
||||||
assert_equal 2 , message_ind
|
|
||||||
@mess.set_receiver( 55)
|
|
||||||
assert_equal 55 , @mess.get_internal_word(message_ind)
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_variable_index
|
def test_variable_index
|
||||||
assert_equal 1 , @type.variable_index(:next_message)
|
assert_equal 1 , @type.variable_index(:next_message)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user