rubyx/lib/vool/return_statement.rb
Torsten Rüger b9bdc55059 A good start on the macro idea
I call it macro because it lets you insert basically arbitrary risc code into the ruby level. The way it works:
Reserve namespace X
map any X.some_call to a Mom instruction
by the name SomeCall
which must take the same args in constructor as given
And obviously produce whatever risc it wants
Hoping to rewrite builtin around this idea (with the existing Mom builtn instructions)
2019-08-25 14:40:59 +03:00

39 lines
1.0 KiB
Ruby

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