rubyx/test/mom/send/test_send_simple_args.rb

99 lines
3.6 KiB
Ruby
Raw Normal View History

2018-04-05 11:19:29 +02:00
require_relative "../helper"
2018-03-30 17:05:38 +02:00
module Risc
class TestCallSimpleArgs < MiniTest::Test
include Statements
def setup
super
@input = "5.get_internal_word(1)"
2018-04-06 22:37:41 +02:00
@expect = [LoadConstant, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
RegToSlot, SlotToReg, RegToSlot, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
SlotToReg, LoadConstant, FunctionCall, Label]
2018-03-30 17:05:38 +02:00
end
def test_send_instructions
assert_nil msg = check_nil , msg
end
2018-03-30 17:13:17 +02:00
def test_load_5
2018-03-30 17:05:38 +02:00
produced = produce_body
2018-04-06 22:37:41 +02:00
assert_equal 5 , produced.next(15).constant.value
end
def base
18
2018-03-30 17:05:38 +02:00
end
def test_load_arg_const
produced = produce_body
2018-04-06 22:37:41 +02:00
assert_equal LoadConstant , produced.next(base).class
assert_equal Parfait::Integer , produced.next(base).constant.class
assert_equal 1 , produced.next(18).constant.value
end
def test_load_next_m
produced = produce_body
2018-04-06 22:37:41 +02:00
assert_equal SlotToReg , produced.next(base+1).class
assert_equal :r2 , produced.next(base+1).register.symbol
assert_equal :r0 , produced.next(base+1).array.symbol
2018-05-14 14:17:04 +02:00
assert_equal 1 , produced.next(base+1).index
end
def test_load_args
produced = produce_body
2018-04-06 22:37:41 +02:00
assert_equal SlotToReg , produced.next(base+2).class
assert_equal :r3 , produced.next(base+2).register.symbol
assert_equal :r2 , produced.next(base+2).array.symbol
2018-05-14 14:17:04 +02:00
assert_equal 8 , produced.next(base+2).index
end
def test_store_arg_at
produced = produce_body
2018-04-06 22:37:41 +02:00
assert_equal RegToSlot , produced.next(base+3).class
assert_equal :r1 , produced.next(base+3).register.symbol
assert_equal :r3 , produced.next(base+3).array.symbol
assert_equal 2 , produced.next(base+3).index , "first arg must have index 1"
end
2018-03-30 17:13:17 +02:00
def test_load_label
2018-03-30 17:05:38 +02:00
produced = produce_body
2018-04-06 22:37:41 +02:00
assert_equal LoadConstant , produced.next(base+4).class
assert_equal Label , produced.next(base+4).constant.class
2018-03-30 17:05:38 +02:00
end
def test_load_some
produced = produce_body
2018-04-06 22:37:41 +02:00
assert_equal SlotToReg , produced.next(base+5).class
assert_equal :r0 , produced.next(base+5).array.symbol
assert_equal :r3 , produced.next(base+5).register.symbol
2018-05-14 14:17:04 +02:00
assert_equal 1 , produced.next(base+5).index
end
def test_store_
produced = produce_body
2018-04-06 22:37:41 +02:00
assert_equal RegToSlot , produced.next(base+6).class
assert_equal :r3 , produced.next(base+6).array.symbol
assert_equal :r2 , produced.next(base+6).register.symbol
2018-05-14 14:17:04 +02:00
assert_equal 4 , produced.next(base+6).index
end
def test_swap_messages
produced = produce_body
2018-04-06 22:37:41 +02:00
assert_equal SlotToReg , produced.next(base+7).class
assert_equal :r0 , produced.next(base+7).array.symbol
assert_equal :r0 , produced.next(base+7).register.symbol
2018-05-14 14:17:04 +02:00
assert_equal 1 , produced.next(base+7).index
end
2018-03-30 17:13:17 +02:00
def test_function_call
2018-03-30 17:05:38 +02:00
produced = produce_body
2018-04-06 22:37:41 +02:00
assert_equal FunctionCall , produced.next(base+9).class
assert_equal :get_internal_word , produced.next(base+9).method.name
2018-03-30 17:05:38 +02:00
end
2018-03-30 17:13:17 +02:00
def test_call_reg_setup
2018-03-30 17:05:38 +02:00
produced = produce_body
2018-04-06 22:37:41 +02:00
assert_equal produced.next(base+8).register , produced.next(base+9).register
2018-03-30 17:05:38 +02:00
end
2018-03-30 17:13:17 +02:00
def test_check_continue
2018-03-30 17:05:38 +02:00
produced = produce_body
2018-04-06 22:37:41 +02:00
assert produced.next(base+10).name.start_with?("continue_")
2018-03-30 17:05:38 +02:00
end
#TODO check the message setup, type and frame moves
end
end