last instruciton, dynamic_call

next macros
This commit is contained in:
Torsten 2020-03-03 16:44:21 +02:00
parent 7f5ebab800
commit 2af953e1d2
2 changed files with 18 additions and 19 deletions

View File

@ -20,7 +20,7 @@ module SlotMachine
def to_s def to_s
str = "DynamicCall " 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 str
end end
@ -31,17 +31,15 @@ module SlotMachine
# Instead we need a DynamicJump instruction that explicitly takes a register as # Instead we need a DynamicJump instruction that explicitly takes a register as
# a target (not a label) # a target (not a label)
def to_risc(compiler) def to_risc(compiler)
entry = @cache_entry entry = compiler.load_object(@cache_entry)[:cached_method].to_reg
compiler.add_constant( entry ) compiler.add_constant( @cache_entry)
return_label = Risc.label(self, "continue_#{object_id}") return_label = Risc.label(self, "continue_#{object_id}")
compiler.build("DynamicCall") do return_address = compiler.load_object(return_label)
return_address! << return_label
next_message! << message[:next_message] compiler.build(to_s) do
next_message[:return_address] << return_address message[:next_message][:return_address] << return_address
message << message[:next_message] message << message[:next_message]
cache_entry! << entry add_code Risc::DynamicJump.new("DynamicCall", entry )
cache_entry << cache_entry[:cached_method]
add_code Risc::DynamicJump.new("DynamicCall", cache_entry )
add_code return_label add_code return_label
end end
end end

View File

@ -9,26 +9,27 @@ module SlotMachine
assert_equal 9 , all.length , all_str assert_equal 9 , all.length , all_str
end end
def test_1_load def test_1_load
assert_load risc(1) , Risc::Label , :r1 assert_load risc(1) , Parfait::CacheEntry , "id_"
assert_label risc(1).constant , "continue_"
end end
def test_2_slot 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 end
def test_3_reg def test_3_load
assert_reg_to_slot risc(3) , :r1 , :r2 , 4 assert_load risc(3) , Risc::Label , "id_"
assert_label risc(3).constant , "continue_"
end end
def test_4_slot 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 end
def test_5_load def test_5_reg
assert_load risc(5) , Parfait::CacheEntry , :r3 assert_reg_to_slot risc(5) , "id_" , "message.next_message" , 4
end end
def test_6_slot def test_6_slot
assert_slot_to_reg risc(6) ,:r3 , 2 , :r3 assert_slot_to_reg risc(6) , :message , 1 , :message
end end
def test_7_jump def test_7_jump
assert_equal Risc::DynamicJump , risc(7).class assert_equal Risc::DynamicJump , risc(7).class
assert_register :jump , "id_.cached_method" , risc(7).register
end end
def test_8_label def test_8_label
assert_label risc(8) , "continue_" assert_label risc(8) , "continue_"