From 17a1121408455034609ce7c0985ee078c5a95563 Mon Sep 17 00:00:00 2001 From: Torsten Date: Wed, 11 Mar 2020 22:31:16 +0200 Subject: [PATCH] fix putstring registers --- lib/slot_machine/macro/macro.rb | 6 ++--- lib/slot_machine/macro/putstring.rb | 6 ++--- test/slot_machine/macro/test_putstring.rb | 31 ++++++++++++----------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/lib/slot_machine/macro/macro.rb b/lib/slot_machine/macro/macro.rb index f9d86ceb..c5088d39 100644 --- a/lib/slot_machine/macro/macro.rb +++ b/lib/slot_machine/macro/macro.rb @@ -43,11 +43,11 @@ module SlotMachine # This instance is filled with os return value def self.restore_message(builder) r8 = Risc::RegisterValue.new( :saved_message , :Message).set_compiler(builder.compiler) + tmp = Risc::RegisterValue.new( :integer_tmp , :Integer).set_compiler(builder.compiler) builder.build do - integer_reg! << message + tmp << message message << r8 - integer_2! << message[:return_value] - integer_2[Parfait::Integer.integer_index] << integer_reg + message[:return_value][Parfait::Integer.integer_index] << tmp end end end diff --git a/lib/slot_machine/macro/putstring.rb b/lib/slot_machine/macro/putstring.rb index 8be01a91..d746949b 100644 --- a/lib/slot_machine/macro/putstring.rb +++ b/lib/slot_machine/macro/putstring.rb @@ -2,10 +2,10 @@ module SlotMachine class Putstring < Macro def to_risc(compiler) builder = compiler.builder(compiler.source) - builder.prepare_int_return # makes integer_tmp variable as return + integer = builder.prepare_int_return # makes integer_tmp variable as return builder.build do - word! << message[:receiver] - integer! << word[Parfait::Word.get_length_index] + word = message[:receiver].to_reg.known_type(:Word) + integer << word[:char_length] end SlotMachine::Macro.emit_syscall( builder , :putstring ) compiler diff --git a/test/slot_machine/macro/test_putstring.rb b/test/slot_machine/macro/test_putstring.rb index bee638ee..1fb66cd1 100644 --- a/test/slot_machine/macro/test_putstring.rb +++ b/test/slot_machine/macro/test_putstring.rb @@ -14,28 +14,29 @@ module SlotMachine assert_equal Risc::MethodCompiler , @method.to_risc.class end def test_risc_length - assert_equal 44 , @method.to_risc.risc_instructions.length + assert_equal 42 , @method.to_risc.risc_instructions.length end def test_allocate assert_allocate end def test_all - assert_reg_to_slot risc(23) , :r1 , :r0 , 5 - assert_slot_to_reg risc(24),:r0 , 2 , :r1 - assert_slot_to_reg risc(25),:r1 , 1 , :r2 - assert_transfer risc(26) , :r0 , :r8 - assert_equal Risc::Syscall, risc(27).class - assert_transfer risc(28) , :r0 , :r3 - assert_transfer risc(29) , :r8 , :r0 - assert_slot_to_reg risc(30),:r0 , 5 , :r4 - assert_reg_to_slot risc(31) , :r3 , :r4 , 2 - assert_slot_to_reg risc(32),:r0 , 5 , :r2 - assert_reg_to_slot risc(33) , :r2 , :r0 , 5 - assert_branch risc(34) , "return_label" - assert_label risc(35) , "return_label" + s = Risc.allocate_length + 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 , :saved_message + assert_syscall s + 5 , :putstring + assert_transfer s + 6 , :message , :integer_tmp + assert_transfer s + 7 , :saved_message , :message + assert_slot_to_reg s + 8 ,:message , 5 , "message.return_value" + assert_reg_to_slot s + 9 , :integer_tmp , "message.return_value" , 2 + assert_slot_to_reg s + 10 ,:message , 5 , "message.return_value" + assert_reg_to_slot s + 11 , "message.return_value" , :message , 5 + assert_branch s + 12 , "return_label" + assert_label s + 13 , "return_label" end def test_return - assert_return(35) + assert_return(34) end end end