2018-04-23 12:16:46 +02:00
|
|
|
require_relative "../helper"
|
2018-03-24 14:59:54 +01:00
|
|
|
|
|
|
|
module Risc
|
|
|
|
class InterpreterAssignLocal < MiniTest::Test
|
|
|
|
include Ticker
|
|
|
|
|
|
|
|
def setup
|
|
|
|
@string_input = as_main("a = 15 ; return a")
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2018-05-24 20:20:56 +02:00
|
|
|
def test_chain
|
2018-04-04 19:05:09 +02:00
|
|
|
#show_main_ticks # get output of what is
|
2020-03-13 19:18:34 +01:00
|
|
|
check_main_chain [LoadConstant, RegToSlot, SlotToReg, RegToSlot, Branch, #5
|
2019-08-23 14:31:22 +02:00
|
|
|
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg, #10
|
2020-03-15 09:39:09 +01:00
|
|
|
FunctionReturn, Transfer, SlotToReg, SlotToReg, Transfer,
|
|
|
|
Syscall, NilClass,] #20
|
|
|
|
assert_equal ::Integer , get_return.class
|
|
|
|
assert_equal 15 , get_return
|
2018-03-24 14:59:54 +01:00
|
|
|
end
|
2018-05-24 20:20:56 +02:00
|
|
|
def test_call_main
|
2018-04-06 22:37:41 +02:00
|
|
|
call_ins = ticks(main_at)
|
2018-03-24 14:59:54 +01:00
|
|
|
assert_equal FunctionCall , call_ins.class
|
|
|
|
assert :main , call_ins.method.name
|
|
|
|
end
|
|
|
|
def test_load_15
|
2020-03-22 09:42:50 +01:00
|
|
|
assert_load 1 , Parfait::Integer , :r1
|
2020-03-13 19:18:34 +01:00
|
|
|
assert_equal 15 , @interpreter.get_register(@interpreter.instruction.register).value
|
|
|
|
end
|
|
|
|
def test_branch
|
|
|
|
assert_branch 5 , "return_label"
|
2018-03-24 14:59:54 +01:00
|
|
|
end
|
2018-05-24 20:20:56 +02:00
|
|
|
def test_return
|
2020-03-13 19:18:34 +01:00
|
|
|
ret = main_ticks(11)
|
2018-04-05 11:22:14 +02:00
|
|
|
assert_equal FunctionReturn , ret.class
|
|
|
|
link = @interpreter.get_register( ret.register )
|
2020-03-13 19:18:34 +01:00
|
|
|
assert_equal Parfait::ReturnAddress , link.class
|
2018-04-05 11:22:14 +02:00
|
|
|
end
|
2018-05-24 20:20:56 +02:00
|
|
|
def test_transfer
|
2020-03-22 09:42:50 +01:00
|
|
|
assert_transfer 12 , :r0 , :r15
|
2018-03-24 14:59:54 +01:00
|
|
|
end
|
2018-05-24 20:20:56 +02:00
|
|
|
def test_sys
|
2020-03-15 09:39:09 +01:00
|
|
|
assert_syscall 16 , :exit
|
2018-03-24 14:59:54 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|