예제 #1
0
 public MetadataToken GetStandAloneSignature(CallSite call_site)
 {
     var signature = metadata.GetCallSiteBlobIndex(call_site);
     var token = GetStandAloneSignatureToken(signature);
     call_site.MetadataToken = token;
     return token;
 }
		public Instruction Create (OpCode opcode, CallSite site)
		{
			if (site == null)
				throw new ArgumentNullException ("site");
			if (opcode.Code != Code.Calli)
				throw new ArgumentException ("code");

			return FinalCreate (opcode, site);
		}
예제 #3
0
        internal object Invoke(object[] args) {
            Debug.Assert(args != null);

            // If it is a delegate, just let DynamicInvoke do the binding.
            var d = _callable as Delegate;
            if (d != null) {
                return d.DynamicInvoke(args);
            }

            // Otherwise, create a CallSite and invoke it.
            if (_site == null) {
                _site = CallSite<Func<CallSite, object, object[], object>>.Create(SplatInvokeBinder.Instance);
            }

            return _site.Target(_site, _callable, args);
        }
        public FunctionPointerEvaluator(StackValue pointer, Interpreter dsi)
        {
            Validity.Assert(pointer.optype == AddressType.FunctionPointer);
            mRunTime = dsi;
            Core core = dsi.runtime.Core;

            int fptr = (int)pointer.opdata;
            ProtoCore.DSASM.FunctionPointerNode fptrNode;
            if (core.FunctionPointerTable.functionPointerDictionary.TryGetByFirst(fptr, out fptrNode))
            {
                int blockId = fptrNode.blockId;
                int procId = fptrNode.procId;
                mProcNode = dsi.runtime.exe.procedureTable[blockId].procList[procId];
            }

            mCallSite = new ProtoCore.CallSite(ProtoCore.DSASM.Constants.kGlobalScope, Name, core.FunctionTable, core.Options.ExecutionMode);
        }
        public FunctionPointerEvaluator(StackValue pointer, Interpreter dsi)
        {
            Validity.Assert(pointer.IsFunctionPointer);
            interpreter = dsi;
            RuntimeCore runtimeCore = dsi.runtime.RuntimeCore;

            int fptr = (int)pointer.opdata;
            FunctionPointerNode fptrNode;
            int classScope = Constants.kGlobalScope;

            if (runtimeCore.DSExecutable.FuncPointerTable.functionPointerDictionary.TryGetByFirst(fptr, out fptrNode))
            {
                int blockId = fptrNode.blockId;
                int procId = fptrNode.procId;
                classScope = fptrNode.classScope;
                procNode = dsi.runtime.GetProcedureNode(blockId, classScope, procId);
            }

            callsite = new ProtoCore.CallSite(classScope, Name, interpreter.runtime.exe.FunctionTable, runtimeCore.Options.ExecutionMode);
        }
예제 #6
0
            }             // ctor

            private void UpdateCallSite(CallInfo callInfo, CallSite callSite)
            {
                this.callSite = callSite;
            }             // proc UpdateCallSite
		public void FindMethod (CallSite site, object o, object[] args)
		{
			if (o == null) {
				throw new NullReferenceException ();
			}

			InvokeInfo info = this.invokeInfo;
			if (info == null) {
				info = new InvokeInfo();
				info.lastObj = new WeakReference (o);
				info.lastArgTypes = new Type[args.Length];
				this.invokeInfo = info;
			} else {
				this.invokeInfo.lastObj.Target = o;
			}

			var arg_len = args.Length;
			for (var i = 0; i < arg_len; i++) {
				info.lastArgTypes[i] = (args != null && args[i]!=null) ? args[i].GetType () : null;
			}

			if (o is ExpandoObject) {
				var expando = (ExpandoObject)o;
				// special case .hasOwnProperty here
				if (name == "hasOwnProperty")
				{
					info.method = o.GetType().GetMethod("hasOwnProperty");
					info.args = args;
					info.del = null;
					info.generation = 0;
				}
				else
				{
					object delObj;
					expando.TryGetValue(name, out delObj);
					Delegate del = delObj as Delegate;
					if (del == null) {
						throw new Exception ("No delegate found with the name '" + name + "'");
					}
					info.method = null;
					info.del = del;
					info.generation = expando.Generation;
				}
			} else {
				MethodInfo method = null;
				bool isStatic;
				System.Type otype;
				if (o is System.Type) {
					// this is a static method invocation where o is the class
					isStatic = true;
					otype = (System.Type)o;
				} else {
					// this is a non-static method invocation
					isStatic = false;
					otype = o.GetType();
				}

				// find method for type that matches argument list
				method = FindMethodForType(site, otype, name, isStatic, args, out info.args);
				if (method == null) {

					if (!isStatic) {
						// find extension methods
						method = FindExtensionMethodForType(site, otype, name, o, args, out info.args);
					}

					if (method == null) {
						throw new Exception("No matching method found for the type '" + otype.FullName + "' with the name '" + name + "'"); 
					}
				}
				info.method = method;
				info.del = null;
				info.generation = 0;
			}

		}
		public static void Action10 (CallSite site, object o1, object o2, object o3, object o4, object o5, object o6, object o7, object o8, object o9, object o10)
		{
			((Delegate)o1).DynamicInvoke(new [] { o2, o3, o4, o5, o6, o7, o8, o10 });
		}
		public static object Func7 (CallSite site, object o1, object o2, object o3, object o4, object o5, object o6, object o7)
		{
			return ((Delegate)o1).DynamicInvoke(new [] { o2, o3, o4, o5, o6, o7 });
		}
		public static object Func7 (CallSite site, object o1, object o2, object o3, object o4, object o5, object o6, object o7)
		{
			return InvokeConstructor((Type)o1, new [] { o2, o3, o4, o5, o6, o7 });
		}
//		readonly CSharpBinderFlags flags;
//		List<CSharpArgumentInfo> argumentInfo;
//		Type callingContext;

		public static void Action1 (CallSite site, object o1)
		{
			((Delegate)o1).DynamicInvoke(null);
		}
예제 #12
0
        private void PatchRawCode(ByteBuffer buffer, int code_size, CodeWriter writer)
        {
            MetadataBuilder metadata = writer.metadata;

            buffer.WriteBytes(base.ReadBytes(code_size));
            int position = buffer.position;

            buffer.position -= code_size;
            while (buffer.position < position)
            {
                byte   b = buffer.ReadByte();
                OpCode opCode;
                if (b != 254)
                {
                    opCode = OpCodes.OneByteOpCode[(int)b];
                }
                else
                {
                    byte b2 = buffer.ReadByte();
                    opCode = OpCodes.TwoBytesOpCode[(int)b2];
                }
                switch (opCode.OperandType)
                {
                case OperandType.InlineBrTarget:
                case OperandType.InlineI:
                case OperandType.ShortInlineR:
                    buffer.position += 4;
                    break;

                case OperandType.InlineField:
                case OperandType.InlineMethod:
                case OperandType.InlineTok:
                case OperandType.InlineType:
                {
                    IMetadataTokenProvider provider = this.reader.LookupToken(new MetadataToken(buffer.ReadUInt32()));
                    buffer.position -= 4;
                    buffer.WriteUInt32(metadata.LookupToken(provider).ToUInt32());
                    break;
                }

                case OperandType.InlineI8:
                case OperandType.InlineR:
                    buffer.position += 8;
                    break;

                case OperandType.InlineSig:
                {
                    CallSite callSite = this.GetCallSite(new MetadataToken(buffer.ReadUInt32()));
                    buffer.position -= 4;
                    buffer.WriteUInt32(writer.GetStandAloneSignature(callSite).ToUInt32());
                    break;
                }

                case OperandType.InlineString:
                {
                    string @string = this.GetString(new MetadataToken(buffer.ReadUInt32()));
                    buffer.position -= 4;
                    buffer.WriteUInt32(new MetadataToken(TokenType.String, metadata.user_string_heap.GetStringIndex(@string)).ToUInt32());
                    break;
                }

                case OperandType.InlineSwitch:
                {
                    int num = buffer.ReadInt32();
                    buffer.position += num * 4;
                    break;
                }

                case OperandType.InlineVar:
                case OperandType.InlineArg:
                    buffer.position += 2;
                    break;

                case OperandType.ShortInlineBrTarget:
                case OperandType.ShortInlineI:
                case OperandType.ShortInlineVar:
                case OperandType.ShortInlineArg:
                    buffer.position++;
                    break;
                }
            }
        }
예제 #13
0
        private static void InvokeAction0(CallSite site, object o)
        {
            var binder = (PSInvokeMemberBinder)site.Binder;

            Invoke(binder, o, 0);
        }
예제 #14
0
 public Instruction Create(OpCode opcode, CallSite site)
 {
     return(Instruction.Create(opcode, site));
 }
예제 #15
0
        /// <summary>
        /// Gets the value dynamically.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="dynamicMemberName">Name of the dynamic member.</param>
        /// <returns></returns>
        public static object GetValueDynamically(object entity, string dynamicMemberName)
        {
            Func <string, CallSite <Func <CallSite, object, object> > > valueFactory = s => CallSite <Func <CallSite, object, object> > .Create(
                Binder.GetMember(
                    CSharpBinderFlags.None,
                    dynamicMemberName,
                    null,
                    new[] { CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null) }
                    ));

            var callsite = callsitesCache.GetOrAdd(dynamicMemberName, valueFactory);

            return(callsite.Target(callsite, entity));
        }
예제 #16
0
 public void Emit(OpCode opcode, CallSite site)
 {
     Append(Create(opcode, site));
 }
예제 #17
0
        public override T BindDelegate <T>(CallSite <T> site, object[] args)
        {
            Debug.Assert(args[1].GetType() == typeof(CodeContext));

            IFastGettable fastGet = args[0] as IFastGettable;

            if (fastGet != null)
            {
                T res = fastGet.MakeGetBinding <T>(site, this, (CodeContext)args[1], Name);
                if (res != null)
                {
                    PerfTrack.NoteEvent(PerfTrack.Categories.BindingFast, "IFastGettable");
                    return(res);
                }

                PerfTrack.NoteEvent(PerfTrack.Categories.BindingSlow, "IFastGettable");
                return(base.BindDelegate <T>(site, args));
            }

            IPythonObject pyObj = args[0] as IPythonObject;

            if (pyObj != null && !(args[0] is IProxyObject))
            {
                FastBindResult <T> res = UserTypeOps.MakeGetBinding <T>((CodeContext)args[1], site, pyObj, this);
                if (res.Target != null)
                {
                    PerfTrack.NoteEvent(PerfTrack.Categories.BindingFast, "IPythonObject");
                    if (res.ShouldCache)
                    {
                        CacheTarget(res.Target);
                    }
                    return(res.Target);
                }

                PerfTrack.NoteEvent(PerfTrack.Categories.BindingSlow, "IPythonObject Get");
                return(base.BindDelegate <T>(site, args));
            }

            if (args[0] != null)
            {
                if (args[0].GetType() == typeof(PythonModule))
                {
                    if (SupportsLightThrow)
                    {
                        return((T)(object)new Func <CallSite, object, CodeContext, object>(new PythonModuleDelegate(_name).LightThrowTarget));
                    }
                    else if (!IsNoThrow)
                    {
                        return((T)(object)new Func <CallSite, object, CodeContext, object>(new PythonModuleDelegate(_name).Target));
                    }
                    else
                    {
                        return((T)(object)new Func <CallSite, object, CodeContext, object>(new PythonModuleDelegate(_name).NoThrowTarget));
                    }
                }
                else if (args[0].GetType() == typeof(NamespaceTracker))
                {
                    switch (Name)
                    {
                    case "__str__":
                    case "__repr__":
                    case "__doc__":
                        // need to return the built in method descriptor for these...
                        break;

                    case "__file__":
                        return((T)(object)new Func <CallSite, object, CodeContext, object>(new NamespaceTrackerDelegate(_name).GetFile));

                    case "__dict__":
                        return((T)(object)new Func <CallSite, object, CodeContext, object>(new NamespaceTrackerDelegate(_name).GetDict));

                    case "__name__":
                        return((T)(object)new Func <CallSite, object, CodeContext, object>(new NamespaceTrackerDelegate(_name).GetName));

                    default:
                        if (IsNoThrow)
                        {
                            return((T)(object)new Func <CallSite, object, CodeContext, object>(new NamespaceTrackerDelegate(_name).NoThrowTarget));
                        }
                        else
                        {
                            return((T)(object)new Func <CallSite, object, CodeContext, object>(new NamespaceTrackerDelegate(_name).Target));
                        }
                    }
                }
            }

            if (args[0] != null &&
#if FEATURE_COM
                !Microsoft.Scripting.ComInterop.ComBinder.IsComObject(args[0]) &&
#endif
                !(args[0] is IDynamicMetaObjectProvider))
            {
                Type        selfType = typeof(T).GetMethod("Invoke").GetParameters()[1].ParameterType;
                CodeContext context  = (CodeContext)args[1];
                T           res      = null;
                if (selfType == typeof(object))
                {
                    res = (T)(object)MakeGetMemberTarget <object>(Name, args[0], context);
                }
                else if (selfType == typeof(List))
                {
                    res = (T)(object)MakeGetMemberTarget <List>(Name, args[0], context);
                }
                else if (selfType == typeof(string))
                {
                    res = (T)(object)MakeGetMemberTarget <string>(Name, args[0], context);
                }

                if (res != null)
                {
                    return((T)(object)res);
                }
                return(base.BindDelegate <T>(site, args));
            }

            PerfTrack.NoteEvent(PerfTrack.Categories.BindingSlow, "GetNoFast " + IsNoThrow + " " + CompilerHelpers.GetType(args[0]));
            return(this.LightBind <T>(args, this.Context.Options.CompilationThreshold));
        }
 public override T BindDelegate <T>(CallSite <T> site, object[] args)
 {
     throw ExceptionToThrow;
 }
		private static void InvokeAction7 (CallSite site, object o, object a1, object a2, object a3, object a4,
		                            object a5, object a6, object a7)
		{
			var binder = ((CSharpInvokeMemberBinder)site.Binder);
			var info = binder.invokeInfo;
			object[] args;
			if (info == null || !info.InvokeMatches(o, a1, a2, a3, a4, a5, a6, a7)) {
				binder.FindMethod (site, o, new [] { a1, a2, a3, a4, a5, a6, a7 });
				info = binder.invokeInfo;
				args = info.args;
			} else {
				args = info.args;
				args[0] = a1; args[1] = a2; args[2] = a3; args[3] = a4; args[4] = a5; args[5] = a6; args[6] = a7;
			}
			if (info.method != null) 
				info.method.Invoke (o, args);
			else 
				info.del.DynamicInvoke(null, args);
		}
 public static void setCallSiteTargetVolatile(CallSite site, MethodHandle target)
 {
     setCallSiteTargetNormal(site, target);
 }
		private static object InvokeFunc3 (CallSite site, object o, object a1, object a2, object a3)
		{
			var binder = ((CSharpInvokeMemberBinder)site.Binder);
			var info = binder.invokeInfo;
			object[] args;
			if (info == null || !info.InvokeMatches(o, a1, a2, a3)) {
				binder.FindMethod (site, o, new [] { a1, a2, a3 });
				info = binder.invokeInfo;
				args = info.args;
			} else {
				args = info.args;
				args[0] = a1; args[1] = a2; args[2] = a3;
			}
			object ret;
			if (info.method != null) 
				ret = info.method.Invoke (o, args);
			else 
				ret = info.del.DynamicInvoke(null, args);
			return ret;
		}
예제 #22
0
        public void SetUpCallrForDebug(RuntimeCore runtimeCore, DSASM.Executive exec, ProcedureNode fNode, int pc, bool isBaseCall = false,
                                       CallSite callsite = null, List <StackValue> arguments         = null, List <List <ReplicationGuide> > replicationGuides = null, StackFrame stackFrame = null,
                                       List <StackValue> dotCallDimensions = null, bool hasDebugInfo = false, bool isMember = false, StackValue?thisPtr = null)
        {
            //ProtoCore.DSASM.Executive exec = core.CurrentExecutive.CurrentDSASMExec;

            DebugFrame debugFrame = new DebugFrame();

            debugFrame.IsBaseCall       = isBaseCall;
            debugFrame.Arguments        = arguments;
            debugFrame.IsMemberFunction = isMember;
            debugFrame.ThisPtr          = thisPtr;
            debugFrame.HasDebugInfo     = hasDebugInfo;

            if (CoreUtils.IsDisposeMethod(fNode.Name))
            {
                debugFrame.IsDisposeCall = true;
                ReturnPCFromDispose      = DebugEntryPC;
            }

            if (RunMode == Runmode.StepNext)
            {
                debugFrame.FunctionStepOver = true;
            }

            bool isReplicating      = false;
            bool isExternalFunction = false;

            // callsite is set to null for a base class constructor call in CALL
            if (callsite == null)
            {
                isReplicating      = false;
                isExternalFunction = false;

                SetUpCallr(ref debugFrame, isReplicating, isExternalFunction, exec);
                DebugStackFrame.Push(debugFrame);

                return;
            }

            // Comment Jun: A dot call does not replicate and  must be handled immediately
            if (fNode.Name == Constants.kDotMethodName)
            {
                isReplicating                = false;
                isExternalFunction           = false;
                debugFrame.IsDotCall         = true;
                debugFrame.DotCallDimensions = dotCallDimensions;

                SetUpCallr(ref debugFrame, isReplicating, isExternalFunction, exec);
                DebugStackFrame.Push(debugFrame);

                return;
            }

            List <List <ReplicationInstruction> > replicationTrials;
            bool willReplicate = callsite.WillCallReplicate(new Context(), arguments, replicationGuides, stackFrame, runtimeCore, out replicationTrials);

            // the inline conditional built-in is handled separately as 'WillCallReplicate' is always true in this case
            if (fNode.Name.Equals(Constants.kInlineConditionalMethodName))
            {
                // The inline conditional built-in is created only for associative blocks and needs to be handled separately as below
                InstructionStream istream = runtimeCore.DSExecutable.instrStreamList[CurrentBlockId];
                Validity.Assert(istream.language == Language.Associative);
                {
                    runtimeCore.DebugProps.InlineConditionOptions.isInlineConditional = true;
                    runtimeCore.DebugProps.InlineConditionOptions.startPc             = pc;

                    runtimeCore.DebugProps.InlineConditionOptions.endPc = FindEndPCForAssocGraphNode(pc, istream, fNode, exec.Properties.executingGraphNode, runtimeCore.Options.ExecuteSSA);


                    runtimeCore.DebugProps.InlineConditionOptions.instructionStream = runtimeCore.RunningBlock;
                    debugFrame.IsInlineConditional = true;
                }

                // no replication case
                if (willReplicate && replicationTrials.Count == 1)
                {
                    runtimeCore.DebugProps.InlineConditionOptions.ActiveBreakPoints.AddRange(runtimeCore.Breakpoints);

                    isReplicating      = false;
                    isExternalFunction = false;
                }
                else // an inline conditional call that replicates
                {
                    // Clear all breakpoints for outermost replicated call
                    if (!DebugStackFrameContains(StackFrameFlagOptions.IsReplicating))
                    {
                        ActiveBreakPoints.AddRange(runtimeCore.Breakpoints);
                        runtimeCore.Breakpoints.Clear();
                    }
                    isExternalFunction = false;
                    isReplicating      = true;
                }
                SetUpCallr(ref debugFrame, isReplicating, isExternalFunction, exec, 0);

                DebugStackFrame.Push(debugFrame);

                return;
            }
            // Prevent breaking inside a function that is external except for dot calls
            // by clearing all breakpoints from outermost external function call
            // This check takes precedence over the replication check
            else if (fNode.IsExternal && fNode.Name != Constants.kDotMethodName)
            {
                // Clear all breakpoints
                if (!DebugStackFrameContains(StackFrameFlagOptions.IsExternalFunction) && fNode.Name != Constants.kFunctionRangeExpression)
                {
                    ActiveBreakPoints.AddRange(runtimeCore.Breakpoints);
                    runtimeCore.Breakpoints.Clear();
                }

                isExternalFunction = true;
                isReplicating      = false;
            }
            // Find if function call will replicate or not and if so
            // prevent stepping in by removing all breakpoints from outermost replicated call
            else if (willReplicate)
            {
                // Clear all breakpoints for outermost replicated call
                if (!DebugStackFrameContains(StackFrameFlagOptions.IsReplicating))
                {
                    ActiveBreakPoints.AddRange(runtimeCore.Breakpoints);
                    runtimeCore.Breakpoints.Clear();
                }

                isReplicating      = true;
                isExternalFunction = false;
            }
            // For all other function calls
            else
            {
                isReplicating      = false;
                isExternalFunction = false;
            }

            SetUpCallr(ref debugFrame, isReplicating, isExternalFunction, exec);
            DebugStackFrame.Push(debugFrame);
        }
		public static object Func2 (CallSite site, object o1, object o2)
		{
			return InvokeConstructor((Type)o1, new [] { o2 });
		}
예제 #24
0
 public override FrameApplicationBuilder CreateFrameApplicationBuilder(IStorageBinder binder, CallSite site, Expression callee)
 {
     return(new X86FrameApplicationBuilder(this, binder, site, callee, false));
 }
예제 #25
0
 public void Emit(OpCode opcode, CallSite site)
 {
     Append (Create (opcode, site));
 }
예제 #26
0
        /// <summary>
        /// Retrieves an existing instance of a callsite associated with a UID
        /// It creates a new callsite if non was found
        /// </summary>
        /// <param name="core"></param>
        /// <param name="uid"></param>
        /// <returns></returns>
        public CallSite GetCallSite(int classScope, string methodName, Executable executable, RuntimeCore runtimeCore)
        {
            Validity.Assert(null != executable.FunctionTable);
            CallSite csInstance   = null;
            var      graphNode    = executable.ExecutingGraphnode;
            var      topGraphNode = graphNode;

            // If it is a nested function call, append all callsite ids
            List <string> callsiteIdentifiers = new List <string>();

            foreach (var prop in runtimeCore.InterpreterProps)
            {
                if (prop != null && prop.executingGraphNode != null && graphNode != prop.executingGraphNode)
                {
                    topGraphNode = prop.executingGraphNode;
                    if (!string.IsNullOrEmpty(topGraphNode.CallsiteIdentifier))
                    {
                        callsiteIdentifiers.Add(topGraphNode.CallsiteIdentifier);
                    }
                }
            }
            if (graphNode != null)
            {
                callsiteIdentifiers.Add(graphNode.CallsiteIdentifier);
            }
            var callsiteID = string.Join(";", callsiteIdentifiers.ToArray());

            // TODO Jun: Currently generates a new callsite for imperative and
            // internally generated functions.
            // Fix the issues that cause the cache to go out of sync when
            // attempting to cache internal functions. This may require a
            // secondary callsite cache for internal functions so they dont
            // clash with the graphNode UID key
            var  language           = executable.instrStreamList[runtimeCore.RunningBlock].language;
            bool isImperative       = language == Language.Imperative;
            bool isInternalFunction = CoreUtils.IsInternalFunction(methodName);

            if (isInternalFunction || isImperative)
            {
                csInstance = new CallSite(classScope,
                                          methodName,
                                          executable.FunctionTable,
                                          runtimeCore.Options.ExecutionMode);
            }
            else if (!CallsiteCache.TryGetValue(callsiteID, out csInstance))
            {
                // Attempt to retrieve a preloaded callsite data (optional).
                var traceData = GetAndRemoveTraceDataForNode(topGraphNode.guid, callsiteID);

                csInstance = new CallSite(classScope,
                                          methodName,
                                          executable.FunctionTable,
                                          runtimeCore.Options.ExecutionMode,
                                          traceData);

                CallsiteCache[callsiteID] = csInstance;
                CallSiteToNodeMap[csInstance.CallSiteID] = topGraphNode.guid;
            }

            if (graphNode != null && !CoreUtils.IsDisposeMethod(methodName))
            {
                csInstance.UpdateCallSite(classScope, methodName);
                if (runtimeCore.Options.IsDeltaExecution)
                {
                    runtimeCore.RuntimeStatus.ClearWarningForExpression(graphNode.exprUID);
                }
            }

            return(csInstance);
        }
		public static void Action4 (CallSite site, object o1, object o2, object o3, object o4)
		{
			((Delegate)o1).DynamicInvoke(new [] { o2, o3, o4 });
		}
예제 #28
0
 // Dev10 Bug 914027 - Changed the callsite's target parameter from dynamic to object, see comment at top for details
 public static CallSite <Func <CallSite, object, object> > GetMemberAccessCallSite(CallSiteBinder binder)
 {
     return(CallSite <Func <CallSite, object, object> > .Create(binder));
 }
		public static object Func2 (CallSite site, object o1, object o2)
		{
			return ((Delegate)o1).DynamicInvoke(new [] { o2 });
		}
예제 #30
0
 private static CallSite <Func <CallSite, object, object> > CreateCallSiteGetter(string name) =>
 CallSite <Func <CallSite, object, object> > .Create(new NoThrowGetBinderMember((GetMemberBinder)DynamicUtils.BinderWrapper.GetMember(name, typeof(DynamicUtils))));
예제 #31
0
        private static object TestOut(CallSite dummy, object @in, out string @out)
        {
            @out = @in as string;

            return(@out != null);
        }
예제 #32
0
        private void CloneTo(MethodBody body, MethodDefinition parent)
        {
            MethodBody nb = new MethodBody(parent);

            parent.Body = nb;

            nb.MaxStackSize  = body.MaxStackSize;
            nb.InitLocals    = body.InitLocals;
            nb.LocalVarToken = body.LocalVarToken;

            foreach (VariableDefinition var in body.Variables)
            {
                nb.Variables.Add(new VariableDefinition(var.Name,
                                                        Import(var.VariableType, parent)));
            }

            nb.Instructions.SetCapacity(body.Instructions.Count);
            _repackContext.LineIndexer.PreMethodBodyRepack(body, parent);
            foreach (Instruction instr in body.Instructions)
            {
                _repackContext.LineIndexer.ProcessMethodBodyInstruction(instr);

                Instruction ni;

                if (instr.OpCode.Code == Code.Calli)
                {
                    var      callSite = (CallSite)instr.Operand;
                    CallSite ncs      = new CallSite(Import(callSite.ReturnType, parent))
                    {
                        HasThis           = callSite.HasThis,
                        ExplicitThis      = callSite.ExplicitThis,
                        CallingConvention = callSite.CallingConvention
                    };
                    foreach (ParameterDefinition param in callSite.Parameters)
                    {
                        CloneTo(param, parent, ncs.Parameters);
                    }
                    ni = Instruction.Create(instr.OpCode, ncs);
                }
                else
                {
                    switch (instr.OpCode.OperandType)
                    {
                    case OperandType.InlineArg:
                    case OperandType.ShortInlineArg:
                        if (instr.Operand == body.ThisParameter)
                        {
                            ni = Instruction.Create(instr.OpCode, nb.ThisParameter);
                        }
                        else
                        {
                            int param = body.Method.Parameters.IndexOf((ParameterDefinition)instr.Operand);
                            ni = Instruction.Create(instr.OpCode, parent.Parameters[param]);
                        }
                        break;

                    case OperandType.InlineVar:
                    case OperandType.ShortInlineVar:
                        int var = body.Variables.IndexOf((VariableDefinition)instr.Operand);
                        ni = Instruction.Create(instr.OpCode, nb.Variables[var]);
                        break;

                    case OperandType.InlineField:
                        ni = Instruction.Create(instr.OpCode, Import((FieldReference)instr.Operand, parent));
                        break;

                    case OperandType.InlineMethod:
                        ni = Instruction.Create(instr.OpCode, Import((MethodReference)instr.Operand, parent));
                        FixAspNetOffset(nb.Instructions, (MethodReference)instr.Operand, parent);
                        break;

                    case OperandType.InlineType:
                        ni = Instruction.Create(instr.OpCode, Import((TypeReference)instr.Operand, parent));
                        break;

                    case OperandType.InlineTok:
                        if (instr.Operand is TypeReference)
                        {
                            ni = Instruction.Create(instr.OpCode, Import((TypeReference)instr.Operand, parent));
                        }
                        else if (instr.Operand is FieldReference)
                        {
                            ni = Instruction.Create(instr.OpCode, Import((FieldReference)instr.Operand, parent));
                        }
                        else if (instr.Operand is MethodReference)
                        {
                            ni = Instruction.Create(instr.OpCode, Import((MethodReference)instr.Operand, parent));
                        }
                        else
                        {
                            throw new InvalidOperationException();
                        }
                        break;

                    case OperandType.ShortInlineBrTarget:
                    case OperandType.InlineBrTarget:
                        ni = Instruction.Create(instr.OpCode, (Instruction)instr.Operand);
                        break;

                    case OperandType.InlineSwitch:
                        ni = Instruction.Create(instr.OpCode, (Instruction[])instr.Operand);
                        break;

                    case OperandType.InlineR:
                        ni = Instruction.Create(instr.OpCode, (double)instr.Operand);
                        break;

                    case OperandType.ShortInlineR:
                        ni = Instruction.Create(instr.OpCode, (float)instr.Operand);
                        break;

                    case OperandType.InlineNone:
                        ni = Instruction.Create(instr.OpCode);
                        break;

                    case OperandType.InlineString:
                        ni = Instruction.Create(instr.OpCode, (string)instr.Operand);
                        break;

                    case OperandType.ShortInlineI:
                        if (instr.OpCode == OpCodes.Ldc_I4_S)
                        {
                            ni = Instruction.Create(instr.OpCode, (sbyte)instr.Operand);
                        }
                        else
                        {
                            ni = Instruction.Create(instr.OpCode, (byte)instr.Operand);
                        }
                        break;

                    case OperandType.InlineI8:
                        ni = Instruction.Create(instr.OpCode, (long)instr.Operand);
                        break;

                    case OperandType.InlineI:
                        ni = Instruction.Create(instr.OpCode, (int)instr.Operand);
                        break;

                    default:
                        throw new InvalidOperationException();
                    }
                }
                ni.SequencePoint = instr.SequencePoint;
                nb.Instructions.Add(ni);
            }
            _repackContext.LineIndexer.PostMethodBodyRepack(parent);

            for (int i = 0; i < body.Instructions.Count; i++)
            {
                Instruction instr = nb.Instructions[i];
                switch (instr.OpCode.OperandType)
                {
                case OperandType.ShortInlineBrTarget:
                case OperandType.InlineBrTarget:
                    instr.Operand = GetInstruction(body, nb, (Instruction)body.Instructions[i].Operand);
                    break;

                case OperandType.InlineSwitch:
                    instr.Operand = ((Instruction[])body.Instructions[i].Operand).Select(op => GetInstruction(body, nb, op)).ToArray();
                    break;

                default:
                    break;
                }
            }

            foreach (ExceptionHandler eh in body.ExceptionHandlers)
            {
                ExceptionHandler neh = new ExceptionHandler(eh.HandlerType);
                neh.TryStart     = GetInstruction(body, nb, eh.TryStart);
                neh.TryEnd       = GetInstruction(body, nb, eh.TryEnd);
                neh.HandlerStart = GetInstruction(body, nb, eh.HandlerStart);
                neh.HandlerEnd   = GetInstruction(body, nb, eh.HandlerEnd);

                switch (eh.HandlerType)
                {
                case ExceptionHandlerType.Catch:
                    neh.CatchType = Import(eh.CatchType, parent);
                    break;

                case ExceptionHandlerType.Filter:
                    neh.FilterStart = GetInstruction(body, nb, eh.FilterStart);
                    break;
                }

                nb.ExceptionHandlers.Add(neh);
            }
        }
		private MethodInfo FindExtensionMethodForType(CallSite site, System.Type otype, string name, object o, object[] args, out object[] outArgs)
		{
			Type extensionClass = PlayScript.Dynamic.GetExtensionClassForType(otype); 

			if (extensionClass != null) {
				// add 'this' to arguments
				var extArgs = new object[args.Length + 1];
				extArgs[0] = o;
				Array.Copy(args, 0, extArgs, 1, args.Length);

				var methods = extensionClass.GetMethods();
				var len = methods.Length;
				for (var mi = 0; mi < len; mi++) {
					var m = methods[mi];
					if (m.Name == name) {
						// attempt to convert method parameters
						if (Dynamic.ConvertMethodParameters(m, extArgs, out outArgs)) {
							return m;
						}
					}
				}
			}

			// method not found
			outArgs = null;
			return null;
		}
예제 #34
0
 public ParseException(string message, CallSite callsite)
     : base(message, callsite)
 {
 }
		private static void InvokeAction2 (CallSite site, object o, object a1, object a2)
		{
			var binder = ((CSharpInvokeMemberBinder)site.Binder);
			var info = binder.invokeInfo;
			object[] args;
			if (info == null || !info.InvokeMatches(o, a1, a2)) {
				binder.FindMethod (site, o, new [] { a1, a2 });
				info = binder.invokeInfo;
				args = info.args;
			} else {
				args = info.args;
				args[0] = a1; args[1] = a2;
			}
			if (info.method != null) 
				info.method.Invoke (o, args);
			else 
				info.del.DynamicInvoke(null, args);
		}
예제 #36
0
 public PrintfApplicationBuilder(
     IProcessorArchitecture arch, Frame frame, CallSite site, Expression callee, FunctionType sigCallee, bool ensureVariables) :
     base(arch, frame, site, callee, sigCallee, ensureVariables)
 {
 }
		private static object InvokeFunc (CallSite site, object o)
		{
			var binder = ((CSharpInvokeMemberBinder)site.Binder);
			var info = binder.invokeInfo;
			object[] args;
			if (info == null || !info.InvokeMatches (o)) {
				binder.FindMethod (site, o, new object[] {});
				info = binder.invokeInfo;
			}
			args = info.args;
			if (info.method != null) 
				return info.method.Invoke (o, args);
			else 
				return info.del.DynamicInvoke(args);
		}
예제 #38
0
 private static CallSite <Func <CallSite, CodeContext, object, string, object> > MakeGetAttrSite(CodeContext context)
 {
     return(CallSite <Func <CallSite, CodeContext, object, string, object> > .Create(
                PythonContext.GetContext(context).InvokeOne
                ));
 }
		private static object InvokeFunc8 (CallSite site, object o, object a1, object a2, object a3, object a4,
		                                   object a5, object a6, object a7, object a8)
		{
			var binder = ((CSharpInvokeMemberBinder)site.Binder);
			var info = binder.invokeInfo;
			object[] args;
			if (info == null || !info.InvokeMatches(o, a1, a2, a3, a4, a5, a6, a7, a8)) {
				binder.FindMethod (site, o, new [] { a1, a2, a3, a4, a5, a6, a7, a8 });
				info = binder.invokeInfo;
				args = info.args;
			} else {
				args = info.args;
				args[0] = a1; args[1] = a2; args[2] = a3; args[3] = a4; args[4] = a5; args[5] = a6; args[6] = a7; args[7] = a8;
			}			
			object ret;
			if (info.method != null) 
				ret = info.method.Invoke (o, args);
			else 
				ret = info.del.DynamicInvoke(null, args);
			return ret;
		}
예제 #40
0
        internal static Binding.FastBindResult <T> MakeGetBinding <T>(CodeContext codeContext, CallSite <T> site, IPythonObject self, Binding.PythonGetMemberBinder getBinder) where T : class
        {
            Type finalType = PythonTypeOps.GetFinalSystemType(self.PythonType.UnderlyingSystemType);

            if (typeof(IDynamicMetaObjectProvider).IsAssignableFrom(finalType) &&
                !(self is IFastGettable))
            {
                // very tricky, user is inheriting from a class which implements IDO, we
                // don't optimize this yet.
                return(new Binding.FastBindResult <T>());
            }
            return((Binding.FastBindResult <T>)(object) new Binding.MetaUserObject.FastGetBinderHelper(
                       codeContext,
                       (CallSite <Func <CallSite, object, CodeContext, object> >)(object) site,
                       self,
                       getBinder).GetBinding(codeContext, getBinder.Name));
        }
		public static object Func1 (CallSite site, object o1)
		{
			return InvokeConstructor((Type)o1, new object[] {});
		}
예제 #42
0
        internal static FastBindResult <T> MakeSetBinding <T>(CodeContext codeContext, CallSite <T> site, IPythonObject self, object value, Binding.PythonSetMemberBinder setBinder) where T : class
        {
            if (typeof(IDynamicMetaObjectProvider).IsAssignableFrom(self.GetType().BaseType))
            {
                // very tricky, user is inheriting from a class which implements IDO, we
                // don't optimize this yet.
                return(new FastBindResult <T>());
            }

            // optimized versions for possible literals that can show up in code.
            Type setType = typeof(T);

            if (setType == typeof(Func <CallSite, object, object, object>))
            {
                return((FastBindResult <T>)(object) new Binding.MetaUserObject.FastSetBinderHelper <object>(
                           codeContext,
                           self,
                           value,
                           setBinder).MakeSet());
            }
            else if (setType == typeof(Func <CallSite, object, string, object>))
            {
                return((FastBindResult <T>)(object) new Binding.MetaUserObject.FastSetBinderHelper <string>(
                           codeContext,
                           self,
                           value,
                           setBinder).MakeSet());
            }
            else if (setType == typeof(Func <CallSite, object, int, object>))
            {
                return((FastBindResult <T>)(object) new Binding.MetaUserObject.FastSetBinderHelper <int>(
                           codeContext,
                           self,
                           value,
                           setBinder).MakeSet());
            }
            else if (setType == typeof(Func <CallSite, object, double, object>))
            {
                return((FastBindResult <T>)(object) new Binding.MetaUserObject.FastSetBinderHelper <double>(
                           codeContext,
                           self,
                           value,
                           setBinder).MakeSet());
            }
            else if (setType == typeof(Func <CallSite, object, List, object>))
            {
                return((FastBindResult <T>)(object) new Binding.MetaUserObject.FastSetBinderHelper <List>(
                           codeContext,
                           self,
                           value,
                           setBinder).MakeSet());
            }
            else if (setType == typeof(Func <CallSite, object, PythonTuple, object>))
            {
                return((FastBindResult <T>)(object) new Binding.MetaUserObject.FastSetBinderHelper <PythonTuple>(
                           codeContext,
                           self,
                           value,
                           setBinder).MakeSet());
            }
            else if (setType == typeof(Func <CallSite, object, PythonDictionary, object>))
            {
                return((FastBindResult <T>)(object) new Binding.MetaUserObject.FastSetBinderHelper <PythonDictionary>(
                           codeContext,
                           self,
                           value,
                           setBinder).MakeSet());
            }

            return(new FastBindResult <T>());
        }
		public static object Func4 (CallSite site, object o1, object o2, object o3, object o4)
		{
			return InvokeConstructor((Type)o1, new [] { o2, o3, o4 });
		}
예제 #44
0
        private static CallSite <Func <CallSite, object, object?, object> > CreateCallSiteSetter(string name)
        {
            SetMemberBinder binder = (SetMemberBinder)DynamicUtils.BinderWrapper.SetMember(name, typeof(DynamicUtils));

            return(CallSite <Func <CallSite, object, object?, object> > .Create(new NoThrowSetBinderMember(binder)));
        }
		public static object Func10 (CallSite site, object o1, object o2, object o3, object o4, object o5, object o6, object o7, object o8, object o9, object o10)
		{
			return InvokeConstructor((Type)o1, new [] { o2, o3, o4, o5, o6, o7, o8, o9, o10 });
		}
예제 #46
0
 public override bool Handle(ulong remoteUserId, CallSite site, BitStream stream, object obj)
 {
     return(true);
 }
예제 #47
0
 public Instruction Create(OpCode opcode, CallSite site)
 {
     return Instruction.Create (opcode, site);
 }
예제 #48
0
        public override T BindDelegate <T>(CallSite <T> site, object[] args)
        {
            //Debug.Assert(typeof(T).GetMethod("Invoke").ReturnType == Type);

            object target = args[0];
            T      res    = null;

            if (typeof(T) == typeof(Func <CallSite, object, string>) && target is string)
            {
                res = (T)(object)new Func <CallSite, object, string>(StringConversion);
            }
            else if (typeof(T) == typeof(Func <CallSite, object, int>))
            {
                if (target is int)
                {
                    res = (T)(object)new Func <CallSite, object, int>(IntConversion);
                }
                else if (target is bool)
                {
                    res = (T)(object)new Func <CallSite, object, int>(BoolToIntConversion);
                }
            }
            else if (typeof(T) == typeof(Func <CallSite, bool, int>))
            {
                res = (T)(object)new Func <CallSite, bool, int>(BoolToIntConversion);
            }
            else if (typeof(T) == typeof(Func <CallSite, object, bool>))
            {
                if (target is bool)
                {
                    res = (T)(object)new Func <CallSite, object, bool>(BoolConversion);
                }
                else if (target is string)
                {
                    res = (T)(object)new Func <CallSite, object, bool>(StringToBoolConversion);
                }
                else if (target is int)
                {
                    res = (T)(object)new Func <CallSite, object, bool>(IntToBoolConversion);
                }
                else if (target == null)
                {
                    res = (T)(object)new Func <CallSite, object, bool>(NullToBoolConversion);
                }
                else if (target.GetType() == typeof(object))
                {
                    res = (T)(object)new Func <CallSite, object, bool>(ObjectToBoolConversion);
                }
                else if (target.GetType() == typeof(List))
                {
                    res = (T)(object)new Func <CallSite, object, bool>(ListToBoolConversion);
                }
                else if (target.GetType() == typeof(PythonTuple))
                {
                    res = (T)(object)new Func <CallSite, object, bool>(TupleToBoolConversion);
                }
            }
            else if (target != null)
            {
                // Special cases:
                //  - string or bytes to IEnumerable or IEnumerator
                //  - CLR 4 only: BigInteger -> Complex
#if !CLR2
                if (target is BigInteger)
                {
                    if (typeof(T) == typeof(Func <CallSite, BigInteger, Complex>))
                    {
                        res = (T)(object)new Func <CallSite, BigInteger, Complex>(BigIntegerToComplexConversion);
                    }
                    else if (typeof(T) == typeof(Func <CallSite, object, Complex>))
                    {
                        res = (T)(object)new Func <CallSite, object, Complex>(BigIntegerObjectToComplexConversion);
                    }
                    else if (typeof(T) == typeof(Func <CallSite, BigInteger, object>))
                    {
                        res = (T)(object)new Func <CallSite, BigInteger, object>(BigIntegerToComplexObjectConversion);
                    }
                }
                else
#endif
                if (target is string)
                {
                    if (typeof(T) == typeof(Func <CallSite, string, IEnumerable>))
                    {
                        res = (T)(object)new Func <CallSite, string, IEnumerable>(StringToIEnumerableConversion);
                    }
                    else if (typeof(T) == typeof(Func <CallSite, string, IEnumerator>))
                    {
                        res = (T)(object)new Func <CallSite, string, IEnumerator>(StringToIEnumeratorConversion);
                    }
                    else if (typeof(T) == typeof(Func <CallSite, object, IEnumerable>))
                    {
                        res = (T)(object)new Func <CallSite, object, IEnumerable>(ObjectToIEnumerableConversion);
                    }
                    else if (typeof(T) == typeof(Func <CallSite, object, IEnumerator>))
                    {
                        res = (T)(object)new Func <CallSite, object, IEnumerator>(ObjectToIEnumeratorConversion);
                    }
                }
                else if (target.GetType() == typeof(Bytes))
                {
                    if (typeof(T) == typeof(Func <CallSite, Bytes, IEnumerable>))
                    {
                        res = (T)(object)new Func <CallSite, Bytes, IEnumerable>(BytesToIEnumerableConversion);
                    }
                    else if (typeof(T) == typeof(Func <CallSite, Bytes, IEnumerator>))
                    {
                        res = (T)(object)new Func <CallSite, Bytes, IEnumerator>(BytesToIEnumeratorConversion);
                    }
                    else if (typeof(T) == typeof(Func <CallSite, object, IEnumerable>))
                    {
                        res = (T)(object)new Func <CallSite, object, IEnumerable>(ObjectToIEnumerableConversion);
                    }
                    else if (typeof(T) == typeof(Func <CallSite, object, IEnumerator>))
                    {
                        res = (T)(object)new Func <CallSite, object, IEnumerator>(ObjectToIEnumeratorConversion);
                    }
                }

                if (res == null && (target.GetType() == Type || Type.IsAssignableFrom(target.GetType())))
                {
                    if (typeof(T) == typeof(Func <CallSite, object, object>))
                    {
                        // called via a helper call site in the runtime (e.g. Converter.Convert)
                        res = (T)(object)new Func <CallSite, object, object>(new IdentityConversion(target.GetType()).Convert);
                    }
                    else
                    {
                        // called via an embedded call site
                        Debug.Assert(typeof(T).GetMethod("Invoke").ReturnType == Type);
                        if (typeof(T).GetMethod("Invoke").GetParameters()[1].ParameterType == typeof(object))
                        {
                            object identityConversion = Activator.CreateInstance(typeof(IdentityConversion <>).MakeGenericType(Type), target.GetType());
                            res = (T)(object)Delegate.CreateDelegate(typeof(T), identityConversion, identityConversion.GetType().GetMethod("Convert"));
                        }
                    }
                }
            }

            if (res != null)
            {
                CacheTarget(res);
                return(res);
            }

            PerfTrack.NoteEvent(PerfTrack.Categories.Binding, "Convert " + Type.FullName + " " + CompilerHelpers.GetType(args[0]) + " " + typeof(T));
            return(base.BindDelegate(site, args));
        }
		public static void Action2 (CallSite site, object o1, object o2)
		{
			((Delegate)o1).DynamicInvoke(new [] { o2 });
		}
예제 #50
0
 public int BoolToIntConversion(CallSite site, bool value)
 {
     return((bool)value ? 1 : 0);
 }
		public static void Action7 (CallSite site, object o1, object o2, object o3, object o4, object o5, object o6, object o7)
		{
			((Delegate)o1).DynamicInvoke(new [] { o2, o3, o4, o5, o6, o7 });
		}
예제 #52
0
 public Complex BigIntegerToComplexConversion(CallSite site, BigInteger value)
 {
     return(BigIntegerOps.ConvertToComplex(value));
 }
		public static object Func1 (CallSite site, object o1)
		{
			return ((Delegate)o1).DynamicInvoke(null);
		}
예제 #54
0
 public void NullBinder()
 {
     AssertExtensions.Throws <ArgumentNullException>("binder", () => CallSite <Func <CallSite, object, object> > .Create(null));
 }
		public static object Func4 (CallSite site, object o1, object o2, object o3, object o4)
		{
			return ((Delegate)o1).DynamicInvoke(new [] { o2, o3, o4 });
		}
예제 #56
0
        private static object InvokeFunc0(CallSite site, object o)
        {
            var binder = (PSInvokeMemberBinder)site.Binder;

            return(Invoke(binder, o, 0));
        }
		public static object Func10 (CallSite site, object o1, object o2, object o3, object o4, object o5, object o6, object o7, object o8, object o9, object o10)
		{
			return ((Delegate)o1).DynamicInvoke(new [] { o2, o3, o4, o5, o6, o7, o8, o9, o10 });
		}
		private MethodInfo FindMethodForType(CallSite site, System.Type otype, string name, bool isStatic, object[] args, out object[] outArgs)
		{
			BindingFlags bindingFlags = isStatic ? BindingFlags.Static | BindingFlags.FlattenHierarchy : BindingFlags.Instance;
			var methods = otype.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | bindingFlags);
			var len = methods.Length;
			for (var mi = 0; mi < len; mi++) {
				var m = methods[mi];
				if ((m.IsStatic == isStatic) && m.Name == name) {
					// attempt to convert method parameters
					if (Dynamic.ConvertMethodParameters(m, args, out outArgs)) {
						return m;
					}
				}
			}

			// method not found
			outArgs = null;
			return null;
		}
예제 #59
0
 public void NonGenericCreateNullBinder()
 {
     AssertExtensions.Throws <ArgumentNullException>("binder", () => CallSite.Create(typeof(Func <string>), null));
 }
        public override T BindDelegate <T>(CallSite <T> site, object[] args)
        {
            switch (Operation)
            {
            case ExpressionType.Negate:
                if (CompilerHelpers.GetType(args[0]) == typeof(int))
                {
                    if (typeof(T) == typeof(Func <CallSite, object, object>))
                    {
                        return((T)(object)new Func <CallSite, object, object>(IntNegate));
                    }
                }
                break;

            case ExpressionType.IsFalse:
                if (args[0] == null)
                {
                    if (typeof(T) == typeof(Func <CallSite, object, bool>))
                    {
                        return((T)(object)new Func <CallSite, object, bool>(NoneIsFalse));
                    }
                }
                else if (args[0].GetType() == typeof(string))
                {
                    if (typeof(T) == typeof(Func <CallSite, object, bool>))
                    {
                        return((T)(object)new Func <CallSite, object, bool>(StringIsFalse));
                    }
                }
                else if (args[0].GetType() == typeof(bool))
                {
                    if (typeof(T) == typeof(Func <CallSite, object, bool>))
                    {
                        return((T)(object)new Func <CallSite, object, bool>(BoolIsFalse));
                    }
                }
                else if (args[0].GetType() == typeof(List))
                {
                    if (typeof(T) == typeof(Func <CallSite, object, bool>))
                    {
                        return((T)(object)new Func <CallSite, object, bool>(ListIsFalse));
                    }
                }
                else if (args[0].GetType() == typeof(PythonTuple))
                {
                    if (typeof(T) == typeof(Func <CallSite, object, bool>))
                    {
                        return((T)(object)new Func <CallSite, object, bool>(TupleIsFalse));
                    }
                }
                else if (args[0].GetType() == typeof(int))
                {
                    if (typeof(T) == typeof(Func <CallSite, object, bool>))
                    {
                        return((T)(object)new Func <CallSite, object, bool>(IntIsFalse));
                    }
                }
                break;

            case ExpressionType.Not:
                if (args[0] == null)
                {
                    if (typeof(T) == typeof(Func <CallSite, object, object>))
                    {
                        return((T)(object)new Func <CallSite, object, object>(NoneNot));
                    }
                }
                else if (args[0].GetType() == typeof(string))
                {
                    if (typeof(T) == typeof(Func <CallSite, object, object>))
                    {
                        return((T)(object)new Func <CallSite, object, object>(StringNot));
                    }
                }
                else if (args[0].GetType() == typeof(bool))
                {
                    if (typeof(T) == typeof(Func <CallSite, object, object>))
                    {
                        return((T)(object)new Func <CallSite, object, object>(BoolNot));
                    }
                }
                else if (args[0].GetType() == typeof(List))
                {
                    if (typeof(T) == typeof(Func <CallSite, object, object>))
                    {
                        return((T)(object)new Func <CallSite, object, object>(ListNot));
                    }
                }
                else if (args[0].GetType() == typeof(PythonTuple))
                {
                    if (typeof(T) == typeof(Func <CallSite, object, object>))
                    {
                        return((T)(object)new Func <CallSite, object, object>(TupleNot));
                    }
                }
                else if (args[0].GetType() == typeof(int))
                {
                    if (typeof(T) == typeof(Func <CallSite, object, object>))
                    {
                        return((T)(object)new Func <CallSite, object, object>(IntNot));
                    }
                }
                break;
            }

            return(base.BindDelegate(site, args));
        }