Exemple #1
0
        public string ReorderPost(string code)
        {
            var d0 = code.ToStack();
            var d1 = ReorderInterpreter.RunReorderPost(d0);

            return(interpreter.StackToString(d1));
        }
Exemple #2
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());
 }
        public void testLotsOfReordering()
        {
            Assert.Equal("[[] d c b a 10]", Run("[[2 a 3 b c 5 + d +]]"));

            Stack s1, s2;

            // Assert.Equal("[[] d c b a R[2 R[3 5 +] +]]", (s1 = interpreter.RunReorderPre("[[2 a 3 b c 5 + d +]]".ToStack())).ToRepr());
            Assert.Equal("[[] d c b a R<int>[2 R<int>[3 5 +] +]]", (s1 = reorderInterpreter.Run("[[2 a 3 b c 5 + d +]]".ToStack())).ToRepr());

            Assert.Equal("[[2 3 5 + + a b c d]]", (s2 = ReorderInterpreter.RunReorderPost(s1)).ToRepr());
            Assert.Equal("[[] d c b a 10]", strictInterpreter.Run(s2).ToRepr());
        }
        public void TestReorderWithAssignment()
        {
            Assert.Equal("[[] 3]", Run("[[1 x 2 ! x +]]"));
            var s = new Stack(new object[] { new Defer("[x 2 !]".ToStack(), typeof(void)),
                                             new Defer("[1 x +]".ToStack(), typeof(int)), new Stack() });

            Assert.Equal("[[] R<int>[1 x +] R<Void>[x 2 !]]", s.ToRepr());
            Assert.Equal("[[x 2 ! 1 x +]]", ReorderInterpreter.RunReorderPost(s).ToRepr());
            Assert.Equal("[[] R<int>[1 R<int>[x] +] R<Void>[x 2 !]]", ReorderPre("[[1 x 2 ! x +]]"));
            reorderInterpreter.instructions.Remove("x");
            Assert.Equal("[[x 2 ! 1 x +]]", Reorder("[[1 x 2 ! x +]]"));
            interpreter.instructions.Remove("x");
            Assert.Equal("[[] x 1]", Run("[[1 x + x 2 !]]"));
            interpreter.instructions.Remove("x");
            Assert.Equal("[[] 2 1]", Run("[[1 x 2 ! x]]"));
        }
        public void TestReorderBugFoundInWild()
        {
            interpreter = reorderInterpreter;
            Assert.Equal("[[]]", Run("[[dup]]"));
            Assert.Equal("[[]]", Run("[[pop]]"));
            // Assert.Equal("[[] R[-3 pop]]", Run("[[-3 pop]]"));
            Assert.Equal("[[] R<Void>[-3 pop]]", Run("[[-3 pop]]"));
            Assert.Equal("[[] R<int>[1 dup] R<int>[1 dup] R<Void>[-3 pop]]", Run("[[1 -3 pop dup]]"));

            Assert.Equal("[[] R<Void>[-3 pop]]", Run("[[-3 pop]]"));
            Assert.Equal("[[] R<Void>[-3 pop]]", Run("[[-3 pop dup]]"));
            Assert.Equal("[[] R<Void>[-3 pop]]", Run("[[swap -3 pop dup]]"));
            Assert.Equal("[[] R<Void>[-3 pop]]", Run("[[dup / pop < swap -3 pop dup dup]]"));
            Assert.Equal("[]", ReorderInterpreter.RunReorderPost("[]".ToStack()).ToRepr());
            Assert.Equal("[[]]", ReorderInterpreter.RunReorderPost("[[]]".ToStack()).ToRepr());
            Assert.Equal("[[-3 pop]]", Reorder("[[dup / pop < swap -3 pop dup dup]]"));
        }