diff --git a/lib/mom/instruction/dynamic_call.rb b/lib/mom/instruction/dynamic_call.rb index fc65b223..e15131ad 100644 --- a/lib/mom/instruction/dynamic_call.rb +++ b/lib/mom/instruction/dynamic_call.rb @@ -32,15 +32,14 @@ module Mom # a target (not a label) def to_risc(compiler) compiler.add_constant( @cache_entry ) - reg = compiler.use_reg( :Object ) + entry = compiler.use_reg( :CacheEntry ) return_label = Risc.label(self, "continue_#{object_id}") save_return = SlotLoad.new([:message,:next_message,:return_address],[return_label],self) moves = save_return.to_risc(compiler) moves << Risc.slot_to_reg(self, Risc.message_reg , :next_message , Risc.message_reg) - moves << Risc.load_constant( self , @cache_entry , reg ) - method_index = Risc.resolve_to_index(:cache_entry , :cached_method) - moves << Risc::SlotToReg.new( self , reg ,method_index, reg) - moves << Risc::DynamicJump.new(self, reg ) + moves << Risc.load_constant( self , @cache_entry , entry ) + moves << Risc.slot_to_reg( self , entry ,:cached_method , entry) + moves << Risc::DynamicJump.new(self, entry ) moves << return_label end end diff --git a/lib/mom/instruction/return_sequence.rb b/lib/mom/instruction/return_sequence.rb index d3ae8c6d..6538d17e 100644 --- a/lib/mom/instruction/return_sequence.rb +++ b/lib/mom/instruction/return_sequence.rb @@ -22,13 +22,12 @@ module Mom def to_risc(compiler) return_move = SlotLoad.new( [:message , :caller,:return_value] , [:message , :return_value],self) moves = return_move.to_risc(compiler) - return_address = compiler.use_reg(:Object) compiler.reset_regs - caller_index = Risc.resolve_to_index(:message , :caller) - return_index = Risc.resolve_to_index(:message , :return_address) - moves << Risc::SlotToReg.new(self, Risc.message_reg, return_index , return_address) - moves << Risc::SlotToReg.new( self , return_address , Parfait::Integer.integer_index , return_address) - moves << Risc::SlotToReg.new(self, Risc.message_reg , caller_index , Risc.message_reg) + return_address = compiler.use_reg(:ReturnAddress) + message = Risc.message_reg + moves << Risc.slot_to_reg(self,message, :return_address , return_address) + moves << Risc.slot_to_reg(self,return_address , Parfait::Integer.integer_index , return_address) + moves << Risc.slot_to_reg(self,message , :caller , message) moves << Risc::FunctionReturn.new(self, return_address) end diff --git a/lib/mom/instruction/slot_definition.rb b/lib/mom/instruction/slot_definition.rb index 4b097de8..322361e1 100644 --- a/lib/mom/instruction/slot_definition.rb +++ b/lib/mom/instruction/slot_definition.rb @@ -46,7 +46,13 @@ module Mom end end 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 ) case known_object when Constant @@ -57,8 +63,7 @@ module Mom const = Risc.load_constant(source, known_object , right) if slots.length > 0 # desctructively replace the existing value to be loaded if more slots - index = Risc.resolve_to_index(known_object , slots[0] ,compiler) - const << Risc::SlotToReg.new( source , right ,index, right) + const << Risc.slot_to_reg( source , right ,slots[0], right) end when Symbol return sym_to_risc(compiler , source) diff --git a/lib/mom/instruction/slot_load.rb b/lib/mom/instruction/slot_load.rb index c6ff2b5f..eda583bb 100644 --- a/lib/mom/instruction/slot_load.rb +++ b/lib/mom/instruction/slot_load.rb @@ -46,10 +46,9 @@ module Mom when Symbol sym_to_risc(compiler , const) when Parfait::CacheEntry - left = compiler.use_reg( :Object ) + left = compiler.use_reg( :CacheEntry ) 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_index) + const << Risc.reg_to_slot(original_source, const.register , left, left_slots.first) else raise "We have left #{@left.known_object}" end diff --git a/lib/parfait/cache_entry.rb b/lib/parfait/cache_entry.rb index 72ed47c4..19c76bf8 100644 --- a/lib/parfait/cache_entry.rb +++ b/lib/parfait/cache_entry.rb @@ -7,12 +7,15 @@ # module Parfait class CacheEntry < Object + attr :cached_type attr :cached_method + def initialize(type , method) @cached_type = type @cached_method = method end + def to_s "CacheEntry" + "#{cached_method&.name}" end diff --git a/lib/risc/builder.rb b/lib/risc/builder.rb index 711882d6..697486ed 100644 --- a/lib/risc/builder.rb +++ b/lib/risc/builder.rb @@ -89,10 +89,10 @@ module Risc source += "add_new_int " space = compiler.use_reg(:Space) 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_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 value" , from , to , Parfait::Integer.integer_index) end @@ -209,7 +209,7 @@ module Risc # variable name to an 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 - 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) case object when :frame diff --git a/lib/risc/instructions/reg_to_byte.rb b/lib/risc/instructions/reg_to_byte.rb index e2ae0541..1ad2183f 100644 --- a/lib/risc/instructions/reg_to_byte.rb +++ b/lib/risc/instructions/reg_to_byte.rb @@ -12,9 +12,8 @@ module Risc # from and to are translated (from symbol to register if neccessary) # but index is left as is. def self.reg_to_byte( source , from , to , index) - from = resolve_to_register from - index = resolve_to_index( to , index) - to = resolve_to_register to + raise "Not register #{to}" unless RegisterValue.look_like_reg(to) + index = to.resolve_index(index) if index.is_a?(Symbol) RegToByte.new( source, from , to , index) end diff --git a/test/parfait/type/test_basic.rb b/test/parfait/type/test_basic.rb index 219faf38..93c96be5 100644 --- a/test/parfait/type/test_basic.rb +++ b/test/parfait/type/test_basic.rb @@ -56,14 +56,6 @@ module Parfait assert_equal 55 , @mess.receiver 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 assert_equal 1 , @type.variable_index(:next_message) end