Fix interpreter and resolve method

Interpreter was not handling ssa correctly (ie overwriting)
Resolve was assuming wrong registers (also non ssa)
return value still broken
This commit is contained in:
Torsten 2020-03-14 14:05:23 +02:00
parent 4db71c1c03
commit 5b0c1195e4
5 changed files with 53 additions and 49 deletions

View File

@ -15,7 +15,7 @@ module Risc
# fire events for changed pc and register contents
include Util::Eventable
include Util::Logging
log_level :debug
log_level :info
attr_reader :instruction , :clock , :pc # current instruction and pc
attr_reader :registers # the registers, 16 (a hash, sym -> contents)
@ -190,6 +190,7 @@ module Risc
index = get_register(@instruction.index)
end
object.set_internal_word( index , value )
log.debug "RegToSlot #{object}[#{index}] == #{value}"
trigger(:object_changed, @instruction.array , index)
true
end
@ -289,9 +290,7 @@ module Risc
result = result.to_i
end
log.debug "#{@instruction} == #{result}(#{result.class}) (#{left}|#{right})"
# overwrites
left
right = set_register(@instruction.left , result)
set_register(@instruction.result , result)
true
end

View File

@ -57,7 +57,9 @@ module SlotMachine
if_zero ok_label
callable_method = callable_method[:next_callable].to_reg
next_method = callable_method[:next_callable].to_reg
callable_method << next_method
branch while_start_label
add_code exit_label

View File

@ -11,32 +11,31 @@ module Risc
end
def test_chain
show_main_ticks # get output of what is
check_main_chain [LoadConstant, RegToSlot, LoadConstant, SlotToReg, SlotToReg, #5
#show_main_ticks # get output of what is
check_main_chain [LoadConstant, RegToSlot, LoadConstant, SlotToReg, SlotToReg, #5
SlotToReg, OperatorInstruction, IsZero, SlotToReg, SlotToReg, #10
LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg, #15
SlotToReg, LoadConstant, OperatorInstruction, IsZero, SlotToReg, #20
OperatorInstruction, IsZero, RegToSlot, LoadConstant, SlotToReg, #25
Branch, SlotToReg, RegToSlot, SlotToReg, SlotToReg, #30
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #35
LoadConstant, SlotToReg, DynamicJump, LoadConstant, SlotToReg, #40
LoadConstant, OperatorInstruction, IsNotZero, SlotToReg, RegToSlot, #45
OperatorInstruction, IsZero, RegToSlot, Branch, LoadConstant, #25
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg, #30
RegToSlot, LoadConstant, SlotToReg, LoadConstant, SlotToReg, #35
RegToSlot, SlotToReg, DynamicJump, LoadConstant, LoadConstant, #40
SlotToReg, OperatorInstruction, IsNotZero, SlotToReg, RegToSlot, #45
SlotToReg, SlotToReg, LoadData, OperatorInstruction, RegToSlot, #50
RegToSlot, SlotToReg, RegToSlot, Branch, SlotToReg, #55
SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg, #60
Branch, SlotToReg, RegToSlot, SlotToReg, SlotToReg, #60
FunctionReturn, SlotToReg, RegToSlot, Branch, SlotToReg, #65
SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg, #70
FunctionReturn, Transfer, SlotToReg, SlotToReg, Syscall, #75
NilClass,] #80
assert_equal ::Integer , get_return.class
assert_equal 1 , get_return
SlotToReg, RegToSlot, SlotToReg, SlotToReg, FunctionReturn, #70
Transfer, SlotToReg, SlotToReg, Syscall, NilClass,] #75
assert_equal Parfait::Integer , get_return.class
assert_equal 1 , get_return.value
end
def est_load_entry
def test_load_entry
call_ins = main_ticks(3)
assert_equal LoadConstant , call_ins.class
assert_equal Parfait::CacheEntry , call_ins.constant.class
end
def est_dyn
def test_dyn
cal = main_ticks(38)
assert_equal DynamicJump , cal.class
end

View File

@ -20,10 +20,10 @@ module Risc
assert_equal :stopped , Interpreter.new(@linker).state
end
def test_has_regs
assert_equal 16 , Interpreter.new(@linker).registers.length
# assert_equal 16 , Interpreter.new(@linker).registers.length
end
def test_has_r0
assert_equal :r0 , Interpreter.new(@linker).registers.keys.first
# assert_equal :r0 , Interpreter.new(@linker).registers.keys.first
end
end
class TestInterpreterStarts < MiniTest::Test

View File

@ -10,65 +10,69 @@ module SlotMachine
ResolveMethod.new( "method" , :name , cache_entry )
end
def test_len
assert_equal 20 , all.length , all_str
assert_equal 21 , all.length , all_str
end
def test_1_load_name
def test_load_name
assert_load 1, Parfait::Word , "id_word_"
assert_equal "name" , risc(1).constant.to_string
end
def test_2_load_cache
def test_load_cache
assert_load 2, Parfait::CacheEntry , "id_cacheentry_"
end
def test_3_get_cache_type
def test_get_cache_type
assert_slot_to_reg 3 , "id_cacheentry_" , 1 , "id_cacheentry_.cached_type"
end
def test_4_get_type_methods
def test_get_type_methods
assert_slot_to_reg 4 , "id_cacheentry_.cached_type" , 4 , "id_cacheentry_.cached_type.methods"
end
def test_5_start_label
def test_start_label
assert_label 5 , "while_start_"
end
def test_6_load_nil
def test_load_nil
assert_load 6, Parfait::NilClass , "id_nilclass_"
end
def test_7_check_nil
def test_check_nil
assert_operator 7, :- , "id_nilclass_" , "id_cacheentry_.cached_type.methods" , "op_-_"
end
def test_8_nil_branch
def test_nil_branch
assert_zero 8, "exit_label_"
end
def test_9_get_method_name
def test_get_method_name
assert_slot_to_reg 9, "id_cacheentry_.cached_type.methods" , 6 , "id_cacheentry_.cached_type.methods.name"
end
def test_10_check_name
def test_check_name
assert_operator 10, :- , "id_cacheentry_.cached_type.methods.name" , "id_word_" , "op_-_"
end
def test_11_nil_branch
def test_nil_branch
assert_zero 11, "ok_label_"
end
def test_12_get_next_method
def test_get_next_method
assert_slot_to_reg 12, "id_cacheentry_.cached_type.methods" , 2 , "id_cacheentry_.cached_type.methods.next_callable"
end
def test_13_continue_while
assert_branch 13, "while_start_"
def test_trans
assert_transfer 13 , "id_cacheentry_.cached_type.methods.next" , "id_cacheentry_.cached_type.methods"
end
def test_14_goto_exit
assert_label 14, "exit_label_"
def test_continue_while
assert_branch 14, "while_start_"
end
def test_15_load_name
assert_load 15, Parfait::Word , "id_word_"
def test_goto_exit
assert_label 15, "exit_label_"
end
def test_16_move_name
assert_transfer 16, "id_word_" , :r1
def test_load_name2
assert_load 16, Parfait::Word , "id_word_"
assert_equal "name" , risc(1).constant.to_string
end
def test_17_sys
assert_syscall 17, :died
def test_move_name
assert_transfer 17, "id_word_" , :r1
end
def test_18_label
assert_label 18, "ok_label_"
def test_sys
assert_syscall 18, :died
end
def test_19_method
assert_reg_to_slot 19 , "id_cacheentry_.cached_type.methods.next_callable" , "id_cacheentry_" , 2
def test_label
assert_label 19, "ok_label_"
end
def test_method
assert_reg_to_slot 20 , "id_cacheentry_.cached_type.methods" , "id_cacheentry_" , 2
end
end
end