2019-10-04 17:38:51 +03:00
|
|
|
module SlotLanguage
|
2020-02-13 13:10:04 +07: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 19:09:00 +07:00
|
|
|
# (names of variables) to be able to create the Slot instance
|
2020-02-12 15:41:16 +07:00
|
|
|
#
|
2020-02-13 13:02:23 +07: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 13:10:04 +07:00
|
|
|
# uses two Variables.
|
|
|
|
class Variable
|
2020-02-12 15:41:16 +07:00
|
|
|
# stores the (instance) names that allow us to create a Slot
|
2020-02-13 19:09:00 +07:00
|
|
|
attr_reader :name , :chain
|
2019-10-05 19:37:24 +03:00
|
|
|
|
2020-02-13 19:09:00 +07:00
|
|
|
def initialize(name)
|
|
|
|
@name = name
|
|
|
|
raise "No name given #{name}" unless name.is_a?(Symbol)
|
2019-10-05 19:37:24 +03:00
|
|
|
end
|
|
|
|
|
2020-02-13 19:09:00 +07: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 20:14:40 +03:00
|
|
|
end
|
|
|
|
|
2020-02-12 15:41:16 +07:00
|
|
|
def to_slot(compiler)
|
2020-02-15 21:02:03 +07:00
|
|
|
SlotMachine::Slotted.for(:message , name)
|
2019-10-04 17:38:51 +03:00
|
|
|
end
|
2020-02-09 21:33:34 +07:00
|
|
|
|
|
|
|
def to_s
|
2020-02-13 19:09:00 +07:00
|
|
|
str = "message.#{name}"
|
|
|
|
str += chain.to_s if @chain
|
|
|
|
str
|
2020-02-09 21:33:34 +07:00
|
|
|
end
|
2019-10-04 17:38:51 +03:00
|
|
|
end
|
2020-02-13 19:09:00 +07:00
|
|
|
|
|
|
|
class MessageVariable < Variable
|
|
|
|
end
|
|
|
|
class Constant < Variable
|
|
|
|
end
|
2019-10-04 17:38:51 +03:00
|
|
|
end
|