rubyx/test/vm/method_compiler/test_while_statement.rb

44 lines
2.0 KiB
Ruby
Raw Normal View History

2015-10-16 12:17:02 +02:00
require_relative 'helper'
module Register
2016-12-10 21:42:02 +01:00
class TestWhile < MiniTest::Test
2015-10-16 12:17:02 +02:00
include Statements
def test_while_mini
2016-12-10 22:07:04 +01:00
@input = s(:statements, s(:while_statement, :plus, s(:conditional, s(:int, 1)), s(:statements, s(:return, s(:int, 3)))))
2016-12-10 21:42:02 +01:00
@expect = [Label, Branch, Label, LoadConstant, RegToSlot, Label ,
LoadConstant, IsPlus, LoadConstant, SlotToReg, RegToSlot, Label ,
FunctionReturn]
assert_nil msg = check_nil , msg
2015-10-16 12:17:02 +02:00
end
def test_while_assign
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)))
2016-12-10 21:42:02 +01:00
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Branch, Label ,
SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, SlotToReg, RegToSlot ,
Label, SlotToReg, SlotToReg, IsPlus, SlotToReg, SlotToReg ,
RegToSlot, LoadConstant, SlotToReg, RegToSlot, Label, FunctionReturn]
assert_nil msg = check_nil , msg
2015-10-16 12:17:02 +02:00
end
def test_while_return
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)))))
2016-12-10 21:42:02 +01:00
@expect = [Label, LoadConstant, SlotToReg, RegToSlot, Branch, Label ,
SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, SlotToReg, RegToSlot ,
SlotToReg, SlotToReg, RegToSlot, Label, SlotToReg, SlotToReg ,
LoadConstant, OperatorInstruction, IsPlus, LoadConstant, SlotToReg, RegToSlot ,
Label, FunctionReturn]
assert_nil msg = check_nil , msg
2015-10-16 12:17:02 +02:00
end
end
end