2016-12-16 23:15:27 +01:00
|
|
|
require_relative "../helper"
|
2015-11-18 11:00:30 +01:00
|
|
|
require "register/interpreter"
|
2015-09-27 21:39:10 +02:00
|
|
|
|
2017-01-03 21:42:40 +01:00
|
|
|
module Register
|
|
|
|
module Ticker
|
|
|
|
include AST::Sexp
|
2015-11-08 13:30:28 +01:00
|
|
|
|
2017-01-03 21:42:40 +01:00
|
|
|
def setup
|
|
|
|
Register.machine.boot
|
|
|
|
do_clean_compile
|
2017-01-14 18:28:44 +01:00
|
|
|
Vm.compile( @input )
|
2017-01-04 20:35:50 +01:00
|
|
|
Collector.collect_space
|
|
|
|
@interpreter = Interpreter.new
|
2017-01-03 21:42:40 +01:00
|
|
|
@interpreter.start Register.machine.init
|
|
|
|
end
|
2016-12-21 21:35:36 +01:00
|
|
|
|
2017-01-03 21:42:40 +01:00
|
|
|
# must be after boot, but before main compile, to define method
|
|
|
|
def do_clean_compile
|
2015-11-08 13:30:28 +01:00
|
|
|
end
|
|
|
|
|
2017-01-03 21:42:40 +01:00
|
|
|
def check_chain should
|
|
|
|
should.each_with_index do |name , index|
|
|
|
|
got = ticks(1)
|
2017-01-04 20:35:50 +01:00
|
|
|
assert_equal got.class ,name , "Wrong class for #{index+1}, expect #{name} , got #{got}"
|
2017-01-03 21:42:40 +01:00
|
|
|
end
|
|
|
|
end
|
2015-11-08 14:15:55 +01:00
|
|
|
|
2017-01-03 21:42:40 +01:00
|
|
|
def check_return val
|
|
|
|
assert_equal Parfait::Message , @interpreter.get_register(:r0).class
|
|
|
|
assert_equal val , @interpreter.get_register(:r0).return_value
|
2015-09-27 21:39:10 +02:00
|
|
|
end
|
2015-10-16 18:04:17 +02:00
|
|
|
|
2017-01-03 21:42:40 +01:00
|
|
|
def ticks num
|
|
|
|
last = nil
|
|
|
|
num.times do
|
|
|
|
last = @interpreter.instruction
|
|
|
|
@interpreter.tick
|
2015-10-16 18:04:17 +02:00
|
|
|
end
|
2017-01-03 21:42:40 +01:00
|
|
|
return last
|
2015-10-16 18:04:17 +02:00
|
|
|
end
|
2017-01-03 21:42:40 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
puts e.backtrace
|
|
|
|
end
|
2017-01-04 20:35:50 +01:00
|
|
|
str = classes.to_s.gsub("Register::","")
|
|
|
|
str.split(",").each_slice(5).each do |line|
|
|
|
|
puts " " + line.join(",") + ","
|
2017-01-03 21:42:40 +01:00
|
|
|
end
|
2017-01-04 20:35:50 +01:00
|
|
|
puts "length = #{classes.length}"
|
2017-01-03 21:42:40 +01:00
|
|
|
exit(1)
|
2015-10-16 18:04:17 +02:00
|
|
|
end
|
|
|
|
end
|
2015-09-27 21:39:10 +02:00
|
|
|
end
|