introduce return_sequence instruction to mom
This commit is contained in:
@ -7,3 +7,4 @@ module Mom
|
||||
end
|
||||
|
||||
require_relative "slot_load"
|
||||
require_relative "return_sequence"
|
||||
|
24
lib/mom/return_sequence.rb
Normal file
24
lib/mom/return_sequence.rb
Normal file
@ -0,0 +1,24 @@
|
||||
module Mom
|
||||
|
||||
# The ReturnSequence models the return from a method.
|
||||
#
|
||||
# This involves the jump to the return address stored in the message, and
|
||||
# the reinstantiation of the previous message.
|
||||
#
|
||||
# The machine (mom) only ever "knows" one message, the current message.
|
||||
# Messages are a double linked list, calling involves going forward,
|
||||
# returning means going back.
|
||||
#
|
||||
# The return value of the current message is transferred into the return value of the
|
||||
# callers return value during the swap of messages, and just before the jump.
|
||||
#
|
||||
# The callers perspective of a call is the magical apperance of a return_value
|
||||
# in it's message at the instruction after the call.
|
||||
#
|
||||
# The instruction is not parameterized as it translates to a constant
|
||||
# set of lower level instructions.
|
||||
#
|
||||
class ReturnSequence < Instruction
|
||||
end
|
||||
|
||||
end
|
@ -13,10 +13,10 @@ module Vool
|
||||
|
||||
# To return form a method in mom instructions we need to do three things:
|
||||
# - store the given return value, this is a SlotMove / SlotConstant
|
||||
# - restore the previous message
|
||||
# - jump to the return address
|
||||
# - activate return sequence (reinstantiate old message and jump to return address)
|
||||
def to_mom( method )
|
||||
[Mom::SlotConstant.new([:message , :return_value] , @return_value)]
|
||||
[Mom::SlotConstant.new([:message , :return_value] , @return_value) ,
|
||||
Mom::ReturnSequence.new]
|
||||
end
|
||||
|
||||
end
|
||||
|
Reference in New Issue
Block a user