예제 #1
0
 public void TestReorderInstruction()
 {
     interpreter = reorderInterpreter;
     Assert.Equal("[[] R<int>[2 R<int>[3 5 +] +]]", Run("[[2 3 5 + +]]"));
     Assert.Equal("[[2 3 5 + +]]", ReorderInterpreter.ReorderPost(lastRun).ToRepr());
     Assert.Equal("[[] a R<int>[2 R<int>[3 5 +] +]]", Run("[[2 3 a 5 + +]]"));
     Assert.Equal("[[2 3 5 + + a]]", ReorderInterpreter.RunReorderPost(lastRun).ToRepr());
     Assert.Equal("[[] R<int>[3 5 +]]", Run("[[3 5 + +]]"));
     Assert.Equal("[[3 5 +]]", ReorderInterpreter.RunReorderPost(lastRun).ToRepr());
 }
예제 #2
0
        public void TestReorder()
        {
            interpreter = reorderInterpreter;
            var d0 = "[[2 a 1 +]]".ToStack();
            var d1 = interpreter.Eval(d0);

            Assert.Equal("[[a 1 +] 2]".ToStack(), d1);
            var d2 = interpreter.Eval(d1);

            Assert.Equal("[[1 +] a 2]".ToStack(), d2);
            var d3 = interpreter.Eval(d2);

            Assert.Equal("[[+] 1 a 2]".ToStack(), d3);
            var d4 = interpreter.Eval(d3);

            // Assert.Equal(interpreter.ParseWithResolution("[[+ a ] 1 2]"), d4);
            Assert.Equal("[[+ a] 1 2]", interpreter.StackToString(d4));
            // var d4b = "[[' reorder run] [[+ a ] 1 2] []]".ToStack();
            // var d4b = "[[reorder] [[+ a ] 1 2] []]".ToStack();
            // var d5 = interpreter.Eval(d4b);
            Assert.Equal("[[a] R<int>[2 1 +]]",
                         Eval("[[+ a ] 1 2]"));
            var e1 = interpreter.Eval("[[+ a ] 1 2]".ToStack());

            Assert.Equal("[[a] R<int>[2 1 +]]",
                         e1.ToRepr());
            var s = e1;

            Assert.Equal("[[a] R<int>[2 1 +]]",
                         s.ToRepr());
            var e2 = ReorderInterpreter.ReorderPost(s);

            Assert.Equal("[[2 1 + a]]",
                         e2.ToRepr());

            // R<T>[1,2,3] is not parsing properly.
            // Assert.Equal("[[] [[a] R<System.Int32> [2 1 +]]]",
            //              Eval("[[reorder-post] [[] a R<System.Int32> [2 1 +]]]"));

            // Assert.Equal("[[] [[a] R<System.Int32> [2 1 +]]]",
            //              Eval("[[reorder-post] [[a] R<System.Int32> [2 1 +]]]"));
            // var d6 = interpreter.Eval(d5);
            // Assert.Equal("[[2 1 +] [[] a]]".ToStack(), d6);
        }