rubyx/lib/vool/return_statement.rb
Torsten Rüger e6c30d98fb Fix if statements hoisting, now that send is working
Same same, just have to remembe to actually execute the condition if it is a send
Having send a possible expression, removes one tmp variable and associated move, for a little extra work.
Next return and assign (rest)
2019-08-16 18:42:57 +03:00

35 lines
990 B
Ruby

module Vool
class ReturnStatement < Statement
attr_reader :return_value
def initialize(value)
@return_value = value
end
def each(&block)
block.call(@return_value)
end
# 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)
def to_mom( compiler )
load = Mom::SlotLoad.new( self , [:message , :return_value] ,
@return_value.slot_definition(compiler) )
if @return_value.is_a?(SendStatement)
ret = @return_value.to_mom(compiler)
ret << load
else
ret = load
end
ret << Mom::ReturnJump.new(self , compiler.return_label )
end
def to_s(depth = 0)
at_depth(depth , "return #{@return_value.to_s}")
end
end
end