start with #11

by adding striaght to compiler
This commit is contained in:
Torsten Ruger
2018-08-19 12:56:44 +03:00
parent 5b2c7745fe
commit 047a36178f
4 changed files with 27 additions and 21 deletions

View File

@ -45,6 +45,10 @@ module Mom
"unknown"
end
end
# load the slots into a register
# the code is added to compiler
# the register returned
def to_register(compiler, source)
if known_object.respond_to?(:ct_type)
type = known_object.ct_type
@ -57,13 +61,15 @@ module Mom
case known_object
when Constant
parfait = known_object.to_parfait(compiler)
const = Risc.load_constant(source, parfait , right)
const = Risc.load_constant(source, parfait , right)
compiler.add_code const
raise "Can't have slots into Constants" if slots.length > 0
when Parfait::Object , Risc::Label
const = Risc.load_constant(source, known_object , right)
const = Risc::SlotToReg.new( source , right ,index, right)
compiler.add_code const Risc.load_constant(source, known_object , right)
if slots.length > 0
# desctructively replace the existing value to be loaded if more slots
const << Risc.slot_to_reg( source , right ,slots[0], right)
compiler.add_code Risc.slot_to_reg( source , right ,slots[0], right)
end
when Symbol
return sym_to_risc(compiler , source)
@ -73,29 +79,27 @@ module Mom
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( source , right ,index, right)
compiler.add_code 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( source , right , Parfait::TYPE_INDEX, right)
compiler.add_code Risc::SlotToReg.new( source , right , Parfait::TYPE_INDEX, right)
end
end
const
return const.register
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)
left = left.resolve_and_add( slots.shift , compiler)
reg = compiler.current.register
while( !slots.empty? )
left = left.resolve_and_add( slots.shift , instructions , compiler)
left = left.resolve_and_add( slots.shift , compiler)
end
return instructions.next
return reg
end
end