2019-10-04 16:38:51 +02:00
|
|
|
module SlotLanguage
|
2020-02-13 07:10:04 +01:00
|
|
|
# A Variable makes Slots. A Slot is the central SlotMachines description of a
|
|
|
|
# variable in an object. At the Language level this holds the information
|
2020-02-13 13:09:00 +01:00
|
|
|
# (names of variables) to be able to create the Slot instance
|
2020-02-12 09:41:16 +01:00
|
|
|
#
|
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-13 07:10:04 +01:00
|
|
|
# uses two Variables.
|
|
|
|
class Variable
|
2020-02-12 09:41:16 +01:00
|
|
|
# stores the (instance) names that allow us to create a Slot
|
2020-02-13 13:09:00 +01:00
|
|
|
attr_reader :name , :chain
|
2019-10-05 18:37:24 +02:00
|
|
|
|
2020-02-13 13:09:00 +01:00
|
|
|
def initialize(name)
|
|
|
|
@name = name
|
|
|
|
raise "No name given #{name}" unless name.is_a?(Symbol)
|
2019-10-05 18:37:24 +02:00
|
|
|
end
|
|
|
|
|
2020-02-13 13:09:00 +01:00
|
|
|
def chained(to)
|
|
|
|
raise "Must chain to variable #{to}" unless to.is_a?(Variable)
|
|
|
|
if(@chain)
|
|
|
|
@chain.chained(to)
|
|
|
|
else
|
|
|
|
@chain = to
|
|
|
|
end
|
|
|
|
self
|
2019-10-07 19:14:40 +02:00
|
|
|
end
|
|
|
|
|
2020-02-12 09:41:16 +01:00
|
|
|
def to_slot(compiler)
|
2020-02-13 13:09:00 +01:00
|
|
|
SlotMachine::Slot.for(:message , name)
|
2019-10-04 16:38:51 +02:00
|
|
|
end
|
2020-02-09 15:33:34 +01:00
|
|
|
|
|
|
|
def to_s
|
2020-02-13 13:09:00 +01:00
|
|
|
str = "message.#{name}"
|
|
|
|
str += chain.to_s if @chain
|
|
|
|
str
|
2020-02-09 15:33:34 +01:00
|
|
|
end
|
2019-10-04 16:38:51 +02:00
|
|
|
end
|
2020-02-13 13:09:00 +01:00
|
|
|
|
|
|
|
class MessageVariable < Variable
|
|
|
|
end
|
|
|
|
class Constant < Variable
|
|
|
|
end
|
2019-10-04 16:38:51 +02:00
|
|
|
end
|