From 8dfcc0f5de3bef3d030431cfc6ba88314be934f3 Mon Sep 17 00:00:00 2001 From: Torsten Date: Sat, 28 Mar 2020 18:39:49 +0200 Subject: [PATCH] add decent method to get the programs return to interpreter only had such methods in tests, but they really belong in code also adding fake values to true ,false and nil --- lib/parfait/integer.rb | 3 +++ lib/risc/interpreter.rb | 11 ++++++++++- test/mains/helper.rb | 2 +- test/parfait/test_integer.rb | 17 ++++++++++++++++- test/risc/test_interpreter.rb | 6 +++++- 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/lib/parfait/integer.rb b/lib/parfait/integer.rb index 8a15535b..25e8ad57 100644 --- a/lib/parfait/integer.rb +++ b/lib/parfait/integer.rb @@ -71,6 +71,7 @@ module Parfait #FIXME: this is "just" for compilation def initialize super + set_internal_word( Integer.integer_index , 0 ) end def self.type_length 1 # 0 type @@ -80,6 +81,7 @@ module Parfait #FIXME: this is "just" for compilation def initialize super + set_internal_word( Integer.integer_index , 1 ) end def self.type_length 1 # 0 type @@ -89,6 +91,7 @@ module Parfait #FIXME: this is "just" for compilation def initialize super + set_internal_word( Integer.integer_index , 0 ) end def self.type_length 1 # 0 type diff --git a/lib/risc/interpreter.rb b/lib/risc/interpreter.rb index 46ab0af5..32874ef6 100644 --- a/lib/risc/interpreter.rb +++ b/lib/risc/interpreter.rb @@ -266,7 +266,7 @@ module Risc set_instruction(nil) return false when :died - raise "Method #{@registers[:r1].to_string} not found for #{@registers[std_reg(:syscall_1)]}" + raise "Method #{@registers[:r1]} not found for #{@registers[std_reg(:syscall_1)]}" else raise "un-implemented syscall #{name}" end @@ -274,6 +274,15 @@ module Risc true end + def get_sys_return + val = get_register( std_reg(:syscall_1) ) # syscalls return into syscall_1 + end + + def run_all + tick while(@instruction) + clock + end + def handle_putstring # should test length, syscall_3 (syscall_1 is file_descriptor, ie stdout) str = get_register( std_reg(:syscall_2) ) diff --git a/test/mains/helper.rb b/test/mains/helper.rb index 2a254feb..5296ecf5 100644 --- a/test/mains/helper.rb +++ b/test/mains/helper.rb @@ -69,7 +69,7 @@ module Mains interpreter.tick while(interpreter.instruction) saved_in = interpreter.std_reg(:saved_message) assert_equal Parfait::Message , interpreter.get_register(saved_in).class - ret = interpreter.get_register(interpreter.std_reg(:syscall_1)) + ret = interpreter.get_sys_return puts "Interpret #{interpreter.stdout} #{ret}" if ENV["TEST_ARM"] == "DEBUG" return ret , interpreter.stdout end diff --git a/test/parfait/test_integer.rb b/test/parfait/test_integer.rb index 9b273a0d..fe708780 100644 --- a/test/parfait/test_integer.rb +++ b/test/parfait/test_integer.rb @@ -54,5 +54,20 @@ module Parfait assert_equal 33 , addr.value end end - + class TrueTest < MiniTest::Test + def test_true + assert TrueClass.new + end + def test_set + tru = TrueClass.new + assert_equal 20 , tru.set_internal_word( Integer.integer_index , 20 ) + assert_equal 20 , tru.get_internal_word( Integer.integer_index ) + end + def test_get_true + assert_equal 1 , TrueClass.new.get_internal_word( Integer.integer_index ) + end + def test_get_false + assert_equal 0 , FalseClass.new.get_internal_word( Integer.integer_index ) + end + end end diff --git a/test/risc/test_interpreter.rb b/test/risc/test_interpreter.rb index 646b7da4..96330fde 100644 --- a/test/risc/test_interpreter.rb +++ b/test/risc/test_interpreter.rb @@ -38,6 +38,10 @@ module Risc def test_pos assert_equal 1 , @interpreter.clock end + def test_return_value + @interpreter.run_all + assert_equal 5 , @interpreter.get_sys_return + end end class TestInterpreterTicks < MiniTest::Test include Ticker @@ -98,7 +102,7 @@ module Risc def test_tick_15 #more than a binary code worth 15.times {@interpreter.tick} end - class TestInterpreterDies #< MiniTest::Test + class TestInterpreterDies < MiniTest::Test include Ticker def setup @string_input = as_main("random.call")