mostly finish index resolve in slot_definition

alas, it reveals error, types may not be set correctly
This commit is contained in:
Torsten Ruger 2018-03-18 10:51:46 +05:30
parent be79388cc5
commit e7b878a353
3 changed files with 25 additions and 5 deletions

View File

@ -8,7 +8,7 @@ module Mom
# #
# The Slot on the left hand side is always a SlotDefinition. # 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 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) # (* 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 # A maybe not immediately obvious corrolar of this design is the total absence of
@ -39,9 +39,14 @@ module Mom
when Constant when Constant
const = Risc.load_constant(self, @right , right) const = Risc.load_constant(self, @right , right)
when Symbol 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) 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 else
raise "We have a #{@right} #{@right.known_object}" raise "We have a #{@right} #{@right.known_object}"
end end
@ -61,6 +66,21 @@ module Mom
return const return const
end 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 end
class SlotDefinition class SlotDefinition

View File

@ -13,7 +13,7 @@
# Instructions derive from class Instruction and form a linked list # Instructions derive from class Instruction and form a linked list
# - binary: The binary (jumpable) code that the instructions get assembled into # - binary: The binary (jumpable) code that the instructions get assembled into
# - arguments: A type object describing the arguments (name+types) to be passed # - 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 # - for_type: The Type the Method is for

View File

@ -107,7 +107,7 @@ module Vool
def build_method_cache_update(in_method) def build_method_cache_update(in_method)
receiver = StringConstant.new(@name) receiver = StringConstant.new(@name)
resolve = SendStatement.new(:resolve_method , receiver , [SelfExpression.new]) 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 resolve.to_mom(in_method) << move_method
end end
end end