From 13d8a65e070f80183a45ae4c1fcd9ff59c8dedcf Mon Sep 17 00:00:00 2001 From: Torsten Ruger Date: Thu, 19 Apr 2018 19:23:12 +0300 Subject: [PATCH] add while interpreter test --- lib/vool/statements/basic_values.rb | 9 +++ test/mom/assign/test_assign_local_false.rb | 33 +++++++++++ ...ocal_const.rb => test_assign_local_int.rb} | 2 +- test/risc/interpreter/test_while_simple.rb | 59 +++++++++++++++++++ 4 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 test/mom/assign/test_assign_local_false.rb rename test/mom/assign/{test_assign_local_const.rb => test_assign_local_int.rb} (94%) create mode 100644 test/risc/interpreter/test_while_simple.rb diff --git a/lib/vool/statements/basic_values.rb b/lib/vool/statements/basic_values.rb index 7b04a60e..c8e16654 100644 --- a/lib/vool/statements/basic_values.rb +++ b/lib/vool/statements/basic_values.rb @@ -33,16 +33,25 @@ module Vool def ct_type Parfait.object_space.get_class_by_name(:True).instance_type end + def slot_definition(method) + return Mom::SlotDefinition.new(Parfait.object_space.true_object , []) + end end class FalseConstant < Constant def ct_type Parfait.object_space.get_class_by_name(:False).instance_type end + def slot_definition(method) + return Mom::SlotDefinition.new(Parfait.object_space.false_object , []) + end end class NilConstant < Constant def ct_type Parfait.object_space.get_class_by_name(:Nil).instance_type end + def slot_definition(method) + return Mom::SlotDefinition.new(Parfait.object_space.nil_object , []) + end end class SelfExpression < Expression attr_reader :my_type diff --git a/test/mom/assign/test_assign_local_false.rb b/test/mom/assign/test_assign_local_false.rb new file mode 100644 index 00000000..5908f71b --- /dev/null +++ b/test/mom/assign/test_assign_local_false.rb @@ -0,0 +1,33 @@ +require_relative '../helper' + +module Risc + class TestAssignLocalFalse < MiniTest::Test + include Statements + + def setup + super + @input = "r = false" + @expect = [LoadConstant,SlotToReg, RegToSlot] + end + def test_local_assign_instructions + assert_nil msg = check_nil , msg + end + + def test_constant_load + produced = produce_body + assert_equal Parfait::FalseClass , produced.constant.class + end + + def test_frame_load + produced = produce_body + assert_equal :Message , produced.next(1).array.type + assert_equal 4 , produced.next(1).index # 4 is frame + end + def test_value_load + produced = produce_body + assert_equal produced.next(2).register , produced.register + assert_equal 2 , produced.next(2).index #type == 1 , r == 2 + end + + end +end diff --git a/test/mom/assign/test_assign_local_const.rb b/test/mom/assign/test_assign_local_int.rb similarity index 94% rename from test/mom/assign/test_assign_local_const.rb rename to test/mom/assign/test_assign_local_int.rb index 77229702..8c6cd83f 100644 --- a/test/mom/assign/test_assign_local_const.rb +++ b/test/mom/assign/test_assign_local_int.rb @@ -1,7 +1,7 @@ require_relative '../helper' module Risc - class TestAssignLocalConst < MiniTest::Test + class TestAssignLocalInt < MiniTest::Test include Statements def setup diff --git a/test/risc/interpreter/test_while_simple.rb b/test/risc/interpreter/test_while_simple.rb new file mode 100644 index 00000000..0aac3cfe --- /dev/null +++ b/test/risc/interpreter/test_while_simple.rb @@ -0,0 +1,59 @@ +require_relative "helper" + +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 + check_main_chain [Label, LoadConstant, SlotToReg, RegToSlot, Label, + SlotToReg, SlotToReg, LoadConstant, OperatorInstruction, IsZero, + LoadConstant, OperatorInstruction, IsZero, LoadConstant, SlotToReg, + RegToSlot, Branch, Label, SlotToReg, SlotToReg, + LoadConstant, OperatorInstruction, IsZero, Label, SlotToReg, + SlotToReg, RegToSlot, SlotToReg, SlotToReg, RegToSlot, + SlotToReg, SlotToReg, FunctionReturn, Transfer, Syscall, + NilClass] + assert_kind_of Parfait::FalseClass , get_return + end + def test_load_false_const + load = main_ticks(2) + assert_equal LoadConstant , load.class + assert_kind_of Parfait::TrueClass , load.constant + end + def test_load_false + load = main_ticks(8) + assert_equal LoadConstant , load.class + assert_equal Parfait::FalseClass , load.constant.class + end + def test_compare + op = main_ticks(9) + assert_equal OperatorInstruction , op.class + assert_equal :- , op.operator + end + def test_not_zero + check = main_ticks(10) + assert_equal IsZero , check.class + assert check.label.name.start_with?("merge_label") , check.label.name + end + def test_compare2 + op = main_ticks(12) + assert_equal OperatorInstruction , op.class + assert_equal :- , op.operator + end + def test_not_zero2 + check = main_ticks(13) + assert_equal IsZero , check.class + assert check.label.name.start_with?("merge_label") , check.label.name + end + def test_exit + done = main_ticks(35) + assert_equal Syscall , done.class + end + end +end