public void TestReturnStack()
        {
            DynamicMethod dynMeth = new DynamicMethod("Run",
                                                      typeof(Stack),
                                                      new Type[] {},
                                                      typeof(CompilerTests).Module);

            ILGenerator il  = dynMeth.GetILGenerator(256);
            var         ils = new ILStack(il);

            ils.Push(1);
            ils.Push(4);
            ils.Push(5);
            ils.MakeReturnStack(3);
            il.Emit(OpCodes.Ret);
            var f = (Func <Stack>)dynMeth.CreateDelegate(typeof(Func <Stack>));

            var r = new Stack();

            r.Push(5);
            r.Push(4);
            r.Push(1);
            // Unfortunately, it's kind of backwards.
            Assert.Equal(r, f());
        }
        public void TestReturnArray()
        {
            DynamicMethod dynMeth = new DynamicMethod("Run",
                                                      typeof(int[]),
                                                      new Type[] {},
                                                      typeof(CompilerTests).Module);
            ILGenerator il  = dynMeth.GetILGenerator(256);
            var         ils = new ILStack(il);

            ils.Push(1);
            ils.Push(4);
            ils.Push(5);
            ils.MakeReturnArray();
            il.Emit(OpCodes.Ret);
            var f = (Func <int[]>)dynMeth.CreateDelegate(typeof(Func <int[]>));

            // That's better.
            Assert.Equal(new [] { 5, 4, 1 }, f());
        }
        public void TestReturnStack2()
        {
            DynamicMethod dynMeth = new DynamicMethod("Run",
                                                      typeof(Stack),
                                                      new Type[] {},
                                                      typeof(CompilerTests).Module);
            ILGenerator il  = dynMeth.GetILGenerator(256);
            var         ils = new ILStack(il);

            ils.Push("[1 2 3]".ToStack());
            il.Emit(OpCodes.Ret);
            var f = (Func <Stack>)dynMeth.CreateDelegate(typeof(Func <Stack>));

            // That's better.
            Assert.Equal("[1 2 3]".ToStack(), f());
        }