From e7b878a353c2d250597a611603cc528ff0fd217d Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Sun, 18 Mar 2018 10:51:46 +0530 Subject: [PATCH] mostly finish index resolve in slot_definition alas, it reveals error, types may not be set correctly --- lib/mom/instruction/slot_load.rb | 26 +++++++++++++++++++++++--- lib/parfait/typed_method.rb | 2 +- lib/vool/statements/send_statement.rb | 2 +- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/lib/mom/instruction/slot_load.rb b/lib/mom/instruction/slot_load.rb index 70107003..ca5aabf5 100644 --- a/lib/mom/instruction/slot_load.rb +++ b/lib/mom/instruction/slot_load.rb @@ -8,7 +8,7 @@ module Mom # # The Slot on the left hand side is always a SlotDefinition. # The only known object (*) for the left side is the current message, which is a bit like - # the oo version of a PC (program Counter) + # the oo version of a Stack (Stack Register, Frame Pointer, ..) # (* off course all class objects are global, and so they are allowed too) # # A maybe not immediately obvious corrolar of this design is the total absence of @@ -39,9 +39,14 @@ module Mom when Constant const = Risc.load_constant(self, @right , right) when Symbol - const = Risc::SlotToReg.new( self , Risc.message_reg , + const = Risc::SlotToReg.new( self , Risc.resolve_to_register(@right.known_object) , Risc.resolve_to_index(:message , @right.slots[0]), right) - puts "more slots #{@right.slots}" if @right.slots.length > 1 + if @right.slots.length > 1 + # desctructively replace the existing value to be loaded if more slots + index = resolve_to_index(@right.slots[0] , @right.slots[1] ,compiler) + const << Risc::SlotToReg.new( self , right ,index, right) + raise "more slots not implemented #{@right.slots}" if @right.slots.length > 2 + end else raise "We have a #{@right} #{@right.known_object}" end @@ -61,6 +66,21 @@ module Mom return const end + def resolve_to_index(object , variable_name ,compiler) + case object + when :frame + type = compiler.method.frame + when :arguments + type = compiler.method.arguments + when :receiver + type = compiler.method.for_type + else + raise "Not implemented/found object #{object}" + end + index = type.variable_index(variable_name) + raise "Index not found for #{variable_name} in #{object} of type #{type}" unless index + return index + end end class SlotDefinition diff --git a/lib/parfait/typed_method.rb b/lib/parfait/typed_method.rb index b9078cf0..b57c8053 100644 --- a/lib/parfait/typed_method.rb +++ b/lib/parfait/typed_method.rb @@ -13,7 +13,7 @@ # Instructions derive from class Instruction and form a linked list # - binary: The binary (jumpable) code that the instructions get assembled into # - arguments: A type object describing the arguments (name+types) to be passed -# - locals: A type object describing the local variables that the method has +# - frame: A type object describing the local variables that the method has # - for_type: The Type the Method is for diff --git a/lib/vool/statements/send_statement.rb b/lib/vool/statements/send_statement.rb index 2fe16ae9..0a530369 100644 --- a/lib/vool/statements/send_statement.rb +++ b/lib/vool/statements/send_statement.rb @@ -107,7 +107,7 @@ module Vool def build_method_cache_update(in_method) receiver = StringConstant.new(@name) resolve = SendStatement.new(:resolve_method , receiver , [SelfExpression.new]) - move_method = Mom::SlotLoad.new([@dynamic.cache_entry, :cached_method] , [:message ,:receiver , :return]) + move_method = Mom::SlotLoad.new([@dynamic.cache_entry, :cached_method] , [:message , :return_value]) resolve.to_mom(in_method) << move_method end end