2018-04-23 12:16:46 +02:00
|
|
|
require_relative "../helper"
|
2018-04-19 18:23:12 +02:00
|
|
|
|
|
|
|
module Risc
|
|
|
|
class InterpreterWhileSimle < MiniTest::Test
|
|
|
|
include Ticker
|
|
|
|
|
|
|
|
def setup
|
|
|
|
@string_input = as_main 'a = true; while( a ); a = false;end;return a'
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_if
|
|
|
|
#show_main_ticks # get output of what is in main
|
2018-05-24 20:20:56 +02:00
|
|
|
check_main_chain [LoadConstant, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
|
|
|
LoadConstant, OperatorInstruction, IsZero, LoadConstant, OperatorInstruction,
|
|
|
|
IsZero, LoadConstant, SlotToReg, RegToSlot, Branch,
|
2018-04-19 18:23:12 +02:00
|
|
|
SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero,
|
2018-05-24 20:20:56 +02:00
|
|
|
SlotToReg, SlotToReg, RegToSlot, SlotToReg, SlotToReg,
|
|
|
|
RegToSlot, SlotToReg, SlotToReg, FunctionReturn, Transfer,
|
|
|
|
Syscall, NilClass]
|
2018-04-19 18:23:12 +02:00
|
|
|
assert_kind_of Parfait::FalseClass , get_return
|
|
|
|
end
|
|
|
|
def test_load_false_const
|
2018-05-24 20:20:56 +02:00
|
|
|
load = main_ticks(1)
|
2018-04-19 18:23:12 +02:00
|
|
|
assert_equal LoadConstant , load.class
|
|
|
|
assert_kind_of Parfait::TrueClass , load.constant
|
|
|
|
end
|
2018-05-24 20:20:56 +02:00
|
|
|
def base
|
|
|
|
6
|
|
|
|
end
|
2018-04-19 18:23:12 +02:00
|
|
|
def test_load_false
|
2018-05-24 20:20:56 +02:00
|
|
|
load = main_ticks(base)
|
2018-04-19 18:23:12 +02:00
|
|
|
assert_equal LoadConstant , load.class
|
|
|
|
assert_equal Parfait::FalseClass , load.constant.class
|
|
|
|
end
|
|
|
|
def test_compare
|
2018-05-24 20:20:56 +02:00
|
|
|
op = main_ticks(base+1)
|
2018-04-19 18:23:12 +02:00
|
|
|
assert_equal OperatorInstruction , op.class
|
|
|
|
assert_equal :- , op.operator
|
|
|
|
end
|
|
|
|
def test_not_zero
|
2018-05-24 20:20:56 +02:00
|
|
|
check = main_ticks(base + 2)
|
2018-04-19 18:23:12 +02:00
|
|
|
assert_equal IsZero , check.class
|
|
|
|
assert check.label.name.start_with?("merge_label") , check.label.name
|
|
|
|
end
|
|
|
|
def test_compare2
|
2018-05-24 20:20:56 +02:00
|
|
|
op = main_ticks(base + 4)
|
2018-04-19 18:23:12 +02:00
|
|
|
assert_equal OperatorInstruction , op.class
|
|
|
|
assert_equal :- , op.operator
|
|
|
|
end
|
|
|
|
def test_not_zero2
|
2018-05-24 20:20:56 +02:00
|
|
|
check = main_ticks(base + 5)
|
2018-04-19 18:23:12 +02:00
|
|
|
assert_equal IsZero , check.class
|
|
|
|
assert check.label.name.start_with?("merge_label") , check.label.name
|
|
|
|
end
|
|
|
|
def test_exit
|
2018-05-24 20:20:56 +02:00
|
|
|
done = main_ticks(31)
|
2018-04-19 18:23:12 +02:00
|
|
|
assert_equal Syscall , done.class
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|