interpreter tests working again

This commit is contained in:
Torsten Ruger 2018-07-02 17:29:26 +03:00
parent 6af651a886
commit a1197fb70c
4 changed files with 27 additions and 28 deletions

View File

@ -33,7 +33,7 @@ module Risc
end
def start_program
initialize
initialize(@linker)
init = @linker.cpu_init
set_state(:running)
set_pc( Position.get(init).at )
@ -62,7 +62,7 @@ module Risc
end
def set_instruction( instruction )
raise "set to same instruction #{instruction}:#{instruction.class}" if @instruction == instruction
raise "set to same instruction #{instruction}:#{instruction.class} at #{clock}" if @instruction == instruction
log.debug "Setting Instruction #{instruction.class}"
old = @instruction
@instruction = instruction

View File

@ -24,12 +24,13 @@ module RubyX
mom.translate(platform)
end
def ruby_to_binary(platform = :arm)
def ruby_to_binary(platform)
Parfait.boot!
Risc.boot!
linker = ruby_to_risc(platform)
linker.position_all
linker.create_binary
linker
end
end
end

View File

@ -2,48 +2,49 @@ require_relative "helper"
module Risc
class TestInterpreterBasics < MiniTest::Test
def setup
Parfait.boot!
Risc.boot!
@linker = Mom::MomCompiler.new.translate(:interpreter)
end
def test_class
assert_equal Risc::Interpreter , Interpreter.new.class
assert_equal Risc::Interpreter , Interpreter.new(@linker).class
end
def test_starts_stopped
assert_equal :stopped , Interpreter.new.state
assert_equal :stopped , Interpreter.new(@linker).state
end
def test_has_regs
assert_equal 12 , Interpreter.new.registers.length
assert_equal 12 , Interpreter.new(@linker).registers.length
end
def test_has_r0
assert_equal :r0 , Interpreter.new.registers.keys.first
assert_equal :r0 , Interpreter.new(@linker).registers.keys.first
end
end
class TestInterpreterStarts < MiniTest::Test
include Ticker
def setup
Parfait.boot!
@machine = Risc.machine.boot
@machine.translate(:interpreter)
@machine.position_all
@interpreter = Interpreter.new
@string_input = as_main("return 5")
super
end
def test_starts
assert_equal 0 , @interpreter.start_machine
assert_equal 0 , @interpreter.start_program
end
def test_started
@interpreter.start_machine
@interpreter.start_program
assert_equal :running , @interpreter.state
end
def test_pos
@interpreter.start_machine
@interpreter.start_program
assert_equal 1 , @interpreter.clock
end
end
class TestInterpreterTicks < MiniTest::Test
include Ticker
def setup
Parfait.boot!
@machine = Risc.machine.boot
@machine.translate(:interpreter)
@machine.position_all
@interpreter = Interpreter.new
@interpreter.start_machine
@string_input = as_main("return 5")
super
@interpreter.start_program
end
def test_tick1
assert_equal 2 , @interpreter.tick
@ -54,7 +55,7 @@ module Risc
end
def test_pc1
@interpreter.tick
assert_equal 20728 , @interpreter.pc
assert_equal 21304 , @interpreter.pc
end
def test_tick2
@interpreter.tick
@ -68,7 +69,7 @@ module Risc
def test_pc2
@interpreter.tick
@interpreter.tick
assert_equal 20732 , @interpreter.pc
assert_equal 21308 , @interpreter.pc
end
def test_tick_14_jump
14.times {@interpreter.tick}

View File

@ -7,11 +7,8 @@ module Risc
include ScopeHelper
def setup
Parfait.boot!
Risc.boot!
RubyX::RubyXCompiler.new(@string_input).ruby_to_binary( :interpreter)
@interpreter = Interpreter.new
@interpreter.start_machine
@linker = RubyX::RubyXCompiler.new(@string_input).ruby_to_binary( :interpreter)
@interpreter = Interpreter.new(@linker)
end
alias :do_setup :setup