2020-02-10 12:58:48 +01:00
|
|
|
module SlotMachine
|
2020-02-17 08:26:50 +01:00
|
|
|
class SlottedConstant < Slotted
|
2020-02-15 09:26:49 +01:00
|
|
|
|
|
|
|
attr_reader :known_object
|
2020-02-10 12:58:48 +01:00
|
|
|
|
|
|
|
def initialize( object , slots)
|
2020-02-15 09:26:49 +01:00
|
|
|
super(slots)
|
|
|
|
@known_object = object
|
|
|
|
raise "Not known #{slots}" unless object
|
2020-02-10 12:58:48 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def known_name
|
|
|
|
known_object.class.short_name
|
|
|
|
end
|
|
|
|
|
|
|
|
# load the slots into a register
|
|
|
|
# the code is added to compiler
|
|
|
|
# the register returned
|
|
|
|
def to_register(compiler, source)
|
|
|
|
if known_object.respond_to?(:ct_type)
|
|
|
|
type = known_object.ct_type
|
|
|
|
else
|
|
|
|
type = :Object
|
|
|
|
end
|
2020-02-15 09:26:49 +01:00
|
|
|
parfait = known_object.to_parfait(compiler)
|
2020-02-29 16:19:53 +01:00
|
|
|
last = Risc.load_constant(source, parfait )
|
|
|
|
compiler.add_code(last)
|
2020-02-17 08:29:45 +01:00
|
|
|
if slots_length == 2
|
|
|
|
raise "only type allowed for constants, not #{slots}" unless slots.name == :type
|
2020-02-29 16:19:53 +01:00
|
|
|
last = Risc.slot_to_reg( source , last.register , Parfait::TYPE_INDEX )
|
|
|
|
compiler.add_code(last)
|
2020-02-10 12:58:48 +01:00
|
|
|
end
|
2020-02-17 08:29:45 +01:00
|
|
|
raise "Can't have slots into Constants #{slots}" if slots_length > 2
|
2020-02-29 16:19:53 +01:00
|
|
|
return last.register
|
2020-02-10 12:58:48 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|