From 4bae5c418bee83e5933d73a48ab08ac648b34c9a Mon Sep 17 00:00:00 2001 From: Torsten Date: Wed, 25 Mar 2020 18:58:10 +0200 Subject: [PATCH] fix register use in putstring was off by one, the syscall is write and the first arg is file_descriptor ie 1 == stdout --- lib/risc/interpreter.rb | 3 ++- lib/risc/platform.rb | 2 ++ lib/slot_machine/macro/putstring.rb | 4 ++-- test/risc/interpreter/calling/test_puts.rb | 6 +++--- test/risc/test_builder1.rb | 5 +++++ test/slot_machine/macro/test_putstring.rb | 4 ++-- 6 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/risc/interpreter.rb b/lib/risc/interpreter.rb index 08514477..46ab0af5 100644 --- a/lib/risc/interpreter.rb +++ b/lib/risc/interpreter.rb @@ -275,7 +275,8 @@ module Risc end def handle_putstring - str = get_register( :r0 ) # should test length, ie r2 + # should test length, syscall_3 (syscall_1 is file_descriptor, ie stdout) + str = get_register( std_reg(:syscall_2) ) case str when Symbol @stdout << str.to_s diff --git a/lib/risc/platform.rb b/lib/risc/platform.rb index 0e18180f..bc6f9e0e 100644 --- a/lib/risc/platform.rb +++ b/lib/risc/platform.rb @@ -40,6 +40,8 @@ module Risc :r0 when :syscall_2 :r1 + when :syscall_3 + :r2 when :saved_message :r14 else diff --git a/lib/slot_machine/macro/putstring.rb b/lib/slot_machine/macro/putstring.rb index 9371d620..b34605e1 100644 --- a/lib/slot_machine/macro/putstring.rb +++ b/lib/slot_machine/macro/putstring.rb @@ -3,8 +3,8 @@ module SlotMachine def to_risc(compiler) builder = compiler.builder(compiler.source) integer = builder.prepare_int_return # makes integer_tmp variable as return - word = Risc.syscall_reg(1).set_compiler(compiler) - length = Risc.syscall_reg(2).set_compiler(compiler) + word = Risc.syscall_reg(2).set_compiler(compiler) + length = Risc.syscall_reg(3).set_compiler(compiler) builder.build do string = message[:receiver].to_reg.known_type(:Word) integer << string[:char_length] diff --git a/test/risc/interpreter/calling/test_puts.rb b/test/risc/interpreter/calling/test_puts.rb index 9072e826..9e38d219 100644 --- a/test/risc/interpreter/calling/test_puts.rb +++ b/test/risc/interpreter/calling/test_puts.rb @@ -35,9 +35,9 @@ module Risc def test_pre_sys done = main_ticks(24) - assert_equal Parfait::Word , @interpreter.get_register(:r0).class - assert_equal "Hello again" , @interpreter.get_register(:r0).to_string - assert_equal 11 , @interpreter.get_register(:r1) + assert_equal Parfait::Word , @interpreter.get_register(@interpreter.std_reg(:syscall_2)).class + assert_equal "Hello again" , @interpreter.get_register(@interpreter.std_reg(:syscall_2)).to_string + assert_equal 11 , @interpreter.get_register(@interpreter.std_reg(:syscall_3)) end def test_sys diff --git a/test/risc/test_builder1.rb b/test/risc/test_builder1.rb index 77ba406e..5bb5e907 100644 --- a/test/risc/test_builder1.rb +++ b/test/risc/test_builder1.rb @@ -26,5 +26,10 @@ module Risc int = @builder.allocate_int assert_allocate end + def test_compiler + int = @builder.allocate_int + assert int.compiler + assert int.symbol.to_s.start_with?("id_fac") + end end end diff --git a/test/slot_machine/macro/test_putstring.rb b/test/slot_machine/macro/test_putstring.rb index ec447f67..218e84fd 100644 --- a/test/slot_machine/macro/test_putstring.rb +++ b/test/slot_machine/macro/test_putstring.rb @@ -24,8 +24,8 @@ module SlotMachine assert_reg_to_slot s + 1 , "id_factory_.next_object" , :message , 5 assert_slot_to_reg s + 2 ,:message , 2 , "message.receiver" assert_slot_to_reg s + 3 ,"message.receiver" , 1 , "id_factory_.next_object" - assert_transfer s + 4 , :"message.receiver" , :syscall_1 - assert_transfer s + 5 , "id_factory_.next_object" , :syscall_2 + assert_transfer s + 4 , :"message.receiver" , :syscall_2 + assert_transfer s + 5 , "id_factory_.next_object" , :syscall_3 assert_transfer s + 6 , :message , :saved_message assert_syscall s + 7 , :putstring assert_transfer s + 8 , :syscall_1 , :restore_integer_return