refactored the SlotLoad into SlotDefs

That sort of removes the last horrible code.
Surely can still be improved, but mostly oo now
This commit is contained in:
2020-02-11 16:03:51 +07:00
parent 8d02d82ff2
commit 31c8a0aac5
5 changed files with 41 additions and 92 deletions

View File

@ -1,20 +1,6 @@
module SlotMachine
class ObjectDefinition < SlotDefinition
# get the right definition, depending on the object
def self.for(object , slots)
case object
when :message
MessageDefinition.new(slots)
when Constant
ConstantDefinition.new(object , slots)
when Parfait::Object
ObjectDefinition.new(object , slots)
else
SlotDefinition.new(object,slots)
end
end
def initialize( object , slots)
super(object , slots )
end
@ -47,5 +33,14 @@ module SlotMachine
return const.register
end
# 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 "only cache" unless known_object.is_a?( Parfait::CacheEntry)
left = compiler.use_reg( :CacheEntry )
compiler.add_code Risc.load_constant(original_source, known_object , left)
compiler.add_code Risc.reg_to_slot(original_source, const_reg , left, slots.first)
end
end
end