2015-11-18 11:07:37 +01:00
|
|
|
require_relative "../../helper"
|
2015-11-18 11:00:30 +01:00
|
|
|
require "register/interpreter"
|
2015-09-27 21:39:10 +02:00
|
|
|
|
|
|
|
module Ticker
|
2015-11-08 13:30:28 +01:00
|
|
|
|
|
|
|
def setup
|
|
|
|
machine = Register.machine.boot
|
|
|
|
syntax = Parser::Salama.new.parse_with_debug(@string_input)
|
|
|
|
parts = Parser::Transform.new.apply(syntax)
|
|
|
|
#puts parts.inspect
|
|
|
|
Soml.compile( parts )
|
|
|
|
machine.collect
|
2015-11-18 11:00:30 +01:00
|
|
|
@interpreter = Register::Interpreter.new
|
2015-11-08 13:30:28 +01:00
|
|
|
@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
|
|
|
|
|
2015-11-08 14:15:55 +01:00
|
|
|
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
|
2015-10-16 18:04:17 +02:00
|
|
|
|
|
|
|
def show_ticks
|
|
|
|
classes = []
|
|
|
|
tick = 1
|
|
|
|
begin
|
2015-10-19 13:46:12 +02:00
|
|
|
while true and (classes.length < 200)
|
2015-10-16 18:04:17 +02:00
|
|
|
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::","") + '",' }
|
2015-10-18 16:20:19 +02:00
|
|
|
classes << "length = #{classes.length}"
|
2015-10-16 18:04:17 +02:00
|
|
|
classes.each_slice(5).each do |line|
|
|
|
|
puts " " + line.join
|
|
|
|
end
|
|
|
|
exit(1)
|
|
|
|
end
|
2015-09-27 21:39:10 +02:00
|
|
|
end
|