unite the two resolve_to_index functions

This commit is contained in:
Torsten Ruger
2018-04-05 20:10:00 +03:00
parent f4ce6d6253
commit f09086e524
11 changed files with 105 additions and 46 deletions

View File

@ -43,10 +43,14 @@ module Mom
return risc
end
private
def source
"method setup "
end
# get the method from method_source into the given register
# return instruction that do this
# return instructions to do this
def move_method_to(compiler, register)
Risc.load_constant("message setup move method" , @method_source ,register)
Risc.load_constant(source + " move method" , @method_source ,register)
end
# get the next message from space and unlink it there
@ -54,7 +58,11 @@ module Mom
# use given message regster
# return instructions to do this
def get_message_to( compiler , message)
Risc.load_constant("message setup move method" , @method_source ,message)
space = compiler.use_reg(:Space)
risc = Risc.load_constant("message setup move method" , Parfait.object_space ,space)
risc << Risc.slot_to_reg(source + "get next message" , space , :first_message , message)
next_message = compiler.use_reg( :Message )
risc << Risc.slot_to_reg(source + "get next message" , message , :next_message , next_message)
end
end

View File

@ -46,13 +46,13 @@ module Mom
new_left = compiler.use_reg( :Object )
const << Risc::SlotToReg.new( original_source , left ,left_index, new_left)
left = new_left
left_index = SlotLoad.resolve_to_index(left_slots[0] , left_slots[1] ,compiler)
left_index = Risc.resolve_to_index(left_slots[0] , left_slots[1] ,compiler)
if left_slots.length > 2
#same again, once more updating target
new_left = compiler.use_reg( :Object )
const << Risc::SlotToReg.new( original_source , left ,left_index, new_left)
left = new_left
left_index = SlotLoad.resolve_to_index(left_slots[1] , left_slots[2] ,compiler)
left_index = Risc.resolve_to_index(left_slots[1] , left_slots[2] ,compiler)
end
raise "more slots not implemented #{left_slots}" if left_slots.length > 3
end
@ -67,27 +67,6 @@ module Mom
compiler.reset_regs
return const
end
def self.resolve_to_index(object , variable_name ,compiler)
return variable_name if variable_name.is_a?(Integer)
case object
when :frame
type = compiler.method.frame_type
when :message , :next_message , :caller
type = Parfait.object_space.get_class_by_name(:Message).instance_type
when :arguments
type = compiler.method.arguments_type
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
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
@ -116,7 +95,7 @@ module Mom
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)
index = Risc.resolve_to_index(known_object , slots[0] ,compiler)
const << Risc::SlotToReg.new( instruction , right ,index, right)
end
when Symbol
@ -127,7 +106,7 @@ module Mom
end
if slots.length > 1
# desctructively replace the existing value to be loaded if more slots
index = SlotLoad.resolve_to_index(slots[0] , slots[1] ,compiler)
index = Risc.resolve_to_index(slots[0] , slots[1] ,compiler)
const << Risc::SlotToReg.new( instruction , right ,index, right)
raise "more slots not implemented #{slots}" if slots.length > 2
end