Esempio n. 1
0
        unsafe StackObject *ILInvokeSub(ILIntepreter intp, StackObject *esp, IList <object> mStack)
        {
            var  ebp = esp;
            bool unhandled;

            if (method.HasThis)
            {
                esp = ILIntepreter.PushObject(esp, mStack, instance);
            }
            int paramCnt = method.ParameterCount;

            for (int i = paramCnt; i > 0; i--)
            {
                intp.CopyToStack(esp, Minus(ebp, i), mStack);
                esp++;
            }
            var ret = intp.Execute(method, esp, out unhandled);

            if (next != null)
            {
                if (method.ReturnType != appdomain.VoidType)
                {
                    intp.Free(ret - 1);//Return value for multicast delegate doesn't make sense, only return the last one's value
                }
                DelegateAdapter n = (DelegateAdapter)next;
                ret = n.ILInvokeSub(intp, ebp, mStack);
            }
            return(ret);
        }
Esempio n. 2
0
        public void Invoke()
        {
            if (invocated)
            {
                throw new NotSupportedException("A invocation context can only be used once");
            }
            invocated = true;
            var cnt = method.HasThis ? method.ParameterCount + 1 : method.ParameterCount;

            if (cnt != paramCnt)
            {
                throw new ArgumentException("Argument count mismatch");
            }
            bool unhandledException;

            if (useRegister)
            {
                esp = intp.ExecuteR(method, esp, out unhandledException);
            }
            else
            {
                esp = intp.Execute(method, esp, out unhandledException);
            }
            esp--;
        }
Esempio n. 3
0
        unsafe StackObject *ILInvokeSub(ILIntepreter intp, StackObject *esp, IList <object> mStack)
        {
            var  ebp = esp;
            bool unhandled;

            if (method.HasThis)
            {
                esp = ILIntepreter.PushObject(esp, mStack, instance);
            }
            int paramCnt = method.ParameterCount;

            if (method.IsExtend && instance != null)
            {
                esp = ILIntepreter.PushObject(esp, mStack, instance);
                paramCnt--;
            }
            bool useRegister = method.ShouldUseRegisterVM;

            for (int i = paramCnt; i > 0; i--)
            {
                intp.CopyToStack(esp, Minus(ebp, i), mStack);
                if (esp->ObjectType < ObjectTypes.Object && useRegister)
                {
                    mStack.Add(null);
                }
                esp++;
            }
            StackObject *ret;

            if (useRegister)
            {
                ret = intp.ExecuteR(method, esp, out unhandled);
            }
            else
            {
                ret = intp.Execute(method, esp, out unhandled);
            }
            if (next != null)
            {
                if (method.ReturnType != appdomain.VoidType)
                {
                    intp.Free(ret - 1);//Return value for multicast delegate doesn't make sense, only return the last one's value
                }
                DelegateAdapter n = (DelegateAdapter)next;
                ret = n.ILInvokeSub(intp, ebp, mStack);
            }
            return(ret);
        }
Esempio n. 4
0
        /*public static object GetTypeFromHandle(ILContext ctx, object instance, object[] param, IType[] genericArguments)
         * {
         *  return param[0];
         * }*/

        public unsafe static StackObject *MethodInfoInvoke(ILIntepreter intp, StackObject *esp, IList <object> mStack, CLRMethod method, bool isNewObj)
        {
            AppDomain domain = intp.AppDomain;
            //Don't ask me why not esp - 3, unity won't return the right result
            var ret   = ILIntepreter.Minus(esp, 3);
            var param = esp - 1;
            var p     = StackObject.ToObject(param, domain, mStack);

            intp.Free(param);

            param = esp - 1 - 1;
            var obj = StackObject.ToObject(param, domain, mStack);

            intp.Free(param);

            param = ILIntepreter.Minus(esp, 3);
            object instance = CheckCrossBindingAdapter(StackObject.ToObject(param, domain, mStack));

            intp.Free(param);

            if (instance is ILRuntimeMethodInfo)
            {
                if (obj != null)
                {
                    esp = ILIntepreter.PushObject(ret, mStack, obj);
                }
                else
                {
                    esp = ret;
                }
                var ilmethod = ((ILRuntimeMethodInfo)instance).ILMethod;
                if (p != null)
                {
                    object[] arr = (object[])p;
                    for (int i = 0; i < ilmethod.ParameterCount; i++)
                    {
                        esp = ILIntepreter.PushObject(esp, mStack, CheckCrossBindingAdapter(arr[i]));
                    }
                }
                bool unhandled;
                ret = intp.Execute(ilmethod, esp, out unhandled);
                ILRuntimeMethodInfo imi = (ILRuntimeMethodInfo)instance;
                var rt = imi.ILMethod.ReturnType;
                if (rt != domain.VoidType)
                {
                    var res = ret - 1;
                    if (res->ObjectType < ObjectTypes.Object)
                    {
                        return(ILIntepreter.PushObject(res, mStack, rt.TypeForCLR.CheckCLRTypes(StackObject.ToObject(res, domain, mStack)), true));
                    }
                    else
                    {
                        return(ret);
                    }
                }
                else
                {
                    return(ILIntepreter.PushNull(ret));
                }
            }
            else
            {
                return(ILIntepreter.PushObject(ret, mStack, ((MethodInfo)instance).Invoke(obj, (object[])p)));
            }
        }