fixes all but interpreter tests

This commit is contained in:
Torsten Ruger 2018-04-06 23:37:41 +03:00
parent eea92399ee
commit 3c90eb31c6
9 changed files with 111 additions and 105 deletions

View File

@ -7,11 +7,12 @@ module Risc
def setup
super
@input = "r = 5.mod4"
@expect = [LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg ,
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg ,
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg ,
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, LoadConstant ,
FunctionCall, Label, SlotToReg, SlotToReg, RegToSlot]
@expect = [LoadConstant, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
RegToSlot, SlotToReg, RegToSlot, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
RegToSlot, SlotToReg, LoadConstant, FunctionCall, Label,
SlotToReg, SlotToReg, RegToSlot]
end
def test_local_assign_instructions
assert_nil msg = check_nil , msg
@ -19,7 +20,9 @@ module Risc
def test_constant_load
produced = produce_body
assert_equal 5 , produced.next(16).constant.value
load = produced.next(15)
assert_equal LoadConstant , load.class
assert_equal 5 , load.constant.value
end
end
end

View File

@ -9,18 +9,18 @@ module Risc
@input = "@a.mod4"
@expect = [LoadConstant, SlotToReg, SlotToReg, SlotToReg, OperatorInstruction,
IsZero, SlotToReg, SlotToReg, LoadConstant, RegToSlot,
LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
SlotToReg, SlotToReg, SlotToReg, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg,
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
SlotToReg, RegToSlot, SlotToReg, LoadConstant, FunctionCall,
Label, SlotToReg, LoadConstant, RegToSlot, Label,
LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
SlotToReg, SlotToReg, SlotToReg, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg,
RegToSlot, SlotToReg, SlotToReg, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, DynamicJump]
LoadConstant, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
RegToSlot, SlotToReg, RegToSlot, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
RegToSlot, SlotToReg, LoadConstant, FunctionCall, Label,
SlotToReg, LoadConstant, RegToSlot, Label, LoadConstant,
LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot,
SlotToReg, RegToSlot, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
DynamicJump]
end
def test_send_instructions
@ -28,23 +28,23 @@ module Risc
end
def test_function_call
produced = produce_body
assert_equal DynamicJump , produced.next(67).class
assert_equal DynamicJump , produced.next(65).class
end
def test_load_address
produced = produce_body
assert_equal LoadConstant , produced.next(65).class
assert_equal Parfait::CacheEntry , produced.next(65).constant.class
assert_equal LoadConstant , produced.next(63).class
assert_equal Parfait::CacheEntry , produced.next(63).constant.class
end
def test_cache_check
produced = produce_body
assert_equal IsZero , produced.next(5).class
assert_equal Label , produced.next(44).class
assert_equal produced.next(44) , produced.next(5).label
assert_equal Label , produced.next(43).class
assert_equal produced.next(43) , produced.next(5).label
end
def test_check_resolve
produced = produce_body
assert_equal FunctionCall , produced.next(39).class
assert_equal :resolve_method ,produced.next(39).method.name
assert_equal FunctionCall , produced.next(38).class
assert_equal :resolve_method ,produced.next(38).method.name
end
end
end

View File

@ -7,12 +7,11 @@ module Risc
def setup
super
@input = "5.mod4"
@expect = [LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
SlotToReg, SlotToReg, SlotToReg, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg,
RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant,
SlotToReg, RegToSlot, SlotToReg, LoadConstant, FunctionCall,
Label]
@expect = [LoadConstant, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
RegToSlot, SlotToReg, RegToSlot, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
RegToSlot, SlotToReg, LoadConstant, FunctionCall, Label]
end
def test_send_instructions
@ -20,24 +19,24 @@ module Risc
end
def test_load_5
produced = produce_body
assert_equal 5 , produced.next(16).constant.value
assert_equal 5 , produced.next(15).constant.value
end
def test_load_label
produced = produce_body
assert_equal Label , produced.next(19).constant.class
assert_equal Label , produced.next(18).constant.class
end
def test_call_reg_setup
produced = produce_body
assert_equal produced.next(23).register , produced.next(24).register
assert_equal produced.next(22).register , produced.next(23).register
end
def test_function_call
produced = produce_body
assert_equal FunctionCall , produced.next(24).class
assert_equal :mod4 , produced.next(24).method.name
assert_equal FunctionCall , produced.next(23).class
assert_equal :mod4 , produced.next(23).method.name
end
def test_check_continue
produced = produce_body
assert produced.next(25).name.start_with?("continue_")
assert produced.next(24).name.start_with?("continue_")
end
#TODO check the message setup, type and frame moves
end

View File

@ -7,12 +7,12 @@ module Risc
def setup
super
@input = "5.get_internal_word(1)"
@expect = [LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
SlotToReg, SlotToReg, SlotToReg, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg,
RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant,
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
RegToSlot, SlotToReg, LoadConstant, FunctionCall, Label]
@expect = [LoadConstant, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
RegToSlot, SlotToReg, RegToSlot, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
SlotToReg, LoadConstant, FunctionCall, Label]
end
def test_send_instructions
@ -20,75 +20,78 @@ module Risc
end
def test_load_5
produced = produce_body
assert_equal 5 , produced.next(16).constant.value
assert_equal 5 , produced.next(15).constant.value
end
def base
18
end
def test_load_arg_const
produced = produce_body
assert_equal LoadConstant , produced.next(19).class
assert_equal Parfait::Integer , produced.next(19).constant.class
assert_equal 1 , produced.next(19).constant.value
assert_equal LoadConstant , produced.next(base).class
assert_equal Parfait::Integer , produced.next(base).constant.class
assert_equal 1 , produced.next(18).constant.value
end
def test_load_next_m
produced = produce_body
assert_equal SlotToReg , produced.next(20).class
assert_equal :r2 , produced.next(20).register.symbol
assert_equal :r0 , produced.next(20).array.symbol
assert_equal 2 , produced.next(20).index
assert_equal SlotToReg , produced.next(base+1).class
assert_equal :r2 , produced.next(base+1).register.symbol
assert_equal :r0 , produced.next(base+1).array.symbol
assert_equal 2 , produced.next(base+1).index
end
def test_load_args
produced = produce_body
assert_equal SlotToReg , produced.next(21).class
assert_equal :r3 , produced.next(21).register.symbol
assert_equal :r2 , produced.next(21).array.symbol
assert_equal 9 , produced.next(21).index
assert_equal SlotToReg , produced.next(base+2).class
assert_equal :r3 , produced.next(base+2).register.symbol
assert_equal :r2 , produced.next(base+2).array.symbol
assert_equal 9 , produced.next(base+2).index
end
def test_store_arg_at
produced = produce_body
assert_equal RegToSlot , produced.next(22).class
assert_equal :r1 , produced.next(22).register.symbol
assert_equal :r3 , produced.next(22).array.symbol
assert_equal 2 , produced.next(22).index , "first arg must have index 1"
assert_equal RegToSlot , produced.next(base+3).class
assert_equal :r1 , produced.next(base+3).register.symbol
assert_equal :r3 , produced.next(base+3).array.symbol
assert_equal 2 , produced.next(base+3).index , "first arg must have index 1"
end
def test_load_label
produced = produce_body
assert_equal LoadConstant , produced.next(23).class
assert_equal Label , produced.next(23).constant.class
assert_equal LoadConstant , produced.next(base+4).class
assert_equal Label , produced.next(base+4).constant.class
end
def test_load_some
produced = produce_body
assert_equal SlotToReg , produced.next(24).class
assert_equal :r0 , produced.next(24).array.symbol
assert_equal :r3 , produced.next(24).register.symbol
assert_equal 2 , produced.next(24).index
assert_equal SlotToReg , produced.next(base+5).class
assert_equal :r0 , produced.next(base+5).array.symbol
assert_equal :r3 , produced.next(base+5).register.symbol
assert_equal 2 , produced.next(base+5).index
end
def test_store_
produced = produce_body
assert_equal RegToSlot , produced.next(25).class
assert_equal :r3 , produced.next(25).array.symbol
assert_equal :r2 , produced.next(25).register.symbol
assert_equal 5 , produced.next(25).index
assert_equal RegToSlot , produced.next(base+6).class
assert_equal :r3 , produced.next(base+6).array.symbol
assert_equal :r2 , produced.next(base+6).register.symbol
assert_equal 5 , produced.next(base+6).index
end
def test_swap_messages
produced = produce_body
assert_equal SlotToReg , produced.next(26).class
assert_equal :r0 , produced.next(26).array.symbol
assert_equal :r0 , produced.next(26).register.symbol
assert_equal 2 , produced.next(26).index
assert_equal SlotToReg , produced.next(base+7).class
assert_equal :r0 , produced.next(base+7).array.symbol
assert_equal :r0 , produced.next(base+7).register.symbol
assert_equal 2 , produced.next(base+7).index
end
def test_function_call
produced = produce_body
assert_equal FunctionCall , produced.next(28).class
assert_equal :get_internal_word , produced.next(28).method.name
assert_equal FunctionCall , produced.next(base+9).class
assert_equal :get_internal_word , produced.next(base+9).method.name
end
def test_call_reg_setup
produced = produce_body
assert_equal produced.next(27).register , produced.next(28).register
assert_equal produced.next(base+8).register , produced.next(base+9).register
end
def test_check_continue
produced = produce_body
assert produced.next(29).name.start_with?("continue_")
assert produced.next(base+10).name.start_with?("continue_")
end
#TODO check the message setup, type and frame moves
end

View File

@ -7,12 +7,13 @@ module Risc
def setup
super
@input = "return 5.mod4"
@expect = [LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg ,
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg ,
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg ,
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, LoadConstant ,
FunctionCall, Label, SlotToReg, SlotToReg, RegToSlot, SlotToReg ,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg ,
@expect = [LoadConstant, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
RegToSlot, SlotToReg, RegToSlot, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
RegToSlot, SlotToReg, LoadConstant, FunctionCall, Label,
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, FunctionReturn]
end
@ -21,12 +22,12 @@ module Risc
end
def test_function_return
produced = produce_body
assert_equal FunctionReturn , produced.next(37).class
assert_equal FunctionReturn , produced.next(36).class
end
def test_load_5
produced = produce_body
assert_equal LoadConstant , produced.next(16).class
assert_equal 5 , produced.next(16).constant.value
assert_equal LoadConstant , produced.next(15).class
assert_equal 5 , produced.next(15).constant.value
end
end
end

View File

@ -9,20 +9,20 @@ module Risc
@input = "return @a.mod4"
@expect = [LoadConstant, SlotToReg, SlotToReg, SlotToReg, OperatorInstruction,
IsZero, SlotToReg, SlotToReg, LoadConstant, RegToSlot,
LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
SlotToReg, SlotToReg, SlotToReg, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg,
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
SlotToReg, RegToSlot, SlotToReg, LoadConstant, FunctionCall,
Label, SlotToReg, LoadConstant, RegToSlot, Label,
LoadConstant, SlotToReg, SlotToReg, RegToSlot, LoadConstant,
SlotToReg, SlotToReg, SlotToReg, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg,
RegToSlot, SlotToReg, SlotToReg, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, DynamicJump, SlotToReg, SlotToReg,
RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, FunctionReturn]
LoadConstant, LoadConstant, SlotToReg, RegToSlot, RegToSlot,
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
RegToSlot, SlotToReg, RegToSlot, SlotToReg, RegToSlot,
LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
RegToSlot, SlotToReg, LoadConstant, FunctionCall, Label,
SlotToReg, LoadConstant, RegToSlot, Label, LoadConstant,
LoadConstant, SlotToReg, RegToSlot, RegToSlot, SlotToReg,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot,
SlotToReg, RegToSlot, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
DynamicJump, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot,
SlotToReg, SlotToReg, FunctionReturn]
end
def test_return_instructions
@ -30,7 +30,7 @@ module Risc
end
def test_function_return
produced = produce_body
assert_equal FunctionReturn , produced.next(79).class
assert_equal FunctionReturn , produced.next(77).class
end
def test_cache_check
produced = produce_body

View File

@ -15,11 +15,11 @@ module Risc
SlotToReg , RegToSlot, SlotToReg, SlotToReg, RegToSlot,
SlotToReg, SlotToReg, FunctionReturn, Transfer, Syscall,
NilClass]
#assert_equal 15 , get_return.value
assert_equal 15 , get_return.value
end
def test_call_main
call_ins = ticks(24)
call_ins = ticks(main_at)
assert_equal FunctionCall , call_ins.class
assert :main , call_ins.method.name
end

View File

@ -18,7 +18,7 @@ module Risc
end
def test_call_main
call_ins = ticks(26)
call_ins = ticks(main_at)
assert_equal FunctionCall , call_ins.class
assert :main , call_ins.method.name
end

View File

@ -19,7 +19,7 @@ module Risc
# how many instruction up until the main starts, ie
# ticks(main_at) will be the label for main
def main_at
24
25
end
def get_return