fix all mom tests
still quite brittle, but easy to fix
This commit is contained in:
parent
1eb6430880
commit
4656ea8ffb
@ -7,10 +7,10 @@ module Risc
|
||||
def setup
|
||||
super
|
||||
@input = "r = 5.div4;return"
|
||||
@expect = [LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #4
|
||||
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #9
|
||||
Label, SlotToReg, RegToSlot, LoadConstant, RegToSlot, #14
|
||||
Branch,] #19
|
||||
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5
|
||||
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #10
|
||||
FunctionCall, Label, SlotToReg, RegToSlot, LoadConstant, #15
|
||||
RegToSlot, Branch,] #20
|
||||
end
|
||||
def test_local_assign_instructions
|
||||
assert_nil msg = check_nil , msg
|
||||
@ -18,7 +18,7 @@ module Risc
|
||||
|
||||
def test_constant_load
|
||||
produced = produce_body
|
||||
load = produced.next(2)
|
||||
load = produced.next(3)
|
||||
assert_equal LoadConstant , load.class
|
||||
assert_equal 5 , load.constant.value
|
||||
end
|
||||
|
@ -7,10 +7,10 @@ module Risc
|
||||
def setup
|
||||
super
|
||||
@input = as_block("return 5")
|
||||
@expect = [LoadConstant, RegToSlot, LoadConstant, RegToSlot, SlotToReg, #4
|
||||
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #9
|
||||
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #14
|
||||
Label,] #19
|
||||
@expect = [LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #5
|
||||
SlotToReg, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #10
|
||||
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #15
|
||||
FunctionCall, Label,] #20
|
||||
end
|
||||
|
||||
def test_send_instructions
|
||||
@ -27,22 +27,22 @@ module Risc
|
||||
assert_equal 5 , produced.constant.value
|
||||
end
|
||||
def test_load_block
|
||||
produced = produce_body.next(7)
|
||||
produced = produce_body.next(8)
|
||||
assert_load( produced , Parfait::Block)
|
||||
assert_equal :main_block , produced.constant.name
|
||||
end
|
||||
def test_load_return
|
||||
produced = produce_body.next(10)
|
||||
produced = produce_body.next(11)
|
||||
assert_load( produced , Label)
|
||||
assert produced.constant.name.start_with?("continue_")
|
||||
end
|
||||
def test_function_call
|
||||
produced = produce_body.next(14)
|
||||
produced = produce_body.next(15)
|
||||
assert_equal FunctionCall , produced.class
|
||||
assert_equal :main , produced.method.name
|
||||
end
|
||||
def test_check_continue
|
||||
produced = produce_body.next(15)
|
||||
produced = produce_body.next(16)
|
||||
assert_equal Label , produced.class
|
||||
assert produced.name.start_with?("continue_") , produced.name
|
||||
end
|
||||
|
@ -11,7 +11,7 @@ module Mom
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
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
|
||||
|
@ -9,9 +9,10 @@ module Mom
|
||||
end
|
||||
def test_compile
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
assert_equal :div4 , @method.callable.name
|
||||
end
|
||||
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
|
||||
|
@ -11,7 +11,7 @@ module Mom
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
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
|
||||
|
@ -11,7 +11,7 @@ module Mom
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
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
|
||||
|
@ -11,7 +11,7 @@ module Mom
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
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
|
||||
|
@ -11,7 +11,7 @@ module Mom
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
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
|
||||
|
@ -13,6 +13,9 @@ module Mom
|
||||
def test_mom_length
|
||||
assert_equal 5 , @method.mom_instructions.length
|
||||
end
|
||||
def test_return
|
||||
assert_equal ReturnSequence , @method.mom_instructions.next(3).class
|
||||
end
|
||||
end
|
||||
class TestObjectSet < BootTest
|
||||
def setup
|
||||
@ -59,7 +62,7 @@ module Mom
|
||||
assert_equal Mom::MethodCompiler , @method.class
|
||||
end
|
||||
def test_mom_length
|
||||
assert_equal 5 , @method.mom_instructions.length
|
||||
assert_equal 2 , @method.mom_instructions.length
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -19,7 +19,7 @@ module Mom
|
||||
end
|
||||
def test_risc_length
|
||||
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
|
||||
|
@ -11,7 +11,7 @@ module Mom
|
||||
assert_equal Risc::MethodCompiler , @method.to_risc.class
|
||||
end
|
||||
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
|
||||
|
@ -7,17 +7,18 @@ module Risc
|
||||
def setup
|
||||
super
|
||||
@input = "@a.div4"
|
||||
@expect = [LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg, #4
|
||||
OperatorInstruction, IsZero, SlotToReg, SlotToReg, SlotToReg, #9
|
||||
LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg, #14
|
||||
SlotToReg, Label, LoadConstant, OperatorInstruction, IsZero, #19
|
||||
SlotToReg, OperatorInstruction, IsZero, SlotToReg, Branch, #24
|
||||
Label, LoadConstant, SlotToReg, Transfer, Syscall, #29
|
||||
Transfer, Transfer, SlotToReg, RegToSlot, Label, #34
|
||||
RegToSlot, Label, LoadConstant, SlotToReg, RegToSlot, #39
|
||||
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, #44
|
||||
SlotToReg, RegToSlot, SlotToReg, LoadConstant, SlotToReg, #49
|
||||
DynamicJump, Label, SlotToReg, RegToSlot, Branch,] #54
|
||||
@expect = [LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg, #5
|
||||
OperatorInstruction, IsZero, SlotToReg, SlotToReg, SlotToReg, #10
|
||||
LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg, #15
|
||||
SlotToReg, Label, LoadConstant, OperatorInstruction, IsZero, #20
|
||||
SlotToReg, OperatorInstruction, IsZero, SlotToReg, Branch, #25
|
||||
Label, LoadConstant, SlotToReg, Transfer, Syscall, #30
|
||||
Transfer, Transfer, SlotToReg, RegToSlot, Label, #35
|
||||
RegToSlot, Label, LoadConstant, SlotToReg, SlotToReg, #40
|
||||
RegToSlot, SlotToReg, SlotToReg, SlotToReg, RegToSlot, #45
|
||||
LoadConstant, SlotToReg, RegToSlot, SlotToReg, LoadConstant, #50
|
||||
SlotToReg, DynamicJump, Label, SlotToReg, RegToSlot, #55
|
||||
Branch,] #60
|
||||
end
|
||||
|
||||
def test_send_instructions
|
||||
@ -35,7 +36,7 @@ module Risc
|
||||
end
|
||||
def test_function_call
|
||||
produced = produce_body
|
||||
assert_equal DynamicJump , produced.next(50).class
|
||||
assert_equal DynamicJump , produced.next(51).class
|
||||
end
|
||||
def test_cache_check
|
||||
produced = produce_body
|
||||
|
@ -7,30 +7,30 @@ module Risc
|
||||
def setup
|
||||
super
|
||||
@input = "5.div4"
|
||||
@expect = [LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #4
|
||||
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #9
|
||||
Label, SlotToReg, RegToSlot, Branch,] #14
|
||||
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5
|
||||
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #10
|
||||
FunctionCall, Label, SlotToReg, RegToSlot, Branch,] #15
|
||||
end
|
||||
|
||||
def test_send_instructions
|
||||
assert_nil msg = check_nil , msg
|
||||
end
|
||||
def test_load_5
|
||||
produced = produce_body.next(2)
|
||||
produced = produce_body.next(3)
|
||||
assert_load( produced , Parfait::Integer)
|
||||
assert_equal 5 , produced.constant.value
|
||||
end
|
||||
def test_load_label
|
||||
produced = produce_body.next(5)
|
||||
produced = produce_body.next(6)
|
||||
assert_load( produced , Label)
|
||||
end
|
||||
def test_function_call
|
||||
produced = produce_body.next(9)
|
||||
produced = produce_body.next(10)
|
||||
assert_equal FunctionCall , produced.class
|
||||
assert_equal :div4 , produced.method.name
|
||||
end
|
||||
def test_check_continue
|
||||
produced = produce_body.next(10)
|
||||
produced = produce_body.next(11)
|
||||
assert_equal Label , produced.class
|
||||
assert produced.name.start_with?("continue_")
|
||||
end
|
||||
|
@ -7,10 +7,10 @@ module Risc
|
||||
def setup
|
||||
super
|
||||
@input = "5.get_internal_word(1)"
|
||||
@expect = [LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #4
|
||||
LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #9
|
||||
RegToSlot, SlotToReg, FunctionCall, Label, SlotToReg, #14
|
||||
RegToSlot, Branch,] #19
|
||||
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5
|
||||
RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant, #10
|
||||
SlotToReg, RegToSlot, SlotToReg, FunctionCall, Label, #15
|
||||
SlotToReg, RegToSlot, Branch,] #20
|
||||
end
|
||||
|
||||
def test_send_instructions
|
||||
@ -18,11 +18,11 @@ module Risc
|
||||
end
|
||||
def test_load_5
|
||||
produced = produce_body
|
||||
assert_equal LoadConstant , produced.next(2).class
|
||||
assert_equal 5 , produced.next(2).constant.value
|
||||
assert_equal LoadConstant , produced.next(3).class
|
||||
assert_equal 5 , produced.next(3).constant.value
|
||||
end
|
||||
def base
|
||||
5
|
||||
6
|
||||
end
|
||||
def test_load_arg_const
|
||||
produced = produce_body
|
||||
|
@ -7,9 +7,9 @@ module Risc
|
||||
def setup
|
||||
super
|
||||
@input = "return 5.div4"
|
||||
@expect = [LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #4
|
||||
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #9
|
||||
Label, SlotToReg, RegToSlot, Branch] #14
|
||||
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5
|
||||
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #10
|
||||
FunctionCall, Label, SlotToReg, RegToSlot, Branch,] #15
|
||||
@produced = produce_body
|
||||
end
|
||||
|
||||
@ -22,7 +22,7 @@ module Risc
|
||||
assert_equal :div4 , method.constant.name
|
||||
end
|
||||
def test_store_method_in_message
|
||||
sl = @produced.next( 1 )
|
||||
sl = @produced.next( 2 )
|
||||
assert_reg_to_slot( sl , :r1 , :r2 , 7 )
|
||||
end
|
||||
end
|
||||
|
@ -7,21 +7,21 @@ module Risc
|
||||
def setup
|
||||
super
|
||||
@input = "return 5.div4"
|
||||
@expect = [LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #4
|
||||
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #9
|
||||
Label, SlotToReg, RegToSlot, Branch,] #14
|
||||
@expect = [LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg, #5
|
||||
RegToSlot, LoadConstant, SlotToReg, RegToSlot, SlotToReg, #10
|
||||
FunctionCall, Label, SlotToReg, RegToSlot, Branch,] #15
|
||||
end
|
||||
|
||||
def test_return_instructions
|
||||
assert_nil msg = check_nil , msg
|
||||
end
|
||||
def test_function_return
|
||||
produced = produce_body.next(13)
|
||||
produced = produce_body.next(14)
|
||||
assert_equal Branch , produced.class
|
||||
assert_equal "return_label" , produced.label.name
|
||||
end
|
||||
def test_load_5
|
||||
produced = produce_body.next(2)
|
||||
produced = produce_body.next(3)
|
||||
assert_equal LoadConstant , produced.class
|
||||
assert_equal 5 , produced.constant.value
|
||||
end
|
||||
|
@ -7,17 +7,18 @@ module Risc
|
||||
def setup
|
||||
super
|
||||
@input = "return @a.div4"
|
||||
@expect =[LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg, #4
|
||||
OperatorInstruction, IsZero, SlotToReg, SlotToReg, SlotToReg, #9
|
||||
LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg, #14
|
||||
SlotToReg, Label, LoadConstant, OperatorInstruction, IsZero, #19
|
||||
SlotToReg, OperatorInstruction, IsZero, SlotToReg, Branch, #24
|
||||
Label, LoadConstant, SlotToReg, Transfer, Syscall, #29
|
||||
Transfer, Transfer, SlotToReg, RegToSlot, Label, #34
|
||||
RegToSlot, Label, LoadConstant, SlotToReg, RegToSlot, #39
|
||||
SlotToReg, SlotToReg, SlotToReg, RegToSlot, LoadConstant, #44
|
||||
SlotToReg, RegToSlot, SlotToReg, LoadConstant, SlotToReg, #49
|
||||
DynamicJump, Label, SlotToReg, RegToSlot, Branch,] #54
|
||||
@expect = [LoadConstant, SlotToReg, SlotToReg, SlotToReg, SlotToReg, #5
|
||||
OperatorInstruction, IsZero, SlotToReg, SlotToReg, SlotToReg, #10
|
||||
LoadConstant, RegToSlot, LoadConstant, LoadConstant, SlotToReg, #15
|
||||
SlotToReg, Label, LoadConstant, OperatorInstruction, IsZero, #20
|
||||
SlotToReg, OperatorInstruction, IsZero, SlotToReg, Branch, #25
|
||||
Label, LoadConstant, SlotToReg, Transfer, Syscall, #30
|
||||
Transfer, Transfer, SlotToReg, RegToSlot, Label, #35
|
||||
RegToSlot, Label, LoadConstant, SlotToReg, SlotToReg, #40
|
||||
RegToSlot, SlotToReg, SlotToReg, SlotToReg, RegToSlot, #45
|
||||
LoadConstant, SlotToReg, RegToSlot, SlotToReg, LoadConstant, #50
|
||||
SlotToReg, DynamicJump, Label, SlotToReg, RegToSlot, #55
|
||||
Branch,] #60
|
||||
end
|
||||
|
||||
def test_return_instructions
|
||||
@ -25,7 +26,7 @@ module Risc
|
||||
end
|
||||
def test_function_return
|
||||
produced = produce_body
|
||||
assert_equal Branch , produced.next(54).class
|
||||
assert_equal Branch , produced.next(55).class
|
||||
end
|
||||
def test_cache_check
|
||||
produced = produce_body
|
||||
|
@ -9,8 +9,8 @@ module Risc
|
||||
@input = "return 5.div4"
|
||||
@expect = "something"
|
||||
end
|
||||
def instruction(num) # 15 is the main, see length in support/risc_interpreter.rb main_at
|
||||
produce_main.next( 15 + num)
|
||||
def instruction(num) # 16 is the main, see length in support/risc_interpreter.rb main_at
|
||||
produce_main.next( 16 + num)
|
||||
end
|
||||
def test_postamble_classes
|
||||
postamble.each_with_index do |ins , index|
|
||||
|
@ -7,12 +7,13 @@ module Risc
|
||||
def setup
|
||||
super
|
||||
@input = "while(5 > 0) ; @a = true; end;return"
|
||||
@expect = [Label, LoadConstant, RegToSlot, LoadConstant, SlotToReg, #4
|
||||
RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant, #9
|
||||
SlotToReg, RegToSlot, SlotToReg, FunctionCall, Label, #14
|
||||
SlotToReg, LoadConstant, OperatorInstruction, IsZero, LoadConstant, #19
|
||||
OperatorInstruction, IsZero, LoadConstant, SlotToReg, RegToSlot, #24
|
||||
Branch, Label, LoadConstant, RegToSlot, Branch,] #29
|
||||
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant, #5
|
||||
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, #10
|
||||
LoadConstant, SlotToReg, RegToSlot, SlotToReg, FunctionCall, #15
|
||||
Label, SlotToReg, LoadConstant, OperatorInstruction, IsZero, #20
|
||||
LoadConstant, OperatorInstruction, IsZero, LoadConstant, SlotToReg, #25
|
||||
RegToSlot, Branch, Label, LoadConstant, RegToSlot, #30
|
||||
Branch,] #35
|
||||
end
|
||||
|
||||
def test_while_instructions
|
||||
@ -23,33 +24,33 @@ module Risc
|
||||
end
|
||||
def test_int_load_5
|
||||
produced = produce_body
|
||||
load = produced.next(3)
|
||||
load = produced.next(4)
|
||||
assert_equal Risc::LoadConstant , load.class
|
||||
assert_equal Parfait::Integer , load.constant.class
|
||||
assert_equal 5 , load.constant.value
|
||||
end
|
||||
def test_int_load_0
|
||||
produced = produce_body
|
||||
load = produced.next(6)
|
||||
load = produced.next(7)
|
||||
assert_equal Risc::LoadConstant , load.class
|
||||
assert_equal Parfait::Integer , load.constant.class
|
||||
assert_equal 0 , load.constant.value
|
||||
end
|
||||
def test_false_check
|
||||
produced = produce_body
|
||||
assert_equal Risc::IsZero , produced.next(18).class
|
||||
assert produced.next(18).label.name.start_with?("merge_label") , produced.next(18).label.name
|
||||
assert_equal Risc::IsZero , produced.next(19).class
|
||||
assert produced.next(19).label.name.start_with?("merge_label") , produced.next(19).label.name
|
||||
end
|
||||
def test_nil_load
|
||||
produced = produce_body
|
||||
assert_equal Risc::LoadConstant , produced.next(22).class
|
||||
assert_equal Parfait::TrueClass , produced.next(22).constant.class
|
||||
assert_equal Risc::LoadConstant , produced.next(23).class
|
||||
assert_equal Parfait::TrueClass , produced.next(23).constant.class
|
||||
end
|
||||
|
||||
def ttest_back_jump # should jump back to condition label
|
||||
def test_back_jump # should jump back to condition label
|
||||
produced = produce_body
|
||||
assert_equal Risc::Branch , produced.next(31).class
|
||||
assert_equal produced.name , produced.next(31).label.name
|
||||
assert_equal Risc::Branch , produced.next(26).class
|
||||
assert_equal produced.name , produced.next(26).label.name
|
||||
end
|
||||
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user