rubyx/lib/vool/return_statement.rb

34 lines
883 B
Ruby
Raw Normal View History

2017-04-01 20:28:57 +02:00
module Vool
class ReturnStatement < Statement
2018-03-16 14:56:27 +01:00
include Normalizer
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 normalize
val , rest = *normalize_name(@return_value)
me = ReturnStatement.new(val)
return me unless rest
rest << me
rest
end
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
# - activate return sequence (reinstantiate old message and jump to return address)
2017-04-14 09:52:23 +02:00
def to_mom( method )
2018-03-16 14:56:27 +01:00
ret = Mom::SlotLoad.new( [:message , :return_value] , @return_value.slot_definition(method) )
ret << Mom::ReturnSequence.new
2017-04-14 09:52:23 +02:00
end
2017-04-01 20:28:57 +02:00
end
end