From 22409c93ee9632a73d9588e1c25dfddf94ed5a35 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Fri, 6 Apr 2018 22:40:58 +0300 Subject: [PATCH] remove >>, consistent use of << makes code easier to read, like assignments does remind of Passengers --- lib/mom/instruction/message_setup.rb | 44 +++++++++++++--------------- lib/risc/builder.rb | 6 ++-- lib/risc/risc_value.rb | 31 ++++++++------------ test/risc/test_builder.rb | 4 ++- test/risc/test_risc_value.rb | 4 +-- 5 files changed, 40 insertions(+), 49 deletions(-) diff --git a/lib/mom/instruction/message_setup.rb b/lib/mom/instruction/message_setup.rb index ce5e5824..ce3521de 100644 --- a/lib/mom/instruction/message_setup.rb +++ b/lib/mom/instruction/message_setup.rb @@ -30,16 +30,8 @@ module Mom builder = Risc::Builder.new(compiler) from = method_source risc = builder.build { typed_method << from } - get_message_to(builder) - - # move name args frame - # this time using Risc instructions (create helpers?) - name_move = SlotLoad.new( [:message , :next_message,:name] , [method_source , :name],self) - moves = name_move.to_risc(compiler) - args_move = SlotLoad.new( [:message , :next_message, :arguments, :type] , [method_source , :arguments_type],self) - moves << args_move.to_risc(compiler) - type_move = SlotLoad.new( [:message , :next_message, :frame, :type] , [method_source , :frame_type],self) - moves << type_move.to_risc(compiler) + build_message_data(builder) + compiler.reset_regs return risc end private @@ -49,24 +41,28 @@ module Mom # get the next message from space and unlink it there # also put it into next_message of current message - # use given message register - # return instructions to do this - def get_message_to( builder ) + def build_message_data( builder ) builder.build do space << Parfait.object_space next_message << space[:first_message] + message[:next_message] << next_message + next_message[:caller] << message + + named_list << next_message[:arguments] + type << typed_method[:arguments_type] + named_list[:type] << type + + named_list << next_message[:frame] + type << typed_method[:arguments_type] + named_list[:type] << type + + name << typed_method[:arguments_type] + named_list[:type] << name + + #store next.next back into space + next_message << next_message[:next_message] + space[:first_message] << next_message end end - def nnop - space = compiler.use_reg(:Space) - risc = Risc.load_constant("message setup move method" , Parfait.object_space ,space) - risc << Risc.slot_to_reg(source + "get next message" , space , :first_message , message) - next_message = compiler.use_reg( :Message ) - risc << Risc.slot_to_reg(source + "get next message" , message , :next_message , next_message) - risc << Risc.reg_to_slot(source + "store next message" , next_message , space , :first_message) - risc << Risc.reg_to_slot(source + "store message in current" , message , :message , :next_message) - end end - - end diff --git a/lib/risc/builder.rb b/lib/risc/builder.rb index c5479332..ebf6de8a 100644 --- a/lib/risc/builder.rb +++ b/lib/risc/builder.rb @@ -19,7 +19,7 @@ module Risc reg.builder = self reg end - + def build(&block) instance_eval(&block) return built @@ -58,8 +58,8 @@ module Risc def self.resolve_type( object , compiler ) object = object.type if object.is_a?(RiscValue) case object - when :typed_method - type = Parfait.object_space.get_class_by_name( :TypedMethod ).instance_type + when :name + type = Parfait.object_space.get_class_by_name( :Word ).instance_type when :frame type = compiler.method.frame_type when :message , :next_message , :caller diff --git a/lib/risc/risc_value.rb b/lib/risc/risc_value.rb index 34cdab40..ed4a8639 100644 --- a/lib/risc/risc_value.rb +++ b/lib/risc/risc_value.rb @@ -61,15 +61,15 @@ module Risc # right value may be # - constant (Parfait object) , resulting in a LoadConstant # - another RiscValue, resulting in a Transfer instruction - # - an RValue, which gets procuced by the [] below - def <<( load ) - case load + # - an RValue, resulting in an SlotToReg + def <<( right ) + case right when Parfait::Object - ins = Risc.load_constant("#{load.class} to #{self.type}" , load , self) + ins = Risc.load_constant("#{right.class} to #{self.type}" , right , self) when RiscValue - ins = Risc.transfer("#{load.type} to #{self.type}" , load , self) + ins = Risc.transfer("#{right.type} to #{self.type}" , right , self) when RValue - load >> self + ins = Risc.slot_to_reg("#{right.register.type}[#{right.index}] -> #{self.type}" , right.register , right.index , self) else raise "not implemented" end @@ -77,14 +77,6 @@ module Risc return ins end - # create a RegToSlot instruction - # right hand must be an RValue - def >>( slot ) - raise "not RValue #{slot}" unless slot.is_a?(RValue) - reg_to_slot = Risc.reg_to_slot("#{self.type} -> #{slot.register.type}[#{slot.index}]" , self, slot.register, slot.index) - builder.add_instruction(reg_to_slot) if builder - reg_to_slot - end # just capture the values in an intermediary object (RValue) # The RValue then gets used in a RegToSlot ot SlotToReg, where # the values are unpacked to call Risc.reg_to_slot or Risc.slot_to_reg @@ -101,14 +93,15 @@ module Risc @register , @index , @builder = register , index , builder end - # fullfil the objects purpose by creating a SlotToReg instruction from + # fullfil the objects purpose by creating a RegToSlot instruction from # itself (the slot) and the register given - def >>( reg ) + def <<( reg ) raise "not reg #{reg}" unless reg.is_a?(RiscValue) - slot = Risc.slot_to_reg("#{register.type}[#{index}] -> #{reg.type}" , @register , @index , reg) - builder.add_instruction(slot) if builder - slot + reg_to_slot = Risc.reg_to_slot("#{reg.type} -> #{register.type}[#{index}]" , reg , register, index) + builder.add_instruction(reg_to_slot) if builder + reg_to_slot end + end # The register we use to store the current message object is :r0 diff --git a/test/risc/test_builder.rb b/test/risc/test_builder.rb index d44ad916..db9998dd 100644 --- a/test/risc/test_builder.rb +++ b/test/risc/test_builder.rb @@ -31,12 +31,14 @@ module Risc end def test_returns_slot r2 = RiscValue.new(:r2 , :Message) - built = @builder.build{ space[:first_message] >> r2 } + r2.builder = @builder + built = @builder.build{ r2 << space[:first_message] } assert_equal SlotToReg , built.class assert_equal :r1 , built.array.symbol end def test_returns_slot_reverse r2 = RiscValue.new(:r2 , :Message) + r2.builder = @builder built = @builder.build{ r2 << space[:first_message] } assert_equal SlotToReg , built.class assert_equal :r1 , built.array.symbol diff --git a/test/risc/test_risc_value.rb b/test/risc/test_risc_value.rb index 4af98be4..b05814b1 100644 --- a/test/risc/test_risc_value.rb +++ b/test/risc/test_risc_value.rb @@ -38,14 +38,14 @@ module Risc assert_equal @r0 , message.register end def test_slot_to_reg - instr = @r1[:first_message] >> @r0 + instr = @r0 << @r1[:first_message] assert_equal SlotToReg , instr.class assert_equal @r1 , instr.array assert_equal @r0 , instr.register assert_equal 4 , instr.index end def test_reg_to_slot - instr = @r0 >> @r1[:first_message] + instr = @r1[:first_message] << @r0 assert_equal RegToSlot , instr.class assert_equal @r1 , instr.array assert_equal @r0 , instr.register