From ab8b574e9c1228e3a365045b8838655b655bc2e5 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sat, 14 Jul 2018 22:39:00 +0300 Subject: [PATCH] also recode the slot_definition resolution much like in the slot_load. In fact suspiciously so. wip, as also changing to storing type (not sym) in reg --- lib/mom/instruction/slot_definition.rb | 32 +++++++++++++++++++------- lib/mom/instruction/slot_load.rb | 2 +- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/lib/mom/instruction/slot_definition.rb b/lib/mom/instruction/slot_definition.rb index 9a3a3770..4b097de8 100644 --- a/lib/mom/instruction/slot_definition.rb +++ b/lib/mom/instruction/slot_definition.rb @@ -45,37 +45,53 @@ module Mom "unknown" end end - def to_register(compiler, instruction) + def to_register(compiler, source) type = known_object.respond_to?(:ct_type) ? known_object.ct_type : :Object right = compiler.use_reg( type ) case known_object when Constant parfait = known_object.to_parfait(compiler) - const = Risc.load_constant(instruction, parfait , right) + const = Risc.load_constant(source, parfait , right) raise "Can't have slots into Constants" if slots.length > 0 when Parfait::Object , Risc::Label - const = Risc.load_constant(instruction, known_object , right) + const = Risc.load_constant(source, known_object , right) if slots.length > 0 # desctructively replace the existing value to be loaded if more slots index = Risc.resolve_to_index(known_object , slots[0] ,compiler) - const << Risc::SlotToReg.new( instruction , right ,index, right) + const << Risc::SlotToReg.new( source , 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) + return sym_to_risc(compiler , source) else raise "We have a #{self} #{known_object}" end if slots.length > 1 # desctructively replace the existing value to be loaded if more slots index = Risc.resolve_to_index(slots[0] , slots[1] ,compiler) - const << Risc::SlotToReg.new( instruction , right ,index, right) + const << Risc::SlotToReg.new( source , right ,index, right) if slots.length > 2 raise "3 slots only for type #{slots}" unless slots[2] == :type - const << Risc::SlotToReg.new( instruction , right , Parfait::TYPE_INDEX, right) + const << Risc::SlotToReg.new( source , right , Parfait::TYPE_INDEX, right) end end const end + + # resolve the slots one by one to slot_to_reg instructions using the + # type information inferred from their names / type hierachy + def sym_to_risc(compiler , source) + #label just to collect the instructions + # (they should be added to the compiler/builder anyway) + instructions = Risc.label( "" , "tmp") + slots = @slots.dup + raise "Not Message #{object}" unless @known_object == :message + left = Risc.message_reg + left = left.resolve_and_add( slots.shift , instructions , compiler) + while( !slots.empty? ) + left = left.resolve_and_add( slots.shift , instructions , compiler) + end + return instructions.next + end + end end diff --git a/lib/mom/instruction/slot_load.rb b/lib/mom/instruction/slot_load.rb index 2fb64aa3..ecb83136 100644 --- a/lib/mom/instruction/slot_load.rb +++ b/lib/mom/instruction/slot_load.rb @@ -58,7 +58,7 @@ module Mom end def sym_to_risc(compiler , const) - left_slots = @left.slots + left_slots = @left.slots.dup raise "Not Message #{object}" unless @left.known_object == :message left = Risc.message_reg slot = left_slots.shift