2015-10-16 12:17:02 +02:00
|
|
|
require_relative 'helper'
|
|
|
|
|
|
|
|
module Register
|
|
|
|
class TestWhile < MiniTest::Test
|
|
|
|
include Statements
|
|
|
|
|
|
|
|
|
|
|
|
def test_while_mini
|
|
|
|
@string_input = <<HERE
|
|
|
|
class Object
|
|
|
|
int main()
|
2015-10-19 14:31:48 +02:00
|
|
|
while_plus(1)
|
2015-10-16 12:17:02 +02:00
|
|
|
return 3
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
HERE
|
2015-10-19 15:08:00 +02:00
|
|
|
@expect = [[SaveReturn],[LoadConstant,IsZero,LoadConstant,Branch],
|
2015-10-18 16:32:32 +02:00
|
|
|
[],[RegisterTransfer,GetSlot,FunctionReturn]]
|
2015-10-16 12:17:02 +02:00
|
|
|
check
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_while_assign
|
|
|
|
@string_input = <<HERE
|
|
|
|
class Object
|
|
|
|
int main()
|
|
|
|
int n = 5
|
2015-10-19 14:31:48 +02:00
|
|
|
while_minus(n > 0)
|
2015-10-16 12:17:02 +02:00
|
|
|
n = n - 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
HERE
|
2015-10-18 16:39:35 +02:00
|
|
|
@expect = [[SaveReturn,LoadConstant,GetSlot,SetSlot],[GetSlot,GetSlot,LoadConstant,OperatorInstruction,
|
2015-10-19 15:08:00 +02:00
|
|
|
IsZero,GetSlot,GetSlot,LoadConstant,OperatorInstruction,GetSlot,SetSlot,Branch],
|
2015-10-18 16:32:32 +02:00
|
|
|
[],[RegisterTransfer,GetSlot,FunctionReturn]]
|
2015-10-16 12:17:02 +02:00
|
|
|
check
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def test_while_return
|
|
|
|
@string_input = <<HERE
|
|
|
|
class Object
|
|
|
|
int main()
|
|
|
|
int n = 10
|
2015-10-19 14:31:48 +02:00
|
|
|
while_notzero( n > 5)
|
2015-10-16 12:17:02 +02:00
|
|
|
n = n + 1
|
|
|
|
return n
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
HERE
|
2015-10-18 16:39:35 +02:00
|
|
|
@expect = [[SaveReturn,LoadConstant,GetSlot,SetSlot],
|
2015-10-19 15:08:00 +02:00
|
|
|
[GetSlot,GetSlot,LoadConstant,OperatorInstruction,IsZero,GetSlot,
|
2015-10-18 16:20:19 +02:00
|
|
|
GetSlot,LoadConstant,OperatorInstruction,GetSlot,SetSlot,GetSlot,
|
2015-10-19 15:08:00 +02:00
|
|
|
GetSlot,Branch] ,
|
2015-10-18 16:32:32 +02:00
|
|
|
[],[RegisterTransfer,GetSlot,FunctionReturn]]
|
2015-10-16 12:17:02 +02:00
|
|
|
check
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|