2014-05-27 15:33:24 +02:00
|
|
|
module Ast
|
|
|
|
class ReturnExpression < Expression
|
2014-06-04 21:03:45 +02:00
|
|
|
# attr_reader :expression
|
2014-06-10 22:57:56 +02:00
|
|
|
def compile context
|
2014-06-10 12:29:01 +02:00
|
|
|
puts "compiling return expression #{expression}, now return in return_regsiter"
|
2014-06-10 22:57:56 +02:00
|
|
|
expression_value = expression.compile(context)
|
2014-05-28 19:13:03 +02:00
|
|
|
# copied from function expression: TODO make function
|
|
|
|
|
2014-06-10 12:29:01 +02:00
|
|
|
return_reg = Vm::Integer.new(Vm::RegisterMachine.instance.return_register)
|
2014-06-07 16:59:44 +02:00
|
|
|
if expression_value.is_a?(Vm::IntegerConstant) or expression_value.is_a?(Vm::ObjectConstant)
|
2014-05-31 15:43:03 +02:00
|
|
|
return_reg.load into , expression_value
|
2014-05-28 19:13:03 +02:00
|
|
|
else
|
2014-06-07 16:59:44 +02:00
|
|
|
return_reg.move( into, expression_value ) if expression_value.register_symbol != return_reg.register_symbol
|
2014-05-28 19:13:03 +02:00
|
|
|
end
|
|
|
|
#function.set_return return_reg
|
|
|
|
return return_reg
|
2014-05-27 15:33:24 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
end
|