Exemple #1
0
        public override Delegate CreateDelegate(DeleFunction delefunc)
        {
            DeleFunction _func = delefunc;
            Delegate     _dele = delefunc.cacheFunction(this._type, null);

            if (_dele != null)
            {
                return(_dele);
            }
            Action <T> dele = (T param0) =>
            {
                var func = _func.calltype.functions[_func.function];
                if (func.expr_runtime != null)
                {
                    CQ_Content content = CQ_ObjPool.PopContent();
                    try
                    {
                        content.CallThis = _func.callthis;
                        content.CallType = _func.calltype;
                                                #if CQUARK_DEBUG
                        content.function = _func.function;
                                                #endif

                        CQ_Value p0 = new CQ_Value();
                        p0.SetObject(func._paramtypes[0].typeBridge, param0);
                        content.DefineAndSet(func._paramnames[0], func._paramtypes[0].typeBridge, p0);

                        func.expr_runtime.ComputeValue(content);
                        content.DepthRemove();
                    }
                    catch (Exception err)
                    {
                        string errinfo = "Dump Call in:";
                        if (_func.calltype != null)
                        {
                            errinfo += _func.calltype.Name + "::";
                        }
                        if (_func.function != null)
                        {
                            errinfo += _func.function;
                        }
                        errinfo += "\n";
                        DebugUtil.Log(errinfo + content.Dump());
                        throw err;
                    }
                    CQ_ObjPool.PushContent(content);
                }
            };
            Delegate d = dele as Delegate;

            if ((Type)this.typeBridge != typeof(Action))
            {
                _dele = Delegate.CreateDelegate(this.typeBridge, d.Target, d.Method);
            }
            else
            {
                _dele = dele;
            }
            return(delefunc.cacheFunction(this._type, _dele));
        }
        public override Delegate CreateDelegate(DeleFunction delefunc)
        {
            DeleFunction _func = delefunc;
            Delegate     _dele = delefunc.cacheFunction(this._type, null);

            if (_dele != null)
            {
                return(_dele);
            }
            NonVoidDelegate dele = delegate(T param, T1 param1)
            {
                var func = _func.calltype.functions[_func.function];
                if (func.expr_runtime != null)
                {
                    CQ_Content content = CQ_ObjPool.PopContent();
                    try
                    {
                        content.CallThis = _func.callthis;
                        content.CallType = _func.calltype;
                                                #if CQUARK_DEBUG
                        content.function = _func.function;
                                                #endif

                        CQ_Value p0 = new CQ_Value();
                        p0.SetObject(func._paramtypes[0].typeBridge, param);
                        content.DefineAndSet(func._paramnames[0], typeof(T), p0);

                        CQ_Value p1 = new CQ_Value();
                        p1.SetObject(func._paramtypes[0].typeBridge, param1);
                        content.DefineAndSet(func._paramnames[1], typeof(T1), p1);

                        CQ_Value retValue = func.expr_runtime.ComputeValue(content);
                        content.DepthRemove();
                        CQ_ObjPool.PushContent(content);
                        return((ReturnType)retValue.GetObject());
                    }
                    catch (Exception err)
                    {
                        string errinfo = "Dump Call in:";
                        if (_func.calltype != null)
                        {
                            errinfo += _func.calltype.Name + "::";
                        }
                        if (_func.function != null)
                        {
                            errinfo += _func.function;
                        }
                        errinfo += "\n";
                        DebugUtil.Log(errinfo + content.Dump());
                        throw err;
                    }
                }
                return(default(ReturnType));
            };

            _dele = Delegate.CreateDelegate(this.typeBridge, dele.Target, dele.Method);
            return(delefunc.cacheFunction(this._type, _dele));
        }
Exemple #3
0
        public virtual IEnumerator CoroutineCall(CQ_Content contentParent, object object_this, string func, CQ_Value[] _params, UnityEngine.MonoBehaviour coroutine)
        {
            Function funccache = null;

            if (this.functions.TryGetValue(func, out funccache))
            {
                if (!funccache.bStatic)
                {
                    CQ_Content content = CQ_ObjPool.PopContent();
                    content.CallType = this;
                    content.CallThis = object_this as CQ_ClassInstance;
#if CQUARK_DEBUG
                    content.function = func;
                    contentParent.InStack(content);//把这个上下文推给上层的上下文,这样如果崩溃是可以一层层找到原因的
#endif
                    for (int i = 0; i < funccache._paramtypes.Count; i++)
                    {
                        content.DefineAndSet(funccache._paramnames[i], _params[i].typeBridge, _params[i]);
                    }

                    var funcobj = funccache;
                    if (this.bInterface)
                    {
                        content.CallType = (object_this as CQ_ClassInstance).type;
                        funcobj          = (object_this as CQ_ClassInstance).type.functions[func];
                    }
                    if (funcobj.expr_runtime != null)
                    {
                        yield return(coroutine.StartCoroutine(funcobj.expr_runtime.CoroutineCompute(content, coroutine)));
                    }
#if CQUARK_DEBUG
                    contentParent.OutStack(content);
#endif
                    CQ_ObjPool.PushContent(content);
                }
            }
            else
            {
                yield return(MemberCall(contentParent, object_this, func, _params, null));
            }
        }
Exemple #4
0
        public CQ_Value MemberCall(CQ_Content contentParent, object object_this, string func, CQ_Value[] _params, MethodCache cache)
        {
            if (cache != null)
            {
                cache.cachefail = true;
            }
            Function funccache = null;

            if (this.functions.TryGetValue(func, out funccache))
            {
                if (funccache.bStatic == false)
                {
                    CQ_Content content = CQ_ObjPool.PopContent();
                    content.CallType = this;
                    content.CallThis = object_this as CQ_ClassInstance;

#if CQUARK_DEBUG
                    content.function = func;
                    contentParent.InStack(content);//把这个上下文推给上层的上下文,这样如果崩溃是可以一层层找到原因的
#endif
                    for (int i = 0; i < funccache._paramtypes.Count; i++)
                    {
                        //content.DefineAndSet(funccache._paramnames[i], funccache._paramtypes[i].typeBridge, _params[i].GetValue());
                        content.DefineAndSet(funccache._paramnames[i], _params[i].typeBridge, _params[i]);
                    }

                    //如果返回值是IEnumerator的话,这里把方法返回出来
                    if (funccache._returntype != null && funccache._returntype.typeBridge.type == typeof(IEnumerator))
                    {
                        CQ_Value            ienumerator = new CQ_Value();
                        CQ_Expression_Block funcCQ      = funccache.expr_runtime as CQ_Expression_Block;
                        funcCQ.callObj = content;
                        ienumerator.SetObject(typeof(CQ_Expression_Block), funcCQ);
                        return(ienumerator);
                    }


                    CQ_Value value   = CQ_Value.Null;
                    var      funcobj = funccache;
                    if (this.bInterface)
                    {
                        content.CallType = (object_this as CQ_ClassInstance).type;
                        funcobj          = (object_this as CQ_ClassInstance).type.functions[func];
                    }
                    if (funcobj.expr_runtime != null)
                    {
                        value = funcobj.expr_runtime.ComputeValue(content);
                    }
#if CQUARK_DEBUG
                    contentParent.OutStack(content);
#endif
                    CQ_ObjPool.PushContent(content);
                    return(value);
                }
            }
            else if (this.members.ContainsKey(func))
            {
                if (this.members[func].bStatic == false)
                {
                    Delegate dele = (object_this as CQ_ClassInstance).member[func].GetObject() as Delegate;
                    if (dele != null)
                    {
                        CQ_Value value = new CQ_Value();
                        object[] objs  = new object[_params.Length];
                        for (int i = 0; i < _params.Length; i++)
                        {
                            objs[i] = _params[i].GetObject();
                        }
                        object obj = dele.DynamicInvoke(objs);
                        if (obj == null)
                        {
                            return(CQ_Value.Null);
                        }
                        else
                        {
                            value.SetObject(obj.GetType(), obj);
                            return(value);
                        }
                    }
                }
            }
            throw new NotImplementedException();
        }
Exemple #5
0
        public CQ_Value StaticCall(CQ_Content contentParent, string function, CQ_Value[] _params, MethodCache cache)
        {
            if (cache != null)
            {
                cache.cachefail = true;
            }
            NewStatic();
            if (this.functions.ContainsKey(function))
            {
                if (this.functions[function].bStatic == true)
                {
                    CQ_Content content = CQ_ObjPool.PopContent();
                    content.CallType = this;
                    content.CallThis = null;

#if CQUARK_DEBUG
                    content.function = function;
                    contentParent.InStack(content);//把这个上下文推给上层的上下文,这样如果崩溃是可以一层层找到原因的
#endif
                    // int i = 0;
                    for (int i = 0; i < functions[function]._paramtypes.Count; i++)
                    {
                        //content.DefineAndSet(functions[function]._paramnames[i], functions[function]._paramtypes[i].typeBridge, _params[i].GetValue());
                        content.DefineAndSet(functions[function]._paramnames[i], _params[i].typeBridge, _params[i]);
                    }
                    CQ_Value value = CQ_Value.Null;
                    if (this.functions[function].expr_runtime != null)
                    {
                        value = this.functions[function].expr_runtime.ComputeValue(content);
                    }
#if CQUARK_DEBUG
                    contentParent.OutStack(content);
#endif
                    CQ_ObjPool.PushContent(content);
                    return(value);
                }
            }
            else if (this.members.ContainsKey(function))
            {
                if (this.members[function].bStatic == true)
                {
                    Delegate dele = this.staticMemberInstance[function].GetObject() as Delegate;
                    if (dele != null)
                    {
                        CQ_Value value = new CQ_Value();
                        object[] objs  = new object[_params.Length];
                        for (int i = 0; i < _params.Length; i++)
                        {
                            objs[i] = _params[i].GetObject();
                        }
                        object obj = dele.DynamicInvoke(objs);
                        if (obj == null)
                        {
                            return(CQ_Value.Null);
                        }
                        else
                        {
                            value.SetObject(obj.GetType(), obj);
                            return(value);
                        }
                        //value.breakBlock = BreakType.None;
                    }
                }
            }
            throw new NotImplementedException();
        }