public void CallingOneFunctionFromAnother()
        {
            //Arrange
            Func <Int32, Int32> addFive = (Int32 num) =>
            {
                Int32 r = num + 5;
                return(r);
            };

            Func <Int32> mainFunc = () =>
            {
                Int32 num = 10;
                Int32 r   = addFive(num);
                return(r);
            };

            MethodLoader mainFuncLoader = new MethodLoader(mainFunc.GetMethodInfo());
            MethodLoader addFiveLoader  = new MethodLoader(addFive.GetMethodInfo());

            MethodDesc mainFuncMethodDesc = mainFuncLoader.ConstructMethodDesc();
            MethodDesc addFiveMethodDesc  = addFiveLoader.ConstructMethodDesc();

            mainFuncMethodDesc.EntryPoint().AddInheritanceAttributeFlag(MethodInheritanceAttributes.Global);
            addFiveMethodDesc.AddInheritanceAttributeFlag(MethodInheritanceAttributes.Global);

            var executor = GetExecutionEngineForGlobalEntryPoint(mainFuncMethodDesc, addFiveMethodDesc);

            //Act
            executor.Start();

            //Assert
            var res = mainFunc();

            Assert.IsTrue(executor.EntryPointReturn.Equals(res));
        }
        public void Simple_AND_Branching_False_True()
        {
            //Arrange
            Func <Int32> func = () =>
            {
                Boolean a      = false;
                Boolean b      = true;
                Int32   result = 0;
                if (a && b)
                {
                    result = 1;
                }
                else
                {
                    result = -1;
                }
                return(result);
            };

            MethodLoader loader     = new MethodLoader(func.GetMethodInfo());
            MethodDesc   methodDesc = loader.ConstructMethodDesc();

            methodDesc.EntryPoint()
            .AddInheritanceAttributeFlag(MethodInheritanceAttributes.Global);
            var executor = GetExecutionEngineForGlobalEntryPoint(methodDesc);

            //Act
            executor.Start();

            //Assert
            var res = func();

            Assert.IsTrue(executor.EntryPointReturn.Equals(res));
        }
예제 #3
0
        public void SimpleFunctionWithIfElseBranching()
        {
            //Arrange
            Func <Int32> func = () =>
            {
                Int32 a      = 5;
                Int32 b      = 3;
                Int32 result = 0;
                if (a - b > 0)
                {
                    result = 1;
                }
                else
                {
                    result = -1;
                }
                return(result);
            };

            MethodLoader loader     = new MethodLoader(func.GetMethodInfo());
            MethodDesc   methodDesc = loader.ConstructMethodDesc();

            methodDesc.EntryPoint()
            .AddInheritanceAttributeFlag(MethodInheritanceAttributes.Global);
            var executor = GetExecutionEngineForGlobalEntryPoint(methodDesc);

            //Act
            executor.Start();

            //Assert
            var res = func();

            Assert.IsTrue(executor.EntryPointReturn.Equals(res));
        }
        public void SimpleWhileIterationWithIncrement()
        {
            //Arrange
            Func <Int32> func = () =>
            {
                Int32 a = 5;
                while (a < 20)
                {
                    a = a + 1;
                }
                return(a);
            };

            MethodLoader loader     = new MethodLoader(func.GetMethodInfo());
            MethodDesc   methodDesc = loader.ConstructMethodDesc();

            methodDesc.EntryPoint()
            .AddInheritanceAttributeFlag(MethodInheritanceAttributes.Global);
            var executor = GetExecutionEngineForGlobalEntryPoint(methodDesc);

            //Act
            executor.Start();

            //Assert
            var res = func();

            Assert.IsTrue(executor.EntryPointReturn.Equals(res));
        }
        public void Int32_Simple_Greater_Operation_True()
        {
            //Arrange
            Func <Boolean> func = () =>
            {
                Int32   a      = 42;
                Int32   b      = 22;
                Boolean result = a > b;
                return(result);
            };

            MethodLoader loader     = new MethodLoader(func.GetMethodInfo());
            MethodDesc   methodDesc = loader.ConstructMethodDesc();

            methodDesc.EntryPoint()
            .AddInheritanceAttributeFlag(MethodInheritanceAttributes.Global);
            var executor = GetExecutionEngineForGlobalEntryPoint(methodDesc);

            //Act
            executor.Start();

            //Assert
            var res = func();

            Assert.IsTrue(executor.EntryPointReturn.Equals(res));
        }
        public void Int32_Simple_Adding_Positive_Zero()
        {
            //Arrange
            Func <Int32> func = () =>
            {
                Int32 a      = 435;
                Int32 b      = 0;
                Int32 result = a + b;
                return(result);
            };

            MethodLoader loader     = new MethodLoader(func.GetMethodInfo());
            MethodDesc   methodDesc = loader.ConstructMethodDesc();

            methodDesc.EntryPoint()
            .AddInheritanceAttributeFlag(MethodInheritanceAttributes.Global);
            var executor = GetExecutionEngineForGlobalEntryPoint(methodDesc);

            //Act
            executor.Start();

            //Assert
            var res = func();

            Assert.IsTrue(executor.EntryPointReturn.Equals(res));
        }
        public void Int32_Simple_Multiplication_Negative_Overflow()
        {
            //Arrange
            Func <Int32> func = () =>
            {
                Int32 a      = -2147483648;
                Int32 b      = 3;
                Int32 result = a * b;
                return(result);
            };

            MethodLoader loader     = new MethodLoader(func.GetMethodInfo());
            MethodDesc   methodDesc = loader.ConstructMethodDesc();

            methodDesc.EntryPoint()
            .AddInheritanceAttributeFlag(MethodInheritanceAttributes.Global);
            var executor = GetExecutionEngineForGlobalEntryPoint(methodDesc);

            //Act
            executor.Start();

            //Assert
            var res = func();

            Assert.IsTrue(executor.EntryPointReturn.Equals(res));
        }
예제 #8
0
        public void Convert_UInt16_To_SByte()
        {
            //Arrange
            Func <SByte> func = () =>
            {
                UInt16 source = (UInt16)2500;
                SByte  target = (SByte)source;
                return(target);
            };

            MethodLoader loader     = new MethodLoader(func.GetMethodInfo());
            MethodDesc   methodDesc = loader.ConstructMethodDesc();

            methodDesc.EntryPoint()
            .AddInheritanceAttributeFlag(MethodInheritanceAttributes.Global);
            var executor = GetExecutionEngineForGlobalEntryPoint(methodDesc);

            //Act
            executor.Start();

            //Assert
            var res = func();

            Assert.IsTrue(executor.EntryPointReturn.Equals(res));
        }
예제 #9
0
        public void ArithmeticFunctionWithTwoTryFinallies()
        {
            //Arrange
            Func <Int32> func = () =>
            {
                Int32 a = 5;
                try
                {
                    try
                    {
                        Int32 b = a + 33;
                        Int32 c = b * 4;
                        return(a + b + c);
                    }
                    finally
                    {
                        a = a + 1;
                    }
                }
                finally
                {
                    a = a * 2;
                }
            };

            MethodLoader loader     = new MethodLoader(func.GetMethodInfo());
            MethodDesc   methodDesc = loader.ConstructMethodDesc();

            methodDesc.EntryPoint()
            .AddInheritanceAttributeFlag(MethodInheritanceAttributes.Global);
            var executor = GetExecutionEngineForGlobalEntryPoint(methodDesc);

            //Act
            executor.Start();

            //Assert
            var res = func();

            Assert.IsTrue(executor.EntryPointReturn.Equals(res));
        }
예제 #10
0
        public void FunctionWithMixedIntAndFloatArithmeticsAndBranching()
        {
            //Arrange
            Func <Int32> func = () =>
            {
                Int32  a  = 5;
                Int32  b  = -3;
                Int32  c  = a + b;
                Single s1 = 21.6f;
                Single s2 = 33.24f;
                Single s  = s1 + s2;
                Byte   bt = 32;
                if ((s == 54.84f) && (c == -8) && (true == true))
                {
                    Byte mult = 2;
                    bt = (Byte)(bt * mult);
                }

                bt = (Byte)(bt & 6);

                return((Int32)bt);
            };

            MethodLoader loader     = new MethodLoader(func.GetMethodInfo());
            MethodDesc   methodDesc = loader.ConstructMethodDesc();

            methodDesc.EntryPoint()
            .AddInheritanceAttributeFlag(MethodInheritanceAttributes.Global);
            var executor = GetExecutionEngineForGlobalEntryPoint(methodDesc);

            //Act
            executor.Start();

            //Assert
            var res = func();

            Assert.IsTrue(executor.EntryPointReturn.Equals(res));
        }
예제 #11
0
        public void SimpleFunctionReturnsResultOfArithmeticOpers()
        {
            //Arrange
            Func <Int32> func = () =>
            {
                Int32 a = 40;
                Int32 b = a + 2;
                return(b);
            };

            MethodLoader loader     = new MethodLoader(func.GetMethodInfo());
            MethodDesc   methodDesc = loader.ConstructMethodDesc();

            methodDesc.EntryPoint()
            .AddInheritanceAttributeFlag(MethodInheritanceAttributes.Global);
            var executor = GetExecutionEngineForGlobalEntryPoint(methodDesc);

            //Act
            executor.Start();

            //Assert
            Assert.IsTrue(executor.EntryPointReturn.Equals(42));
        }