2018-04-23 12:16:46 +02:00
|
|
|
require_relative "../helper"
|
2015-08-04 21:01:20 +02:00
|
|
|
|
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
|
2019-09-13 13:07:12 +02:00
|
|
|
@preload = "Integer.div4"
|
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
|
2019-08-23 14:31:22 +02:00
|
|
|
#show_main_ticks # get output of what is
|
2019-09-13 13:07:12 +02:00
|
|
|
check_main_chain [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5
|
2019-08-23 18:25:02 +02:00
|
|
|
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #10
|
|
|
|
FunctionCall, LoadConstant, SlotToReg, LoadConstant, OperatorInstruction, #15
|
|
|
|
IsNotZero, SlotToReg, RegToSlot, SlotToReg, SlotToReg, #20
|
|
|
|
LoadData, OperatorInstruction, RegToSlot, RegToSlot, SlotToReg, #25
|
2019-09-13 13:07:12 +02:00
|
|
|
RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot, #30
|
|
|
|
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, SlotToReg, #35
|
|
|
|
RegToSlot, Branch, SlotToReg, SlotToReg, RegToSlot, #40
|
|
|
|
SlotToReg, SlotToReg, SlotToReg, FunctionReturn, Transfer, #45
|
|
|
|
SlotToReg, SlotToReg, Syscall, NilClass,] #50
|
2018-06-19 17:55:47 +02:00
|
|
|
assert_equal 2 , get_return
|
2017-01-03 21:42:40 +01:00
|
|
|
end
|
2015-08-04 21:01:20 +02:00
|
|
|
|
2018-11-24 21:40:22 +01:00
|
|
|
def test_op
|
2019-08-23 18:25:02 +02:00
|
|
|
op = main_ticks(22)
|
2018-11-24 21:40:22 +01:00
|
|
|
assert_equal OperatorInstruction , op.class
|
|
|
|
assert_equal :>> , op.operator
|
|
|
|
assert_equal :r2 , op.left.symbol
|
|
|
|
assert_equal :r3 , op.right.symbol
|
|
|
|
assert_equal 2 , @interpreter.get_register(:r2)
|
|
|
|
assert_equal 2 , @interpreter.get_register(:r3)
|
2017-01-03 21:42:40 +01:00
|
|
|
end
|
2015-08-04 21:01:20 +02:00
|
|
|
end
|
|
|
|
end
|