2019-10-04 16:38:51 +02:00
|
|
|
module SlotLanguage
|
2020-02-12 09:41:16 +01:00
|
|
|
# A SlotMaker makes Slots. A Slot s the central SlotMachines description of a
|
|
|
|
# variable in an object. This Language level "Maker" holds the information
|
|
|
|
# (names of instance variables) to be able to create the Slot instance
|
|
|
|
#
|
2020-02-13 07:02:23 +01:00
|
|
|
# In the SlotLanguage this is used in the Assignment. Just as a Slotload stores
|
|
|
|
# two slots to define what is loaded where, the Assignment, that creates a SlotLoad,
|
2020-02-12 09:41:16 +01:00
|
|
|
# uses two SlotMakers.
|
2019-10-04 16:38:51 +02:00
|
|
|
class SlotMaker
|
2020-02-12 09:41:16 +01:00
|
|
|
# stores the (instance) names that allow us to create a Slot
|
|
|
|
attr_reader :names
|
2019-10-05 18:37:24 +02:00
|
|
|
|
2020-02-12 09:41:16 +01:00
|
|
|
def initialize(names)
|
|
|
|
case names
|
2019-10-07 19:14:40 +02:00
|
|
|
when Array
|
2020-02-12 09:41:16 +01:00
|
|
|
@names = names
|
2019-10-07 19:14:40 +02:00
|
|
|
when nil
|
2020-02-12 09:41:16 +01:00
|
|
|
raise "No names given"
|
2019-10-05 18:37:24 +02:00
|
|
|
else
|
2020-02-12 09:41:16 +01:00
|
|
|
@names = [names]
|
2019-10-05 18:37:24 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_slot_name(name)
|
2020-02-12 09:41:16 +01:00
|
|
|
@names << name
|
2019-10-07 19:14:40 +02:00
|
|
|
end
|
|
|
|
|
2020-02-12 09:41:16 +01:00
|
|
|
def to_slot(compiler)
|
|
|
|
SlotMachine::Slot.for(:message , names)
|
2019-10-04 16:38:51 +02:00
|
|
|
end
|
2020-02-09 15:33:34 +01:00
|
|
|
|
|
|
|
def to_s
|
2020-02-12 09:41:16 +01:00
|
|
|
"message." + names.join(",")
|
2020-02-09 15:33:34 +01:00
|
|
|
end
|
2019-10-04 16:38:51 +02:00
|
|
|
end
|
|
|
|
end
|