Exemplo n.º 1
0
        public void NullDMO()
        {
            BinaryOperationBinder binder = Binder.BinaryOperation(
                CSharpBinderFlags.None,
                ExpressionType.Add,
                GetType(),
                new[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null), CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) }
                ) as BinaryOperationBinder;
            DynamicMetaObject dmo2     = new DynamicMetaObject(Expression.Parameter(typeof(object)), BindingRestrictions.Empty, 2);
            DynamicMetaObject dmoNoVal = new DynamicMetaObject(Expression.Parameter(typeof(object)), BindingRestrictions.Empty);

            AssertExtensions.Throws <ArgumentNullException>("target", () => binder.FallbackBinaryOperation(null, null));
            AssertExtensions.Throws <ArgumentNullException>("arg", () => binder.FallbackBinaryOperation(dmo2, null));
            AssertExtensions.Throws <ArgumentException>("target", () => binder.FallbackBinaryOperation(dmoNoVal, null));
            AssertExtensions.Throws <ArgumentException>("arg", () => binder.FallbackBinaryOperation(dmo2, dmoNoVal));
        }
Exemplo n.º 2
0
 public override DynamicMetaObject BindBinaryOperation(BinaryOperationBinder binder, DynamicMetaObject arg)
 {
     if (!this.IsOverridden("TryBinaryOperation"))
     {
         return(base.BindBinaryOperation(binder, arg));
     }
     return(this.CallMethodWithResult("TryBinaryOperation", binder, DynamicProxyMetaObject <T> .GetArgs(new DynamicMetaObject[]
     {
         arg
     }), (DynamicMetaObject e) => binder.FallbackBinaryOperation(this, arg, e), null));
 }
Exemplo n.º 3
0
 public override DynamicMetaObject _0001(BinaryOperationBinder i, DynamicMetaObject counter)
 {
     //Discarded unreachable code: IL_0002
     //IL_0003: Incompatible stack heights: 0 vs 1
     if (!CancelProperty("TryBinaryOperation"))
     {
         return(base.BindBinaryOperation(i, counter));
     }
     return(DefineProperty("TryBinaryOperation", i, ExcludeProperty(new DynamicMetaObject[1]
     {
         counter
     }), (DynamicMetaObject P_0) => i.FallbackBinaryOperation(this, counter, P_0)));
 }
 public override DynamicMetaObject BindBinaryOperation(
     BinaryOperationBinder binder,
     DynamicMetaObject arg
     )
 {
     return(IsOverridden(nameof(DynamicProxy <T> .TryBinaryOperation))
       ? CallMethodWithResult(
                nameof(DynamicProxy <T> .TryBinaryOperation),
                binder,
                GetArgs(arg),
                e => binder.FallbackBinaryOperation(this, arg, e)
                )
       : base.BindBinaryOperation(binder, arg));
 }
Exemplo n.º 5
0
        public override DynamicMetaObject BindBinaryOperation(BinaryOperationBinder binder, DynamicMetaObject arg)
        {
            Logger.Log(LogLevel.Debug, null, "BindBinaryOperation");

            var binderFallback = binder.FallbackBinaryOperation(this, arg);

            var call = Expression.Call(
                GetClayBehavior(),
                IClayBehavior_BinaryOperation,
                Expression.Lambda(binderFallback.Expression),
                GetLimitedSelf(),
                Expression.Constant(binder.Operation, typeof(ExpressionType)),
                Expression.Convert(arg.Expression, typeof(object)));

            return(new DynamicMetaObject(call, BindingRestrictions.GetTypeRestriction(Expression, LimitType)));
        }
Exemplo n.º 6
0
        public override DynamicMetaObject BindBinaryOperation(BinaryOperationBinder binder, DynamicMetaObject arg)
        {
            if (IsOverridden("TryBinaryOperation"))
            {
                return(CallMethodWithResult("TryBinaryOperation", binder, GetExpressions(new DynamicMetaObject[] { arg }), (e) => binder.FallbackBinaryOperation(this, arg, e)));
            }

            return(base.BindBinaryOperation(binder, arg));
        }
        public static DynamicMetaObject/*!*/ Operation(BinaryOperationBinder/*!*/ operation, DynamicMetaObject target, DynamicMetaObject arg, DynamicMetaObject errorSuggestion) {
            PerfTrack.NoteEvent(PerfTrack.Categories.Binding, "Fallback BinaryOperator " + target.LimitType.FullName + " " + operation.Operation + " " + arg.LimitType.FullName);
            PerfTrack.NoteEvent(PerfTrack.Categories.BindingTarget, operation.Operation.ToString());

            DynamicMetaObject[] args = new[] { target, arg };
            if (BindingHelpers.NeedsDeferral(args)) {
                return operation.Defer(target, arg);
            }

            ValidationInfo valInfo = BindingHelpers.GetValidationInfo(args);

            PythonOperationKind? pyOperator = null;
            switch (operation.Operation) {
                case ExpressionType.Add: pyOperator = PythonOperationKind.Add; break;
                case ExpressionType.And: pyOperator = PythonOperationKind.BitwiseAnd; break;
                case ExpressionType.Divide: pyOperator = PythonOperationKind.Divide; break;
                case ExpressionType.ExclusiveOr: pyOperator = PythonOperationKind.ExclusiveOr; break;
                case ExpressionType.Modulo: pyOperator = PythonOperationKind.Mod; break;
                case ExpressionType.Multiply: pyOperator = PythonOperationKind.Multiply; break;
                case ExpressionType.Or: pyOperator = PythonOperationKind.BitwiseOr; break;
                case ExpressionType.Power: pyOperator = PythonOperationKind.Power; break;
                case ExpressionType.RightShift: pyOperator = PythonOperationKind.RightShift; break;
                case ExpressionType.LeftShift: pyOperator = PythonOperationKind.LeftShift; break;
                case ExpressionType.Subtract: pyOperator = PythonOperationKind.Subtract; break;

                case ExpressionType.AddAssign: pyOperator = PythonOperationKind.InPlaceAdd; break;
                case ExpressionType.AndAssign: pyOperator = PythonOperationKind.InPlaceBitwiseAnd; break;
                case ExpressionType.DivideAssign: pyOperator = PythonOperationKind.InPlaceDivide; break;
                case ExpressionType.ExclusiveOrAssign: pyOperator = PythonOperationKind.InPlaceExclusiveOr; break;
                case ExpressionType.ModuloAssign: pyOperator = PythonOperationKind.InPlaceMod; break;
                case ExpressionType.MultiplyAssign: pyOperator = PythonOperationKind.InPlaceMultiply; break;
                case ExpressionType.OrAssign: pyOperator = PythonOperationKind.InPlaceBitwiseOr; break;
                case ExpressionType.PowerAssign: pyOperator = PythonOperationKind.InPlacePower; break;
                case ExpressionType.RightShiftAssign: pyOperator = PythonOperationKind.InPlaceRightShift; break;
                case ExpressionType.LeftShiftAssign: pyOperator = PythonOperationKind.InPlaceLeftShift; break;
                case ExpressionType.SubtractAssign: pyOperator = PythonOperationKind.InPlaceSubtract; break;

                case ExpressionType.Equal: pyOperator = PythonOperationKind.Equal; break;
                case ExpressionType.GreaterThan: pyOperator = PythonOperationKind.GreaterThan; break;
                case ExpressionType.GreaterThanOrEqual: pyOperator = PythonOperationKind.GreaterThanOrEqual; break;
                case ExpressionType.LessThan: pyOperator = PythonOperationKind.LessThan; break;
                case ExpressionType.LessThanOrEqual: pyOperator = PythonOperationKind.LessThanOrEqual; break;
                case ExpressionType.NotEqual: pyOperator = PythonOperationKind.NotEqual; break;
            }

            DynamicMetaObject res = null;
            if (pyOperator != null) {
                res = MakeBinaryOperation(operation, args, pyOperator.Value, errorSuggestion);
            } else {
                res = operation.FallbackBinaryOperation(target, arg);
            }

            return BindingHelpers.AddDynamicTestAndDefer(operation, BindingHelpers.AddPythonBoxing(res), args, valInfo);
        }
Exemplo n.º 8
0
        public override DynamicMetaObject BindBinaryOperation(BinaryOperationBinder binder, DynamicMetaObject arg)
        {
            if (_runtime.TryBinaryOperation != null)
            {
                return(CallMethodWithResult("TryBinaryOperation", binder, GetArgs(arg), e => binder.FallbackBinaryOperation(this, arg, e)));
            }

            return(base.BindBinaryOperation(binder, arg));
        }
Exemplo n.º 9
0
        public override DynamicMetaObject BindBinaryOperation(BinaryOperationBinder binder, DynamicMetaObject arg)
        {
            DynamicMetaObject messageSendMO = null;
            ESBehavior        esClass       = null;
            ESObjectSpace     kernel;
            ESSymbol          selector = null;

            switch (binder.Operation)
            {
            case ExpressionType.Add:
                if (createMetaObjectToSendMessage("+", argArrayFor(arg), out messageSendMO))
                {
                    return(messageSendMO);
                }
                break;

            case ExpressionType.And:
                if (createMetaObjectToSendMessage("&", argArrayFor(arg), out messageSendMO))
                {
                    return(messageSendMO);
                }
                break;

            case ExpressionType.Divide:
                if (createMetaObjectToSendMessage("/", argArrayFor(arg), out messageSendMO))
                {
                    return(messageSendMO);
                }
                break;

            case ExpressionType.Equal:
                if (createMetaObjectToSendMessage("=", argArrayFor(arg), out messageSendMO))
                {
                    return(messageSendMO);
                }
                break;

            case ExpressionType.ExclusiveOr:
                if (createMetaObjectToSendMessage("xor:", argArrayFor(arg), out messageSendMO))
                {
                    return(messageSendMO);
                }
                break;

            case ExpressionType.GreaterThan:
                if (createMetaObjectToSendMessage(">", argArrayFor(arg), out messageSendMO))
                {
                    return(messageSendMO);
                }
                break;

            case ExpressionType.GreaterThanOrEqual:
                if (createMetaObjectToSendMessage(">=", argArrayFor(arg), out messageSendMO))
                {
                    return(messageSendMO);
                }
                break;

            case ExpressionType.LeftShift:
                if (createMetaObjectToSendMessage("<<", argArrayFor(arg), out messageSendMO))
                {
                    return(messageSendMO);
                }
                break;

            case ExpressionType.LessThan:
                if (createMetaObjectToSendMessage("<", argArrayFor(arg), out messageSendMO))
                {
                    return(messageSendMO);
                }
                break;

            case ExpressionType.LessThanOrEqual:
                if (createMetaObjectToSendMessage("<=", argArrayFor(arg), out messageSendMO))
                {
                    return(messageSendMO);
                }
                break;

            case ExpressionType.Modulo:
                if (createMetaObjectToSendMessage("rem:", argArrayFor(arg), out messageSendMO))
                {
                    return(messageSendMO);
                }
                break;

            case ExpressionType.Multiply:
                if (createMetaObjectToSendMessage("*", argArrayFor(arg), out messageSendMO))
                {
                    return(messageSendMO);
                }
                break;

            case ExpressionType.NotEqual:
                if (createMetaObjectToSendMessage("~=", argArrayFor(arg), out messageSendMO))
                {
                    return(messageSendMO);
                }
                break;

            case ExpressionType.Or:
                if (createMetaObjectToSendMessage("|", argArrayFor(arg), out messageSendMO))
                {
                    return(messageSendMO);
                }
                break;

            case ExpressionType.Power:
                if (createMetaObjectToSendMessage("**", argArrayFor(arg), out messageSendMO))
                {
                    return(messageSendMO);
                }
                break;

            case ExpressionType.RightShift:
                if (createMetaObjectToSendMessage(">>", argArrayFor(arg), out messageSendMO))
                {
                    return(messageSendMO);
                }
                break;

            case ExpressionType.Subtract:
                if (createMetaObjectToSendMessage("-", argArrayFor(arg), out messageSendMO))
                {
                    return(messageSendMO);
                }
                break;

            default:
            case ExpressionType.AddAssign:
                esClass  = ValueClass;
                kernel   = esClass.ObjectSpace;
                selector = kernel.symbolFor("+=");
                break;

            case ExpressionType.AndAssign:
                esClass  = ValueClass;
                kernel   = esClass.ObjectSpace;
                selector = kernel.symbolFor("&=");
                break;

            case ExpressionType.DivideAssign:
                esClass  = ValueClass;
                kernel   = esClass.ObjectSpace;
                selector = kernel.symbolFor("/=");
                break;

            case ExpressionType.ExclusiveOrAssign:
                esClass  = ValueClass;
                kernel   = esClass.ObjectSpace;
                selector = kernel.symbolFor("^=");
                break;

            case ExpressionType.LeftShiftAssign:
                esClass  = ValueClass;
                kernel   = esClass.ObjectSpace;
                selector = kernel.symbolFor("<<=");
                break;

            case ExpressionType.ModuloAssign:
                esClass  = ValueClass;
                kernel   = esClass.ObjectSpace;
                selector = kernel.symbolFor("%=");
                break;

            case ExpressionType.MultiplyAssign:
                esClass  = ValueClass;
                kernel   = esClass.ObjectSpace;
                selector = kernel.symbolFor("*=");
                break;

            case ExpressionType.OrAssign:
                esClass  = ValueClass;
                kernel   = esClass.ObjectSpace;
                selector = kernel.symbolFor("|=");
                break;

            case ExpressionType.PowerAssign:
                esClass  = ValueClass;
                kernel   = esClass.ObjectSpace;
                selector = kernel.symbolFor("**=");
                break;

            case ExpressionType.RightShiftAssign:
                esClass  = ValueClass;
                kernel   = esClass.ObjectSpace;
                selector = kernel.symbolFor(">>=");
                break;

            case ExpressionType.SubtractAssign:
                esClass  = ValueClass;
                kernel   = esClass.ObjectSpace;
                selector = kernel.symbolFor("-=");
                break;

            case ExpressionType.Extension:
                esClass  = ValueClass;
                kernel   = esClass.ObjectSpace;
                selector = kernel.symbolFor("??");
                break;
            }

            if (messageSendMO == null)
            {
                messageSendMO = metaObjectToSendDoesNotUnderstand(selector, argArrayFor(arg));
            }

            return(binder.FallbackBinaryOperation(this, arg, messageSendMO));
        }
Exemplo n.º 10
0
            public override DynamicMetaObject BindBinaryOperation(BinaryOperationBinder binder, DynamicMetaObject arg) {
                if (IsOverridden("TryBinaryOperation")) {
                    return CallMethodWithResult("TryBinaryOperation", binder, GetArgs(arg), (e) => binder.FallbackBinaryOperation(this, arg, e));
                }

                return base.BindBinaryOperation(binder, arg);
            }
 /// <summary>
 /// Performs the binding of the dynamic binary operation.
 /// </summary>
 /// <param name="binder">An instance of the <see cref="BinaryOperationBinder"/> that represents the details of the dynamic operation.</param>
 /// <param name="arg">An instance of the <see cref="DynamicMetaObject"/> representing the right hand side of the binary operation.</param>
 /// <returns>The new <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
 public virtual DynamicMetaObject BindBinaryOperation(BinaryOperationBinder binder, DynamicMetaObject arg) {
     ContractUtils.RequiresNotNull(binder, "binder");
     return binder.FallbackBinaryOperation(this, arg);
 }
Exemplo n.º 12
0
 /// <summary>
 /// Performs the binding of the dynamic binary operation.
 /// </summary>
 /// <param name="binder">An instance of the <see cref="BinaryOperationBinder"/> that represents the details of the dynamic operation.</param>
 /// <param name="arg">An instance of the <see cref="DynamicMetaObject"/> representing the right hand side of the binary operation.</param>
 /// <returns>The new <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
 public virtual DynamicMetaObject BindBinaryOperation(BinaryOperationBinder binder, DynamicMetaObject arg)
 {
     ContractUtils.RequiresNotNull(binder, "binder");
     return(binder.FallbackBinaryOperation(this, arg));
 }
Exemplo n.º 13
0
 public override DynamicMetaObject BindBinaryOperation(BinaryOperationBinder binder, DynamicMetaObject arg)
 {
     return(binder.FallbackBinaryOperation(_baseMetaObject,
                                           arg,
                                           AddTypeRestrictions(_metaObject.BindBinaryOperation(binder, arg))));
 }
Exemplo n.º 14
0
 public override DynamicMetaObject BindBinaryOperation(BinaryOperationBinder binder, DynamicMetaObject arg)
 {
     return(this.IsOverridden("TryBinaryOperation")
            ? this.CallMethodWithResult("TryBinaryOperation", binder, GetArgs(arg), e => binder.FallbackBinaryOperation(this, arg, e))
            : base.BindBinaryOperation(binder, arg));
 }