rubyx/test/compiler/fragments/helper.rb

37 lines
888 B
Ruby
Raw Normal View History

require_relative '../../helper'
require "interpreter/interpreter"
# Fragments are small programs that we run through the interpreter and really only check
# - the no. of instructions processed
# - the stdout output
2014-05-21 20:37:04 +02:00
module Fragments
def setup
@stdout = ""
end
def check
2015-10-22 17:16:29 +02:00
machine = Register.machine.boot
2015-10-09 20:53:22 +02:00
machine.parse_and_compile @string_input
machine.collect
@interpreter = Interpreter::Interpreter.new
@interpreter.start machine.init
count = 0
begin
count += 1
#puts interpreter.instruction
@interpreter.tick
end while( ! @interpreter.instruction.nil?)
assert_equal @length , count
assert_equal @stdout , @interpreter.stdout
end
2015-11-05 16:00:41 +01:00
def check_return val
check
assert_equal Parfait::Message , @interpreter.get_register(:r0).class
assert_equal val , @interpreter.get_register(:r0).return_value
2015-11-05 16:00:41 +01:00
end
end