2017-09-11 13:22:33 +02:00
|
|
|
module Mom
|
|
|
|
|
2018-03-21 07:50:55 +01:00
|
|
|
# As reminder: a statically resolved call (the simplest one) becomes three Mom Instructions.
|
|
|
|
# Ie: MessageSetup,ArgumentTransfer,SimpleCall
|
2017-09-11 13:22:33 +02:00
|
|
|
#
|
2018-03-21 07:50:55 +01:00
|
|
|
# MessageSetup does Setup before a call can be made, acquiring and filling the message
|
2018-04-05 11:24:49 +02:00
|
|
|
# basically.Only after MessageSetup is the next_message safe to use.
|
2017-09-11 13:22:33 +02:00
|
|
|
#
|
2018-04-05 11:24:49 +02:00
|
|
|
# The space keeps a linked list of Messages, from which we take and currenty also return.
|
2018-03-21 07:50:55 +01:00
|
|
|
#
|
2018-04-05 11:24:49 +02:00
|
|
|
# Message setup set the 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
|
|
|
|
#
|
|
|
|
# The only difference between the setup of a static call and a dynamic one is where
|
|
|
|
# the method comes from. A static, or simple call, passes the method, but a dynamic
|
|
|
|
# call passes the cache_entry that holds the resolved method.
|
|
|
|
#
|
|
|
|
# In either case, the method is loaded and name,frame and args set
|
2017-09-11 13:22:33 +02:00
|
|
|
#
|
|
|
|
class MessageSetup < Instruction
|
2018-04-05 11:24:49 +02:00
|
|
|
attr_reader :method_source
|
2017-09-11 13:22:33 +02:00
|
|
|
|
2018-04-05 11:24:49 +02:00
|
|
|
def initialize(method_source)
|
|
|
|
@method_source = method_source
|
2017-09-11 13:22:33 +02:00
|
|
|
end
|
2018-03-13 11:46:06 +01:00
|
|
|
|
2018-04-05 11:24:49 +02:00
|
|
|
# Move method name, frame and arguemnt types from the method to the next_message
|
|
|
|
# Get the message from Space and link it.
|
2018-03-13 11:46:06 +01:00
|
|
|
def to_risc(compiler)
|
2018-04-05 11:24:49 +02:00
|
|
|
method = compiler.use_reg( :TypedMethod )
|
|
|
|
risc = move_method_to(compiler , method)
|
|
|
|
message = compiler.use_reg( :Message )
|
|
|
|
risc << get_message_to(compiler , message)
|
|
|
|
|
|
|
|
# move name args frame
|
|
|
|
# this time using Risc instructions (create helpers?)
|
|
|
|
name_move = SlotLoad.new( [:message , :next_message,:name] , [method_source , :name],self)
|
2018-03-21 07:50:55 +01:00
|
|
|
moves = name_move.to_risc(compiler)
|
2018-04-05 11:24:49 +02:00
|
|
|
args_move = SlotLoad.new( [:message , :next_message, :arguments, :type] , [method_source , :arguments_type],self)
|
2018-03-21 07:50:55 +01:00
|
|
|
moves << args_move.to_risc(compiler)
|
2018-04-05 11:24:49 +02:00
|
|
|
type_move = SlotLoad.new( [:message , :next_message, :frame, :type] , [method_source , :frame_type],self)
|
2018-03-21 07:50:55 +01:00
|
|
|
moves << type_move.to_risc(compiler)
|
2018-04-05 11:24:49 +02:00
|
|
|
return risc
|
|
|
|
end
|
|
|
|
private
|
2018-04-05 19:10:00 +02:00
|
|
|
def source
|
|
|
|
"method setup "
|
|
|
|
end
|
|
|
|
|
2018-04-05 11:24:49 +02:00
|
|
|
# get the method from method_source into the given register
|
2018-04-05 19:10:00 +02:00
|
|
|
# return instructions to do this
|
2018-04-05 11:24:49 +02:00
|
|
|
def move_method_to(compiler, register)
|
2018-04-05 19:10:00 +02:00
|
|
|
Risc.load_constant(source + " move method" , @method_source ,register)
|
2018-03-13 11:46:06 +01:00
|
|
|
end
|
|
|
|
|
2018-04-05 11:24:49 +02:00
|
|
|
# get the next message from space and unlink it there
|
|
|
|
# also put it into next_message of current message
|
|
|
|
# use given message regster
|
|
|
|
# return instructions to do this
|
|
|
|
def get_message_to( compiler , message)
|
2018-04-05 19:10:00 +02:00
|
|
|
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)
|
2018-04-05 11:24:49 +02:00
|
|
|
end
|
2017-09-11 13:22:33 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
end
|