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 end
def start_program def start_program
initialize initialize(@linker)
init = @linker.cpu_init init = @linker.cpu_init
set_state(:running) set_state(:running)
set_pc( Position.get(init).at ) set_pc( Position.get(init).at )
@ -62,7 +62,7 @@ module Risc
end end
def set_instruction( instruction ) 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}" log.debug "Setting Instruction #{instruction.class}"
old = @instruction old = @instruction
@instruction = instruction @instruction = instruction

View File

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

View File

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

View File

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