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, T1, T2> dele = (T param0, T1 param1, T2 param2) =>
            {
                var func = _func.calltype.functions[_func.function];
                if (func.expr_runtime != null)
                {
                    CQ_Content content = new CQ_Content();
                    try
                    {
                        content.DepthAdd();
                        content.CallThis = _func.callthis;
                        content.CallType = _func.calltype;
                                                #if CQUARK_DEBUG
                        content.function = _func.function;
                                                #endif

                        content.DefineAndSet(func._paramnames[0], func._paramtypes[0].typeBridge, param0);
                        content.DefineAndSet(func._paramnames[1], func._paramtypes[1].typeBridge, param1);
                        content.DefineAndSet(func._paramnames[2], func._paramtypes[2].typeBridge, param2);

                        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;
                    }
                }
            };
            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(DeleLambda lambda)
        {
            CQ_Content         content = lambda.content.Clone();
            var                pnames  = lambda.paramNames;
            var                expr    = lambda.expr_func;
            Action <T, T1, T2> dele    = (T param0, T1 param1, T2 param2) =>
            {
                if (expr != null)
                {
                    try
                    {
                        content.DepthAdd();

                        CQ_Value p0 = new CQ_Value();
                        p0.SetObject(typeof(T), param0);
                        content.DefineAndSet(pnames[0], typeof(T), p0);

                        CQ_Value p1 = new CQ_Value();
                        p1.SetObject(typeof(T1), param1);
                        content.DefineAndSet(pnames[1], typeof(T1), p1);

                        CQ_Value p2 = new CQ_Value();
                        p2.SetObject(typeof(T2), param2);
                        content.DefineAndSet(pnames[2], typeof(T2), p2);

                        expr.ComputeValue(content);

                        content.DepthRemove();
                    }
                    catch (Exception err)
                    {
                        string errinfo = "Dump Call lambda in:";
                        if (content.CallType != null)
                        {
                            errinfo += content.CallType.Name + "::";
                        }
                                                #if CQUARK_DEBUG
                        if (content.function != null)
                        {
                            errinfo += content.function;
                        }
                                                #endif
                        errinfo += "\n";
                        DebugUtil.Log(errinfo + content.Dump());
                        throw err;
                    }
                }
            };
            Delegate d = dele as Delegate;

            if ((Type)this.typeBridge != typeof(Action <T, T1, T2>))
            {
                return(Delegate.CreateDelegate(this.typeBridge, d.Target, d.Method));
            }
            else
            {
                return(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));
        }
        public override Delegate CreateDelegate(DeleLambda lambda)
        {
            CQ_Content content = lambda.content.Clone();
            var        pnames  = lambda.paramNames;
            var        expr    = lambda.expr_func;

            NonVoidDelegate dele = delegate(T param0, T1 param1)
            {
                if (expr != null)
                {
                    try
                    {
                        content.DepthAdd();

                        CQ_Value p0 = new CQ_Value();
                        p0.SetObject(typeof(T), param0);
                        content.DefineAndSet(pnames[0], typeof(T), p0);

                        CQ_Value p1 = new CQ_Value();
                        p1.SetObject(typeof(T1), param1);
                        content.DefineAndSet(pnames[1], typeof(T1), p1);

                        CQ_Value retValue = expr.ComputeValue(content);

                        content.DepthRemove();

                        return((ReturnType)retValue.GetObject());
                    }
                    catch (Exception err)
                    {
                        string errinfo = "Dump Call lambda in:";
                        if (content.CallType != null)
                        {
                            errinfo += content.CallType.Name + "::";
                        }
                                                #if CQUARK_DEBUG
                        if (content.function != null)
                        {
                            errinfo += content.function;
                        }
                                                #endif

                        errinfo += "\n";
                        DebugUtil.Log(errinfo + content.Dump());
                        throw err;
                    }
                }
                return(default(ReturnType));
            };

            Delegate d = dele as Delegate;

            return(Delegate.CreateDelegate(this.typeBridge, d.Target, d.Method));
        }
        public Delegate CreateDelegate(ICQ_Environment env, DeleFunction delefunc)
        {
            DeleFunction _func = delefunc;
            Delegate     _dele = delefunc.cacheFunction(this._type, null);

            if (_dele != null)
            {
                return(_dele);
            }
            NonVoidDelegate dele = delegate(T param0, T1 param1, T2 param2)
            {
                var func = _func.calltype.functions[_func.function];
                if (func.expr_runtime != null)
                {
                    CQ_Content content = new CQ_Content(env, true);
                    try
                    {
                        content.DepthAdd();
                        content.CallThis = _func.callthis;
                        content.CallType = _func.calltype;
                        content.function = _func.function;

                        content.DefineAndSet(func._paramnames[0], func._paramtypes[0].type, param0);
                        content.DefineAndSet(func._paramnames[1], func._paramtypes[1].type, param1);
                        content.DefineAndSet(func._paramnames[2], func._paramtypes[2].type, param2);

                        CQ_Content.Value retValue = func.expr_runtime.ComputeValue(content);
                        content.DepthRemove();

                        return((ReturnType)retValue.value);
                    }
                    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";
                        env.logger.Log(errinfo + content.Dump());
                        throw err;
                    }
                }
                return(default(ReturnType));
            };

            _dele = Delegate.CreateDelegate(this.type, dele.Target, dele.Method);
            return(delefunc.cacheFunction(this._type, _dele));
        }
Exemple #6
0
        public Delegate CreateDelegate(ICQ_Environment env, DeleLambda lambda)
        {
            CQ_Content     content = lambda.content.Clone();
            var            pnames  = lambda.paramNames;
            var            expr    = lambda.expr_func;
            Action <T, T1> dele    = (T param0, T1 param1) =>
            {
                if (expr != null)
                {
                    try
                    {
                        content.DepthAdd();

                        content.DefineAndSet(pnames[0], typeof(T), param0);
                        content.DefineAndSet(pnames[1], typeof(T1), param1);

                        expr.ComputeValue(content);

                        content.DepthRemove();
                    }
                    catch (Exception err)
                    {
                        string errinfo = "Dump Call lambda in:";
                        if (content.CallType != null)
                        {
                            errinfo += content.CallType.Name + "::";
                        }
                        if (content.function != null)
                        {
                            errinfo += content.function;
                        }
                        errinfo += "\n";
                        env.logger.Log(errinfo + content.Dump());
                        throw err;
                    }
                }
            };
            Delegate d = dele as Delegate;

            if ((Type)this.type != typeof(Action <T, T1>))
            {
                return(Delegate.CreateDelegate(this.type, d.Target, d.Method));
            }
            else
            {
                return(dele);
            }
        }
        public CQ_Content.Value ComputeValue(CQ_Content content)
        {
            content.InStack(this);

            if (_listParam != null && _listParam.Count > 0)
            {
                CQ_Content.Value v   = _listParam[0].ComputeValue(content);
                object           val = v.value;
                if ((Type)value_type == typeof(CQ_Type_Var.var))
                {
                    if (v.type != null)
                    {
                        value_type = v.type;
                    }
                }
                else if (v.type != value_type)
                {
                    val = content.environment.GetType(v.type).ConvertTo(content, v.value, value_type);
                }

                content.DefineAndSet(value_name, value_type, val);
            }
            else
            {
                content.Define(value_name, value_type);
            }
            //设置环境变量为
            content.OutStack(this);

            return(null);
        }
Exemple #8
0
        public CQ_Value ComputeValue(CQ_Content content)
        {
#if CQUARK_DEBUG
            content.InStack(this);
#endif
            if (__expressions != null && __expressions.Count > 0)
            {
                CQ_Value v   = __expressions[0].ComputeValue(content);
                object   val = v.value;
                if ((Type)value_type == typeof(Type_Var.var))
                {
                    if (v.type != null)
                    {
                        value_type = v.type;
                    }
                }
                else if (v.type != value_type)
                {
                    val = v.ConvertTo(value_type);
                }

                content.DefineAndSet(value_name, value_type, val);
            }
            else
            {
                content.Define(value_name, value_type);
            }
#if CQUARK_DEBUG
            content.OutStack(this);
#endif
            return(null);
        }
Exemple #9
0
        public CQ_Value ComputeValue(CQ_Content content)
        {
#if CQUARK_DEBUG
            content.InStack(this);
#endif
            if (__expressions != null && __expressions.Count > 0)
            {
                CQ_Value v = __expressions[0].ComputeValue(content);
                //object val = v.GetValue();
                //if((Type)value_type == typeof(Type_Var.var)) {
                //    if(!v.TypeIsEmpty)
                //        value_type = v.typeBridge;

                //}
                //else if(v.typeBridge != value_type) {
                //    val = v.ConvertTo(value_type);

                //}

                content.DefineAndSet(value_name, value_type, v);
            }
            else
            {
                content.Define(value_name, value_type);
            }
#if CQUARK_DEBUG
            content.OutStack(this);
#endif
            return(CQ_Value.Null);
        }
        public Delegate CreateDelegate(ICQ_Environment env, DeleLambda lambda)
        {
            CQ_Content content = lambda.content.Clone();
            var        pnames  = lambda.paramNames;
            var        expr    = lambda.expr_func;

            NonVoidDelegate dele = delegate(T param0, T1 param1, T2 param2)
            {
                if (expr != null)
                {
                    try
                    {
                        content.DepthAdd();

                        content.DefineAndSet(pnames[0], typeof(T), param0);
                        content.DefineAndSet(pnames[1], typeof(T1), param1);
                        content.DefineAndSet(pnames[2], typeof(T2), param2);
                        CQ_Content.Value retValue = expr.ComputeValue(content);

                        content.DepthRemove();

                        return((ReturnType)retValue.value);
                    }
                    catch (Exception err)
                    {
                        string errinfo = "Dump Call lambda in:";
                        if (content.CallType != null)
                        {
                            errinfo += content.CallType.Name + "::";
                        }
                        if (content.function != null)
                        {
                            errinfo += content.function;
                        }
                        errinfo += "\n";
                        env.logger.Log(errinfo + content.Dump());
                        throw err;
                    }
                }
                return(default(ReturnType));
            };

            Delegate d = dele as Delegate;

            return(Delegate.CreateDelegate(this.type, d.Target, d.Method));
        }
Exemple #11
0
 public void SetValue(string name, object v)
 {
     if (content == null)
     {
         content = env.CreateContent();
     }
     content.DefineAndSet(name, v.GetType(), v);
 }
        public Delegate CreateDelegate(ICQ_Environment env, 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 = new CQ_Content(env, true);
                    try
                    {
                        content.DepthAdd();
                        content.CallThis = _func.callthis;
                        content.CallType = _func.calltype;
                        content.function = _func.function;

                        content.DefineAndSet(func._paramnames[0], func._paramtypes[0].type, param0);

                        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";
                        env.logger.Log(errinfo + content.Dump());
                        throw err;
                    }
                }
            };
            Delegate d = dele as Delegate;

            if ((Type)this.type != typeof(Action))
            {
                _dele = Delegate.CreateDelegate(this.type, d.Target, d.Method);
            }
            else
            {
                _dele = dele;
            }
            return(delefunc.cacheFunction(this._type, _dele));
        }
Exemple #13
0
        public CQ_Content.Value ComputeValue(CQ_Content content)
        {
            content.InStack(this);
            List <string> depth__;

            content.Record(out depth__);
            try
            {
                ICQ_Expression expr = listParam[0];
                if (expr is CQ_Expression_Block)
                {
                    expr.ComputeValue(content);
                }
                else
                {
                    content.DepthAdd();
                    expr.ComputeValue(content);
                    content.DepthRemove();
                }
            }
            catch (Exception err)
            {
                bool bParse = false;
                int  i      = 1;
                while (i < listParam.Count)
                {
                    CQ_Expression_Define def = listParam[i] as CQ_Expression_Define;
                    if (err.GetType() == (Type)def.value_type || err.GetType().IsSubclassOf((Type)def.value_type))
                    {
                        content.DepthAdd();
                        content.DefineAndSet(def.value_name, def.value_type, err);

                        listParam[i + 1].ComputeValue(content);
                        content.DepthRemove();
                        bParse = true;
                        break;
                    }
                    i += 2;
                }
                if (!bParse)
                {
                    throw err;
                }
            }
            content.Restore(depth__, this);
            //while((bool)expr_continue.value);

            //for 逻辑
            //做数学计算
            //从上下文取值
            //_value = null;
            content.OutStack(this);
            return(null);
        }
        public CQ_Value ComputeValue(CQ_Content content)
        {
#if CQUARK_DEBUG
            content.InStack(this);
#endif
            int oldDepthCount = content.Record();
            try {
                ICQ_Expression expr = _expressions[0];
                if (expr is CQ_Expression_Block)
                {
                    expr.ComputeValue(content);
                }
                else
                {
                    content.DepthAdd();
                    expr.ComputeValue(content);
                    content.DepthRemove();
                }
            }
            catch (Exception err) {
                bool bParse = false;
                int  i      = 1;
                while (i < _expressions.Count)
                {
                    CQ_Expression_Define def = _expressions[i] as CQ_Expression_Define;
                    if (err.GetType() == (Type)def.value_type || err.GetType().IsSubclassOf((Type)def.value_type))
                    {
                        content.DepthAdd();
                        CQ_Value errVal = new CQ_Value();
                        errVal.SetObject(def.value_type, err);
                        content.DefineAndSet(def.value_name, def.value_type, errVal);

                        _expressions[i + 1].ComputeValue(content);
                        content.DepthRemove();
                        bParse = true;
                        break;
                    }
                    i += 2;
                }
                if (!bParse)
                {
                    throw err;
                }
            }
            content.Restore(oldDepthCount, this);
            //while((bool)expr_continue.value);

#if CQUARK_DEBUG
            content.OutStack(this);
#endif
            return(CQ_Value.Null);
        }
Exemple #15
0
        public virtual IEnumerator CoroutineCall(CQ_Content contentParent, object object_this, string func, IList <CQ_Value> _params, ICoroutine coroutine)
        {
            //TODO
            Function funccache = null;

            if (this.functions.TryGetValue(func, out funccache))
            {
                if (funccache.bStatic == false)
                {
                    CQ_Content content = new CQ_Content();

                    content.CallType = this;
                    content.CallThis = object_this as CQClassInstance;
#if CQUARK_DEBUG
                    content.function = func;
                    contentParent.InStack(content);//把这个上下文推给上层的上下文,这样如果崩溃是可以一层层找到原因的
#endif
                    for (int i = 0; i < funccache._paramtypes.Count; i++)
                    //int i = 0;
                    //foreach (var p in this.functions[func]._params)
                    {
                        content.DefineAndSet(funccache._paramnames[i], funccache._paramtypes[i].typeBridge, _params[i].value);
                        //i++;
                    }
                    //CQ_Content.Value value = null;
                    var funcobj = funccache;
                    if (this.bInterface)
                    {
                        content.CallType = (object_this as CQClassInstance).type;
                        funcobj          = (object_this as CQClassInstance).type.functions[func];
                    }
                    if (funcobj.expr_runtime != null)
                    {
                        yield return(coroutine.StartNewCoroutine(funcobj.expr_runtime.CoroutineCompute(content, coroutine)));
                        //						if (value != null)
                        //							value.breakBlock = 0;
                    }
#if CQUARK_DEBUG
                    contentParent.OutStack(content);
#endif

                    //					return value;
                }
            }
            else
            {
                yield return(MemberCall(contentParent, object_this, func, _params, null));
            }
        }
Exemple #16
0
        public virtual IEnumerator CoroutineCall(CQ_Content contentParent, object object_this, string func, IList <CQ_Content.Value> _params, ICoroutine coroutine)
        {
            //TODO
            if (this.functions.ContainsKey(func))
            {
                if (this.functions[func].bStatic == false)
                {
                    CQ_Content content = new CQ_Content(contentParent.environment, true);

                    contentParent.InStack(content);                    //把这个上下文推给上层的上下文,这样如果崩溃是可以一层层找到原因的
                    content.CallType = this;
                    content.CallThis = object_this as SInstance;
                    content.function = func;
                    for (int i = 0; i < this.functions[func]._paramtypes.Count; i++)
                    //int i = 0;
                    //foreach (var p in this.functions[func]._params)
                    {
                        content.DefineAndSet(this.functions[func]._paramnames[i], this.functions[func]._paramtypes[i].type, _params[i].value);
                        //i++;
                    }
                    CQ_Content.Value value = null;
                    var funcobj            = this.functions[func];
                    if (this.bInterface)
                    {
                        content.CallType = (object_this as SInstance).type;
                        funcobj          = (object_this as SInstance).type.functions[func];
                    }
                    if (funcobj.expr_runtime != null)
                    {
                        yield return(coroutine.StartNewCoroutine(funcobj.expr_runtime.CoroutineCompute(content, coroutine)));
//						if (value != null)
//							value.breakBlock = 0;
                    }
                    contentParent.OutStack(content);

//					return value;
                }
            }
            else
            {
                yield return(MemberCall(contentParent, object_this, func, _params, null));
            }
        }
Exemple #17
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 #18
0
        public IEnumerator CoroutineCompute(CQ_Content content, ICoroutine coroutine)
        {
#if CQUARK_DEBUG
            content.InStack(this);
#endif
            if (__expressions != null && __expressions.Count > 0)
            {
                if (__expressions[0].hasCoroutine)
                {
                    yield return(coroutine.StartNewCoroutine(CoroutineCompute(content, coroutine)));
                }
                else
                {
                    CQ_Value v   = __expressions[0].ComputeValue(content);
                    object   val = v.value;
                    if ((Type)value_type == typeof(Type_Var.var))
                    {
                        if (v.type != null)
                        {
                            value_type = v.type;
                        }
                    }
                    else if (v.type != value_type)
                    {
                        val = v.ConvertTo(value_type);
                    }

                    content.DefineAndSet(value_name, value_type, val);
                }
            }
            else
            {
                content.Define(value_name, value_type);
            }
#if CQUARK_DEBUG
            content.OutStack(this);
#endif
        }
Exemple #19
0
        public IEnumerator CoroutineCompute(CQ_Content content, UnityEngine.MonoBehaviour coroutine)
        {
#if CQUARK_DEBUG
            content.InStack(this);
#endif
            if (__expressions != null && __expressions.Count > 0)
            {
                if (__expressions[0].hasCoroutine)
                {
                    yield return(coroutine.StartCoroutine(CoroutineCompute(content, coroutine)));
                }
                else
                {
                    CQ_Value v = __expressions[0].ComputeValue(content);
                    //object val = v.GetValue();
                    //if((Type)value_type == typeof(Type_Var.var)) {
                    //    if(!v.TypeIsEmpty)
                    //        value_type = v.typeBridge;

                    //}
                    //else if(v.typeBridge != value_type) {
                    //    val = v.ConvertTo(value_type);

                    //}

                    content.DefineAndSet(value_name, value_type, v);
                }
            }
            else
            {
                content.Define(value_name, value_type);
            }
#if CQUARK_DEBUG
            content.OutStack(this);
#endif
        }
        public IEnumerator CoroutineCompute(CQ_Content content, ICoroutine coroutine)
        {
            content.InStack(this);

            if (_listParam != null && _listParam.Count > 0)
            {
                if (_listParam[0].hasCoroutine)
                {
                    yield return(coroutine.StartNewCoroutine(CoroutineCompute(content, coroutine)));
                }
                else
                {
                    CQ_Content.Value v   = _listParam[0].ComputeValue(content);
                    object           val = v.value;
                    if ((Type)value_type == typeof(CQ_Type_Var.var))
                    {
                        if (v.type != null)
                        {
                            value_type = v.type;
                        }
                    }
                    else if (v.type != value_type)
                    {
                        val = content.environment.GetType(v.type).ConvertTo(content, v.value, value_type);
                    }

                    content.DefineAndSet(value_name, value_type, val);
                }
            }
            else
            {
                content.Define(value_name, value_type);
            }
            //设置环境变量为
            content.OutStack(this);
        }
Exemple #21
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();
        }
Exemple #22
0
        public CQ_Value MemberCall(CQ_Content contentParent, object object_this, string func, IList <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 = new CQ_Content();

                    content.CallType = this;
                    content.CallThis = object_this as CQClassInstance;
#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].value);
                    }
                    CQ_Value value   = null;
                    var      funcobj = funccache;
                    if (this.bInterface)
                    {
                        content.CallType = (object_this as CQClassInstance).type;
                        funcobj          = (object_this as CQClassInstance).type.functions[func];
                    }
                    if (funcobj.expr_runtime != null)
                    {
                        value = funcobj.expr_runtime.ComputeValue(content);
                        if (value != null)
                        {
                            value.breakBlock = 0;
                        }
                    }
#if CQUARK_DEBUG
                    contentParent.OutStack(content);
#endif

                    return(value);
                }
            }
            else if (this.members.ContainsKey(func))
            {
                if (this.members[func].bStatic == false)
                {
                    Delegate dele = (object_this as CQClassInstance).member[func].value as Delegate;
                    if (dele != null)
                    {
                        CQ_Value value = new CQ_Value();
                        value.type = null;
                        object[] objs = new object[_params.Count];
                        for (int i = 0; i < _params.Count; i++)
                        {
                            objs[i] = _params[i].value;
                        }
                        value.value = dele.DynamicInvoke(objs);
                        if (value.value != null)
                        {
                            value.type = value.value.GetType();
                        }
                        value.breakBlock = 0;
                        return(value);
                    }
                }
            }
            throw new NotImplementedException();
        }
Exemple #23
0
        public CQ_Value StaticCall(CQ_Content contentParent, string function, IList <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 = new CQ_Content();
                    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++)
                    //foreach (var p in this.functions[function]._params)
                    {
                        content.DefineAndSet(functions[function]._paramnames[i], functions[function]._paramtypes[i].typeBridge, _params[i].value);
                        //i++;
                    }
                    //var value = this.functions[function].expr_runtime.ComputeValue(content);
                    CQ_Value value = null;
                    if (this.functions[function].expr_runtime != null)
                    {
                        value = this.functions[function].expr_runtime.ComputeValue(content);
                        if (value != null)
                        {
                            value.breakBlock = 0;
                        }
                    }
#if CQUARK_DEBUG
                    contentParent.OutStack(content);
#endif

                    return(value);
                }
            }
            else if (this.members.ContainsKey(function))
            {
                if (this.members[function].bStatic == true)
                {
                    Delegate dele = this.staticMemberInstance[function].value as Delegate;
                    if (dele != null)
                    {
                        CQ_Value value = new CQ_Value();
                        value.type = null;
                        object[] objs = new object[_params.Count];
                        for (int i = 0; i < _params.Count; i++)
                        {
                            objs[i] = _params[i].value;
                        }
                        value.value = dele.DynamicInvoke(objs);
                        if (value.value != null)
                        {
                            value.type = value.value.GetType();
                        }
                        value.breakBlock = 0;
                        return(value);
                    }
                }
            }
            throw new NotImplementedException();
        }
Exemple #24
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();
        }