2018-04-23 13:16:46 +03:00
|
|
|
require_relative "../helper"
|
2015-08-04 22:01:20 +03:00
|
|
|
|
2017-01-19 09:02:29 +02:00
|
|
|
module Risc
|
2018-03-31 12:38:30 +03:00
|
|
|
class InterpreterMod < MiniTest::Test
|
2017-01-03 22:42:40 +02:00
|
|
|
include Ticker
|
2015-10-06 00:27:13 +03:00
|
|
|
|
2017-01-03 22:42:40 +02:00
|
|
|
def setup
|
2018-04-19 10:00:55 +03:00
|
|
|
@string_input = as_main "return 9.div4"
|
2017-01-03 22:42:40 +02:00
|
|
|
super
|
|
|
|
end
|
2015-10-16 17:13:08 +03:00
|
|
|
|
2018-03-22 18:54:40 +02:00
|
|
|
def test_chain
|
2018-04-04 20:05:09 +03:00
|
|
|
#show_main_ticks # get output of what is
|
2018-05-24 21:20:56 +03:00
|
|
|
check_main_chain [LoadConstant, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
|
2018-04-07 18:58:44 +03:00
|
|
|
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
2018-05-25 20:40:39 +03:00
|
|
|
RegToSlot, SlotToReg, RegToSlot, Branch, SlotToReg,
|
|
|
|
RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant,
|
|
|
|
SlotToReg, RegToSlot, SlotToReg, FunctionCall, SlotToReg,
|
|
|
|
SlotToReg, LoadData, OperatorInstruction, LoadConstant, SlotToReg,
|
|
|
|
SlotToReg, RegToSlot, RegToSlot, RegToSlot, SlotToReg,
|
|
|
|
SlotToReg, RegToSlot, Branch, SlotToReg, SlotToReg,
|
2018-05-30 12:54:40 +03:00
|
|
|
SlotToReg, FunctionReturn, SlotToReg, SlotToReg, RegToSlot,
|
|
|
|
Branch, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
|
|
|
|
SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg,
|
2018-06-19 19:52:06 +03:00
|
|
|
FunctionReturn, Transfer, SlotToReg, Branch, SlotToReg,
|
2018-06-19 18:55:47 +03:00
|
|
|
Syscall, NilClass]
|
|
|
|
assert_equal 2 , get_return
|
2017-01-03 22:42:40 +02:00
|
|
|
end
|
2015-08-04 22:01:20 +03:00
|
|
|
|
2018-04-01 15:13:12 +03:00
|
|
|
def test_load
|
2018-05-25 20:40:39 +03:00
|
|
|
lod = main_ticks(17)
|
2018-04-01 15:13:12 +03:00
|
|
|
assert_equal LoadConstant , lod.class
|
|
|
|
assert_equal 9 , lod.constant.value
|
2017-01-03 22:42:40 +02:00
|
|
|
end
|
2018-04-01 15:13:12 +03:00
|
|
|
def test_fix # reduce self to fix
|
2018-05-25 20:40:39 +03:00
|
|
|
sl = main_ticks(26)
|
2018-04-01 15:13:12 +03:00
|
|
|
assert_equal SlotToReg , sl.class
|
|
|
|
assert_equal :r1 , sl.array.symbol
|
2018-05-28 15:09:59 +03:00
|
|
|
assert_equal 2 , sl.index
|
2018-04-01 15:13:12 +03:00
|
|
|
assert_equal :r1 , sl.register.symbol
|
|
|
|
assert_equal 9 , @interpreter.get_register(:r1)
|
2017-01-03 22:42:40 +02:00
|
|
|
end
|
2017-01-04 21:36:46 +02:00
|
|
|
|
2018-04-01 15:13:12 +03:00
|
|
|
def test_sys
|
2018-06-19 18:55:47 +03:00
|
|
|
sys = main_ticks(61)
|
2018-04-01 15:13:12 +03:00
|
|
|
assert_equal Syscall , sys.class
|
|
|
|
assert_equal :exit , sys.name
|
2017-01-03 22:42:40 +02:00
|
|
|
end
|
2018-04-01 15:13:12 +03:00
|
|
|
|
2015-08-04 22:01:20 +03:00
|
|
|
end
|
|
|
|
end
|