rubyx/test/risc/interpreter/calling/test_plus.rb

87 lines
3.0 KiB
Ruby
Raw Normal View History

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