rubyx/test/register/interpreter/helper.rb

58 lines
1.3 KiB
Ruby
Raw Normal View History

require_relative "../../helper"
require "register/interpreter"
2015-09-27 21:39:10 +02:00
module Ticker
2016-12-08 18:39:16 +01:00
include AST::Sexp
def setup
machine = Register.machine.boot
2016-12-08 18:39:16 +01:00
Typed.compile( @input )
machine.collect
@interpreter = Register::Interpreter.new
@interpreter.start Register.machine.init
end
def check_chain should
should.each_with_index do |name , index|
got = ticks(1)
assert got.class.name.index(name) , "Wrong class for #{index+1}, expect #{name} , got #{got}"
end
end
def check_return val
assert_equal Parfait::Message , @interpreter.get_register(:r0).class
assert_equal val , @interpreter.get_register(:r0).return_value
end
2015-09-27 21:39:10 +02:00
def ticks num
last = nil
num.times do
last = @interpreter.instruction
@interpreter.tick
end
return last
end
def show_ticks
classes = []
tick = 1
begin
while true and (classes.length < 200)
cl = ticks(1).class
tick += 1
classes << cl
break if cl == NilClass
end
rescue => e
puts "Error at tick #{tick}"
puts e
end
classes = classes.collect {|c| '"' + c.name.sub("Register::","") + '",' }
classes << "length = #{classes.length}"
classes.each_slice(5).each do |line|
puts " " + line.join
end
exit(1)
end
2015-09-27 21:39:10 +02:00
end