From b854c075b2d77b16a7ef29002401dc184d49d2ab Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Wed, 14 Mar 2018 17:36:55 +0530 Subject: [PATCH] move each slot instruction into own file --- lib/mom/instruction/instruction.rb | 2 ++ lib/mom/instruction/slot_constant.rb | 25 ++++++++++++++++++++++ lib/mom/instruction/slot_load.rb | 31 +++------------------------- lib/mom/instruction/slot_move.rb | 9 ++++++++ 4 files changed, 39 insertions(+), 28 deletions(-) create mode 100644 lib/mom/instruction/slot_constant.rb create mode 100644 lib/mom/instruction/slot_move.rb diff --git a/lib/mom/instruction/instruction.rb b/lib/mom/instruction/instruction.rb index 56f3d23d..6933dff2 100644 --- a/lib/mom/instruction/instruction.rb +++ b/lib/mom/instruction/instruction.rb @@ -29,6 +29,8 @@ require_relative "truth_check" require_relative "not_same_check" require_relative "jump" require_relative "slot_load" +require_relative "slot_move" +require_relative "slot_constant" require_relative "return_sequence" require_relative "message_setup" require_relative "argument_transfer" diff --git a/lib/mom/instruction/slot_constant.rb b/lib/mom/instruction/slot_constant.rb new file mode 100644 index 00000000..8762f9a2 --- /dev/null +++ b/lib/mom/instruction/slot_constant.rb @@ -0,0 +1,25 @@ +module Mom + # A SlotConstant moves a constant into a known Slot. + # Eg when you write a = 5 , the 5 becomes a constant, and so the right side + # the a is an instance variable on the current frame, and the frame is an instance + # of the current message, so the effect is something like message.frame.a = 5 + # @left: See SlotLoad, an array of symbols + # @right: A Constant from parse, ie an instance of classes in basc_value, like TrueStatement + class SlotConstant < SlotLoad + + def initialize(left , right) + super + raise "right not constant, #{right}" unless right.is_a? Mom::Constant + end + + def to_risc(context) + reg = context.use_reg( @right.ct_type) + const = Risc.load_constant(self, @right , reg) + const.set_next Risc.reg_to_slot(self, reg , @left.known_object, @left.slots.first) + context.release_reg(reg) + return const + end + + end + +end diff --git a/lib/mom/instruction/slot_load.rb b/lib/mom/instruction/slot_load.rb index fa2d0423..987d458c 100644 --- a/lib/mom/instruction/slot_load.rb +++ b/lib/mom/instruction/slot_load.rb @@ -31,37 +31,12 @@ module Mom left = SlotDefinition.new(left.shift , left) if left.is_a? Array @left , @right = left , right raise "left not SlotDefinition, #{left}" unless left.is_a? SlotDefinition -# raise "right not Mom, #{right.to_rxf}" unless right.class.name.include?("Mom") - end - - def to_risc(compiler) - Risc::Label.new(self,"nosense") - end - - end - - # A SlotConstant moves a constant into a known Slot. - # Eg when you write a = 5 , the 5 becomes a constant, and so the right side - # the a is an instance variable on the current frame, and the frame is an instance - # of the current message, so the effect is something like message.frame.a = 5 - # @left: See SlotLoad, an array of symbols - # @right: A Constant from parse, ie an instance of classes in basc_value, like TrueStatement - class SlotConstant < SlotLoad - - def initialize(left , right) - super - raise "right not constant, #{right}" unless right.is_a? Mom::Constant - end - - end - - #SlotMove is a SlotLoad where the right side is a slot, just like the left. - class SlotMove < SlotLoad - def to_risc(compiler) - + raise "right not Mom, #{right.to_rxf}" unless right.class.name.include?("Mom") end end + + class SlotDefinition attr_reader :known_object , :slots def initialize( object , slots) diff --git a/lib/mom/instruction/slot_move.rb b/lib/mom/instruction/slot_move.rb new file mode 100644 index 00000000..141d1410 --- /dev/null +++ b/lib/mom/instruction/slot_move.rb @@ -0,0 +1,9 @@ +module Mom + + #SlotMove is a SlotLoad where the right side is a slot, just like the left. + class SlotMove < SlotLoad + def to_risc(compiler) + + end + end +end