public CQ_Value ComputeValue(CQ_Content content)
        {
#if CQUARK_DEBUG
            content.InStack(this);
#endif
            CQ_Value[] parameters = CQ_ObjPool.PopArray(_expressions.Count);
            for (int i = 0; i < _expressions.Count; i++)
            {
                parameters[i] = _expressions[i].ComputeValue(content);
            }

            CQ_Value value = CQ_Value.Null;

            //这几行是为了快速获取Unity的静态变量,而不需要反射
            if (!Wrap.New(type.typeBridge.type, parameters, out value))
            {
                value = type._class.New(content, parameters);
            }

#if CQUARK_DEBUG
            content.OutStack(this);
#endif
            CQ_ObjPool.PushArray(parameters);
            return(value);
        }
示例#2
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 CQ_Value ComputeValue(CQ_Content content)
        {
#if CQUARK_DEBUG
            content.InStack(this);
#endif

            CQ_Value[] parameters = CQ_ObjPool.PopArray(_expressions.Count);
            for (int i = 0; i < _expressions.Count; i++)
            {
                parameters[i] = _expressions[i].ComputeValue(content);
            }

            CQ_Value value = CQ_Value.Null;

            //这几行是为了快速获取Unity的静态变量,而不需要反射
            if (!Wrap.StaticCall(type.typeBridge.type, functionName, parameters, out value))
            {
                if (cache == null || cache.cachefail)
                {
                    cache = new MethodCache();
                    value = type._class.StaticCall(content, functionName, parameters, cache);
                }
                else
                {
                    value = type._class.StaticCallCache(content, parameters, cache);
                }
            }
#if CQUARK_DEBUG
            content.OutStack(this);
#endif
            CQ_ObjPool.PushArray(parameters);
            return(value);
        }
        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));
        }
示例#5
0
        public CQ_Value New(CQ_Content content, CQ_Value[] _params)
        {
            if (contentMemberCalc == null)
            {
                contentMemberCalc = CQ_ObjPool.PopContent();
            }

            NewStatic();


            CQ_ClassInstance c = new CQ_ClassInstance();

            c.type = this;

            foreach (KeyValuePair <string, Member> i in this.members)
            {
                if (i.Value.bStatic == false)
                {
                    if (i.Value.expr_defvalue == null)
                    {
                        CQ_Value val = new CQ_Value();
                        val.SetObject(i.Value.m_itype.typeBridge, i.Value.m_itype.defaultValue);
                        c.member[i.Key] = val;
                        //sv.value_value.member[i.Key] = new CQ_Value();
                        //sv.value_value.member[i.Key].SetCQType(i.Value.type.cqType);
                        //sv.value_value.member[i.Key].value = i.Value.type.defaultValue;
                    }
                    else
                    {
                        var value = i.Value.expr_defvalue.ComputeValue(contentMemberCalc);
                        if (i.Value.m_itype.typeBridge != value.typeBridge)
                        {
                            CQ_Value val = new CQ_Value();
                            val.SetObject(i.Value.m_itype.typeBridge, value.ConvertTo(i.Value.m_itype.typeBridge));
                            c.member[i.Key] = val;
                            //sv.value_value.member[i.Key] = val;
                            //sv.value_value.member[i.Key] = new CQ_Value();
                            //sv.value_value.member[i.Key].SetCQType(i.Value.type.cqType);
                            //sv.value_value.member[i.Key].value = value.ConvertTo(i.Value.type.cqType);
                        }
                        else
                        {
                            c.member[i.Key] = value;
                        }
                    }
                }
            }
            if (this.functions.ContainsKey(this.Name))//有同名函数就调用
            {
                MemberCall(content, c, this.Name, _params);
            }

            CQ_Value v = new CQ_Value();

            v.SetObject(this, c);
            return(v);
        }
示例#6
0
        public CQ_Content Clone()
        {
            CQ_Content con = CQ_ObjPool.PopContent();

            foreach (var c in this.values)
            {
                con.values.Add(c.Key, c.Value);
            }

            con.CallThis = this.CallThis;
            con.CallType = this.CallType;

            return(con);
        }
示例#7
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));
            }
        }
示例#8
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();
        }
示例#9
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();
        }
示例#10
0
        public CQ_Value ComputeValue(CQ_Content content)
        {
#if CQUARK_DEBUG
            content.InStack(this);
#endif
            CQ_Value parent = _expressions[0].ComputeValue(content);

#if CQUARK_DEBUG
            if (parent == CQ_Value.Null)
            {
                throw new Exception("调用空对象的方法:" + _expressions[0].ToString() + ":" + ToString());
            }
#endif


            CQ_Value[] parameters = CQ_ObjPool.PopArray(_expressions.Count - 1);
            for (int i = 0; i < _expressions.Count - 1; i++)
            {
                parameters[i] = _expressions[i + 1].ComputeValue(content);
            }

            CQ_Value value = CQ_Value.Null;

            //这几行是为了快速获取Unity的静态变量,而不需要反射
            object obj = parent.GetObject();
            if (!Wrap.MemberCall(parent.m_type, obj, functionName, parameters, out value))
            {
                //TODO 要么注册所有基本类型(bool,int,string...)要么这里特殊处理
                if (functionName == "ToString" && parameters.Length == 0)
                {
                    CQ_Value ret = new CQ_Value();
                    ret.SetObject(typeof(string), obj.ToString());
                    return(ret);
                }
                else if (obj is UnityEngine.MonoBehaviour && functionName == "StartCoroutine" &&
                         parameters.Length >= 1 && parameters[0].GetObject() is CQ_Expression_Block)
                {
                    //从西瓜调用的ClassSystem.StartCoroutine(CquarkMethod());不需要走cache
                    UnityEngine.MonoBehaviour mb   = obj as UnityEngine.MonoBehaviour;
                    CQ_Expression_Block       call = parameters[0].GetObject()  as CQ_Expression_Block;

                    CQ_Value ret = new CQ_Value();
                    ret.SetObject(typeof(UnityEngine.Coroutine),
                                  mb.StartCoroutine(call.callObj.CallType.CoroutineCall(call, call.callObj, mb)));
                    return(ret);
                }
                else
                {
                    var iclass = CQuark.AppDomain.GetITypeByCQValue(parent)._class;
                    if (cache == null || cache.cachefail)
                    {
                        cache = new MethodCache();
                        value = iclass.MemberCall(content, obj, functionName, parameters, cache);
                    }
                    else
                    {
                        value = iclass.MemberCallCache(content, obj, parameters, cache);
                    }
                }
            }


#if CQUARK_DEBUG
            content.OutStack(this);
#endif
            CQ_ObjPool.PushArray(parameters);
            return(value);
        }
        public CQ_Value ComputeValue(CQ_Content content)
        {
#if CQUARK_DEBUG
            content.InStack(this);
#endif

            CQ_Value[] parameters = CQ_ObjPool.PopArray(_expressions.Count);
            for (int i = 0; i < _expressions.Count; i++)
            {
                parameters[i] = _expressions[i].ComputeValue(content);
            }

            CQ_Value v = CQ_Value.Null;

            Class_CQuark.Function retFunc = null;
            bool bFind = false;
            if (content.CallType != null)
            {
                bFind = content.CallType.functions.TryGetValue(funcname, out retFunc);
            }

            if (bFind)
            {
                if (retFunc.bStatic)
                {
                    v = content.CallType.StaticCall(content, funcname, parameters);
                }
                else
                {
                    v = content.CallType.MemberCall(content, content.CallThis, funcname, parameters);
                }
            }
            else
            {
                v = content.GetQuiet(funcname);
                if (v.IsDelegate)
                {
                    Delegate d = v.GetObject() as Delegate;
                    v = new CQ_Value();
                    object[] obja = new object[parameters.Length];
                    for (int i = 0; i < parameters.Length; i++)
                    {
                        obja[i] = parameters[i].GetObject();
                    }
                    object obj = d.DynamicInvoke(obja);

                    if (obj == null)
                    {
                        v.SetNoneTypeObject(null);
                    }
                    else
                    {
                        v.SetObject(obj.GetType(), obj);
                    }
                }
                else
                {
                    throw new Exception(funcname + "没有这样的方法");
                    //v = CQuark.AppDomain.GetMethod(funcname).Call(content, list);
                }
            }
            //操作变量之
            //做数学计算
            //从上下文取值
            //_value = null;
#if CQUARK_DEBUG
            content.OutStack(this);
#endif
            CQ_ObjPool.PushArray(parameters);
            return(v);
        }