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
This commit is contained in:
Torsten 2020-03-28 18:39:49 +02:00
parent 8fa00d1413
commit 8dfcc0f5de
5 changed files with 35 additions and 4 deletions

View File

@ -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

View File

@ -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) )

View File

@ -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

View File

@ -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

View File

@ -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")