2016-12-11 11:08:47 +01:00
|
|
|
require_relative "helper"
|
|
|
|
|
2017-01-19 08:02:29 +01:00
|
|
|
module Risc
|
2017-01-03 21:42:40 +01:00
|
|
|
class AddChange < MiniTest::Test
|
|
|
|
include Ticker
|
|
|
|
|
|
|
|
def setup
|
|
|
|
@input = s(:statements, s(:return, s(:operator_value, :+, s(:int, 5), s(:int, 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-03-11 12:32:42 +01:00
|
|
|
def pest_state_change
|
2017-01-03 21:42:40 +01:00
|
|
|
@interpreter.register_event :state_changed , self
|
|
|
|
ticks 30
|
|
|
|
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-03-11 12:32:42 +01:00
|
|
|
def pest_instruction_events
|
2017-01-03 21:42:40 +01:00
|
|
|
@interpreter.register_event :instruction_changed , self
|
|
|
|
ticks 30
|
2017-01-04 20:36:46 +01:00
|
|
|
assert_equal 20 , @instruction_events.length
|
2017-01-03 21:42:40 +01:00
|
|
|
@interpreter.unregister_event :instruction_changed , self
|
|
|
|
end
|
|
|
|
|
2018-03-11 12:32:42 +01:00
|
|
|
def pest_chain
|
2017-01-03 21:42:40 +01:00
|
|
|
#show_ticks # get output of what is
|
2017-01-04 20:36:46 +01:00
|
|
|
check_chain [Branch, Label, LoadConstant, SlotToReg, RegToSlot,
|
|
|
|
LoadConstant, RegToSlot, FunctionCall, Label, LoadConstant,
|
|
|
|
LoadConstant, OperatorInstruction, RegToSlot, LoadConstant, SlotToReg,
|
2018-03-21 11:18:04 +01:00
|
|
|
RegToSlot, Label, FunctionReturn, Transfer, Syscall,
|
2017-01-04 20:36:46 +01:00
|
|
|
NilClass]
|
2017-01-03 21:42:40 +01:00
|
|
|
end
|
2016-12-11 11:08:47 +01:00
|
|
|
|
|
|
|
end
|
|
|
|
end
|