2018-11-24 21:40:22 +01:00
|
|
|
require_relative "../helper"
|
|
|
|
|
|
|
|
module Risc
|
|
|
|
# Test the alloc sequence used by all integer operations
|
|
|
|
class InterpreterIntAlloc < MiniTest::Test
|
|
|
|
include Ticker
|
|
|
|
|
|
|
|
def setup
|
2019-09-13 13:07:12 +02:00
|
|
|
@preload = "Integer.plus"
|
2018-11-24 21:40:22 +01:00
|
|
|
@string_input = as_main("return 5 + 5")
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_chain
|
2019-09-13 13:07:12 +02:00
|
|
|
#show_main_ticks # get output of what is
|
2019-08-23 18:25:02 +02:00
|
|
|
check_main_chain [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5
|
|
|
|
RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant, #10
|
|
|
|
SlotToReg, RegToSlot, SlotToReg, FunctionCall, LoadConstant, #15
|
2020-03-15 14:15:07 +01:00
|
|
|
LoadConstant, SlotToReg, OperatorInstruction, IsNotZero, SlotToReg, #20
|
2019-08-23 18:25:02 +02:00
|
|
|
RegToSlot, SlotToReg, SlotToReg, SlotToReg, SlotToReg, #25
|
2019-09-13 13:07:12 +02:00
|
|
|
OperatorInstruction, RegToSlot, RegToSlot, SlotToReg, RegToSlot, #30
|
2020-03-15 14:15:07 +01:00
|
|
|
Branch, SlotToReg, SlotToReg, RegToSlot, SlotToReg, #35
|
|
|
|
SlotToReg, FunctionReturn, SlotToReg, RegToSlot, Branch, #40
|
|
|
|
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg, #45
|
|
|
|
FunctionReturn, Transfer, SlotToReg, SlotToReg, Transfer, #50
|
|
|
|
Syscall, NilClass,] #55
|
2018-11-24 21:40:22 +01:00
|
|
|
assert_equal 10 , get_return
|
|
|
|
end
|
2020-03-15 14:15:07 +01:00
|
|
|
|
2018-11-24 21:40:22 +01:00
|
|
|
def test_load_factory
|
2020-03-22 10:29:56 +01:00
|
|
|
assert_load( 15 , Parfait::Factory , :r0)
|
2020-03-15 14:15:07 +01:00
|
|
|
assert_equal :next_integer , @instruction.constant.attribute_name
|
2018-11-24 21:40:22 +01:00
|
|
|
end
|
|
|
|
def test_load_nil
|
2020-03-22 10:29:56 +01:00
|
|
|
assert_load( 16 , Parfait::NilClass , :r1)
|
2020-03-15 14:15:07 +01:00
|
|
|
end
|
|
|
|
def test_slot_receiver #load next_object from factory
|
2020-03-22 10:29:56 +01:00
|
|
|
assert_slot_to_reg( 17 , :r0 , 2 , :r2)
|
2018-11-24 21:40:22 +01:00
|
|
|
end
|
|
|
|
def test_nil_check
|
2020-03-22 10:29:56 +01:00
|
|
|
assert_operator 18 , :- , :r1 , :r2 , :r3
|
2020-03-15 14:15:07 +01:00
|
|
|
value = @interpreter.get_register(@instruction.result)
|
|
|
|
assert_equal ::Integer , value.class
|
|
|
|
assert 0 != value
|
2018-11-24 21:40:22 +01:00
|
|
|
end
|
|
|
|
def test_branch
|
2020-03-15 14:15:07 +01:00
|
|
|
assert_not_zero 19 , "cont_label"
|
2018-11-24 21:40:22 +01:00
|
|
|
end
|
|
|
|
def test_load_next_int
|
2020-03-22 10:29:56 +01:00
|
|
|
assert_slot_to_reg( 20 , :r2 , 1 , :r1)
|
2018-11-24 21:40:22 +01:00
|
|
|
end
|
|
|
|
def test_move_next_back_to_factory
|
2020-03-22 10:29:56 +01:00
|
|
|
assert_reg_to_slot( 21 , :r1 , :r0 , 2)
|
2018-11-24 21:40:22 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|