2014-05-27 15:33:24 +02:00
|
|
|
module Ast
|
|
|
|
class ReturnExpression < Expression
|
|
|
|
attr_reader :expression
|
|
|
|
def initialize expression
|
|
|
|
@expression = expression
|
|
|
|
end
|
|
|
|
def inspect
|
|
|
|
self.class.name + ".new(" + expression.inspect + " )"
|
|
|
|
end
|
|
|
|
def to_s
|
|
|
|
"return #{expression}\n"
|
|
|
|
end
|
|
|
|
def attributes
|
|
|
|
[:expression]
|
|
|
|
end
|
|
|
|
def compile context , into
|
2014-06-02 14:11:48 +02:00
|
|
|
puts "compiling return expression #{expression}, now return in 7"
|
2014-05-28 14:03:54 +02:00
|
|
|
expression_value = expression.compile(context , into)
|
2014-05-28 19:13:03 +02:00
|
|
|
# copied from function expression: TODO make function
|
|
|
|
|
|
|
|
return_reg = Vm::Integer.new(7)
|
|
|
|
if expression_value.is_a?(Vm::IntegerConstant) or expression_value.is_a?(Vm::StringConstant)
|
2014-05-31 15:43:03 +02:00
|
|
|
return_reg.load into , expression_value
|
2014-05-28 19:13:03 +02:00
|
|
|
else
|
|
|
|
return_reg.move( into, expression_value ) if expression_value.register != return_reg.register
|
|
|
|
end
|
|
|
|
#function.set_return return_reg
|
|
|
|
return return_reg
|
2014-05-27 15:33:24 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
end
|