more fix for multilevel constant load

was ignoring first level which is already the second for a constant
as the constant is the first load.
first interpreter test working but looking dodgy
This commit is contained in:
Torsten Ruger
2018-03-22 19:14:22 +02:00
parent 34903829ca
commit 55832315eb
6 changed files with 47 additions and 33 deletions

View File

@ -78,6 +78,8 @@ module Mom
type = compiler.method.arguments
when :receiver
type = compiler.method.for_type
when Parfait::Object
type = Parfait.object_space.get_class_by_name( object.class.name.split("::").last.to_sym).instance_type
else
raise "Not implemented/found object #{object}"
end
@ -98,6 +100,7 @@ module Mom
@known_object , @slots = object , slots
slot = [slot] unless slot.is_a?(Array)
raise "Not known #{slots}" unless object
raise "No slots #{object}" unless slots
end
def to_register(compiler, instruction)
@ -106,6 +109,11 @@ module Mom
case known_object
when Constant , Parfait::Object , Risc::Label
const = Risc.load_constant(instruction, known_object , right)
if slots.length > 0
# desctructively replace the existing value to be loaded if more slots
index = SlotLoad.resolve_to_index(known_object , slots[0] ,compiler)
const << Risc::SlotToReg.new( instruction , right ,index, right)
end
when Symbol
const = Risc::SlotToReg.new( instruction , Risc.resolve_to_register(known_object) ,
Risc.resolve_to_index(:message , slots[0]), right)

View File

@ -17,10 +17,10 @@ module Mom
def to_risc(compiler)
false_label = @false_jump.to_risc(compiler)
left = @condition.to_register(compiler,self)
false_load = SlotDefinition.new( FalseConstant.new , nil ).to_register(compiler,self)
false_load = SlotDefinition.new( FalseConstant.new , [] ).to_register(compiler,self)
left << false_load
left << Risc::IsSame.new(self , left.register , false_load.register , false_label)
nil_load = SlotDefinition.new( NilConstant.new , nil ).to_register(compiler,self)
nil_load = SlotDefinition.new( NilConstant.new , [] ).to_register(compiler,self)
left << nil_load
left << Risc::IsSame.new(self , left.register , nil_load.register , false_label)
left