Exemplo n.º 1
0
        public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args) {
            ContractUtils.RequiresNotNull(binder, "binder");

            ComMethodDesc method;
            if (_self.TryGetGetItem(out method)) {

                bool[] isByRef = ComBinderHelpers.ProcessArgumentsForCom(ref args);
                return BindComInvoke(args, method, binder.CallInfo, isByRef);
            }

            return base.BindInvoke(binder, args);
        }
Exemplo n.º 2
0
            public override MetaObject/*!*/ BindInvoke(InvokeBinder/*!*/ action, MetaObject/*!*/[]/*!*/ args) {
                RubyCallSignature callSignature;
                if (RubyCallSignature.TryCreate(action.Arguments, out callSignature)) {
                    return action.FallbackInvoke(this, args);
                }

                var context = new MetaObject(
                    Methods.GetContextFromProc.OpCall(AstUtils.Convert(Expression, typeof(Proc))),
                    Restrictions.Empty,
                    RubyOps.GetContextFromProc((Proc)Value)
                );

                var metaBuilder = new MetaObjectBuilder();
                Proc.SetCallActionRule(metaBuilder, new CallArguments(context, this, args, callSignature), true);
                return metaBuilder.CreateMetaObject(action, args);
            }
Exemplo n.º 3
0
        public Runtime()
        {
            unaryOps = new Dictionary<ExpressionType, UnaryOperationBinder>();
            binaryOps = new Dictionary<ExpressionType, BinaryOperationBinder>();
            InvokeCallSite = new InvokeBinder();
            ConvertCallSite = new ConvertBinder();
            GetIndexCallSite = new GetIndexBinder();
            SetIndexCallSite = new SetIndexBinder();

            BuiltIns = new Dictionary<string, Expression>();

            RegisterClass("Foo", null);
            RegisterFunction("range", args =>
                {
                    return Iter.Range(((Number)args[0]).Value, ((Number)args[1]).Value);
                });
            RegisterFunction("using", args =>
                {
                    var filename = args[0].ToString();
                    var scanner = new Scanner(File.ReadAllText(filename));
                    var parser = new Parser(this, scanner);
                    var expr = parser.Parse();

                    var func = expr.Compile();
                    return func();
                });
            RegisterFunction("print", args => Console.WriteLine(string.Join(" ", args)));

            RegisterModule("maths", new Dictionary<string, Any>
                {
                    {"PI", new Number(Math.PI)},
                    {"cos", new Function(args => new Number(Math.Cos(((Number) args[0]).Value)))},
                    {"sin", new Function(args => new Number(Math.Sin(((Number) args[0]).Value)))},

                });
        }
Exemplo n.º 4
0
 public override bool TryInvoke(InvokeBinder binder, object[] args, out object result)
 {
     return(base.TryInvoke(binder, args, out result));
 }
Exemplo n.º 5
0
        public override bool TryInvoke(InvokeBinder binder, object[] args, out object result)
        {
            result = InvokeAsync(null, Arguments.From(args, binder.CallInfo.ArgumentNames));

            return(true);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Makes it easier to call this builtin as if it was a normal callable.
 /// You'll have to use the 'dynamic' type for your FlameBuiltin object though.
 /// </summary>
 public override bool TryInvoke(InvokeBinder binder, object[] args, out object result)
 {
     result = flameserver.call("invokeBuiltin", builtin, args, new Hashtable(0));
     return(true);
 }
Exemplo n.º 7
0
Arquivo: Any.cs Projeto: gavin-zyi/Rin
 internal virtual bool InvokeOperation(InvokeBinder binder, Args args, out Any result)
 {
     result = null;
     return(false);
 }
Exemplo n.º 8
0
                public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args) {
                    CodeContext context = BinderState.GetBinderState(binder).Context;
                    PythonContext ctx = PythonContext.GetContext(context);

                    ArgumentMarshaller[] signature = GetArgumentMarshallers(args);

                    BindingRestrictions restrictions = BindingRestrictions.GetTypeRestriction(
                        Expression,
                        Value.GetType()
                    ).Merge(
                        BindingRestrictions.GetExpressionRestriction(
                            Expression.Call(
                                typeof(ModuleOps).GetMethod("CheckFunctionId"),
                                Expression.Convert(Expression, typeof(_CFuncPtr)),
                                Expression.Constant(Value.Id)
                            )
                        )
                    );

                    foreach (var arg in signature) {
                        restrictions = restrictions.Merge(arg.GetRestrictions());
                    }

                    Expression call = MakeCall(signature, GetNativeReturnType());
                    List<Expression> block = new List<Expression>();
                    Expression res;

                    if (call.Type != typeof(void)) {
                        ParameterExpression tmp = Expression.Parameter(call.Type, "ret");
                        block.Add(Expression.Assign(tmp, call));
                        AddKeepAlives(signature, block);
                        block.Add(tmp);
                        res = Expression.Block(new[] { tmp }, block);
                    } else {
                        block.Add(call);
                        AddKeepAlives(signature, block);
                        res = Expression.Block(block);
                    }

                    return new DynamicMetaObject(Utils.Convert(res, typeof(object)), restrictions);
                }
Exemplo n.º 9
0
 public override DynamicMetaObject/*!*/ BindInvoke(InvokeBinder/*!*/ call, params DynamicMetaObject/*!*/[]/*!*/ args) {
     return new FunctionBinderHelper(call, this, null, args).MakeMetaObject();
 }
Exemplo n.º 10
0
 public override DynamicMetaObject/*!*/ BindInvoke(InvokeBinder/*!*/ call, params DynamicMetaObject/*!*/[]/*!*/ args) {
     return MakeCallRule(call, AstUtils.Constant(BinderState.GetBinderState(call).Context), args);
 }
Exemplo n.º 11
0
 public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args)
 {
     return(IsOverridden(nameof(DynamicProxy <T> .TryInvoke))
         ? CallMethodWithResult(nameof(DynamicProxy <T> .TryInvoke), binder, GetArgArray(args), e => binder.FallbackInvoke(this, args, e))
         : base.BindInvoke(binder, args));
 }
Exemplo n.º 12
0
            public override bool TryInvoke(InvokeBinder binder, object[] args, out object result)
            {
                result = null;
                if (args.Length == 2)
                {
                    object temp = args[0];
                    args[0] = args[1];
                    args[1] = temp;
                    return true;
                }

                return false;
            }
Exemplo n.º 13
0
 public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args) {
     return BindGetOrInvoke(args, binder.CallInfo) ??
         base.BindInvoke(binder, args);
 }
Exemplo n.º 14
0
            public new bool TryInvoke(InvokeBinder binder, object[] args, out object result)
            {
                if (args.Length == 2)
                {
                    int x;
                    int y;
                    try
                    {
                        x = Convert.ToInt32(args[0]);
                        y = Convert.ToInt32(args[1]);
                    }
                    catch (Exception)
                    {
                        result = null;
                        return false;
                    }

                    result = checked((int)Math.Pow(x, y));
                    return true;
                }

                result = null;
                return false;
            }
Exemplo n.º 15
0
 public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args) {
     ContractUtils.RequiresNotNull(binder, "binder");
     return binder.Defer(args.AddFirst(WrapSelf()));
 }
Exemplo n.º 16
0
 public override MetaObject BindInvoke(InvokeBinder binder, MetaObject[] args) {
     if (args.Any(arg => ComBinderHelpers.IsStrongBoxArg(arg))) {
         return ComBinderHelpers.RewriteStrongBoxAsRef(binder, this, args);
     }
     return BindComInvoke(binder.Arguments, args);
 }
Exemplo n.º 17
0
 public override bool TryInvoke(InvokeBinder binder, object[] args, out object result)
 {
     throw new InvalidOperationException("不能当作函数使用");
 }
Exemplo n.º 18
0
 public virtual bool TryInvoke(T instance, InvokeBinder binder, object[] args, out object result)
 {
     result = null;
     return(false);
 }
Exemplo n.º 19
0
 public sealed override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args)
 => VariantValue.BindInvoke(binder, args);
Exemplo n.º 20
0
 public override DynamicMetaObject/*!*/ BindInvoke(InvokeBinder/*!*/ call, params DynamicMetaObject/*!*/[]/*!*/ args) {
     return MakeCallRule(call, AstUtils.Constant(PythonContext.GetPythonContext(call).SharedContext), args);
 }
 public override bool TryInvoke(InvokeBinder binder, object[] args, out object result)
 {
     return(((MemberAccessWrapper)MemberAccessWrapper).TryInvoke(binder, args, out result));
 }
Exemplo n.º 22
0
 public virtual bool TryInvoke(InvokeBinder binder, object[] args, out object result) {
     throw new NotSupportedException();
 }
 public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args)
 {
     return(BindGetOrInvoke(args, binder.CallInfo) ??
            base.BindInvoke(binder, args));
 }
Exemplo n.º 24
0
        public static bool TryBindInvoke(InvokeBinder binder, DynamicMetaObject instance, DynamicMetaObject[] args, out DynamicMetaObject result) {
            ContractUtils.RequiresNotNull(binder, "binder");
            ContractUtils.RequiresNotNull(instance, "instance");
            ContractUtils.RequiresNotNull(args, "args");
            
            if (TryGetMetaObject(ref instance)) {
                //
                // Demand Full Trust to proceed with the binding.
                //

                new PermissionSet(PermissionState.Unrestricted).Demand();

                result = instance.BindInvoke(binder, args);
                return true;
            } else {
                result = null;
                return false;
            }
        }
Exemplo n.º 25
0
 public override DynamicMetaObject/*!*/ BindInvoke(InvokeBinder/*!*/ callAction, params DynamicMetaObject/*!*/[]/*!*/ args) {
     return InvokeWorker(callAction, args);
 }
 /// <summary>
 /// Performs the binding of the dynamic invoke operation.
 /// </summary>
 /// <param name="binder">An instance of the <see cref="InvokeBinder"/> that represents the details of the dynamic operation.</param>
 /// <param name="args">An array of <see cref="DynamicMetaObject"/> instances - arguments to the invoke operation.</param>
 /// <returns>The new <see cref="DynamicMetaObject"/> representing the result of the binding.</returns>
 public virtual DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args) {
     ContractUtils.RequiresNotNull(binder, "binder");
     return binder.FallbackInvoke(this, args);
 }
Exemplo n.º 27
0
		public override DynamicMetaObject BindInvoke( InvokeBinder binder, DynamicMetaObject[] args )
		{
			DEBUG.IndentLine( "\n-- BindInvoke: {0}", TypeHelper.ToString( MetaList2List( args ), "()" ) );

			var obj = (DynamicNode)this.Value;
			var node = new DynamicNode.Invoke( obj, MetaList2List( args ) ) { _Parser = obj._Parser };
			obj._Parser._LastNode = node;

			var par = Expression.Variable( typeof( DynamicNode ), "ret" );
			var exp = Expression.Block(
				new ParameterExpression[] { par },
				Expression.Assign( par, Expression.Constant( node ) )
				);

			DEBUG.Unindent();
			return new DynamicMetaNode( exp, this.Restrictions, node );
		}
Exemplo n.º 28
0
 public virtual bool TryInvoke(InvokeBinder binder, object[] args, out object result) {
     result = null;
     return false;
 }
Exemplo n.º 29
0
 public override bool TryInvoke(InvokeBinder binder, object[] args, out object result)
 {
     result = PerformOperation(String.Empty, args);
     return(true);
 }
Exemplo n.º 30
0
            public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args) {
                if (IsOverridden("TryInvoke")) {
                    return CallMethodWithResult("TryInvoke", binder, GetArgArray(args), (e) => binder.FallbackInvoke(this, args, e));
                }

                return base.BindInvoke(binder, args);
            }
Exemplo n.º 31
0
        internal static Delegate CreateDelegateForDynamicObject(LanguageContext context, object dynamicObject, Type delegateType, MethodInfo invoke)
        {
            PerfTrack.NoteEvent(PerfTrack.Categories.DelegateCreate, delegateType.ToString());

            Type returnType = invoke.ReturnType;

            ParameterInfo[] parameterInfos = invoke.GetParameters();

            var parameters = new List <ParameterExpression>();

            for (int i = 0; i < parameterInfos.Length; i++)
            {
                parameters.Add(Expression.Parameter(parameterInfos[i].ParameterType, "p" + i));
            }

            InvokeBinder  invokeBinder  = context.CreateInvokeBinder(new CallInfo(parameterInfos.Length));
            ConvertBinder convertBinder = (returnType != typeof(void)) ? context.CreateConvertBinder(returnType, explicitCast: true) : null;

            CallSite invokeSite     = CallSite.Create(DynamicSiteHelpers.MakeCallSiteDelegate(MakeSiteSignature(parameterInfos)), invokeBinder);
            Type     invokeSiteType = invokeSite.GetType();

            Type     convertSiteType;
            CallSite convertSite;

            if (convertBinder != null)
            {
                convertSite     = CallSite.Create(DynamicSiteHelpers.MakeCallSiteDelegate(typeof(object), returnType), convertBinder);
                convertSiteType = convertSite.GetType();
            }
            else
            {
                convertSiteType = null;
                convertSite     = null;
            }

            var locals = new List <ParameterExpression>();

            ParameterExpression invokeSiteVar  = Expression.Parameter(invokeSiteType, "site");
            ParameterExpression convertSiteVar = null;

            var args = new List <Expression>();

            args.Add(invokeSiteVar);
            args.Add(Expression.Constant(dynamicObject));

            int strongBoxVarsStart = locals.Count;

            for (int i = 0; i < parameterInfos.Length; i++)
            {
                if (parameterInfos[i].ParameterType.IsByRef)
                {
                    var argType = parameterInfos[i].ParameterType;

                    Type elementType  = argType.GetElementType();
                    Type concreteType = typeof(StrongBox <>).MakeGenericType(elementType);

                    var strongBox = Expression.Parameter(concreteType, "box" + i);
                    locals.Add(strongBox);

                    args.Add(
                        Expression.Assign(
                            strongBox,
                            Expression.New(
                                concreteType.GetConstructor(new Type[] { elementType }),
                                parameters[i]
                                )
                            )
                        );
                }
                else
                {
                    args.Add(parameters[i]);
                }
            }

            int strongBoxVarsEnd = locals.Count;

            Expression invocation = Expression.Invoke(
                Expression.Field(
                    Expression.Assign(
                        invokeSiteVar,
                        Expression.Convert(Expression.Constant(invokeSite), invokeSiteType)
                        ),
                    invokeSiteType.GetDeclaredField("Target")
                    ),
                args
                );

            if (convertBinder != null)
            {
                convertSiteVar = Expression.Parameter(convertSiteType, "convertSite");

                invocation = Expression.Invoke(
                    Expression.Field(
                        Expression.Assign(
                            convertSiteVar,
                            Expression.Convert(Expression.Constant(convertSite), convertSiteType)
                            ),
                        convertSiteType.GetDeclaredField("Target")
                        ),
                    convertSiteVar,
                    invocation
                    );
            }

            locals.Add(invokeSiteVar);
            if (convertSiteVar != null)
            {
                locals.Add(convertSiteVar);
            }

            Expression body;

            // copy back from StrongBox.Value
            if (strongBoxVarsEnd > strongBoxVarsStart)
            {
                var block = new Expression[1 + strongBoxVarsEnd - strongBoxVarsStart + 1];

                var resultVar = Expression.Parameter(invocation.Type, "result");
                locals.Add(resultVar);

                int b = 0;
                int l = strongBoxVarsStart;

                // values of strong boxes are initialized in invocation expression:
                block[b++] = Expression.Assign(resultVar, invocation);

                for (int i = 0; i < parameterInfos.Length; i++)
                {
                    if (parameterInfos[i].ParameterType.IsByRef)
                    {
                        var local = locals[l++];
                        block[b++] = Expression.Assign(
                            parameters[i],
                            Expression.Field(local, local.Type.GetDeclaredField("Value"))
                            );
                    }
                }

                block[b++] = resultVar;

                Debug.Assert(l == strongBoxVarsEnd);
                Debug.Assert(b == block.Length);

                body = Expression.Block(locals, block);
            }
            else
            {
                body = Expression.Block(locals, invocation);
            }

            var lambda = Expression.Lambda(delegateType, body, "_Scripting_", parameters);

            return(lambda.Compile());
        }
Exemplo n.º 32
0
 public override DynamicMetaObject /*!*/ BindInvoke(InvokeBinder /*!*/ call, params DynamicMetaObject /*!*/[] /*!*/ args)
 {
     // TODO: Context should come from BuiltinFunction
     return(InvokeWorker(call, PythonContext.GetCodeContext(call), args));
 }
Exemplo n.º 33
0
 public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args)
 => GetTargetDynamicCall(binder, binder.ReturnType, args);
Exemplo n.º 34
0
 public override bool TryInvoke(InvokeBinder binder, object[] args, out object result)
 {
     throw new NotSupportedException();
 }
Exemplo n.º 35
0
 public override DynamicMetaObject /*!*/ BindInvoke(InvokeBinder /*!*/ callAction, params DynamicMetaObject /*!*/[] /*!*/ args)
 {
     return(InvokeWorker(callAction, args));
 }
Exemplo n.º 36
0
 public override bool TryInvoke(InvokeBinder binder, object[] args, out object result)
 {
     result = new DynamicArray(_function.Call(args), _state);
     return(true);
 }
Exemplo n.º 37
0
 public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args)
 {
     return(Create());
 }
Exemplo n.º 38
0
                public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args)
                {
                    CodeContext context = PythonContext.GetPythonContext(binder).SharedContext;

                    ArgumentMarshaller[] signature = GetArgumentMarshallers(args);

                    BindingRestrictions restrictions = BindingRestrictions.GetTypeRestriction(
                        Expression,
                        Value.GetType()
                        ).Merge(
                        BindingRestrictions.GetExpressionRestriction(
                            Expression.Call(
                                typeof(ModuleOps).GetMethod(nameof(ModuleOps.CheckFunctionId)),
                                Expression.Convert(Expression, typeof(_CFuncPtr)),
                                Expression.Constant(Value.Id)
                                )
                            )
                        );

                    foreach (var arg in signature)
                    {
                        restrictions = restrictions.Merge(arg.GetRestrictions());
                    }

                    int argCount = args.Length;

                    if (Value._comInterfaceIndex != -1)
                    {
                        argCount--;
                    }
                    // need to verify we have the correct # of args
                    if (Value._argtypes != null)
                    {
                        if (argCount < Value._argtypes.Count || (Value.CallingConvention != CallingConvention.Cdecl && argCount > Value._argtypes.Count))
                        {
                            return(IncorrectArgCount(binder, restrictions, Value._argtypes.Count, argCount));
                        }
                    }
                    else
                    {
                        CFuncPtrType funcType = ((CFuncPtrType)Value.NativeType);
                        if (funcType._argtypes != null &&
                            (argCount < funcType._argtypes.Length || (Value.CallingConvention != CallingConvention.Cdecl && argCount > funcType._argtypes.Length)))
                        {
                            return(IncorrectArgCount(binder, restrictions, funcType._argtypes.Length, argCount));
                        }
                    }

                    if (Value._comInterfaceIndex != -1 && args.Length == 0)
                    {
                        return(NoThisParam(binder, restrictions));
                    }

                    Expression        call  = MakeCall(signature, GetNativeReturnType(), Value.Getrestype() == null, GetFunctionAddress(args));
                    List <Expression> block = new List <Expression>();
                    Expression        res;

                    if (call.Type != typeof(void))
                    {
                        ParameterExpression tmp = Expression.Parameter(call.Type, "ret");
                        block.Add(Expression.Assign(tmp, call));
                        AddKeepAlives(signature, block);
                        block.Add(tmp);
                        res = Expression.Block(new[] { tmp }, block);
                    }
                    else
                    {
                        block.Add(call);
                        AddKeepAlives(signature, block);
                        res = Expression.Block(block);
                    }

                    res = AddReturnChecks(context, args, res);

                    return(new DynamicMetaObject(Utils.Convert(res, typeof(object)), restrictions));
                }
Exemplo n.º 39
0
 /// <summary>
 /// Tries to invoke.
 /// </summary>
 /// <param name="binder"></param>
 /// <param name="args"></param>
 /// <param name="result"></param>
 /// <returns></returns>
 public override bool TryInvoke(InvokeBinder binder, object[] args, out object result)
 {
     result = Impromptu.InvokeConstructor(_type, Util.NameArgsIfNecessary(binder.CallInfo, args));
     return(true);
 }
Exemplo n.º 40
0
 public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args) => _innerMetaObject.BindInvoke(binder, args);
Exemplo n.º 41
0
 public override DynamicMetaObject /*!*/ BindInvoke(InvokeBinder /*!*/ call, params DynamicMetaObject /*!*/[] /*!*/ args)
 {
     return(InvokeWorker(call, args, PythonContext.GetCodeContext(call)));
 }
Exemplo n.º 42
0
            public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args)
            {
                var expression = MetamethodFallbacks.Call(null, this, args);

                return(new DynamicMetaObject(expression, RuntimeHelpers.MergeTypeRestrictions(this)));
            }
Exemplo n.º 43
0
 /// <inheritdoc/>
 /// <exception cref="ArgumentException">
 /// One of the supplied arguments is a <see cref="LuaReference"/> which is tied to a different <see cref="Lua"/> environment.
 /// </exception>
 /// <exception cref="InvalidOperationException">The <see cref="LuaThread"/> cannot be resumed.</exception>
 /// <exception cref="LuaException">A Lua error occurs.</exception>
 public override bool TryInvoke(InvokeBinder binder, object[] args, out object result)
 {
     result = Resume(args);
     return(true);
 }
Exemplo n.º 44
0
 public override bool TryInvoke(InvokeBinder binder, object[] args, out object result)
 {
     Console.WriteLine("TryInvoke被调用了");
     return(base.TryInvoke(binder, args, out result));
 }
Exemplo n.º 45
0
                public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args) {
                    CodeContext context = PythonContext.GetPythonContext(binder).SharedContext;
                    PythonContext ctx = PythonContext.GetContext(context);

                    ArgumentMarshaller[] signature = GetArgumentMarshallers(args);

                    BindingRestrictions restrictions = BindingRestrictions.GetTypeRestriction(
                        Expression,
                        Value.GetType()
                    ).Merge(
                        BindingRestrictions.GetExpressionRestriction(
                            Expression.Call(
                                typeof(ModuleOps).GetMethod("CheckFunctionId"),
                                Expression.Convert(Expression, typeof(_CFuncPtr)),
                                Expression.Constant(Value.Id)
                            )
                        )
                    );

                    foreach (var arg in signature) {
                        restrictions = restrictions.Merge(arg.GetRestrictions());
                    }

                    // need to verify we have the correct # of args
                    if (Value._argtypes != null) {
                        if (args.Length < Value._argtypes.Count || (Value.CallingConvention != CallingConvention.Cdecl && args.Length > Value._argtypes.Count)) {
                            return IncorrectArgCount(restrictions, Value._argtypes.Count, args.Length);
                        }
                    } else {
                        CFuncPtrType funcType = ((CFuncPtrType)Value.NativeType);
                        if (funcType._argtypes != null &&
                            (args.Length  < funcType._argtypes.Length || (Value.CallingConvention != CallingConvention.Cdecl && args.Length > funcType._argtypes.Length))) {
                            return IncorrectArgCount(restrictions, funcType._argtypes.Length, args.Length);
                        }
                    }

                    Expression call = MakeCall(signature, GetNativeReturnType(), Value.Getrestype() == null);
                    List<Expression> block = new List<Expression>();
                    Expression res;

                    if (call.Type != typeof(void)) {
                        ParameterExpression tmp = Expression.Parameter(call.Type, "ret");
                        block.Add(Expression.Assign(tmp, call));
                        AddKeepAlives(signature, block);
                        block.Add(tmp);
                        res = Expression.Block(new[] { tmp }, block);
                    } else {
                        block.Add(call);
                        AddKeepAlives(signature, block);
                        res = Expression.Block(block);
                    }

                    res = AddReturnChecks(context, args, res);

                    return new DynamicMetaObject(Utils.Convert(res, typeof(object)), restrictions);
                }
 public virtual bool \u200F‫‍‏‪‍‫‎‍‫‮​‫‌‭‭‮​‮‬‪‪‮(\u0001 _param1, InvokeBinder _param2, object[] _param3, out object _param4)
 {
     // ISSUE: unable to decompile the method.
 }
Exemplo n.º 47
0
        public override DynamicMetaObject/*!*/ BindInvoke(InvokeBinder/*!*/ action, DynamicMetaObject/*!*/[]/*!*/ args) {
            Expression context = Ast.Call(
                typeof(PythonOps).GetMethod("GetPythonTypeContext"),
                Ast.Property(
                    AstUtils.Convert(Expression, typeof(IPythonObject)),
                    "PythonType"
                )
            );

            return InvokeWorker(
                action, 
                context, 
                args
            );
        }
        public override bool TryInvoke(InvokeBinder binder, object[] args, out object result)
        {
            List <Type>   outReturnTypes = new List <Type>();
            List <object> returns        = new List <object>();
            int           startIndex     = 0;

            ParameterInfo[] pis = _mi.GetParameters();

            for (startIndex = pis.Length; startIndex > 0; --startIndex)
            {
                ParameterInfo pi = pis[startIndex - 1];

                if ((pi.Attributes & ParameterAttributes.Out) == ParameterAttributes.Out)
                {
                    outReturnTypes.Insert(0, pi.ParameterType);
                }
                else
                {
                    break;
                }
            }

            object[] uargs = UnwrapArray(args, outReturnTypes.Count);

            // Possible varargs
            if ((outReturnTypes.Count == 0) && (pis.Length > 0) && (uargs.Length >= pis.Length) && (pis[pis.Length - 1].ParameterType == typeof(object[])))
            {
                // Copy up to last argument (pis.Length - 1)
                object[] xargs = new object[pis.Length];
                Array.Copy(uargs, xargs, pis.Length - 1);

                // Copy remaining parameters into a trailing array
                object[] targs = new object[uargs.Length - pis.Length + 1];

                Array.Copy(uargs, pis.Length - 1, targs, 0, targs.Length);

                xargs[pis.Length - 1] = targs;

                uargs = xargs;
            }

            object ret = _mi.Invoke(_target, uargs);

            if (_mi.ReturnType != typeof(void))
            {
                returns.Add(DynamicComObjectWrapper.Wrap(_registry, ret, _mi.ReturnType));
            }

            // Promote out parameters
            if (outReturnTypes.Count > 0)
            {
                for (int i = 0; i < outReturnTypes.Count; ++i)
                {
                    returns.Add(DynamicComObjectWrapper.Wrap(_registry, uargs[startIndex + i], outReturnTypes[i]));
                }
            }

            if (returns.Count == 0)
            {
                ret = null;
            }
            else if (returns.Count == 1)
            {
                ret = returns[0];
            }
            else
            {
                ret = Activator.CreateInstance(typeof(Tuple <>).MakeGenericType(returns.Select(o => o != null ? o.GetType() : typeof(object)).ToArray()), returns.ToArray());
            }

            result = ret;

            return(true);
        }
Exemplo n.º 49
0
 public override DynamicMetaObject/*!*/ BindInvoke(InvokeBinder/*!*/ call, params DynamicMetaObject/*!*/[]/*!*/ args) {
     return InvokeWorker(call, args, PythonContext.GetCodeContext(call));
 }
Exemplo n.º 50
0
        public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args)
        {
            var expression = Info.GetInvokeExpression(binder.CallInfo, binder.ReturnType, null, args);

            return(new DynamicMetaObject(expression, typeRestriction));
        }
Exemplo n.º 51
0
 public override DynamicMetaObject/*!*/ BindInvoke(InvokeBinder/*!*/ call, params DynamicMetaObject/*!*/[]/*!*/ args) {
     // TODO: Context should come from BuiltinFunction
     return InvokeWorker(call, BinderState.GetCodeContext(call), args);
 }
Exemplo n.º 52
0
 /// <summary>
 /// Override on DynamicObject
 /// </summary>
 /// <param name="binder"></param>
 /// <param name="args"></param>
 /// <param name="result"></param>
 /// <returns></returns>
 public override bool TryInvoke(InvokeBinder binder, object[] args, out object result)
 {
     result = new Mimic();
     return(true);
 }
Exemplo n.º 53
0
 public override DynamicMetaObject/*!*/ BindInvoke(InvokeBinder/*!*/ invoke, params DynamicMetaObject/*!*/[]/*!*/ args) {
     return InvokeWorker(invoke, PythonContext.GetCodeContext(invoke), args);
 }
Exemplo n.º 54
0
 public override DynamicMetaObject BindInvoke(InvokeBinder binder, DynamicMetaObject[] args)
 {
     return(scriptItem.PostProcessBindResult(metaDynamic.BindInvoke(binder, args)));
 }