2018-04-23 13:16:46 +03:00
|
|
|
require_relative "../helper"
|
2015-11-08 14:30:28 +02:00
|
|
|
|
2017-01-19 09:02:29 +02:00
|
|
|
module Risc
|
2018-03-30 17:09:02 +03:00
|
|
|
class InterpreterPlusTest < MiniTest::Test
|
2017-01-03 22:42:40 +02:00
|
|
|
include Ticker
|
2015-11-08 14:30:28 +02:00
|
|
|
|
2017-01-03 22:42:40 +02:00
|
|
|
def setup
|
2018-04-01 14:01:17 +03:00
|
|
|
@string_input = as_main("return 5 + 5")
|
2017-01-03 22:42:40 +02:00
|
|
|
super
|
|
|
|
end
|
2015-11-08 14:30:28 +02:00
|
|
|
|
2018-08-06 14:07:17 +03:00
|
|
|
def test_chain
|
2019-08-22 23:10:29 +03:00
|
|
|
#show_main_ticks # get output of what is
|
2019-08-22 12:26:40 +03:00
|
|
|
check_main_chain [LoadConstant, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
|
2018-08-12 15:02:23 +03:00
|
|
|
RegToSlot, RegToSlot, RegToSlot, LoadConstant, SlotToReg, # 10
|
2019-08-22 23:10:29 +03:00
|
|
|
RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant,
|
|
|
|
SlotToReg, RegToSlot, SlotToReg, FunctionCall, LoadConstant, # 20
|
|
|
|
SlotToReg, LoadConstant, OperatorInstruction, IsNotZero, SlotToReg,
|
|
|
|
RegToSlot, SlotToReg, SlotToReg, SlotToReg, SlotToReg, # 30
|
|
|
|
Branch, OperatorInstruction, RegToSlot, RegToSlot, SlotToReg,
|
|
|
|
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, # 40
|
|
|
|
RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn,
|
|
|
|
SlotToReg, RegToSlot, Branch, SlotToReg, SlotToReg, # 50
|
|
|
|
RegToSlot, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
|
|
|
|
Branch, SlotToReg, SlotToReg, SlotToReg, FunctionReturn, # 60
|
|
|
|
Transfer, SlotToReg, SlotToReg, Syscall, NilClass, ]
|
2018-06-19 18:55:47 +03:00
|
|
|
assert_equal 10 , get_return
|
2017-01-03 22:42:40 +02:00
|
|
|
end
|
2018-11-24 22:40:22 +02:00
|
|
|
def base_ticks(num)
|
2019-08-22 12:26:40 +03:00
|
|
|
main_ticks(21 + num)
|
2018-11-24 22:40:22 +02:00
|
|
|
end
|
2018-03-31 19:37:24 +03:00
|
|
|
def test_load_5
|
2018-08-12 15:02:23 +03:00
|
|
|
lod = main_ticks( 12 )
|
2018-08-08 15:49:47 +03:00
|
|
|
assert_load( lod , Parfait::Integer , :r1)
|
2018-03-31 19:37:24 +03:00
|
|
|
assert_equal 5 , lod.constant.value
|
|
|
|
end
|
2018-11-24 22:40:22 +02:00
|
|
|
def test_load_receiver
|
2019-08-22 23:10:29 +03:00
|
|
|
sl = base_ticks( 6 )
|
2018-11-24 22:40:22 +02:00
|
|
|
assert_slot_to_reg( sl , :r0 , 2 , :r2)
|
2018-05-24 21:20:56 +03:00
|
|
|
end
|
2018-11-24 22:40:22 +02:00
|
|
|
def test_reduce_receiver
|
2019-08-22 23:10:29 +03:00
|
|
|
sl = base_ticks( 7 )
|
2018-11-24 22:40:22 +02:00
|
|
|
assert_slot_to_reg( sl , :r2 , 2 , :r2)
|
2018-03-30 18:05:38 +03:00
|
|
|
end
|
2018-03-31 19:37:24 +03:00
|
|
|
def test_slot_args #load args from message
|
2019-08-22 23:10:29 +03:00
|
|
|
sl = base_ticks( 8 )
|
|
|
|
assert_slot_to_reg( sl , :r0 , 9 , :r3)
|
2018-03-30 18:05:38 +03:00
|
|
|
end
|
2018-11-24 22:40:22 +02:00
|
|
|
def test_reduce_arg
|
2019-08-22 23:10:29 +03:00
|
|
|
sl = base_ticks( 9 )
|
2018-11-24 22:40:22 +02:00
|
|
|
assert_slot_to_reg( sl , :r3 , 2 , :r3)
|
|
|
|
assert_equal 5 , @interpreter.get_register(:r3)
|
2017-01-03 22:42:40 +02:00
|
|
|
end
|
2018-03-31 19:37:24 +03:00
|
|
|
def test_op
|
2019-08-22 23:10:29 +03:00
|
|
|
op = base_ticks(11)
|
2018-03-31 19:37:24 +03:00
|
|
|
assert_equal OperatorInstruction , op.class
|
2018-08-08 15:49:47 +03:00
|
|
|
assert_equal :+ , op.operator
|
2018-11-24 22:40:22 +02:00
|
|
|
assert_equal :r2 , op.left.symbol
|
|
|
|
assert_equal :r3 , op.right.symbol
|
|
|
|
assert_equal 10 , @interpreter.get_register(:r2)
|
|
|
|
assert_equal 5 , @interpreter.get_register(:r3)
|
2017-01-03 22:42:40 +02:00
|
|
|
end
|
2018-11-24 22:40:22 +02:00
|
|
|
def test_move_res_to_int
|
2019-08-22 23:10:29 +03:00
|
|
|
int = base_ticks( 12 )
|
2018-11-24 22:40:22 +02:00
|
|
|
assert_reg_to_slot( int , :r2 , :r1 , 2)
|
2018-04-01 12:00:59 +03:00
|
|
|
end
|
2018-11-24 22:40:22 +02:00
|
|
|
def test_move_int_to_reg
|
2019-08-22 23:10:29 +03:00
|
|
|
int = base_ticks( 13 )
|
2018-11-24 22:40:22 +02:00
|
|
|
assert_reg_to_slot( int , :r1 , :r0 , 5)
|
2018-04-01 12:00:59 +03:00
|
|
|
end
|
2018-11-24 22:40:22 +02:00
|
|
|
def test_move_fix_to_result
|
2019-08-22 23:10:29 +03:00
|
|
|
sl = base_ticks( 14 )
|
2018-11-24 22:40:22 +02:00
|
|
|
assert_slot_to_reg( sl , :r0 , 5 , :r1)
|
2018-04-01 12:00:59 +03:00
|
|
|
end
|
2018-11-24 22:40:22 +02:00
|
|
|
def test_start_return_sequence
|
2019-08-22 23:10:29 +03:00
|
|
|
sl = base_ticks( 15 )
|
2018-11-24 22:40:22 +02:00
|
|
|
assert_slot_to_reg( sl , :r0 , 6 , :r2)
|
2018-04-01 14:56:01 +03:00
|
|
|
end
|
2015-11-08 15:15:55 +02:00
|
|
|
end
|
2015-11-08 14:30:28 +02:00
|
|
|
end
|