From 504fc3509e0b07c2629a3d35703c4ef7e24604cf Mon Sep 17 00:00:00 2001 From: Torsten Date: Thu, 12 Mar 2020 21:39:01 +0200 Subject: [PATCH] fix set_internal_word register --- lib/slot_machine/macro/set_internal_word.rb | 8 +++---- .../macro/test_get_internal_byte.rb | 2 +- .../macro/test_set_internal_word.rb | 23 +++++++++---------- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/lib/slot_machine/macro/set_internal_word.rb b/lib/slot_machine/macro/set_internal_word.rb index 524e233b..4d50d952 100644 --- a/lib/slot_machine/macro/set_internal_word.rb +++ b/lib/slot_machine/macro/set_internal_word.rb @@ -2,11 +2,9 @@ module SlotMachine class SetInternalWord < Macro def to_risc(compiler) compiler.builder(compiler.source).build do - object! << message[:receiver] - integer! << message[:arg1] # "index" - object_reg! << message[:arg2]#"value" - integer.reduce_int - object[integer] << object_reg + integer = message[:arg1].to_reg.reduce_int(false) + object_reg = message[:arg2].to_reg + message[:receiver][integer] << object_reg message[:return_value] << object_reg end return compiler diff --git a/test/slot_machine/macro/test_get_internal_byte.rb b/test/slot_machine/macro/test_get_internal_byte.rb index b18784dc..2024b99f 100644 --- a/test/slot_machine/macro/test_get_internal_byte.rb +++ b/test/slot_machine/macro/test_get_internal_byte.rb @@ -2,7 +2,7 @@ require_relative "helper" module SlotMachine module Builtin - class TestWordGetRisc < BootTest + class TestGetInternalByte < BootTest def setup super @method = get_compiler("Word",:get_byte) diff --git a/test/slot_machine/macro/test_set_internal_word.rb b/test/slot_machine/macro/test_set_internal_word.rb index 91c5a7bb..490581df 100644 --- a/test/slot_machine/macro/test_set_internal_word.rb +++ b/test/slot_machine/macro/test_set_internal_word.rb @@ -14,22 +14,21 @@ module SlotMachine assert_equal Risc::MethodCompiler , @method.to_risc.class end def test_risc_length - assert_equal 20 , @method.to_risc.risc_instructions.length + assert_equal 18 , @method.to_risc.risc_instructions.length end def test_all - assert_slot_to_reg risc(1),:r0 , 2 , :r1 - assert_slot_to_reg risc(2),:r0 , 10 , :r2 - assert_reg_to_slot risc(3) , :r2 , :r0 , 5 - assert_slot_to_reg risc(4),:r0 , 9 , :r3 - assert_slot_to_reg risc(5),:r3 , 2 , :r3 - assert_slot_to_reg risc(6),:r2 , 2 , :r2 - assert_equal Risc::RegToByte , risc(7).class - assert_slot_to_reg risc(8),:r0 , 5 , :r2 - assert_reg_to_slot risc(9) , :r2 , :r0 , 5 - assert_branch risc(10) , "return_label" + assert_slot_to_reg 1 ,:message , 9 , "message.arg1" + assert_slot_to_reg 2 ,"message.arg1" , 2 , "message.arg1.data_1" + assert_slot_to_reg 3 ,:message , 10 , "message.arg2" + assert_slot_to_reg 4 ,:message , 2 , "message.receiver" + assert_reg_to_slot 5 , "message.arg2" , "message.receiver" , :"message.arg1.data_1" + assert_reg_to_slot 6 , "message.arg2" , :message , 5 + assert_slot_to_reg 7 ,:message , 5 , :"message.return_value" + assert_reg_to_slot 8 , "message.return_value" , :message , 5 + assert_branch 9 , "return_label" end def test_return - assert_return(11) + assert_return(10) end end end