From 2af953e1d2fd330b1c4b084ba3208e0eca80a518 Mon Sep 17 00:00:00 2001 From: Torsten Date: Tue, 3 Mar 2020 16:44:21 +0200 Subject: [PATCH] last instruciton, dynamic_call next macros --- lib/slot_machine/instructions/dynamic_call.rb | 18 ++++++++---------- .../instructions/test_dynamic_call.rb | 19 ++++++++++--------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/lib/slot_machine/instructions/dynamic_call.rb b/lib/slot_machine/instructions/dynamic_call.rb index a45782ca..accc05ce 100644 --- a/lib/slot_machine/instructions/dynamic_call.rb +++ b/lib/slot_machine/instructions/dynamic_call.rb @@ -20,7 +20,7 @@ module SlotMachine def to_s str = "DynamicCall " - str += cache_entry.cached_method&.name if cache_entry + str += cache_entry.cached_method&.name if cache_entry and cache_entry.cached_method str end @@ -31,17 +31,15 @@ module SlotMachine # Instead we need a DynamicJump instruction that explicitly takes a register as # a target (not a label) def to_risc(compiler) - entry = @cache_entry - compiler.add_constant( entry ) + entry = compiler.load_object(@cache_entry)[:cached_method].to_reg + compiler.add_constant( @cache_entry) return_label = Risc.label(self, "continue_#{object_id}") - compiler.build("DynamicCall") do - return_address! << return_label - next_message! << message[:next_message] - next_message[:return_address] << return_address + return_address = compiler.load_object(return_label) + + compiler.build(to_s) do + message[:next_message][:return_address] << return_address message << message[:next_message] - cache_entry! << entry - cache_entry << cache_entry[:cached_method] - add_code Risc::DynamicJump.new("DynamicCall", cache_entry ) + add_code Risc::DynamicJump.new("DynamicCall", entry ) add_code return_label end end diff --git a/test/slot_machine/instructions/test_dynamic_call.rb b/test/slot_machine/instructions/test_dynamic_call.rb index b312cf46..16ff9e62 100644 --- a/test/slot_machine/instructions/test_dynamic_call.rb +++ b/test/slot_machine/instructions/test_dynamic_call.rb @@ -9,26 +9,27 @@ module SlotMachine assert_equal 9 , all.length , all_str end def test_1_load - assert_load risc(1) , Risc::Label , :r1 - assert_label risc(1).constant , "continue_" + assert_load risc(1) , Parfait::CacheEntry , "id_" end def test_2_slot - assert_slot_to_reg risc(2) ,:r0 , 1 , :r2 + assert_slot_to_reg risc(2) , "id_" , 2 , "id_.cached_method" end - def test_3_reg - assert_reg_to_slot risc(3) , :r1 , :r2 , 4 + def test_3_load + assert_load risc(3) , Risc::Label , "id_" + assert_label risc(3).constant , "continue_" end def test_4_slot - assert_slot_to_reg risc(4) ,:r0 , 1 , :r0 + assert_slot_to_reg risc(4) , :message , 1 , "message.next_message" end - def test_5_load - assert_load risc(5) , Parfait::CacheEntry , :r3 + def test_5_reg + assert_reg_to_slot risc(5) , "id_" , "message.next_message" , 4 end def test_6_slot - assert_slot_to_reg risc(6) ,:r3 , 2 , :r3 + assert_slot_to_reg risc(6) , :message , 1 , :message end def test_7_jump assert_equal Risc::DynamicJump , risc(7).class + assert_register :jump , "id_.cached_method" , risc(7).register end def test_8_label assert_label risc(8) , "continue_"