2018-04-20 09:27:06 +02:00
|
|
|
require_relative "helper"
|
|
|
|
|
|
|
|
module Risc
|
|
|
|
class TestWhileCmp < MiniTest::Test
|
|
|
|
include Statements
|
|
|
|
|
|
|
|
def setup
|
|
|
|
super
|
|
|
|
@input = "while(5 > 0) ; @a = true; end"
|
|
|
|
@expect = [Label, LoadConstant, LoadConstant, SlotToReg, RegToSlot,
|
|
|
|
RegToSlot, SlotToReg, SlotToReg, RegToSlot, SlotToReg,
|
2018-07-22 21:29:32 +02:00
|
|
|
SlotToReg, RegToSlot, RegToSlot, SlotToReg, RegToSlot,
|
|
|
|
LoadConstant, SlotToReg, RegToSlot, LoadConstant, SlotToReg,
|
|
|
|
SlotToReg, RegToSlot, LoadConstant, SlotToReg, RegToSlot,
|
|
|
|
SlotToReg, FunctionCall, Label, SlotToReg, SlotToReg,
|
|
|
|
RegToSlot, SlotToReg, SlotToReg, LoadConstant, OperatorInstruction,
|
|
|
|
IsZero, LoadConstant, OperatorInstruction, IsZero, LoadConstant,
|
|
|
|
SlotToReg, RegToSlot, Branch, Label]
|
2018-04-20 09:27:06 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_while_instructions
|
|
|
|
assert_nil msg = check_nil , msg
|
|
|
|
end
|
|
|
|
def test_label
|
|
|
|
assert_equal Risc::Label , produce_body.class
|
|
|
|
end
|
|
|
|
def test_int_load_5
|
|
|
|
produced = produce_body
|
2018-07-22 21:29:32 +02:00
|
|
|
load = produced.next(15)
|
2018-04-20 09:27:06 +02:00
|
|
|
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
|
2018-07-22 21:29:32 +02:00
|
|
|
load = produced.next(18)
|
2018-04-20 09:27:06 +02:00
|
|
|
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
|
2018-07-22 21:29:32 +02:00
|
|
|
assert_equal Risc::IsZero , produced.next(35).class
|
|
|
|
assert produced.next(35).label.name.start_with?("merge_label") , produced.next(35).label.name
|
2018-04-20 09:27:06 +02:00
|
|
|
end
|
|
|
|
def test_nil_load
|
|
|
|
produced = produce_body
|
2018-07-22 21:29:32 +02:00
|
|
|
assert_equal Risc::LoadConstant , produced.next(36).class
|
|
|
|
assert_equal Parfait::NilClass , produced.next(36).constant.class
|
2018-04-20 09:27:06 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_back_jump # should jump back to condition label
|
|
|
|
produced = produce_body
|
2018-07-22 21:29:32 +02:00
|
|
|
assert_equal Risc::Branch , produced.next(42).class
|
|
|
|
assert_equal produced , produced.next(42).label
|
2018-04-20 09:27:06 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|