2018-04-01 21:50:15 +02:00
|
|
|
require_relative "helper"
|
|
|
|
|
|
|
|
module Risc
|
|
|
|
class InterpreterEvents < MiniTest::Test
|
|
|
|
include Ticker
|
|
|
|
|
|
|
|
def setup
|
|
|
|
@string_input = as_main("return 5 + 7")
|
|
|
|
@state_events = {}
|
|
|
|
@instruction_events = []
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def state_changed( a , b)
|
|
|
|
@state_events[:state_changed] = [a , b]
|
|
|
|
end
|
|
|
|
|
|
|
|
def instruction_changed(was , is )
|
|
|
|
@instruction_events << was
|
|
|
|
end
|
2018-04-07 17:58:44 +02:00
|
|
|
def length
|
2018-06-19 17:55:47 +02:00
|
|
|
94
|
2018-04-07 17:58:44 +02:00
|
|
|
end
|
2018-05-17 19:13:33 +02:00
|
|
|
def test_state_change
|
2018-04-01 21:50:15 +02:00
|
|
|
@interpreter.register_event :state_changed , self
|
2018-04-07 17:58:44 +02:00
|
|
|
ticks length
|
2018-04-01 21:50:15 +02:00
|
|
|
assert @state_events[:state_changed]
|
|
|
|
assert_equal 2 , @state_events[:state_changed].length
|
|
|
|
assert_equal :running, @state_events[:state_changed][0]
|
|
|
|
@interpreter.unregister_event :state_changed , self
|
|
|
|
end
|
|
|
|
|
2018-05-17 19:13:33 +02:00
|
|
|
def test_instruction_events
|
2018-04-01 21:50:15 +02:00
|
|
|
@interpreter.register_event :instruction_changed , self
|
2018-04-07 17:58:44 +02:00
|
|
|
ticks length
|
|
|
|
assert_equal length , @instruction_events.length
|
2018-04-01 21:50:15 +02:00
|
|
|
@interpreter.unregister_event :instruction_changed , self
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_chain
|
|
|
|
#show_ticks # get output of what is
|
2018-05-24 18:20:06 +02:00
|
|
|
check_chain [Branch, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
|
|
|
|
LoadConstant, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
|
2018-05-25 19:40:39 +02:00
|
|
|
SlotToReg, SlotToReg, RegToSlot, SlotToReg, Branch,
|
|
|
|
SlotToReg, RegToSlot, SlotToReg, RegToSlot, SlotToReg,
|
|
|
|
RegToSlot, SlotToReg, RegToSlot, LoadConstant, RegToSlot,
|
|
|
|
FunctionCall, LoadConstant, LoadConstant, SlotToReg, RegToSlot,
|
|
|
|
RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
|
|
|
|
SlotToReg, RegToSlot, SlotToReg, RegToSlot, Branch,
|
2018-04-07 17:58:44 +02:00
|
|
|
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
|
2018-05-25 19:40:39 +02:00
|
|
|
LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
|
|
|
|
SlotToReg, RegToSlot, SlotToReg, Branch, FunctionCall,
|
|
|
|
SlotToReg, SlotToReg, SlotToReg, SlotToReg, SlotToReg,
|
|
|
|
OperatorInstruction, LoadConstant, SlotToReg, SlotToReg, RegToSlot,
|
|
|
|
RegToSlot, RegToSlot, SlotToReg, Branch, SlotToReg,
|
2018-05-30 11:54:40 +02:00
|
|
|
RegToSlot, SlotToReg, SlotToReg, SlotToReg, FunctionReturn,
|
2018-04-07 17:58:44 +02:00
|
|
|
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
2018-05-30 11:54:40 +02:00
|
|
|
RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
|
2018-06-19 17:55:47 +02:00
|
|
|
SlotToReg, SlotToReg, Branch, FunctionReturn, SlotToReg,
|
|
|
|
SlotToReg, Branch, Transfer, Syscall, NilClass]
|
|
|
|
assert_equal Fixnum , get_return.class
|
|
|
|
assert_equal 12 , get_return
|
2018-04-01 21:50:15 +02:00
|
|
|
end
|
2018-05-30 11:54:40 +02:00
|
|
|
def test_length
|
|
|
|
run_all
|
|
|
|
assert_equal length , @interpreter.clock
|
|
|
|
end
|
2018-04-01 21:50:15 +02:00
|
|
|
end
|
|
|
|
end
|