diff --git a/lib/risc/interpreter.rb b/lib/risc/interpreter.rb index 2e67dec1..33355899 100644 --- a/lib/risc/interpreter.rb +++ b/lib/risc/interpreter.rb @@ -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 diff --git a/lib/rubyx/rubyx_compiler.rb b/lib/rubyx/rubyx_compiler.rb index aebbcc24..45b9aead 100644 --- a/lib/rubyx/rubyx_compiler.rb +++ b/lib/rubyx/rubyx_compiler.rb @@ -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 diff --git a/test/risc/test_interpreter.rb b/test/risc/test_interpreter.rb index 338c0206..75c6a68b 100644 --- a/test/risc/test_interpreter.rb +++ b/test/risc/test_interpreter.rb @@ -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} diff --git a/test/support/risc_interpreter.rb b/test/support/risc_interpreter.rb index 2143980b..96ba413e 100644 --- a/test/support/risc_interpreter.rb +++ b/test/support/risc_interpreter.rb @@ -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