2020-03-27 19:04:10 +02:00
|
|
|
require_relative "helper"
|
2018-04-19 19:23:12 +03:00
|
|
|
|
|
|
|
module Risc
|
2019-09-18 13:10:55 +03:00
|
|
|
class InterpreterWhileSimple < MiniTest::Test
|
2018-04-19 19:23:12 +03:00
|
|
|
include Ticker
|
|
|
|
|
|
|
|
def setup
|
|
|
|
@string_input = as_main 'a = true; while( a ); a = false;end;return a'
|
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2018-08-06 14:07:17 +03:00
|
|
|
def test_while
|
2018-04-19 19:23:12 +03:00
|
|
|
#show_main_ticks # get output of what is in main
|
2019-08-23 15:31:22 +03:00
|
|
|
check_main_chain [LoadConstant, RegToSlot, SlotToReg, LoadConstant, OperatorInstruction, #5
|
|
|
|
IsZero, LoadConstant, OperatorInstruction, IsZero, LoadConstant, #10
|
|
|
|
RegToSlot, Branch, SlotToReg, LoadConstant, OperatorInstruction, #15
|
|
|
|
IsZero, SlotToReg, RegToSlot, Branch, SlotToReg, #20
|
2020-03-17 11:18:51 +02:00
|
|
|
SlotToReg, RegToSlot, SlotToReg, SlotToReg, FunctionReturn, #25
|
|
|
|
Transfer, SlotToReg, SlotToReg, Transfer, Syscall, #30
|
2019-08-23 15:31:22 +03:00
|
|
|
NilClass,] #35
|
2020-03-22 10:42:50 +02:00
|
|
|
assert_kind_of Parfait::NilClass , get_return
|
2018-04-19 19:23:12 +03:00
|
|
|
end
|
|
|
|
def test_load_false_const
|
2018-05-24 21:20:56 +03:00
|
|
|
load = main_ticks(1)
|
2018-04-19 19:23:12 +03:00
|
|
|
assert_equal LoadConstant , load.class
|
|
|
|
assert_kind_of Parfait::TrueClass , load.constant
|
|
|
|
end
|
2018-05-24 21:20:56 +03:00
|
|
|
def base
|
2019-08-23 10:20:39 +03:00
|
|
|
4
|
2018-05-24 21:20:56 +03:00
|
|
|
end
|
2018-04-19 19:23:12 +03:00
|
|
|
def test_load_false
|
2018-05-24 21:20:56 +03:00
|
|
|
load = main_ticks(base)
|
2018-04-19 19:23:12 +03:00
|
|
|
assert_equal LoadConstant , load.class
|
|
|
|
assert_equal Parfait::FalseClass , load.constant.class
|
|
|
|
end
|
|
|
|
def test_compare
|
2018-05-24 21:20:56 +03:00
|
|
|
op = main_ticks(base+1)
|
2018-04-19 19:23:12 +03:00
|
|
|
assert_equal OperatorInstruction , op.class
|
|
|
|
assert_equal :- , op.operator
|
|
|
|
end
|
|
|
|
def test_not_zero
|
2018-05-24 21:20:56 +03:00
|
|
|
check = main_ticks(base + 2)
|
2018-04-19 19:23:12 +03:00
|
|
|
assert_equal IsZero , check.class
|
|
|
|
assert check.label.name.start_with?("merge_label") , check.label.name
|
|
|
|
end
|
2019-08-23 10:20:39 +03:00
|
|
|
def test_load_false
|
|
|
|
load = main_ticks(base+3)
|
|
|
|
assert_equal LoadConstant , load.class
|
|
|
|
assert_equal Parfait::NilClass , load.constant.class
|
|
|
|
end
|
2018-04-19 19:23:12 +03:00
|
|
|
def test_compare2
|
2018-05-24 21:20:56 +03:00
|
|
|
op = main_ticks(base + 4)
|
2018-04-19 19:23:12 +03:00
|
|
|
assert_equal OperatorInstruction , op.class
|
|
|
|
assert_equal :- , op.operator
|
|
|
|
end
|
|
|
|
def test_not_zero2
|
2018-05-24 21:20:56 +03:00
|
|
|
check = main_ticks(base + 5)
|
2018-04-19 19:23:12 +03:00
|
|
|
assert_equal IsZero , check.class
|
|
|
|
assert check.label.name.start_with?("merge_label") , check.label.name
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|