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-08-06 12:03:33 +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-06-29 12:27:57 +02:00
|
|
|
builder = compiler.code_builder(self)
|
2018-04-08 22:45:23 +02:00
|
|
|
build_with(builder)
|
2018-04-06 23:14:02 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
# directly called by to_risc
|
|
|
|
# but also used directly in __init
|
|
|
|
def build_with(builder)
|
2018-04-08 22:45:23 +02:00
|
|
|
case from = method_source
|
2018-07-07 08:11:09 +02:00
|
|
|
when Parfait::CallableMethod
|
2018-07-27 09:46:22 +02:00
|
|
|
builder.build { callable << from }
|
2018-04-08 22:45:23 +02:00
|
|
|
when Parfait::CacheEntry
|
|
|
|
builder.build do
|
|
|
|
cache_entry << from
|
2018-07-27 09:46:22 +02:00
|
|
|
callable << cache_entry[:cached_method]
|
2018-04-08 22:45:23 +02:00
|
|
|
end
|
2018-07-24 10:35:49 +02:00
|
|
|
when Integer
|
|
|
|
builder.build do
|
|
|
|
arguments << message[:arguments]
|
2018-07-27 09:46:22 +02:00
|
|
|
callable << arguments[ from ]
|
2018-07-24 10:35:49 +02:00
|
|
|
end
|
2018-04-08 22:45:23 +02:00
|
|
|
else
|
2018-07-24 10:35:49 +02:00
|
|
|
raise "unknown source #{method_source.class}:#{method_source}"
|
2018-04-08 22:45:23 +02:00
|
|
|
end
|
2018-04-08 17:55:17 +02:00
|
|
|
build_message_data(builder)
|
|
|
|
return builder.built
|
2018-04-05 11:24:49 +02:00
|
|
|
end
|
2018-04-06 23:14:02 +02:00
|
|
|
|
2018-04-05 11:24:49 +02:00
|
|
|
private
|
2018-04-05 19:10:00 +02:00
|
|
|
def source
|
|
|
|
"method setup "
|
|
|
|
end
|
|
|
|
|
2018-04-05 11:24:49 +02:00
|
|
|
# get the next message from space and unlink it there
|
2018-04-06 21:54:54 +02:00
|
|
|
# also put it into next_message of current message (and reverse)
|
|
|
|
# set name and type data in the message, from the method loaded
|
2018-04-06 21:40:58 +02:00
|
|
|
def build_message_data( builder )
|
2018-04-08 17:55:17 +02:00
|
|
|
builder.build do
|
2018-04-06 19:58:58 +02:00
|
|
|
space << Parfait.object_space
|
2018-07-02 14:49:51 +02:00
|
|
|
next_message << space[:next_message]
|
2018-04-06 21:40:58 +02:00
|
|
|
message[:next_message] << next_message
|
|
|
|
next_message[:caller] << message
|
|
|
|
|
2018-07-27 09:46:22 +02:00
|
|
|
type << callable[:arguments_type]
|
2018-04-06 22:11:08 +02:00
|
|
|
named_list << next_message[:arguments]
|
2018-04-06 21:40:58 +02:00
|
|
|
named_list[:type] << type
|
|
|
|
|
2018-07-27 09:46:22 +02:00
|
|
|
type << callable[:frame_type]
|
2018-04-06 21:40:58 +02:00
|
|
|
named_list << next_message[:frame]
|
|
|
|
named_list[:type] << type
|
|
|
|
|
2018-07-27 09:46:22 +02:00
|
|
|
next_message[:method] << callable
|
2018-04-06 21:40:58 +02:00
|
|
|
|
|
|
|
#store next.next back into space
|
2018-04-06 22:11:08 +02:00
|
|
|
#FIXME in a multithreaded future this should be done soon after getting
|
|
|
|
# the first_message, using lock free compare and swap. Now saving regs
|
2018-04-06 21:40:58 +02:00
|
|
|
next_message << next_message[:next_message]
|
2018-07-02 14:49:51 +02:00
|
|
|
space[:next_message] << next_message
|
2018-04-06 13:21:38 +02:00
|
|
|
end
|
2018-04-06 15:08:35 +02:00
|
|
|
end
|
2017-09-11 13:22:33 +02:00
|
|
|
end
|
|
|
|
end
|