2018-03-24 11:21:46 +01:00
|
|
|
require_relative "helper"
|
|
|
|
|
|
|
|
module Risc
|
2018-04-01 13:01:17 +02:00
|
|
|
class InterpreterDiv10 < MiniTest::Test
|
2018-03-24 11:21:46 +01:00
|
|
|
include Ticker
|
|
|
|
|
|
|
|
def setup
|
2018-04-01 13:50:13 +02:00
|
|
|
@string_input = as_main("return 25.div10")
|
2018-03-24 11:21:46 +01:00
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_chain
|
|
|
|
#show_ticks # get output of what is
|
2018-03-24 15:51:26 +01:00
|
|
|
check_chain [Branch, Label, LoadConstant, SlotToReg, LoadConstant,
|
|
|
|
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
|
|
|
|
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
|
2018-03-24 11:21:46 +01:00
|
|
|
SlotToReg, SlotToReg, SlotToReg, SlotToReg, RegToSlot,
|
2018-04-02 22:25:52 +02:00
|
|
|
SlotToReg, LoadConstant, RegToSlot, LoadConstant, RegToSlot,
|
|
|
|
FunctionCall, Label, LoadConstant, SlotToReg, SlotToReg,
|
2018-03-24 15:51:26 +01:00
|
|
|
RegToSlot, LoadConstant, SlotToReg, SlotToReg, SlotToReg,
|
2018-04-02 22:25:52 +02:00
|
|
|
SlotToReg, RegToSlot, LoadConstant, SlotToReg, SlotToReg,
|
|
|
|
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
|
|
|
|
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg,
|
|
|
|
LoadConstant, FunctionCall, Label, SlotToReg, SlotToReg,
|
|
|
|
SlotToReg, SlotToReg, SlotToReg, SlotToReg, LoadData,
|
|
|
|
OperatorInstruction, LoadData, OperatorInstruction, OperatorInstruction, LoadData,
|
|
|
|
Transfer, OperatorInstruction, OperatorInstruction, LoadData, Transfer,
|
2018-04-01 13:50:13 +02:00
|
|
|
OperatorInstruction, OperatorInstruction, LoadData, Transfer, OperatorInstruction,
|
2018-04-02 22:25:52 +02:00
|
|
|
OperatorInstruction, LoadData, OperatorInstruction, LoadData, Transfer,
|
|
|
|
OperatorInstruction, OperatorInstruction, Transfer, LoadData, OperatorInstruction,
|
|
|
|
LoadData, OperatorInstruction, OperatorInstruction, LoadConstant, SlotToReg,
|
|
|
|
SlotToReg, RegToSlot, RegToSlot, RegToSlot, SlotToReg,
|
|
|
|
SlotToReg, RegToSlot, SlotToReg, SlotToReg, FunctionReturn,
|
2018-04-01 13:50:13 +02:00
|
|
|
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
2018-04-02 22:25:52 +02:00
|
|
|
RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
|
|
|
|
SlotToReg, FunctionReturn, Transfer, Syscall, NilClass]
|
2018-04-01 13:01:17 +02:00
|
|
|
assert_equal Parfait::Integer , get_return.class
|
2018-04-01 13:50:13 +02:00
|
|
|
assert_equal 2 , get_return.value
|
2018-03-24 11:21:46 +01:00
|
|
|
end
|
|
|
|
|
2018-03-24 15:51:26 +01:00
|
|
|
def test_call_main
|
2018-04-02 22:25:52 +02:00
|
|
|
call_ins = ticks(26)
|
2018-03-24 11:21:46 +01:00
|
|
|
assert_equal FunctionCall , call_ins.class
|
|
|
|
assert :main , call_ins.method.name
|
|
|
|
end
|
2018-04-01 13:50:13 +02:00
|
|
|
def test_load_25
|
2018-04-02 22:25:52 +02:00
|
|
|
load_ins = ticks 44
|
2018-03-24 11:21:46 +01:00
|
|
|
assert_equal LoadConstant , load_ins.class
|
2018-04-01 13:50:13 +02:00
|
|
|
assert_equal 25 , @interpreter.get_register(load_ins.register).value
|
2018-03-24 11:21:46 +01:00
|
|
|
end
|
2018-03-24 15:51:26 +01:00
|
|
|
def test_return
|
2018-04-02 22:25:52 +02:00
|
|
|
ret = ticks(100)
|
2018-03-24 11:21:46 +01:00
|
|
|
assert_equal FunctionReturn , ret.class
|
|
|
|
link = @interpreter.get_register( ret.register )
|
|
|
|
assert_equal Label , link.class
|
|
|
|
end
|
2018-04-01 13:50:13 +02:00
|
|
|
def test_sys
|
2018-04-02 22:25:52 +02:00
|
|
|
sys = ticks(114)
|
2018-04-01 13:50:13 +02:00
|
|
|
assert_equal Syscall , sys.class
|
|
|
|
assert_equal :exit , sys.name
|
|
|
|
end
|
2018-03-24 11:21:46 +01:00
|
|
|
end
|
|
|
|
end
|