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