2017-04-01 20:28:57 +02:00
|
|
|
module Vool
|
|
|
|
class ReturnStatement < Statement
|
2018-03-16 14:56:27 +01:00
|
|
|
|
2017-04-06 15:06:51 +02:00
|
|
|
attr_reader :return_value
|
2017-04-04 09:42:20 +02:00
|
|
|
|
|
|
|
def initialize(value)
|
|
|
|
@return_value = value
|
|
|
|
end
|
2017-04-08 11:10:42 +02:00
|
|
|
|
2018-03-16 14:56:27 +01:00
|
|
|
def each(&block)
|
|
|
|
block.call(@return_value)
|
2017-04-08 11:10:42 +02:00
|
|
|
end
|
2017-04-14 09:52:23 +02:00
|
|
|
|
2018-03-16 14:56:27 +01:00
|
|
|
# Since the return is normalized to only allow simple values it is simple.
|
|
|
|
# To return form a method in mom instructions we only need to do two things:
|
|
|
|
# - store the given return value, this is a SlotMove
|
2017-04-14 20:01:50 +02:00
|
|
|
# - activate return sequence (reinstantiate old message and jump to return address)
|
2018-07-05 13:02:38 +02:00
|
|
|
def to_mom( compiler )
|
|
|
|
ret = Mom::SlotLoad.new( [:message , :return_value] ,
|
|
|
|
@return_value.slot_definition(compiler) )
|
2018-08-02 16:36:39 +02:00
|
|
|
ret << Mom::ReturnJump.new
|
2017-04-14 09:52:23 +02:00
|
|
|
end
|
|
|
|
|
2018-07-03 21:18:19 +02:00
|
|
|
def to_s(depth = 0)
|
|
|
|
at_depth(depth , "return #{@return_value.to_s}")
|
|
|
|
end
|
2017-04-01 20:28:57 +02:00
|
|
|
end
|
|
|
|
end
|