first go at message setups translation to risc

simplest possible implementation, ie the method and next_messages are
loaded many times.

But the layer design shines, it’s easy to understand
This commit is contained in:
Torsten Ruger 2018-03-21 12:20:55 +05:30
parent b99fdc3425
commit 12c71fa394
3 changed files with 23 additions and 11 deletions

View File

@ -1,14 +1,18 @@
module Mom module Mom
# Preamble when entering the method body. # As reminder: a statically resolved call (the simplest one) becomes three Mom Instructions.
# Acquiring the message basically. # Ie: MessageSetup,ArgumentTransfer,SimpleCall
# #
# Currently messages are hardwired as a linked list, # MessageSetup does Setup before a call can be made, acquiring and filling the message
# but this does not account for continuations or closures and # basically.
# so will have to be changed.
# #
# With the current setup this maps to a single SlotMove, ie 2 risc Instructions # With the current design the next message is already ready (hardwired as a linked list),
# But clearer this way. # so nothing to be done there.
# (but this does not account for continuations or closures and so will have to be changed)
#
# But we do need to set the message name to the called method's name,
# and also set the arg and local types on the new message, currently for debugging
# but later for dynamic checking
# #
class MessageSetup < Instruction class MessageSetup < Instruction
attr_reader :method attr_reader :method
@ -17,8 +21,15 @@ module Mom
@method = method @method = method
end end
# Move method name, frame and arguemnt types from the method to the neext_message
# Assumes the message is ready, see class description
def to_risc(compiler) def to_risc(compiler)
Risc::Label.new(self,"MethodSetup") name_move = SlotLoad.new( [:message , :next_message,:name] , [method , :name])
moves = name_move.to_risc(compiler)
args_move = SlotLoad.new( [:message , :next_message, :arguments,:type] , [method , :arguments, :type])
moves << args_move.to_risc(compiler)
type_move = SlotLoad.new( [:message , :next_message, :frame,:type] , [method , :frame,:type])
moves << type_move.to_risc(compiler)
end end
end end

View File

@ -102,7 +102,7 @@ module Mom
type = known_object.respond_to?(:ct_type) ? known_object.ct_type : :int type = known_object.respond_to?(:ct_type) ? known_object.ct_type : :int
right = compiler.use_reg( type ) right = compiler.use_reg( type )
case known_object case known_object
when Constant when Constant , Parfait::Object
const = Risc.load_constant(instruction, self , right) const = Risc.load_constant(instruction, self , right)
when Symbol when Symbol
const = Risc::SlotToReg.new( instruction , Risc.resolve_to_register(known_object) , const = Risc::SlotToReg.new( instruction , Risc.resolve_to_register(known_object) ,

View File

@ -7,8 +7,9 @@ module Risc
def setup def setup
super super
@input = "r = 5.mod4" @input = "r = 5.mod4"
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, SlotToReg , @expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, SlotToReg ,
SlotToReg, RegToSlot] RegToSlot, LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant ,
SlotToReg, RegToSlot, Label, SlotToReg, SlotToReg, RegToSlot]
end end
def test_local_assign_instructions def test_local_assign_instructions
assert_nil msg = check_nil , msg assert_nil msg = check_nil , msg