2020-02-10 12:12:39 +01:00
|
|
|
module SlotMachine
|
2020-02-17 08:26:50 +01:00
|
|
|
class SlottedMessage < Slotted
|
2020-02-10 12:12:39 +01:00
|
|
|
|
|
|
|
def known_name
|
2020-02-10 12:58:48 +01:00
|
|
|
:message
|
2020-02-10 12:12:39 +01:00
|
|
|
end
|
2020-02-15 15:02:03 +01:00
|
|
|
alias :known_object :known_name
|
2020-02-10 12:12:39 +01:00
|
|
|
|
2020-02-17 08:45:54 +01:00
|
|
|
def initialize(slots)
|
|
|
|
super(slots)
|
|
|
|
raise "Message must have slots, but none given" unless slots
|
|
|
|
end
|
2020-02-10 12:12:39 +01:00
|
|
|
# load the slots into a register
|
|
|
|
# the code is added to compiler
|
|
|
|
# the register returned
|
|
|
|
def to_register(compiler, source)
|
2020-02-17 08:29:45 +01:00
|
|
|
slots = @slots
|
2020-02-29 16:19:53 +01:00
|
|
|
left = Risc.message_named_reg
|
2020-02-17 08:26:50 +01:00
|
|
|
while( slots )
|
2020-02-17 08:29:45 +01:00
|
|
|
left = left.resolve_and_add( slots.name , compiler)
|
2020-02-17 08:26:50 +01:00
|
|
|
slots = slots.next_slot
|
2020-02-10 12:12:39 +01:00
|
|
|
end
|
2020-02-29 16:19:53 +01:00
|
|
|
return left
|
2020-02-10 12:12:39 +01:00
|
|
|
end
|
|
|
|
|
2020-02-11 10:03:51 +01:00
|
|
|
# load the data in const_reg into the slot that is named by slot symbols
|
|
|
|
# actual lifting is done by RegisterValue resolve_and_add
|
|
|
|
#
|
|
|
|
# Note: this is the left hand case, the right hand being to_register
|
|
|
|
# They are very similar (apart from the final reg_to_slot here) and should
|
|
|
|
# most likely be united
|
|
|
|
def reduce_and_load(const_reg , compiler , original_source )
|
|
|
|
raise "Not Message #{object}" unless known_object == :message
|
2020-02-29 16:19:53 +01:00
|
|
|
left = Risc.message_named_reg
|
2020-02-17 08:29:45 +01:00
|
|
|
slot = slots
|
|
|
|
while( slot.next_slot )
|
|
|
|
left = left.resolve_and_add( slot.name , compiler)
|
|
|
|
slot = slot.next_slot
|
2020-02-11 10:03:51 +01:00
|
|
|
end
|
2020-02-17 08:29:45 +01:00
|
|
|
compiler.add_code Risc.reg_to_slot(original_source, const_reg , left, slot.name)
|
2020-02-11 10:03:51 +01:00
|
|
|
end
|
|
|
|
|
2020-02-10 12:12:39 +01:00
|
|
|
end
|
|
|
|
end
|