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 #FIXME: this is "just" for compilation
def initialize def initialize
super super
set_internal_word( Integer.integer_index , 0 )
end end
def self.type_length def self.type_length
1 # 0 type 1 # 0 type
@ -80,6 +81,7 @@ module Parfait
#FIXME: this is "just" for compilation #FIXME: this is "just" for compilation
def initialize def initialize
super super
set_internal_word( Integer.integer_index , 1 )
end end
def self.type_length def self.type_length
1 # 0 type 1 # 0 type
@ -89,6 +91,7 @@ module Parfait
#FIXME: this is "just" for compilation #FIXME: this is "just" for compilation
def initialize def initialize
super super
set_internal_word( Integer.integer_index , 0 )
end end
def self.type_length def self.type_length
1 # 0 type 1 # 0 type

View File

@ -266,7 +266,7 @@ module Risc
set_instruction(nil) set_instruction(nil)
return false return false
when :died 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 else
raise "un-implemented syscall #{name}" raise "un-implemented syscall #{name}"
end end
@ -274,6 +274,15 @@ module Risc
true true
end 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 def handle_putstring
# should test length, syscall_3 (syscall_1 is file_descriptor, ie stdout) # should test length, syscall_3 (syscall_1 is file_descriptor, ie stdout)
str = get_register( std_reg(:syscall_2) ) str = get_register( std_reg(:syscall_2) )

View File

@ -69,7 +69,7 @@ module Mains
interpreter.tick while(interpreter.instruction) interpreter.tick while(interpreter.instruction)
saved_in = interpreter.std_reg(:saved_message) saved_in = interpreter.std_reg(:saved_message)
assert_equal Parfait::Message , interpreter.get_register(saved_in).class 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" puts "Interpret #{interpreter.stdout} #{ret}" if ENV["TEST_ARM"] == "DEBUG"
return ret , interpreter.stdout return ret , interpreter.stdout
end end

View File

@ -54,5 +54,20 @@ module Parfait
assert_equal 33 , addr.value assert_equal 33 , addr.value
end end
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 end

View File

@ -38,6 +38,10 @@ module Risc
def test_pos def test_pos
assert_equal 1 , @interpreter.clock assert_equal 1 , @interpreter.clock
end end
def test_return_value
@interpreter.run_all
assert_equal 5 , @interpreter.get_sys_return
end
end end
class TestInterpreterTicks < MiniTest::Test class TestInterpreterTicks < MiniTest::Test
include Ticker include Ticker
@ -98,7 +102,7 @@ module Risc
def test_tick_15 #more than a binary code worth def test_tick_15 #more than a binary code worth
15.times {@interpreter.tick} 15.times {@interpreter.tick}
end end
class TestInterpreterDies #< MiniTest::Test class TestInterpreterDies < MiniTest::Test
include Ticker include Ticker
def setup def setup
@string_input = as_main("random.call") @string_input = as_main("random.call")