コード例 #1
0
ファイル: Unsafe.cs プロジェクト: lsgxeva/IronScheme
 public static Expression FxXor(params Expression[] args)
 {
     if (Expect <int>(args, 2))
     {
         return(Ast.ExclusiveOr(UnwrapAndCast <int>(args[0]), UnwrapAndCast <int>(args[1])));
     }
     return(null);
 }
コード例 #2
0
        private static DynamicMetaObject TryPrimitiveOperator(OperatorInfo info, DynamicMetaObject[] args)
        {
            if (args.Length == 2 &&
                TypeUtils.GetNonNullableType(args[0].GetLimitType()) == TypeUtils.GetNonNullableType(args[1].GetLimitType()) &&
                TypeUtils.IsArithmetic(args[0].GetLimitType()))
            {
                // TODO: Nullable<PrimitveType> Support
                Expression        expr;
                DynamicMetaObject self = args[0].Restrict(args[0].GetLimitType());
                DynamicMetaObject arg0 = args[1].Restrict(args[0].GetLimitType());

                switch (info.Operator)
                {
                case ExpressionType.Add: expr = Ast.Add(self.Expression, arg0.Expression); break;

                case ExpressionType.Subtract: expr = Ast.Subtract(self.Expression, arg0.Expression); break;

                case ExpressionType.Divide: expr = Ast.Divide(self.Expression, arg0.Expression); break;

                case ExpressionType.Modulo: expr = Ast.Modulo(self.Expression, arg0.Expression); break;

                case ExpressionType.Multiply: expr = Ast.Multiply(self.Expression, arg0.Expression); break;

                case ExpressionType.LeftShift: expr = Ast.LeftShift(self.Expression, arg0.Expression); break;

                case ExpressionType.RightShift: expr = Ast.RightShift(self.Expression, arg0.Expression); break;

                case ExpressionType.And: expr = Ast.And(self.Expression, arg0.Expression); break;

                case ExpressionType.Or: expr = Ast.Or(self.Expression, arg0.Expression); break;

                case ExpressionType.ExclusiveOr: expr = Ast.ExclusiveOr(self.Expression, arg0.Expression); break;

                default: throw new InvalidOperationException();
                }

                return(new DynamicMetaObject(
                           expr,
                           self.Restrictions.Merge(arg0.Restrictions)
                           ));
            }

            return(null);
        }
コード例 #3
0
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity")] // TODO: fix
        private void MakeOperatorRule(OperatorInfo info)
        {
            MethodInfo[] targets = GetApplicableMembers(info);
            if (targets.Length == 0)
            {
                targets = GetFallbackMembers(_types[0], info);
            }

            if (targets.Length > 0 && TryMakeBindingTarget(targets))
            {
                return;
            }

            if (_types.Length > 1)
            {
                targets = GetApplicableMembers(_types[1], info);
                if (targets.Length > 0 && TryMakeBindingTarget(targets))
                {
                    return;
                }
            }

            Operators op = CompilerHelpers.InPlaceOperatorToOperator(info.Operator);

            if (op != Operators.None)
            {
                // recurse to try and get the non-inplace action...
                MakeOperatorRule(OperatorInfo.GetOperatorInfo(op));
                return;
            }

            if (_types.Length == 2 &&
                TypeUtils.GetNonNullableType(_types[0]) == TypeUtils.GetNonNullableType(_types[1]) &&
                TypeUtils.IsArithmetic(_types[0]))
            {
                // TODO: Nullable<PrimitveType> Support
                Expression expr;
                switch (info.Operator)
                {
                case Operators.Add: expr = Ast.Add(Param0, Param1); break;

                case Operators.Subtract: expr = Ast.Subtract(Param0, Param1); break;

                case Operators.Divide: expr = Ast.Divide(Param0, Param1); break;

                case Operators.Mod: expr = Ast.Modulo(Param0, Param1); break;

                case Operators.Multiply: expr = Ast.Multiply(Param0, Param1); break;

                case Operators.LeftShift: expr = Ast.LeftShift(Param0, Param1); break;

                case Operators.RightShift: expr = Ast.RightShift(Param0, Param1); break;

                case Operators.BitwiseAnd: expr = Ast.And(Param0, Param1); break;

                case Operators.BitwiseOr: expr = Ast.Or(Param0, Param1); break;

                case Operators.ExclusiveOr: expr = Ast.ExclusiveOr(Param0, Param1); break;

                default: throw new InvalidOperationException();
                }
                _rule.Target = _rule.MakeReturn(Binder, expr);
                return;
            }
            else if (_types.Length == 1 && TryMakeDefaultUnaryRule(info))
            {
                return;
            }

            SetErrorTarget(info);
        }