2020-02-15 15:02:03 +01:00
|
|
|
module SlotMachine
|
|
|
|
|
|
|
|
class Slotted
|
|
|
|
|
2020-02-17 08:45:54 +01:00
|
|
|
def self.for(object , slots = nil)
|
2020-02-15 15:02:03 +01:00
|
|
|
case object
|
|
|
|
when :message
|
|
|
|
SlottedMessage.new(slots)
|
|
|
|
when Constant
|
|
|
|
SlottedConstant.new(object , slots)
|
|
|
|
when Parfait::Object , Risc::Label
|
|
|
|
SlottedObject.new(object , slots)
|
|
|
|
else
|
2020-02-17 08:29:45 +01:00
|
|
|
raise "not supported type #{object}:#{object.class}"
|
2020-02-15 15:02:03 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-02-17 08:26:50 +01:00
|
|
|
# The first in a possible chain of slots, that name instance variables in the
|
|
|
|
# previous object
|
2020-02-17 08:29:45 +01:00
|
|
|
attr_reader :slots
|
2020-02-17 08:26:50 +01:00
|
|
|
|
2020-02-17 08:45:54 +01:00
|
|
|
def initialize( slots = nil )
|
|
|
|
return unless slots
|
2020-02-18 20:19:14 +01:00
|
|
|
raise "stopped #{slots.class}" unless slots.is_a?(Array)
|
2020-02-17 08:26:50 +01:00
|
|
|
first = slots.shift
|
2020-02-17 08:45:54 +01:00
|
|
|
raise "ended" unless first
|
2020-02-17 08:29:45 +01:00
|
|
|
@slots = Slot.new(first)
|
2020-02-17 08:26:50 +01:00
|
|
|
until(slots.empty?)
|
2020-02-17 08:29:45 +01:00
|
|
|
@slots.set_next( Slot.new( slots.shift ))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def slots_length
|
|
|
|
return 0 unless @slots
|
|
|
|
1 + @slots.length
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_next(slot)
|
|
|
|
if(@slots)
|
|
|
|
@slots.set_next(slot)
|
|
|
|
else
|
|
|
|
@slots = slot
|
2020-02-17 08:26:50 +01:00
|
|
|
end
|
2020-02-15 15:02:03 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_s
|
2020-02-17 08:26:50 +01:00
|
|
|
names = known_name.to_s
|
2020-02-17 08:29:45 +01:00
|
|
|
names += ".#{@slots}" if @slots
|
2020-02-17 08:26:50 +01:00
|
|
|
names
|
2020-02-15 15:02:03 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|