private static void EmitOp(GroboIL il, ExpressionType nodeType, Type type)
        {
            switch (nodeType)
            {
            case ExpressionType.Add:
                il.Add();
                break;

            case ExpressionType.AddChecked:
                il.Add_Ovf(type.Unsigned());
                break;

            case ExpressionType.Subtract:
                il.Sub();
                break;

            case ExpressionType.SubtractChecked:
                il.Sub_Ovf(type.Unsigned());
                break;

            case ExpressionType.Multiply:
                il.Mul();
                break;

            case ExpressionType.MultiplyChecked:
                il.Mul_Ovf(type.Unsigned());
                break;

            case ExpressionType.Divide:
                il.Div(type.Unsigned());
                break;

            case ExpressionType.Modulo:
                il.Rem(type.Unsigned());
                break;

            case ExpressionType.LeftShift:
                il.Shl();
                break;

            case ExpressionType.RightShift:
                il.Shr(type.Unsigned());
                break;

            case ExpressionType.And:
                il.And();
                break;

            case ExpressionType.Or:
                il.Or();
                break;

            case ExpressionType.ExclusiveOr:
                il.Xor();
                break;

            default:
                throw new NotSupportedException("Node type '" + nodeType + "' is not supported");
            }
        }
Exemple #2
0
        private void TestSuccess(Type type1, Type type2)
        {
            var method = new DynamicMethod(Guid.NewGuid().ToString(), typeof(void), new[] { type1, type2, }.Where(type => type != null).ToArray(), typeof(string), true);

            using (var il = new GroboIL(method))
            {
                var index = 0;
                if (type1 != null)
                {
                    il.Ldarg(index++);
                }
                else
                {
                    il.Ldnull();
                }
                if (type2 != null)
                {
                    il.Ldarg(index++);
                }
                else
                {
                    il.Ldnull();
                }
                il.Mul_Ovf(false);
                il.Pop();
                il.Ret();
                Console.WriteLine(il.GetILCode());
            }
        }
Exemple #3
0
        private void TestFailure(Type type1, Type type2)
        {
            var method = new DynamicMethod(Guid.NewGuid().ToString(), typeof(void), new[] { type1, type2, }.Where(type => type != null).ToArray(), typeof(string), true);
            var il     = new GroboIL(method);
            var index  = 0;

            if (type1 != null)
            {
                il.Ldarg(index++);
            }
            else
            {
                il.Ldnull();
            }
            if (type2 != null)
            {
                il.Ldarg(index++);
            }
            else
            {
                il.Ldnull();
            }
            Assert.Throws <InvalidOperationException>(() => il.Mul_Ovf(false));
        }