implement assignment type check

This commit is contained in:
Torsten Ruger
2016-12-28 19:20:16 +02:00
parent 9cf56b3aa6
commit af31774074
3 changed files with 33 additions and 30 deletions

View File

@ -52,7 +52,7 @@ class TestAssignStatement < MiniTest::Test
assert_equal 1 + 1, get.index , "Get to named_list index must be offset, not #{get.index}"
end
def test_assign_int
def test_assign_local_int
Register.machine.space.get_main.add_local(:r , :Integer)
@input = s(:statements, s(:assignment, s(:name, :r), s(:int, 5)) )
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
@ -62,6 +62,13 @@ class TestAssignStatement < MiniTest::Test
assert_equal 1 + 1, set.index , "Set to named_list index must be offset, not #{set.index}"
end
def test_misassign_local
Register.machine.space.get_main.add_local(:r , :Integer)
@input = s(:statements, s(:assignment, s(:name, :r), s(:string, "5")) )
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
assert_raises {check }
end
def test_assign_arg
Register.machine.space.get_main.add_argument(:blar , :Integer)
@input = s(:statements, s(:assignment, s(:name, :blar), s(:int, 5)))
@ -72,6 +79,13 @@ class TestAssignStatement < MiniTest::Test
assert_equal 1 + 1, set.index , "Set to args index must be offset, not #{set.index}"
end
def test_misassign_arg
Register.machine.space.get_main.add_argument(:blar , :Integer)
@input = s(:statements, s(:assignment, s(:name, :blar), s(:string, "5")))
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
assert_raises {check }
end
def test_arg_get
# have to define bar externally, just because redefining main. Otherwise that would be automatic
Register.machine.space.get_main.add_argument(:balr , :Integer)