fixing tests for assignment split

This commit is contained in:
Torsten Ruger 2017-01-15 13:01:44 +02:00
parent f9824079d6
commit 8b364eb566
6 changed files with 26 additions and 18 deletions

View File

@ -7,7 +7,7 @@ module Register
def test_assign_op def test_assign_op
Parfait.object_space.get_main.add_local(:r , :Integer) Parfait.object_space.get_main.add_local(:r , :Integer)
@input = s(:statements, s(:assignment, s(:name, :r), s(:operator_value, :+, s(:int, 10), s(:int, 1)))) @input = s(:statements, s(:l_assignment, s(:name, :r), s(:operator_value, :+, s(:int, 10), s(:int, 1))))
@expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, SlotToReg, RegToSlot , @expect = [Label, LoadConstant, LoadConstant, OperatorInstruction, SlotToReg, RegToSlot ,
LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn] LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
@ -16,7 +16,7 @@ module Register
def test_assign_local def test_assign_local
Parfait.object_space.get_main.add_local(:r , :Integer) Parfait.object_space.get_main.add_local(:r , :Integer)
@input =s(:statements, s(:assignment, s(:name, :r), s(:int, 5))) @input =s(:statements, s(:l_assignment, s(:name, :r), s(:int, 5)))
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg , @expect = [Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg ,
RegToSlot, Label, FunctionReturn] RegToSlot, Label, FunctionReturn]
@ -26,7 +26,7 @@ module Register
def test_assign_local_assign def test_assign_local_assign
Parfait.object_space.get_main.add_local(:r , :Integer) Parfait.object_space.get_main.add_local(:r , :Integer)
@input = s(:statements, s(:assignment, s(:name, :r), s(:int, 5))) @input = s(:statements, s(:l_assignment, s(:name, :r), s(:int, 5)))
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg , @expect = [Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg ,
RegToSlot, Label, FunctionReturn] RegToSlot, Label, FunctionReturn]
@ -35,7 +35,7 @@ module Register
def test_assign_call def test_assign_call
Parfait.object_space.get_main.add_local(:r , :Integer) Parfait.object_space.get_main.add_local(:r , :Integer)
@input = s(:statements, s(:assignment, s(:name, :r), s(:call, s(:name, :main), s(:arguments)))) @input = s(:statements, s(:l_assignment, s(:name, :r), s(:call, s(:name, :main), s(:arguments))))
@expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot , @expect = [Label, SlotToReg, SlotToReg, RegToSlot, LoadConstant, RegToSlot ,
LoadConstant, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer , LoadConstant, SlotToReg, RegToSlot, LoadConstant, RegToSlot, RegisterTransfer ,
FunctionCall, Label, RegisterTransfer, SlotToReg, SlotToReg, SlotToReg , FunctionCall, Label, RegisterTransfer, SlotToReg, SlotToReg, SlotToReg ,
@ -45,7 +45,7 @@ module Register
def test_named_list_get def test_named_list_get
Parfait.object_space.get_main.add_local(:r , :Integer) Parfait.object_space.get_main.add_local(:r , :Integer)
@input = s(:statements, s(:assignment, s(:name, :r), s(:int, 5)), s(:return, s(:name, :r))) @input = s(:statements, s(:l_assignment, s(:name, :r), s(:int, 5)), s(:return, s(:name, :r)))
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg , @expect = [Label, LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg ,
RegToSlot, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn] RegToSlot, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
was = check_return was = check_return
@ -56,7 +56,7 @@ module Register
def test_assign_local_int def test_assign_local_int
Parfait.object_space.get_main.add_local(:r , :Integer) Parfait.object_space.get_main.add_local(:r , :Integer)
@input = s(:statements, s(:assignment, s(:name, :r), s(:int, 5)) ) @input = s(:statements, s(:l_assignment, s(:name, :r), s(:int, 5)) )
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg , @expect = [Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg ,
RegToSlot, Label, FunctionReturn] RegToSlot, Label, FunctionReturn]
was = check_return was = check_return
@ -67,14 +67,14 @@ module Register
def test_misassign_local def test_misassign_local
Parfait.object_space.get_main.add_local(:r , :Integer) Parfait.object_space.get_main.add_local(:r , :Integer)
@input = s(:statements, s(:assignment, s(:name, :r), s(:string, "5")) ) @input = s(:statements, s(:l_assignment, s(:name, :r), s(:string, "5")) )
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn] @expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
assert_raises {check } assert_raises {check }
end end
def test_assign_arg def test_assign_arg
Parfait.object_space.get_main.add_argument(:blar , :Integer) Parfait.object_space.get_main.add_argument(:blar , :Integer)
@input = s(:statements, s(:assignment, s(:name, :blar), s(:int, 5))) @input = s(:statements, s(:a_assignment, s(:name, :blar), s(:int, 5)))
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg , @expect = [Label, LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg ,
RegToSlot, Label, FunctionReturn] RegToSlot, Label, FunctionReturn]
was = check_return was = check_return
@ -85,7 +85,7 @@ module Register
def test_misassign_arg def test_misassign_arg
Parfait.object_space.get_main.add_argument(:blar , :Integer) Parfait.object_space.get_main.add_argument(:blar , :Integer)
@input = s(:statements, s(:assignment, s(:name, :blar), s(:string, "5"))) @input = s(:statements, s(:a_assignment, s(:name, :blar), s(:string, "5")))
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn] @expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
assert_raises {check } assert_raises {check }
end end

View File

@ -30,7 +30,7 @@ module Register
def test_call_local_int def test_call_local_int
Parfait.object_space.get_main.add_local(:testi , :Integer) Parfait.object_space.get_main.add_local(:testi , :Integer)
clean_compile :Integer, :putint, {}, s(:statements, s(:return, s(:int, 1))) clean_compile :Integer, :putint, {}, s(:statements, s(:return, s(:int, 1)))
@input = s(:statements, s(:assignment, s(:name, :testi), s(:int, 20)), s(:call, s(:name, :putint), s(:arguments), s(:receiver, s(:name, :testi)))) @input = s(:statements, s(:l_assignment, s(:name, :testi), s(:int, 20)), s(:call, s(:name, :putint), s(:arguments), s(:receiver, s(:name, :testi))))
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg , @expect = [Label, LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg, SlotToReg ,
RegToSlot, LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant , RegToSlot, LoadConstant, RegToSlot, LoadConstant, SlotToReg, RegToSlot, LoadConstant ,

View File

@ -31,7 +31,7 @@ module Register
def test_message_field def test_message_field
Parfait.object_space.get_main.add_local(:name , :Word) Parfait.object_space.get_main.add_local(:name , :Word)
@input = s(:statements, s(:assignment, s(:name, :name), s(:field_access, s(:receiver, s(:name, :message)), s(:field, s(:name, :name)))), s(:return, s(:name, :name))) @input = s(:statements, s(:l_assignment, s(:name, :name), s(:field_access, s(:receiver, s(:name, :message)), s(:field, s(:name, :name)))), s(:return, s(:name, :name)))
@expect = [Label, RegisterTransfer, SlotToReg, SlotToReg, RegToSlot, SlotToReg , @expect = [Label, RegisterTransfer, SlotToReg, SlotToReg, RegToSlot, SlotToReg ,
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, Label , SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot, Label ,

View File

@ -21,7 +21,7 @@ module Register
def test_return_local_assign def test_return_local_assign
Parfait.object_space.get_main.add_local(:runner , :Integer) Parfait.object_space.get_main.add_local(:runner , :Integer)
@input = s(:statements, s(:assignment, s(:name, :runner), s(:int, 5)), s(:return, s(:name, :runner))) @input = s(:statements, s(:l_assignment, s(:name, :runner), s(:int, 5)), s(:return, s(:name, :runner)))
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg , @expect = [Label, LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg ,
RegToSlot, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn] RegToSlot, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
assert_nil msg = check_nil , msg assert_nil msg = check_nil , msg
@ -38,7 +38,7 @@ module Register
def pest_return_space_length # need to add runtime first def pest_return_space_length # need to add runtime first
Parfait.object_space.get_main.add_local(:l , :Type) Parfait.object_space.get_main.add_local(:l , :Type)
@input = s(:statements, s(:assignment, s(:name, :l), s(:call, s(:name, :get_type), s(:arguments), s(:receiver, s(:name, :space)))), s(:return, s(:field_access, s(:receiver, s(:name, :self)), s(:field, s(:name, :runner))))) @input = s(:statements, s(:l_assignment, s(:name, :l), s(:call, s(:name, :get_type), s(:arguments), s(:receiver, s(:name, :space)))), s(:return, s(:field_access, s(:receiver, s(:name, :self)), s(:field, s(:name, :runner)))))
@expect = [Label, SlotToReg,SlotToReg ,RegToSlot,Label,FunctionReturn] @expect = [Label, SlotToReg,SlotToReg ,RegToSlot,Label,FunctionReturn]
assert_nil msg = check_nil , msg assert_nil msg = check_nil , msg
end end

View File

@ -17,7 +17,7 @@ module Register
def test_while_assign def test_while_assign
Parfait.object_space.get_main.add_local(:n , :Integer) Parfait.object_space.get_main.add_local(:n , :Integer)
@input = s(:statements, s(:assignment, s(:name, :n), s(:int, 5)), s(:while_statement, :plus, s(:conditional, s(:name, :n)), s(:statements, s(:assignment, s(:name, :n), s(:operator_value, :-, s(:name, :n), s(:int, 1))))), s(:return, s(:name, :n))) @input = s(:statements, s(:l_assignment, s(:name, :n), s(:int, 5)), s(:while_statement, :plus, s(:conditional, s(:name, :n)), s(:statements, s(:l_assignment, s(:name, :n), s(:operator_value, :-, s(:name, :n), s(:int, 1))))), s(:return, s(:name, :n)))
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Branch, Label , @expect = [Label, LoadConstant, SlotToReg, RegToSlot, Branch, Label ,
SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, SlotToReg, RegToSlot , SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, SlotToReg, RegToSlot ,
@ -30,7 +30,7 @@ module Register
def test_while_return def test_while_return
Parfait.object_space.get_main.add_local(:n , :Integer) Parfait.object_space.get_main.add_local(:n , :Integer)
@input = s(:statements, s(:assignment, s(:name, :n), s(:int, 10)), s(:while_statement, :plus, s(:conditional, s(:operator_value, :-, s(:name, :n), s(:int, 5))), s(:statements, s(:assignment, s(:name, :n), s(:operator_value, :+, s(:name, :n), s(:int, 1))), s(:return, s(:name, :n))))) @input = s(:statements, s(:l_assignment, s(:name, :n), s(:int, 10)), s(:while_statement, :plus, s(:conditional, s(:operator_value, :-, s(:name, :n), s(:int, 5))), s(:statements, s(:l_assignment, s(:name, :n), s(:operator_value, :+, s(:name, :n), s(:int, 1))), s(:return, s(:name, :n)))))
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Branch, Label , @expect = [Label, LoadConstant, SlotToReg, RegToSlot, Branch, Label ,
SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, SlotToReg, RegToSlot , SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, SlotToReg, RegToSlot ,

View File

@ -16,9 +16,17 @@ class ToCodeTest < MiniTest::Test
@statement = s(:while_statement, :false, s(:conditional,s(:int, 1)), s(:statements)) @statement = s(:while_statement, :false, s(:conditional,s(:int, 1)), s(:statements))
check "WhileStatement" check "WhileStatement"
end end
def test_assignment def test_l_assignment
@statement = s(:assignment, s(:name, :i), s(:int, 0)) @statement = s(:l_assignment, s(:name, :i), s(:int, 0))
check "Assignment" check "LocalAssignment"
end
def test_a_assignment
@statement = s(:a_assignment, s(:name, :i), s(:int, 0))
check "ArgAssignment"
end
def test_i_assignment
@statement = s(:i_assignment, s(:name, :i), s(:int, 0))
check "IvarAssignment"
end end
def test_nil def test_nil
@statement = s(:nil) @statement = s(:nil)