From 15337e10be48a3bc2618f1e7a29147e2df947b84 Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Wed, 15 Aug 2018 17:52:21 +0300 Subject: [PATCH] move putstring to use builder --- lib/risc/builtin/word.rb | 9 ++++----- test/risc/interpreter/calling/test_puts.rb | 21 +++++++-------------- test/support/risc_assert.rb | 5 +++++ 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/lib/risc/builtin/word.rb b/lib/risc/builtin/word.rb index 090eebd6..8c0eae8a 100644 --- a/lib/risc/builtin/word.rb +++ b/lib/risc/builtin/word.rb @@ -13,11 +13,10 @@ module Risc def putstring( context) compiler = compiler_for(:Word , :putstring ,{}) builder = compiler.compiler_builder(compiler.source) - new_message = Risc.message_reg.get_new_left(:receiver , compiler) - builder.add_slot_to_reg( "putstring" , Risc.message_reg , :receiver , new_message ) - index = Parfait::Word.get_length_index - index_reg = RegisterValue.new(:r2 , :Integer) - builder.add_slot_to_reg( "putstring" , new_message , index , index_reg ) + builder.build do + word! << message[:receiver] + integer! << word[Parfait::Word.get_length_index] + end Risc::Builtin::Object.emit_syscall( builder , :putstring ) compiler.add_mom( Mom::ReturnSequence.new) compiler diff --git a/test/risc/interpreter/calling/test_puts.rb b/test/risc/interpreter/calling/test_puts.rb index d87ad9eb..effaf2a2 100644 --- a/test/risc/interpreter/calling/test_puts.rb +++ b/test/risc/interpreter/calling/test_puts.rb @@ -43,26 +43,19 @@ module Risc end def test_move_sys_return sl = main_ticks(22) - assert_equal Transfer , sl.class - assert_equal :r0 , sl.from.symbol - assert_equal :r3 , sl.to.symbol - assert_equal 11 , @interpreter.get_register(:r3) + assert_transfer(sl, :r0 ,:r4) + assert_equal 11 , @interpreter.get_register(:r4) end - def test_restore_message + def pest_restore_message sl = main_ticks(23) - assert_equal Transfer , sl.class - assert_equal :r8 , sl.from.symbol - assert_equal :r0 , sl.to.symbol + assert_transfer(sl, :r8 ,:r0) assert_equal Parfait::Message , @interpreter.get_register(:r0).class end - def test_save_sys_return + def pest_save_sys_return sl = main_ticks(28) - assert_equal RegToSlot , sl.class - assert_equal :r3 , sl.register.symbol #return - assert_equal :r2 , sl.array.symbol #parfait integer - assert_equal 2 , sl.index + assert_reg_to_slot( sl , :r3 ,:r2 , 2) end - def test_return + def pest_return done = main_ticks(60) assert_equal FunctionReturn , done.class end diff --git a/test/support/risc_assert.rb b/test/support/risc_assert.rb index 637b4882..30a5732e 100644 --- a/test/support/risc_assert.rb +++ b/test/support/risc_assert.rb @@ -17,5 +17,10 @@ module Minitest assert_equal( clazz , load.constant.class) if clazz assert_equal( register , load.register.symbol, "wrong destination register") if register end + def assert_transfer( transfer , from , to) + assert_equal Risc::Transfer , transfer.class + assert_equal from , transfer.from.symbol + assert_equal to , transfer.to.symbol + end end end