start implementing return for constant

This commit is contained in:
Torsten Ruger 2017-04-14 10:52:23 +03:00
parent 73b7e2b22f
commit c885888f4a
3 changed files with 41 additions and 1 deletions

View File

@ -10,5 +10,14 @@ module Vool
@return_value.collect(arr)
super
end
# To return form a method in mom instructions we need to do three things:
# - store the given return value, this is a SlotMove / SlotConstant
# - restore the previous message
# - jump to the return address
def to_mom( method )
[Mom::SlotConstant.new([:message , :return_value] , @return_value)]
end
end
end

View File

@ -18,7 +18,7 @@ module Vool
def test_slot_starts_at_message
assert_equal :message , @stats.first.left[0]
end
def test_slot_gets_self
def test_slot_gets_frame
assert_equal :frame , @stats.first.left[1]
end
def test_slot_assigns_to_local

View File

@ -0,0 +1,31 @@
require_relative "helper"
module Vool
class TestReturnMom < MiniTest::Test
include MomCompile
def setup
Risc.machine.boot
@stats = compile_first_method( "return 5").first
end
def test_class_compiles
assert_equal Mom::SlotConstant , @stats.first.class , @stats
end
def test_slot_is_set
assert @stats.first.left
end
def test_slot_starts_at_message
assert_equal :message , @stats.first.left[0]
end
def test_slot_gets_self
assert_equal :return_value , @stats.first.left[1]
end
def test_slot_assigns_something
assert @stats.first.right
end
def test_slot_assigns_int
assert_equal IntegerStatement , @stats.first.right.class
end
end
end