Beispiel #1
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);
        }
Beispiel #3
0
        public CQ_Content.Value ComputeValue(CQ_Content content)
        {
            content.InStack(this);
            ICQ_Expression expr_if = listParam[0];
            bool           bif     = (bool)expr_if.ComputeValue(content).value;
            //if (expr_init != null) expr_init.ComputeValue(content);
            ICQ_Expression expr_go1 = listParam[1];
            ICQ_Expression expr_go2 = null;

            if (listParam.Count > 2)
            {
                expr_go2 = listParam[2];
            }
            CQ_Content.Value value = null;
            if (bif && expr_go1 != null)
            {
                if (expr_go1 is CQ_Expression_Block)
                {
                    value = expr_go1.ComputeValue(content);
                }
                else
                {
                    content.DepthAdd();
                    value = expr_go1.ComputeValue(content);
                    content.DepthRemove();
                }
            }
            else if (!bif && expr_go2 != null)
            {
                if (expr_go2 is CQ_Expression_Block)
                {
                    value = expr_go2.ComputeValue(content);
                }
                else
                {
                    content.DepthAdd();
                    value = expr_go2.ComputeValue(content);
                    content.DepthRemove();
                }
            }

            //while((bool)expr_continue.value);

            //for 逻辑
            //做数学计算
            //从上下文取值
            //_value = null;
            content.OutStack(this);
            return(value);
        }
        public CQ_Value ComputeValue(CQ_Content content)
        {
#if CQUARK_DEBUG
            content.InStack(this);
#endif
            ICQ_Expression expr_if = _expressions[0];
            CQ_Value       v       = expr_if.ComputeValue(content);
            bool           bif     = v.GetBool();
            //if (expr_init != null) expr_init.ComputeValue(content);
            ICQ_Expression expr_go1 = _expressions[1];
            ICQ_Expression expr_go2 = null;
            if (_expressions.Count > 2)
            {
                expr_go2 = _expressions[2];                       //else
            }
            CQ_Value value = CQ_Value.Null;
            if (bif && expr_go1 != null)
            {
                if (expr_go1 is CQ_Expression_Block)
                {
                    value = expr_go1.ComputeValue(content);
                }
                else
                {
                    content.DepthAdd();
                    value = expr_go1.ComputeValue(content);
                    content.DepthRemove();
                }
            }
            else if (!bif && expr_go2 != null)
            {
                if (expr_go2 is CQ_Expression_Block)
                {
                    value = expr_go2.ComputeValue(content);
                }
                else
                {
                    content.DepthAdd();
                    value = expr_go2.ComputeValue(content);
                    content.DepthRemove();
                }
            }

#if CQUARK_DEBUG
            content.OutStack(this);
#endif
            return(value);
        }
        public CQ_Value ComputeValue(CQ_Content content)
        {
#if CQUARK_DEBUG
            content.InStack(this);
#endif
            content.DepthAdd();
            CQ_Value value = null;
            foreach (ICQ_Expression i in _expressions)
            {
                ICQ_Expression e = i as ICQ_Expression;
                if (e != null)
                {
                    value = e.ComputeValue(content);
                }

                if (value != null && value.breakBlock != 0)
                {
                    break;
                }
            }
            content.DepthRemove();
#if CQUARK_DEBUG
            content.OutStack(this);
#endif
            return(value);
        }
        public IEnumerator CoroutineCompute(CQ_Content content, ICoroutine coroutine)
        {
#if CQUARK_DEBUG
            content.InStack(this);
#endif
            content.DepthAdd();
            CQ_Value value = null;
            foreach (ICQ_Expression i in _expressions)
            {
                ICQ_Expression e = i as ICQ_Expression;
                if (e != null)
                {
                    if (e.hasCoroutine)
                    {
                        yield return(coroutine.StartNewCoroutine(e.CoroutineCompute(content, coroutine)));
                    }
                    else
                    {
                        value = e.ComputeValue(content);
                        if (value != null && value.breakBlock != 0)
                        {
                            break;
                        }
                    }
                }
            }
            content.DepthRemove();
#if CQUARK_DEBUG
            content.OutStack(this);
#endif
            yield break;
        }
Beispiel #7
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 IEnumerator CoroutineCompute(CQ_Content content, UnityEngine.MonoBehaviour coroutine)
        {
#if CQUARK_DEBUG
            content.InStack(this);
#endif
            content.DepthAdd();
            CQ_Value value = new CQ_Value();
            foreach (ICQ_Expression e in _expressions)
            {
                if (e != null)
                {
                    if (e.hasCoroutine)
                    {
                        yield return(coroutine.StartCoroutine(e.CoroutineCompute(content, coroutine)));
                    }
                    else
                    {
                        value = e.ComputeValue(content);
                        if (value.m_breakBlock != 0)
                        {
                            break;
                        }
                    }
                }
            }
            content.DepthRemove();
#if CQUARK_DEBUG
            content.OutStack(this);
#endif
            yield break;
        }
        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 IEnumerator CoroutineCompute(CQ_Content content, ICoroutine coroutine)
        {
            content.InStack(this);
            content.DepthAdd();
            ICQ_Expression expr_switch = listParam[0] as ICQ_Expression;

            CQ_Content.Value switchVal = null;
            //			CQ_Content.Value vrt = null;
            if (expr_switch != null)
            {
                switchVal = expr_switch.ComputeValue(content);                //switch//
            }
            for (int i = 1; i < listParam.Count - 1; i += 2)
            {
                if (listParam[i] != null)
                {
                    //case xxx://
                    if (switchVal.value.Equals(listParam[i].ComputeValue(content).value))
                    {
                        while (listParam[i + 1] == null)
                        {
                            i += 2;
                        }
                        content.DepthAdd();
                        if (listParam[i + 1].hasCoroutine)
                        {
                            yield return(coroutine.StartNewCoroutine(listParam[i + 1].CoroutineCompute(content, coroutine)));
                        }
                        else
                        {
                            listParam[i + 1].ComputeValue(content);
                        }
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }
                else
                {
                    //default:
                    content.DepthAdd();
                    if (listParam[i + 1].hasCoroutine)
                    {
                        yield return(coroutine.StartNewCoroutine(listParam[i + 1].CoroutineCompute(content, coroutine)));
                    }
                    else
                    {
                        listParam[i + 1].ComputeValue(content);
                    }
                    break;
                }
            }

            content.DepthRemove();
            content.OutStack(this);
        }
        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));
        }
        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));
        }
        public override Delegate CreateDelegate(DeleFunction delefunc)
        {
            DeleFunction _func = delefunc;
            Delegate     _dele = delefunc.cacheFunction(this._type, null);

            if (_dele != null)
            {
                return(_dele);
            }
            NonVoidDelegate dele = delegate()
            {
                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

                        CQ_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";
                        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));
        }
Beispiel #16
0
        public CQ_Value ComputeValue(CQ_Content content)
        {
#if CQUARK_DEBUG
            content.InStack(this);
#endif
            content.DepthAdd();
            ICQ_Expression expr_switch = _expressions[0] as ICQ_Expression;
            CQ_Value       switchVal   = CQ_Value.Null;
            //			CQ_Content.Value vrt = null;
            if (expr_switch != null)
            {
                switchVal = expr_switch.ComputeValue(content);//switch//
            }
            for (int i = 1; i < _expressions.Count - 1; i += 2)
            {
                if (_expressions[i] != null)
                {
                    //case xxx://
                    if (switchVal == _expressions[i].ComputeValue(content))
                    {
                        while (_expressions[i + 1] == null)
                        {
                            i += 2;
                        }
                        //						content.InStack(_expressions[i+1]);
                        content.DepthAdd();
                        _expressions[i + 1].ComputeValue(content);
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }
                else
                {
                    //default:
                    //					content.InStack(_expressions[i+1]);
                    content.DepthAdd();
                    _expressions[i + 1].ComputeValue(content);
                    break;
                }
            }

            content.DepthRemove();
#if CQUARK_DEBUG
            content.OutStack(this);
#endif
            return(CQ_Value.Null);
        }
Beispiel #17
0
        public override Delegate CreateDelegate(DeleLambda lambda)
        {
            CQ_Content content = lambda.content.Clone();
            //var pnames = lambda.paramNames;
            var    expr = lambda.expr_func;
            Action dele = () =>
            {
                if (expr != null)
                {
                    try
                    {
                        content.DepthAdd();


                        //content.DefineAndSet(pnames[0], typeof(T), param0);

                        expr.ComputeValue(content);

                        content.DepthRemove();
                    }
                    catch (Exception)
                    {
                        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());
                    }
                }
            };
            Delegate d = dele as Delegate;

            if ((Type)this.typeBridge != typeof(Action))
            {
                return(Delegate.CreateDelegate(this.typeBridge, d.Target, d.Method));
            }
            else
            {
                return(dele);
            }
        }
        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> dele    = (T param0) =>
            {
                if (expr != null)
                {
                    try
                    {
                        content.DepthAdd();


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

                        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>))
            {
                return(Delegate.CreateDelegate(this.type, d.Target, d.Method));
            }
            else
            {
                return(dele);
            }
        }
        public CQ_Content.Value ComputeValue(CQ_Content content)
        {
            content.InStack(this);
            content.DepthAdd();
            ICQ_Expression expr_switch = listParam[0] as ICQ_Expression;

            CQ_Content.Value switchVal = null;
//			CQ_Content.Value vrt = null;
            if (expr_switch != null)
            {
                switchVal = expr_switch.ComputeValue(content);                //switch//
            }
            for (int i = 1; i < listParam.Count - 1; i += 2)
            {
                if (listParam[i] != null)
                {
                    //case xxx://
                    if (switchVal.value.Equals(listParam[i].ComputeValue(content).value))
                    {
                        while (listParam[i + 1] == null)
                        {
                            i += 2;
                        }
//						content.InStack(listParam[i+1]);
                        content.DepthAdd();
                        listParam[i + 1].ComputeValue(content);
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }
                else
                {
                    //default:
//					content.InStack(listParam[i+1]);
                    content.DepthAdd();
                    listParam[i + 1].ComputeValue(content);
                    break;
                }
            }

            content.DepthRemove();
            content.OutStack(this);
            return(null);
        }
Beispiel #20
0
        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)
            {
                if (expr != null)
                {
                    try
                    {
                        content.DepthAdd();

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

                        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));
        }
        public override Delegate CreateDelegate(DeleLambda lambda)
        {
            CQ_Content content = lambda.content.Clone();
            //var pnames = lambda.paramNames;
            var expr = lambda.expr_func;

            NonVoidDelegate dele = delegate()
            {
                if (expr != null)
                {
                    try
                    {
                        content.DepthAdd();
                        CQ_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 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;

            return(Delegate.CreateDelegate(this.typeBridge, d.Target, d.Method));
        }
Beispiel #22
0
        public CQ_Content.Value ComputeValue(CQ_Content content)
        {
            content.InStack(this);
            content.DepthAdd();
            CQ_Content.Value value = null;
            foreach (ICQ_Expression i in listParam)
            {
                ICQ_Expression e = i  as ICQ_Expression;
                if (e != null)
                {
                    value = e.ComputeValue(content);
                }

                if (value != null && value.breakBlock != 0)
                {
                    break;
                }
            }
            content.DepthRemove();
            content.OutStack(this);
            return(value);
        }
Beispiel #23
0
        public IEnumerator CoroutineCompute(CQ_Content content, UnityEngine.MonoBehaviour coroutine)
        {
#if CQUARK_DEBUG
            content.InStack(this);
#endif
            content.DepthAdd();
            ICQ_Expression expr_switch = _expressions[0] as ICQ_Expression;
            CQ_Value       switchVal   = CQ_Value.Null;
            //			CQ_Content.Value vrt = null;
            if (expr_switch != null)
            {
                switchVal = expr_switch.ComputeValue(content);//switch//
            }
            for (int i = 1; i < _expressions.Count - 1; i += 2)
            {
                if (_expressions[i] != null)
                {
                    //case xxx://
                    if (switchVal == _expressions[i].ComputeValue(content))
                    {
                        while (_expressions[i + 1] == null)
                        {
                            i += 2;
                        }
                        content.DepthAdd();
                        if (_expressions[i + 1].hasCoroutine)
                        {
                            yield return(coroutine.StartCoroutine(_expressions[i + 1].CoroutineCompute(content, coroutine)));
                        }
                        else
                        {
                            _expressions[i + 1].ComputeValue(content);
                        }
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }
                else
                {
                    //default:
                    content.DepthAdd();
                    if (_expressions[i + 1].hasCoroutine)
                    {
                        yield return(coroutine.StartCoroutine(_expressions[i + 1].CoroutineCompute(content, coroutine)));
                    }
                    else
                    {
                        _expressions[i + 1].ComputeValue(content);
                    }
                    break;
                }
            }

            content.DepthRemove();
#if CQUARK_DEBUG
            content.OutStack(this);
#endif
        }
Beispiel #24
0
        public CQ_Content.Value ComputeValue(CQ_Content content)
        {
            content.InStack(this);
            content.DepthAdd();
            CQ_Expression_Define define = listParam[0] as CQ_Expression_Define;

            if (define == null)
            {
            }
            define.ComputeValue(content);

            System.Collections.IEnumerable emu = listParam[1].ComputeValue(content).value as System.Collections.IEnumerable;

            ICQ_Expression expr_block = listParam[2] as ICQ_Expression;

            var it = emu.GetEnumerator();

            CQ_Content.Value vrt = null;
            while (it.MoveNext())
            {
                content.Set(define.value_name, it.Current);
                if (expr_block != null)
                {
                    if (expr_block is CQ_Expression_Block)
                    {
                        var v = expr_block.ComputeValue(content);
                        if (v != null)
                        {
                            if (v.breakBlock > 2)
                            {
                                vrt = v;
                            }
                            if (v.breakBlock > 1)
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        content.DepthAdd();
                        bool bbreak = false;
                        var  v      = expr_block.ComputeValue(content);
                        if (v != null)
                        {
                            if (v.breakBlock > 2)
                            {
                                vrt = v;
                            }
                            if (v.breakBlock > 1)
                            {
                                bbreak = true;
                            }
                        }
                        content.DepthRemove();
                        if (bbreak)
                        {
                            break;
                        }
                    }
                }
            }
            //ICQ_Expression expr_continue = listParam[1] as ICQ_Expression;
            //ICQ_Expression expr_step = listParam[2] as ICQ_Expression;

            //ICQ_Expression expr_block = listParam[3] as ICQ_Expression;

            //for (;(bool)expr_continue.ComputeValue(content).value; expr_step.ComputeValue(content))
            //{
            //    if(expr_block!=null)
            //    {
            //        var v = expr_block.ComputeValue(content);
            //        if (v != null && v.breakBlock > 1) break; ;
            //        //if (v.breakBlock == 1) continue;
            //        //if (v.breakBlock == 2) break;
            //        //if (v.breakBlock == 10) return v;
            //    }
            //}
            content.DepthRemove();
            content.OutStack(this);
            return(vrt);
            //for 逻辑
            //做数学计算
            //从上下文取值
            //_value = null;
        }
        public IEnumerator CoroutineCompute(CQ_Content content, ICoroutine coroutine)
        {
#if CQUARK_DEBUG
            content.InStack(this);
#endif
            content.DepthAdd();
            ICQ_Expression expr_while = _expressions[0] as ICQ_Expression;
            ICQ_Expression expr_block = _expressions[1] as ICQ_Expression;
            //			CQ_Content.Value vrt = null;
            while ((bool)expr_while.ComputeValue(content).value)
            {
                if (expr_block != null)
                {
                    if (expr_block is CQ_Expression_Block)
                    {
                        if (expr_block.hasCoroutine)
                        {
                            yield return(coroutine.StartNewCoroutine(expr_block.CoroutineCompute(content, coroutine)));
                        }
                        else
                        {
                            var v = expr_block.ComputeValue(content);
                            if (v != null)
                            {
                                //								if (v.breakBlock > 2) vrt = v;
                                if (v.breakBlock > 1)
                                {
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        content.DepthAdd();
                        if (expr_block.hasCoroutine)
                        {
                            yield return(coroutine.StartNewCoroutine(expr_block.CoroutineCompute(content, coroutine)));
                        }
                        else
                        {
                            bool bbreak = false;
                            var  v      = expr_block.ComputeValue(content);
                            if (v != null)
                            {
                                //								if (v.breakBlock > 2) vrt = v;
                                if (v.breakBlock > 1)
                                {
                                    bbreak = true;
                                }
                            }
                            content.DepthRemove();
                            if (bbreak)
                            {
                                break;
                            }
                        }
                    }
                    //if (v.breakBlock == 1) continue;
                    //if (v.breakBlock == 2) break;
                    //if (v.breakBlock == 10) return v;
                }
            }
            content.DepthRemove();
#if CQUARK_DEBUG
            content.OutStack(this);
#endif
            //for 逻辑
            //做数学计算
            //从上下文取值
            //_value = null;
        }
        public CQ_Value ComputeValue(CQ_Content content)
        {
#if CQUARK_DEBUG
            content.InStack(this);
#endif
            content.DepthAdd();
            ICQ_Expression expr_while = _expressions[0] as ICQ_Expression;
            ICQ_Expression expr_block = _expressions[1] as ICQ_Expression;
            CQ_Value       vrt        = null;
            while ((bool)expr_while.ComputeValue(content).value)
            {
                if (expr_block != null)
                {
                    if (expr_block is CQ_Expression_Block)
                    {
                        var v = expr_block.ComputeValue(content);
                        if (v != null)
                        {
                            if (v.breakBlock > 2)
                            {
                                vrt = v;
                            }
                            if (v.breakBlock > 1)
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        content.DepthAdd();
                        bool bbreak = false;
                        var  v      = expr_block.ComputeValue(content);
                        if (v != null)
                        {
                            if (v.breakBlock > 2)
                            {
                                vrt = v;
                            }
                            if (v.breakBlock > 1)
                            {
                                bbreak = true;
                            }
                        }
                        content.DepthRemove();
                        if (bbreak)
                        {
                            break;
                        }
                    }
                    //if (v.breakBlock == 1) continue;
                    //if (v.breakBlock == 2) break;
                    //if (v.breakBlock == 10) return v;
                }
            }
            content.DepthRemove();
#if CQUARK_DEBUG
            content.OutStack(this);
#endif
            return(vrt);
            //for 逻辑
            //做数学计算
            //从上下文取值
            //_value = null;
        }
Beispiel #27
0
        public CQ_Content.Value ComputeValue(CQ_Content content)
        {
            content.InStack(this);
            content.DepthAdd();
            ICQ_Expression expr_init = listParam[0] as ICQ_Expression;

            if (expr_init != null)
            {
                expr_init.ComputeValue(content);                   //expr1
            }
            ICQ_Expression expr_continue = listParam[1] as ICQ_Expression;
            ICQ_Expression expr_step     = listParam[2] as ICQ_Expression;

            ICQ_Expression expr_block = listParam[3] as ICQ_Expression;

            CQ_Content.Value vrt = null;
            for (; ;)
            {
                if (expr_continue != null && !(bool)expr_continue.ComputeValue(content).value)
                {
                    break;                                                                           //expr2
                }
                if (expr_block != null)
                {
                    if (expr_block is CQ_Expression_Block)
                    {
                        var v = expr_block.ComputeValue(content);
                        if (v != null)
                        {
                            if (v.breakBlock > 2)
                            {
                                vrt = v;
                            }
                            if (v.breakBlock > 1)
                            {
                                break;
                            }
                        }
                    }
                    else
                    {
                        content.DepthAdd();
                        bool bbreak = false;
                        var  v      = expr_block.ComputeValue(content);
                        if (v != null)
                        {
                            if (v.breakBlock > 2)
                            {
                                vrt = v;
                            }
                            if (v.breakBlock > 1)
                            {
                                bbreak = true;
                            }
                        }
                        content.DepthRemove();
                        if (bbreak)
                        {
                            break;
                        }
                    }
                    //if (v.breakBlock == 1) continue;
                    //if (v.breakBlock == 2) break;
                    //if (v.breakBlock == 10) return v;
                }

                if (expr_step != null)
                {
                    expr_step.ComputeValue(content);//expr3
                }
            }
            content.DepthRemove();
            content.OutStack(this);
            return(vrt);
            //for 逻辑
            //做数学计算
            //从上下文取值
            //_value = null;
        }
Beispiel #28
0
        public IEnumerator CoroutineCompute(CQ_Content content, ICoroutine coroutine)
        {
            content.InStack(this);
            ICQ_Expression expr_if = listParam[0];
            bool           bif     = (bool)expr_if.ComputeValue(content).value;
            //if (expr_init != null) expr_init.ComputeValue(content);
            ICQ_Expression expr_go1 = listParam[1];
            ICQ_Expression expr_go2 = null;

            if (listParam.Count > 2)
            {
                expr_go2 = listParam[2];
            }
//			CQ_Content.Value value = null;
            if (bif && expr_go1 != null)
            {
                if (expr_go1 is CQ_Expression_Block)
                {
                    if (expr_go1.hasCoroutine)
                    {
                        yield return(coroutine.StartNewCoroutine(expr_go1.CoroutineCompute(content, coroutine)));
                    }
                    else
                    {
                        expr_go1.ComputeValue(content);
                    }
                }
                else
                {
                    content.DepthAdd();
                    if (expr_go1.hasCoroutine)
                    {
                        yield return(coroutine.StartNewCoroutine(expr_go1.CoroutineCompute(content, coroutine)));
                    }
                    else
                    {
                        expr_go1.ComputeValue(content);
                    }
                    content.DepthRemove();
                }
            }
            else if (!bif && expr_go2 != null)
            {
                if (expr_go2 is CQ_Expression_Block)
                {
                    if (expr_go2.hasCoroutine)
                    {
                        yield return(coroutine.StartNewCoroutine(expr_go2.CoroutineCompute(content, coroutine)));
                    }
                    else
                    {
                        expr_go2.ComputeValue(content);
                    }
                }
                else
                {
                    content.DepthAdd();
                    if (expr_go2.hasCoroutine)
                    {
                        yield return(coroutine.StartNewCoroutine(expr_go2.CoroutineCompute(content, coroutine)));
                    }
                    else
                    {
                        expr_go2.ComputeValue(content);
                    }
                    content.DepthRemove();
                }
            }

            //while((bool)expr_continue.value);

            //for 逻辑
            //做数学计算
            //从上下文取值
            //_value = null;
            content.OutStack(this);
        }
Beispiel #29
0
        public CQ_Value ComputeValue(CQ_Content content)
        {
#if CQUARK_DEBUG
            content.InStack(this);
#endif
            content.DepthAdd();
            CQ_Expression_Define define = _expressions[0] as CQ_Expression_Define;
            define.ComputeValue(content);

            System.Collections.IEnumerable emu = _expressions[1].ComputeValue(content).GetObject() as System.Collections.IEnumerable;

            ICQ_Expression expr_block = _expressions[2] as ICQ_Expression;

            var      it  = emu.GetEnumerator();
            CQ_Value vrt = CQ_Value.Null;
            while (it.MoveNext())
            {
                //content.Set(define.value_name, it.Current);
                CQ_Value val = new CQ_Value();
                val.SetObject(define.value_type, it.Current);
                content.Set(define.value_name, val);


                if (expr_block != null)
                {
                    if (expr_block is CQ_Expression_Block)
                    {
                        CQ_Value v = expr_block.ComputeValue(content);

                        if (v.m_breakBlock == BreakType.Return)
                        {
                            vrt = v;
                        }
                        if (v.m_breakBlock == BreakType.Return || v.m_breakBlock == BreakType.Break)
                        {
                            break;
                        }
                    }
                    else
                    {
                        content.DepthAdd();
                        bool     bbreak = false;
                        CQ_Value v      = expr_block.ComputeValue(content);

                        if (v.m_breakBlock == BreakType.Return)
                        {
                            vrt = v;
                        }
                        if (v.m_breakBlock == BreakType.Break || v.m_breakBlock == BreakType.Return)
                        {
                            bbreak = true;
                        }

                        content.DepthRemove();
                        if (bbreak)
                        {
                            break;
                        }
                    }
                }
            }

            content.DepthRemove();
#if CQUARK_DEBUG
            content.OutStack(this);
#endif
            return(vrt);
        }
        public IEnumerator CoroutineCompute(CQ_Content content, UnityEngine.MonoBehaviour coroutine)
        {
#if CQUARK_DEBUG
            content.InStack(this);
#endif
            ICQ_Expression expr_if = _expressions[0];
            bool           bif     = expr_if.ComputeValue(content).GetBool();
            //if (expr_init != null) expr_init.ComputeValue(content);
            ICQ_Expression expr_go1 = _expressions[1];
            ICQ_Expression expr_go2 = null;
            if (_expressions.Count > 2)
            {
                expr_go2 = _expressions[2];
            }
            //			CQ_Content.Value value = null;
            if (bif && expr_go1 != null)
            {
                if (expr_go1 is CQ_Expression_Block)
                {
                    if (expr_go1.hasCoroutine)
                    {
                        yield return(coroutine.StartCoroutine(expr_go1.CoroutineCompute(content, coroutine)));
                    }
                    else
                    {
                        expr_go1.ComputeValue(content);
                    }
                }
                else
                {
                    content.DepthAdd();
                    if (expr_go1.hasCoroutine)
                    {
                        yield return(coroutine.StartCoroutine(expr_go1.CoroutineCompute(content, coroutine)));
                    }
                    else
                    {
                        expr_go1.ComputeValue(content);
                    }
                    content.DepthRemove();
                }
            }
            else if (!bif && expr_go2 != null)
            {
                if (expr_go2 is CQ_Expression_Block)
                {
                    if (expr_go2.hasCoroutine)
                    {
                        yield return(coroutine.StartCoroutine(expr_go2.CoroutineCompute(content, coroutine)));
                    }
                    else
                    {
                        expr_go2.ComputeValue(content);
                    }
                }
                else
                {
                    content.DepthAdd();
                    if (expr_go2.hasCoroutine)
                    {
                        yield return(coroutine.StartCoroutine(expr_go2.CoroutineCompute(content, coroutine)));
                    }
                    else
                    {
                        expr_go2.ComputeValue(content);
                    }
                    content.DepthRemove();
                }
            }

#if CQUARK_DEBUG
            content.OutStack(this);
#endif
        }