2017-04-14 09:52:23 +02:00
|
|
|
require_relative "helper"
|
|
|
|
|
|
|
|
module Vool
|
2019-09-12 21:27:10 +02:00
|
|
|
class TestReturnMom < MiniTest::Test
|
2019-08-07 14:08:45 +02:00
|
|
|
include VoolCompile
|
2017-04-14 09:52:23 +02:00
|
|
|
|
|
|
|
def setup
|
2019-09-12 12:10:31 +02:00
|
|
|
@compiler = compile_main( "return 5")
|
2019-08-07 14:08:45 +02:00
|
|
|
@ins = @compiler.mom_instructions.next
|
2017-04-14 09:52:23 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_class_compiles
|
2019-08-07 14:08:45 +02:00
|
|
|
assert_equal SlotLoad , @ins.class , @ins
|
2017-04-14 09:52:23 +02:00
|
|
|
end
|
|
|
|
def test_slot_is_set
|
2019-08-07 14:08:45 +02:00
|
|
|
assert @ins.left
|
2017-04-14 09:52:23 +02:00
|
|
|
end
|
2017-04-14 20:01:50 +02:00
|
|
|
def test_two_instructions_are_returned
|
2019-08-07 14:08:45 +02:00
|
|
|
assert_equal 5 , @ins.length
|
2017-04-14 20:01:50 +02:00
|
|
|
end
|
2017-04-14 09:52:23 +02:00
|
|
|
def test_slot_starts_at_message
|
2019-08-07 14:08:45 +02:00
|
|
|
assert_equal :message , @ins.left.known_object
|
2017-04-14 09:52:23 +02:00
|
|
|
end
|
2017-04-14 20:01:50 +02:00
|
|
|
def test_slot_gets_return
|
2019-08-07 14:08:45 +02:00
|
|
|
assert_equal :return_value , @ins.left.slots[0]
|
2017-04-14 09:52:23 +02:00
|
|
|
end
|
|
|
|
def test_slot_assigns_something
|
2019-08-07 14:08:45 +02:00
|
|
|
assert @ins.right
|
2017-04-14 09:52:23 +02:00
|
|
|
end
|
|
|
|
def test_slot_assigns_int
|
2019-08-07 14:08:45 +02:00
|
|
|
assert_equal Mom::IntegerConstant , @ins.right.known_object.class
|
|
|
|
end
|
|
|
|
def test_second_is_return
|
|
|
|
assert_equal ReturnJump, @ins.next(1).class
|
2018-03-16 14:56:27 +01:00
|
|
|
end
|
|
|
|
def test_array
|
2019-08-07 14:08:45 +02:00
|
|
|
check_array [SlotLoad, ReturnJump, Label, ReturnSequence, Label], @ins
|
2017-04-14 09:52:23 +02:00
|
|
|
end
|
|
|
|
end
|
2017-04-15 19:58:39 +02:00
|
|
|
class TestReturnSendMom < MiniTest::Test
|
2019-08-07 14:08:45 +02:00
|
|
|
include VoolCompile
|
2017-04-15 19:58:39 +02:00
|
|
|
|
|
|
|
def setup
|
2019-09-12 21:27:10 +02:00
|
|
|
@compiler = compile_main( "return 5.div4" , "Integer.div4" )
|
2019-08-07 14:08:45 +02:00
|
|
|
@ins = @compiler.mom_instructions.next
|
2017-04-15 19:58:39 +02:00
|
|
|
end
|
|
|
|
|
2019-08-13 10:14:36 +02:00
|
|
|
def test_return_is_last
|
2019-08-16 20:43:54 +02:00
|
|
|
assert_equal ReturnJump , @ins.next(4).class
|
2018-03-16 15:09:35 +01:00
|
|
|
end
|
2019-08-13 10:14:36 +02:00
|
|
|
def test_array
|
2019-08-16 20:43:54 +02:00
|
|
|
check_array [MessageSetup, ArgumentTransfer, SimpleCall, SlotLoad, ReturnJump ,
|
|
|
|
Label, ReturnSequence, Label] , @ins
|
2017-04-15 19:58:39 +02:00
|
|
|
end
|
|
|
|
end
|
2017-04-14 09:52:23 +02:00
|
|
|
end
|