move each slot instruction into own file

This commit is contained in:
Torsten Ruger 2018-03-14 17:36:55 +05:30
parent a3890afc20
commit b854c075b2
4 changed files with 39 additions and 28 deletions

View File

@ -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"

View File

@ -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

View File

@ -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)

View File

@ -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