diff --git a/lib/ast/return_expression.rb b/lib/ast/return_expression.rb index b664a91f..987f7e05 100644 --- a/lib/ast/return_expression.rb +++ b/lib/ast/return_expression.rb @@ -15,8 +15,17 @@ module Ast end def compile context , into expression_value = expression.compile(context , into) - puts "compiled return expression #{expression_value.inspect}" - return expression_value + puts "compiled return expression #{expression_value.inspect}, now return in 7" + # 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) + return_reg.load into , expression_value if expression_value.register != return_reg.register + else + return_reg.move( into, expression_value ) if expression_value.register != return_reg.register + end + #function.set_return return_reg + return return_reg end end diff --git a/test/fragments/test_recursive_fibo.rb b/test/fragments/test_recursive_fibo.rb index 006a1d49..0c3dda03 100644 --- a/test/fragments/test_recursive_fibo.rb +++ b/test/fragments/test_recursive_fibo.rb @@ -6,18 +6,20 @@ class TestRecursinveFibo < MiniTest::Test def test_recursive_fibo @string_input = <