fix all mom tests

still quite brittle, but easy to fix
This commit is contained in:
Torsten Rüger 2019-08-23 19:24:18 +03:00
parent 1eb6430880
commit 4656ea8ffb
19 changed files with 93 additions and 86 deletions

View File

@ -7,10 +7,10 @@ module Risc
def setup def setup
super super
@input = "r = 5.div4;return" @input = "r = 5.div4;return"
@expect = [LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #4 @expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #9 RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #10
Label, SlotToReg, RegToSlot, LoadConstant, RegToSlot, #14 FunctionCall, Label, SlotToReg, RegToSlot, LoadConstant, #15
Branch,] #19 RegToSlot, Branch,] #20
end end
def test_local_assign_instructions def test_local_assign_instructions
assert_nil msg = check_nil , msg assert_nil msg = check_nil , msg
@ -18,7 +18,7 @@ module Risc
def test_constant_load def test_constant_load
produced = produce_body produced = produce_body
load = produced.next(2) load = produced.next(3)
assert_equal LoadConstant , load.class assert_equal LoadConstant , load.class
assert_equal 5 , load.constant.value assert_equal 5 , load.constant.value
end end

View File

@ -7,10 +7,10 @@ module Risc
def setup def setup
super super
@input = as_block("return 5") @input = as_block("return 5")
@expect = [LoadConstant, RegToSlot, LoadConstant, RegToSlot, SlotToReg, #4 @expect = [LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #5
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #9 SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #10
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #14 RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #15
Label,] #19 FunctionCall, Label,] #20
end end
def test_send_instructions def test_send_instructions
@ -27,22 +27,22 @@ module Risc
assert_equal 5 , produced.constant.value assert_equal 5 , produced.constant.value
end end
def test_load_block def test_load_block
produced = produce_body.next(7) produced = produce_body.next(8)
assert_load( produced , Parfait::Block) assert_load( produced , Parfait::Block)
assert_equal :main_block , produced.constant.name assert_equal :main_block , produced.constant.name
end end
def test_load_return def test_load_return
produced = produce_body.next(10) produced = produce_body.next(11)
assert_load( produced , Label) assert_load( produced , Label)
assert produced.constant.name.start_with?("continue_") assert produced.constant.name.start_with?("continue_")
end end
def test_function_call def test_function_call
produced = produce_body.next(14) produced = produce_body.next(15)
assert_equal FunctionCall , produced.class assert_equal FunctionCall , produced.class
assert_equal :main , produced.method.name assert_equal :main , produced.method.name
end end
def test_check_continue def test_check_continue
produced = produce_body.next(15) produced = produce_body.next(16)
assert_equal Label , produced.class assert_equal Label , produced.class
assert produced.name.start_with?("continue_") , produced.name assert produced.name.start_with?("continue_") , produced.name
end end

View File

@ -11,7 +11,7 @@ module Mom
assert_equal Risc::MethodCompiler , @method.to_risc.class assert_equal Risc::MethodCompiler , @method.to_risc.class
end end
def test_risc_length def test_risc_length
assert_equal 66 , @method.to_risc.risc_instructions.length assert_equal 67 , @method.to_risc.risc_instructions.length
end end
end end
end end

View File

@ -9,9 +9,10 @@ module Mom
end end
def test_compile def test_compile
assert_equal Risc::MethodCompiler , @method.to_risc.class assert_equal Risc::MethodCompiler , @method.to_risc.class
assert_equal :div4 , @method.callable.name
end end
def test_risc_length def test_risc_length
assert_equal 37 , @method.to_risc.risc_instructions.length assert_equal 38 , @method.to_risc.risc_instructions.length
end end
end end
end end

View File

@ -11,7 +11,7 @@ module Mom
assert_equal Risc::MethodCompiler , @method.to_risc.class assert_equal Risc::MethodCompiler , @method.to_risc.class
end end
def test_risc_length def test_risc_length
assert_equal 36 , @method.to_risc.risc_instructions.length assert_equal 37 , @method.to_risc.risc_instructions.length
end end
end end
end end

View File

@ -11,7 +11,7 @@ module Mom
assert_equal Risc::MethodCompiler , @method.to_risc.class assert_equal Risc::MethodCompiler , @method.to_risc.class
end end
def test_risc_length def test_risc_length
assert_equal 37 , @method.to_risc.risc_instructions.length assert_equal 38 , @method.to_risc.risc_instructions.length
end end
end end
end end

View File

@ -11,7 +11,7 @@ module Mom
assert_equal Risc::MethodCompiler , @method.to_risc.class assert_equal Risc::MethodCompiler , @method.to_risc.class
end end
def test_risc_length def test_risc_length
assert_equal 27 , @method.to_risc.risc_instructions.length assert_equal 19 , @method.to_risc.risc_instructions.length
end end
end end
end end

View File

@ -11,7 +11,7 @@ module Mom
assert_equal Risc::MethodCompiler , @method.to_risc.class assert_equal Risc::MethodCompiler , @method.to_risc.class
end end
def test_risc_length def test_risc_length
assert_equal 38 , @method.to_risc.risc_instructions.length assert_equal 39 , @method.to_risc.risc_instructions.length
end end
end end
end end

View File

@ -13,6 +13,9 @@ module Mom
def test_mom_length def test_mom_length
assert_equal 5 , @method.mom_instructions.length assert_equal 5 , @method.mom_instructions.length
end end
def test_return
assert_equal ReturnSequence , @method.mom_instructions.next(3).class
end
end end
class TestObjectSet < BootTest class TestObjectSet < BootTest
def setup def setup
@ -59,7 +62,7 @@ module Mom
assert_equal Mom::MethodCompiler , @method.class assert_equal Mom::MethodCompiler , @method.class
end end
def test_mom_length def test_mom_length
assert_equal 5 , @method.mom_instructions.length assert_equal 2 , @method.mom_instructions.length
end end
end end
end end

View File

@ -19,7 +19,7 @@ module Mom
end end
def test_risc_length def test_risc_length
each_method do |method| each_method do |method|
assert_equal 38 , method.to_risc.risc_instructions.length assert_equal 39 , method.to_risc.risc_instructions.length
end end
end end
end end

View File

@ -11,7 +11,7 @@ module Mom
assert_equal Risc::MethodCompiler , @method.to_risc.class assert_equal Risc::MethodCompiler , @method.to_risc.class
end end
def test_risc_length def test_risc_length
assert_equal 40 , @method.to_risc.risc_instructions.length assert_equal 41 , @method.to_risc.risc_instructions.length
end end
end end
end end

View File

@ -7,17 +7,18 @@ module Risc
def setup def setup
super super
@input = "@a.div4" @input = "@a.div4"
@expect = [LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg, #4 @expect = [LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg, #5
OperatorInstruction, IsZero, SlotToReg, SlotToReg, SlotToReg, #9 OperatorInstruction, IsZero, SlotToReg, SlotToReg, SlotToReg, #10
LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg, #14 LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg, #15
SlotToReg, Label, LoadConstant, OperatorInstruction, IsZero, #19 SlotToReg, Label, LoadConstant, OperatorInstruction, IsZero, #20
SlotToReg, OperatorInstruction, IsZero, SlotToReg, Branch, #24 SlotToReg, OperatorInstruction, IsZero, SlotToReg, Branch, #25
Label, LoadConstant, SlotToReg, Transfer, Syscall, #29 Label, LoadConstant, SlotToReg, Transfer, Syscall, #30
Transfer, Transfer, SlotToReg, RegToSlot, Label, #34 Transfer, Transfer, SlotToReg, RegToSlot, Label, #35
RegToSlot, Label, LoadConstant, SlotToReg, RegToSlot, #39 RegToSlot, Label, LoadConstant, SlotToReg, SlotToReg, #40
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, #44 RegToSlot, SlotToReg, SlotToReg, SlotToReg, RegToSlot, #45
SlotToReg, RegToSlot, SlotToReg, LoadConstant, SlotToReg, #49 LoadConstant, SlotToReg, RegToSlot, SlotToReg, LoadConstant, #50
DynamicJump, Label, SlotToReg, RegToSlot, Branch,] #54 SlotToReg, DynamicJump, Label, SlotToReg, RegToSlot, #55
Branch,] #60
end end
def test_send_instructions def test_send_instructions
@ -35,7 +36,7 @@ module Risc
end end
def test_function_call def test_function_call
produced = produce_body produced = produce_body
assert_equal DynamicJump , produced.next(50).class assert_equal DynamicJump , produced.next(51).class
end end
def test_cache_check def test_cache_check
produced = produce_body produced = produce_body

View File

@ -7,30 +7,30 @@ module Risc
def setup def setup
super super
@input = "5.div4" @input = "5.div4"
@expect = [LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #4 @expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #9 RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #10
Label, SlotToReg, RegToSlot, Branch,] #14 FunctionCall, Label, SlotToReg, RegToSlot, Branch,] #15
end end
def test_send_instructions def test_send_instructions
assert_nil msg = check_nil , msg assert_nil msg = check_nil , msg
end end
def test_load_5 def test_load_5
produced = produce_body.next(2) produced = produce_body.next(3)
assert_load( produced , Parfait::Integer) assert_load( produced , Parfait::Integer)
assert_equal 5 , produced.constant.value assert_equal 5 , produced.constant.value
end end
def test_load_label def test_load_label
produced = produce_body.next(5) produced = produce_body.next(6)
assert_load( produced , Label) assert_load( produced , Label)
end end
def test_function_call def test_function_call
produced = produce_body.next(9) produced = produce_body.next(10)
assert_equal FunctionCall , produced.class assert_equal FunctionCall , produced.class
assert_equal :div4 , produced.method.name assert_equal :div4 , produced.method.name
end end
def test_check_continue def test_check_continue
produced = produce_body.next(10) produced = produce_body.next(11)
assert_equal Label , produced.class assert_equal Label , produced.class
assert produced.name.start_with?("continue_") assert produced.name.start_with?("continue_")
end end

View File

@ -7,10 +7,10 @@ module Risc
def setup def setup
super super
@input = "5.get_internal_word(1)" @input = "5.get_internal_word(1)"
@expect = [LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #4 @expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5
LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #9 RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant, #10
RegToSlot, SlotToReg, FunctionCall, Label, SlotToReg, #14 SlotToReg, RegToSlot, SlotToReg, FunctionCall, Label, #15
RegToSlot, Branch,] #19 SlotToReg, RegToSlot, Branch,] #20
end end
def test_send_instructions def test_send_instructions
@ -18,11 +18,11 @@ module Risc
end end
def test_load_5 def test_load_5
produced = produce_body produced = produce_body
assert_equal LoadConstant , produced.next(2).class assert_equal LoadConstant , produced.next(3).class
assert_equal 5 , produced.next(2).constant.value assert_equal 5 , produced.next(3).constant.value
end end
def base def base
5 6
end end
def test_load_arg_const def test_load_arg_const
produced = produce_body produced = produce_body

View File

@ -7,9 +7,9 @@ module Risc
def setup def setup
super super
@input = "return 5.div4" @input = "return 5.div4"
@expect = [LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #4 @expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #9 RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #10
Label, SlotToReg, RegToSlot, Branch] #14 FunctionCall, Label, SlotToReg, RegToSlot, Branch,] #15
@produced = produce_body @produced = produce_body
end end
@ -22,7 +22,7 @@ module Risc
assert_equal :div4 , method.constant.name assert_equal :div4 , method.constant.name
end end
def test_store_method_in_message def test_store_method_in_message
sl = @produced.next( 1 ) sl = @produced.next( 2 )
assert_reg_to_slot( sl , :r1 , :r2 , 7 ) assert_reg_to_slot( sl , :r1 , :r2 , 7 )
end end
end end

View File

@ -7,21 +7,21 @@ module Risc
def setup def setup
super super
@input = "return 5.div4" @input = "return 5.div4"
@expect = [LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #4 @expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #9 RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #10
Label, SlotToReg, RegToSlot, Branch,] #14 FunctionCall, Label, SlotToReg, RegToSlot, Branch,] #15
end end
def test_return_instructions def test_return_instructions
assert_nil msg = check_nil , msg assert_nil msg = check_nil , msg
end end
def test_function_return def test_function_return
produced = produce_body.next(13) produced = produce_body.next(14)
assert_equal Branch , produced.class assert_equal Branch , produced.class
assert_equal "return_label" , produced.label.name assert_equal "return_label" , produced.label.name
end end
def test_load_5 def test_load_5
produced = produce_body.next(2) produced = produce_body.next(3)
assert_equal LoadConstant , produced.class assert_equal LoadConstant , produced.class
assert_equal 5 , produced.constant.value assert_equal 5 , produced.constant.value
end end

View File

@ -7,17 +7,18 @@ module Risc
def setup def setup
super super
@input = "return @a.div4" @input = "return @a.div4"
@expect =[LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg, #4 @expect = [LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg, #5
OperatorInstruction, IsZero, SlotToReg, SlotToReg, SlotToReg, #9 OperatorInstruction, IsZero, SlotToReg, SlotToReg, SlotToReg, #10
LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg, #14 LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg, #15
SlotToReg, Label, LoadConstant, OperatorInstruction, IsZero, #19 SlotToReg, Label, LoadConstant, OperatorInstruction, IsZero, #20
SlotToReg, OperatorInstruction, IsZero, SlotToReg, Branch, #24 SlotToReg, OperatorInstruction, IsZero, SlotToReg, Branch, #25
Label, LoadConstant, SlotToReg, Transfer, Syscall, #29 Label, LoadConstant, SlotToReg, Transfer, Syscall, #30
Transfer, Transfer, SlotToReg, RegToSlot, Label, #34 Transfer, Transfer, SlotToReg, RegToSlot, Label, #35
RegToSlot, Label, LoadConstant, SlotToReg, RegToSlot, #39 RegToSlot, Label, LoadConstant, SlotToReg, SlotToReg, #40
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, #44 RegToSlot, SlotToReg, SlotToReg, SlotToReg, RegToSlot, #45
SlotToReg, RegToSlot, SlotToReg, LoadConstant, SlotToReg, #49 LoadConstant, SlotToReg, RegToSlot, SlotToReg, LoadConstant, #50
DynamicJump, Label, SlotToReg, RegToSlot, Branch,] #54 SlotToReg, DynamicJump, Label, SlotToReg, RegToSlot, #55
Branch,] #60
end end
def test_return_instructions def test_return_instructions
@ -25,7 +26,7 @@ module Risc
end end
def test_function_return def test_function_return
produced = produce_body produced = produce_body
assert_equal Branch , produced.next(54).class assert_equal Branch , produced.next(55).class
end end
def test_cache_check def test_cache_check
produced = produce_body produced = produce_body

View File

@ -9,8 +9,8 @@ module Risc
@input = "return 5.div4" @input = "return 5.div4"
@expect = "something" @expect = "something"
end end
def instruction(num) # 15 is the main, see length in support/risc_interpreter.rb main_at def instruction(num) # 16 is the main, see length in support/risc_interpreter.rb main_at
produce_main.next( 15 + num) produce_main.next( 16 + num)
end end
def test_postamble_classes def test_postamble_classes
postamble.each_with_index do |ins , index| postamble.each_with_index do |ins , index|

View File

@ -7,12 +7,13 @@ module Risc
def setup def setup
super super
@input = "while(5 > 0) ; @a = true; end;return" @input = "while(5 > 0) ; @a = true; end;return"
@expect = [Label, LoadConstant, RegToSlot, LoadConstant, SlotToReg, #4 @expect = [Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant, #5
RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant, #9 SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #10
SlotToReg, RegToSlot, SlotToReg, FunctionCall, Label, #14 LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #15
SlotToReg, LoadConstant, OperatorInstruction, IsZero, LoadConstant, #19 Label, SlotToReg, LoadConstant, OperatorInstruction, IsZero, #20
OperatorInstruction, IsZero, LoadConstant, SlotToReg, RegToSlot, #24 LoadConstant, OperatorInstruction, IsZero, LoadConstant, SlotToReg, #25
Branch, Label, LoadConstant, RegToSlot, Branch,] #29 RegToSlot, Branch, Label, LoadConstant, RegToSlot, #30
Branch,] #35
end end
def test_while_instructions def test_while_instructions
@ -23,33 +24,33 @@ module Risc
end end
def test_int_load_5 def test_int_load_5
produced = produce_body produced = produce_body
load = produced.next(3) load = produced.next(4)
assert_equal Risc::LoadConstant , load.class assert_equal Risc::LoadConstant , load.class
assert_equal Parfait::Integer , load.constant.class assert_equal Parfait::Integer , load.constant.class
assert_equal 5 , load.constant.value assert_equal 5 , load.constant.value
end end
def test_int_load_0 def test_int_load_0
produced = produce_body produced = produce_body
load = produced.next(6) load = produced.next(7)
assert_equal Risc::LoadConstant , load.class assert_equal Risc::LoadConstant , load.class
assert_equal Parfait::Integer , load.constant.class assert_equal Parfait::Integer , load.constant.class
assert_equal 0 , load.constant.value assert_equal 0 , load.constant.value
end end
def test_false_check def test_false_check
produced = produce_body produced = produce_body
assert_equal Risc::IsZero , produced.next(18).class assert_equal Risc::IsZero , produced.next(19).class
assert produced.next(18).label.name.start_with?("merge_label") , produced.next(18).label.name assert produced.next(19).label.name.start_with?("merge_label") , produced.next(19).label.name
end end
def test_nil_load def test_nil_load
produced = produce_body produced = produce_body
assert_equal Risc::LoadConstant , produced.next(22).class assert_equal Risc::LoadConstant , produced.next(23).class
assert_equal Parfait::TrueClass , produced.next(22).constant.class assert_equal Parfait::TrueClass , produced.next(23).constant.class
end end
def ttest_back_jump # should jump back to condition label def test_back_jump # should jump back to condition label
produced = produce_body produced = produce_body
assert_equal Risc::Branch , produced.next(31).class assert_equal Risc::Branch , produced.next(26).class
assert_equal produced.name , produced.next(31).label.name assert_equal produced.name , produced.next(26).label.name
end end
end end