Ejemplo n.º 1
0
 public bool MathLogic(LogicToken code, CQ_Value left, CQ_Value right)
 {
     if (code == LogicToken.equal)//[6] = {Boolean op_Equality(CQcriptExt.Vector3, CQcriptExt.Vector3)}
     {
         if (left.GetObject() == null || right.TypeIsEmpty)
         {
             return(left.GetObject() == right.GetObject());
         }
         else
         {
             return(left.GetObject() == right.GetObject());
         }
     }
     else if (code == LogicToken.not_equal)//[7] = {Boolean op_Inequality(CQcriptExt.Vector3, CQcriptExt.Vector3)}
     {
         if (left.GetObject() == null || right.TypeIsEmpty)
         {
             return(left.GetObject() != right.GetObject());
         }
         else
         {
             return(left.GetObject() != right.GetObject());
         }
     }
     throw new NotImplementedException();
 }
Ejemplo n.º 2
0
        public IEnumerator CoroutineCompute(CQ_Content content, UnityEngine.MonoBehaviour coroutine)
        {
                        #if CQUARK_DEBUG
            content.InStack(this);
                        #endif
            CQ_Value rv = new CQ_Value();

            if (_expressions.Count > 0 && _expressions[0] != null)
            {
                rv = _expressions[0].ComputeValue(content);
            }
            else
            {
                rv.m_type = typeof(void);
            }
            rv.m_breakBlock = BreakType.YieldReturn;
                        #if CQUARK_DEBUG
            content.OutStack(this);
                        #endif
            if (rv == CQ_Value.Null)
            {
                yield return(null);
            }
            else if (rv.m_type == typeof(IEnumerator))
            {
                yield return(coroutine.StartCoroutine(rv.GetObject() as IEnumerator));
            }
            else
            {
                yield return(rv.GetObject());//这里Unity会非常智能的自动去转型
            }
        }
Ejemplo n.º 3
0
 public bool MathLogic(LogicToken code, CQ_Value left, CQ_Value right)
 {
     if (code == LogicToken.equal)
     {
         return(null == right.GetObject());
     }
     else if (code == LogicToken.not_equal)
     {
         return(null != right.GetObject());
     }
     throw new NotImplementedException();
 }
Ejemplo n.º 4
0
        public virtual bool MathLogic(LogicToken code, CQ_Value left, CQ_Value right)
        {
            System.Reflection.MethodInfo call = null;

            //var m = _type.GetMethods();
            if (code == LogicToken.greater)//[2] = {Boolean op_GreaterThan(CQcriptExt.Vector3, CQcriptExt.Vector3)}
            {
                call = _type.GetMethod("op_GreaterThan");
            }
            else if (code == LogicToken.less)//[4] = {Boolean op_LessThan(CQcriptExt.Vector3, CQcriptExt.Vector3)}
            {
                call = _type.GetMethod("op_LessThan");
            }
            else if (code == LogicToken.greater_equal)//[3] = {Boolean op_GreaterThanOrEqual(CQcriptExt.Vector3, CQcriptExt.Vector3)}
            {
                call = _type.GetMethod("op_GreaterThanOrEqual");
            }
            else if (code == LogicToken.less_equal)//[5] = {Boolean op_LessThanOrEqual(CQcriptExt.Vector3, CQcriptExt.Vector3)}
            {
                call = _type.GetMethod("op_LessThanOrEqual");
            }
            else if (code == LogicToken.equal)//[6] = {Boolean op_Equality(CQcriptExt.Vector3, CQcriptExt.Vector3)}
            {
                if (left.GetObject() == null || right.TypeIsEmpty)
                {
                    return(left.GetObject() == right.GetObject());
                }

                call = _type.GetMethod("op_Equality");
                if (call == null)
                {
                    return(left.GetObject().Equals(right.GetObject()));
                }
            }
            else if (code == LogicToken.not_equal)//[7] = {Boolean op_Inequality(CQcriptExt.Vector3, CQcriptExt.Vector3)}
            {
                if (left.GetObject() == null || right.TypeIsEmpty)
                {
                    return(left.GetObject() != right.GetObject());
                }
                call = _type.GetMethod("op_Inequality");
                if (call == null)
                {
                    return(!left.GetObject().Equals(right.GetObject()));
                }
            }
            return((bool)call.Invoke(null, new object[] { left.GetObject(), right.GetObject() }));
        }
Ejemplo n.º 5
0
        public CQ_Value ComputeValue(CQ_Content content)
        {
#if CQUARK_DEBUG
            content.InStack(this);
#endif
            CQ_Value parent = _expressions[0].ComputeValue(content);
            object   obj    = parent.GetObject();
            if (parent == CQ_Value.Null)
            {
                throw new Exception("调用空对象的方法:" + _expressions[0].ToString() + ":" + ToString());
            }
            var key = _expressions[1].ComputeValue(content);

            CQ_Value value = CQ_Value.Null;
            //这几行是为了快速获取Unity的静态变量,而不需要反射
            if (!Wrap.IndexGet(parent.m_type, obj, key, out value))
            {
                IType type = CQuark.AppDomain.GetITypeByCQValue(parent);
                value = type._class.IndexGet(content, obj, key.GetObject());
            }

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

            return(value);
        }
        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, 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);

                        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 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));
        }
Ejemplo n.º 8
0
 public CQ_Value Math2Value(char code, CQ_Value left, CQ_Value right)
 {
     if (right.m_type == typeof(string))
     {
         CQ_Value returnValue = new CQ_Value();
         returnValue.SetObject(typeof(string), "null" + right.GetObject());
         return(returnValue);
     }
     throw new NotImplementedException();
 }
Ejemplo n.º 9
0
        public CQ_Value ComputeValue(CQ_Content content)
        {
            CQ_Value v = _expressions[0].ComputeValue(content);

            Exception err = v.GetObject() as Exception;

            if (err != null)
            {
                throw err;
            }
            else
            {
                throw new Exception(v.ToString());
            }
        }
Ejemplo n.º 10
0
        public CQ_Value ComputeValue(CQ_Content content)
        {
#if CQUARK_DEBUG
            content.InStack(this);
#endif
            CQ_Value parent = _expressions[0].ComputeValue(content);
            object   obj    = parent.GetObject();
            if (parent == CQ_Value.Null)
            {
                throw new Exception("调用空对象的方法:" + _expressions[0].ToString() + ":" + ToString());
            }
            CQ_Value key   = _expressions[1].ComputeValue(content);
            CQ_Value value = _expressions[2].ComputeValue(content);
            //object setv=value.value;
            //if(value.type!=parent.type)
            //{
            //    var vtype = CQuark.AppDomain.GetType(value.type);
            //    setv = vtype.ConvertTo(CQuark.AppDomain, setv, parent.type);
            //}

            //这几行是为了快速获取Unity的静态变量,而不需要反射
            if (!Wrap.IndexSet(parent.m_type, obj, key, value))
            {
                var type = CQuark.AppDomain.GetITypeByCQValue(parent);
                type._class.IndexSet(content, parent.GetObject(), obj, value.GetObject());
            }

            CQ_Expression_GetValue f = _expressions[0] as CQ_Expression_GetValue;
            content.Set(f.value_name, parent);


#if CQUARK_DEBUG
            content.OutStack(this);
#endif
            return(CQ_Value.Null);
        }
Ejemplo n.º 11
0
        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.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;

            return(Delegate.CreateDelegate(this.typeBridge, d.Target, d.Method));
        }
        public CQ_Value ComputeValue(CQ_Content content)
        {
#if CQUARK_DEBUG
            content.InStack(this);
#endif
            CQ_Value parent = _expressions[0].ComputeValue(content);
            if (parent == CQ_Value.Null)
            {
                throw new Exception("调用空对象的方法:" + _expressions[0].ToString() + ":" + ToString());
            }
            IType type = CQuark.AppDomain.GetITypeByCQValue(parent);

            CQ_Value getvalue = CQ_Value.Null;

            object obj = parent.GetObject();

            //这几行是为了快速获取Unity的静态变量,而不需要反射
            if (!Wrap.MemberValueGet(parent.m_type, obj, membername, out getvalue))
            {
                getvalue = type._class.MemberValueGet(content, obj, membername);
            }

            CQ_Value vright = CQ_Value.One;
            if (_expressions.Count > 1)
            {
                vright = _expressions[1].ComputeValue(content);
            }

            IType    mtype = CQuark.AppDomain.GetITypeByCQValue(getvalue);
            CQ_Value vout  = mtype.Math2Value(mathop, getvalue, vright);

            //这几行是为了快速获取Unity的静态变量,而不需要反射
            if (!Wrap.MemberValueSet(parent.m_type, obj, membername, vout))
            {
                type._class.MemberValueSet(content, obj, membername, vout);
            }

#if CQUARK_DEBUG
            content.OutStack(this);
#endif
            return(vout);
        }
Ejemplo n.º 13
0
        public CQ_Value ComputeValue(CQ_Content content)
        {
#if CQUARK_DEBUG
            content.InStack(this);
#endif
            object[] list  = new object[_expressions.Count - 1];
            int      count = _expressions[0] == null ? (_expressions.Count - 1) : (int)_expressions[0].ComputeValue(content).GetNumber();
//            if(count == 0)
//                throw new Exception("不能创建0长度数组");
            CQ_Value vcount = new CQ_Value();
            vcount.SetNumber(typeof(int), count);
            for (int i = 0; i < _expressions.Count - 1; i++)
            {
                list[i] = (_expressions[i + 1].ComputeValue(content).GetObject());
            }

            CQ_Value[] param    = new CQ_Value[] { vcount };
            CQ_Value   outvalue = CQ_Value.Null;


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

            object obj = outvalue.GetObject();
            for (int i = 0; i < list.Length; i++)
            {
                type._class.IndexSet(content, obj, i, list[i]);
            }

#if CQUARK_DEBUG
            content.OutStack(this);
#endif
            return(outvalue);
        }
        public CQ_Value ComputeValue(CQ_Content content)
        {
#if CQUARK_DEBUG
            content.InStack(this);
#endif
            CQ_Value parent = _expressions[0].ComputeValue(content);
            if (parent == CQ_Value.Null)
            {
                throw new Exception("调用空对象的方法:" + _expressions[0].ToString() + ":" + ToString());
            }

            CQ_Value value = CQ_Value.Null;

            //这几行是为了快速获取Unity的静态变量,而不需要反射
            object obj = parent.GetObject();
            if (!Wrap.MemberValueGet(parent.m_type, obj, membername, out value))
            {
                IClass           iclass = CQuark.AppDomain.GetITypeByCQValue(parent)._class;
                CQ_ClassInstance s      = obj as CQ_ClassInstance;
                if (s != null)
                {
                    iclass = s.type;
                }

                value = iclass.MemberValueGet(content, obj, membername);
            }

#if CQUARK_DEBUG
            content.OutStack(this);
#endif
            return(value);
            //做数学计算
            //从上下文取值
            //_value = null;
            //return null;
        }
        public override CQ_Value Math2Value(char code, CQ_Value left, CQ_Value right)
        {
            if (left.GetObject() is DeleEvent)
            {
                DeleEvent info     = left.GetObject() as DeleEvent;
                Delegate  calldele = null;

                //!--exist bug.

                /*if (right.value is DeleFunction) calldele = CreateDelegate(right.value as DeleFunction);
                 * else if (right.value is DeleLambda) calldele = CreateDelegate(right.value as DeleLambda);
                 * else if (right.value is Delegate) calldele = right.value as Delegate;*/

                object rightValue = right.GetObject();
                if (rightValue is DeleFunction)
                {
                    if (code == '+')
                    {
                        calldele = CreateDelegate(rightValue as DeleFunction);
                    }
                    else if (code == '-')
                    {
                        calldele = CreateDelegate(rightValue as DeleFunction);
                    }
                }
                else if (rightValue is DeleLambda)
                {
                    if (code == '+')
                    {
                        calldele = CreateDelegate(rightValue as DeleLambda);
                    }
                    else if (code == '-')
                    {
                        calldele = CreateDelegate(rightValue as DeleLambda);
                    }
                }
                else if (rightValue is Delegate)
                {
                    calldele = rightValue as Delegate;
                }

                if (code == '+')
                {
                    info._event.AddEventHandler(info.source, calldele);
                    //if (!(rightValue is Delegate)) {
                    //    Dele_Map_Delegate.Map(rightValue as IDeleBase, calldele);
                    //}
                    CQ_Value ret = new CQ_Value();//type保持null
                    ret.SetNoneTypeObject(info);
                    return(ret);
                }
                else if (code == '-')
                {
                    info._event.RemoveEventHandler(info.source, calldele);
                    //if (!(rightValue is Delegate)) {
                    //    Dele_Map_Delegate.Destroy(rightValue as IDeleBase);
                    //}
                    CQ_Value ret = new CQ_Value();//type保持null
                    ret.SetNoneTypeObject(info);
                    return(ret);
                }
            }
            else if (left.GetObject() is Delegate || left.GetObject() == null)
            {
                Delegate info     = left.GetObject() as Delegate;
                Delegate calldele = null;
                if (right.GetObject() is DeleFunction)
                {
                    calldele = CreateDelegate(right.GetObject() as DeleFunction);
                }
                else if (right.GetObject() is DeleLambda)
                {
                    calldele = CreateDelegate(right.GetObject() as DeleLambda);
                }
                else if (right.GetObject() is Delegate)
                {
                    calldele = right.GetObject() as Delegate;
                }
                if (code == '+')
                {
                    CQ_Value ret = new CQ_Value();//type保持null
                    ret.SetNoneTypeObject(Delegate.Combine(info, calldele));
                    return(ret);
                }
                else if (code == '-')
                {
                    CQ_Value ret = new CQ_Value();//type保持null
                    ret.SetNoneTypeObject(Delegate.Remove(info, calldele));
                    return(ret);
                }
            }
            throw new NotSupportedException();
        }
Ejemplo n.º 16
0
        public CQ_Value ComputeValue(CQ_Content content)
        {
#if CQUARK_DEBUG
            content.InStack(this);
#endif

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

            CQ_Value v = CQ_Value.Null;

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

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

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

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


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

            CQ_Value value = CQ_Value.Null;

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

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


#if CQUARK_DEBUG
            content.OutStack(this);
#endif
            CQ_ObjPool.PushArray(parameters);
            return(value);
        }
Ejemplo n.º 18
0
        public bool MemberValueSet(CQ_Content content, object object_this, string valuename, CQ_Value value)
        {
            MemberValueCache c;

            if (!memberValueSetCaches.TryGetValue(valuename, out c))
            {
                c = new MemberValueCache();
                memberValueSetCaches[valuename] = c;
                c.finfo = type.GetField(valuename);
                if (c.finfo == null)
                {
                    c.minfo = type.GetMethod("set_" + valuename);
                    //                    var mss = type.GetMethods();
                    if (c.minfo == null)
                    {
                        if (type.GetMethod("add_" + valuename) != null)
                        {
                            c.type = 3;//event;
                        }
                        else
                        {
                            c.type = -1;
                            return(false);
                        }
                    }

                    else
                    {
                        c.type = 2;
                    }
                }
                else
                {
                    c.type = 1;
                }
            }

            if (c.type < 0)
            {
                return(false);
            }

            object obj = value.GetObject();

            if (c.type == 1)
            {
                if (obj != null && obj.GetType() != c.finfo.FieldType)
                {
                    obj = CQuark.AppDomain.ConvertTo(obj, c.finfo.FieldType);
                }
                c.finfo.SetValue(object_this, obj);
            }
            else if (c.type == 2)
            {
                var ptype = c.minfo.GetParameters()[0].ParameterType;
                if (obj != null && obj.GetType() != ptype)
                {
                    obj = CQuark.AppDomain.ConvertTo(obj, ptype);
                }
                c.minfo.Invoke(object_this, new object[] { obj });
            }
            return(true);
        }
Ejemplo n.º 19
0
 public CQ_Value Math2Value(char code, CQ_Value left, CQ_Value right)
 {
     throw new NotImplementedException("code:" + code + " right:+" + "=" + right.GetObject());
 }
Ejemplo n.º 20
0
        public CQ_Value ComputeValue(CQ_Content content)
        {
#if CQUARK_DEBUG
            content.InStack(this);
#endif

            CQ_Value left  = _expressions[0].ComputeValue(content);
            CQ_Value right = _expressions[1].ComputeValue(content);
            IType    type  = CQuark.AppDomain.GetITypeByCQValue(left);

            CQ_Value val = type.Math2Value(mathop, left, right);
            //val.SetValue(left.typeBridge, type.ConvertTo(val.GetValue(), left.typeBridge));
            left.UsingValue(val);

            if (_expressions[0] is CQ_Expression_MemberValueGet)
            {
                CQ_Expression_MemberValueGet f = _expressions[0] as CQ_Expression_MemberValueGet;

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

                //这几行是为了快速获取Unity的静态变量,而不需要反射
                object obj = parent.GetObject();
                if (!Wrap.MemberValueSet(parent.m_type, obj, f.membername, val))
                {
                    IType ptype = CQuark.AppDomain.GetITypeByCQValue(parent);
                    ptype._class.MemberValueSet(content, obj, f.membername, val);
                }
            }
            else if (_expressions[0] is CQ_Expression_StaticValueGet)
            {
                CQ_Expression_StaticValueGet f = _expressions[0] as CQ_Expression_StaticValueGet;

                //这几行是为了快速获取Unity的静态变量,而不需要反射
                if (!Wrap.StaticValueSet(type.typeBridge.type, f.staticmembername, val))
                {
                    f.type._class.StaticValueSet(content, f.staticmembername, val);
                }
            }
            else if (_expressions[0] is CQ_Expression_GetValue)
            {
                CQ_Expression_GetValue f = _expressions[0] as CQ_Expression_GetValue;
                content.Set(f.value_name, left);
            }
            else if (_expressions[0] is CQ_Expression_IndexGet)
            {
                CQ_Expression_IndexGet f = _expressions[0] as CQ_Expression_IndexGet;
                CQ_Value parent          = f._expressions[0].ComputeValue(content);
                object   obj             = parent.GetObject();
                CQ_Value key             = f._expressions[1].ComputeValue(content);

                IType parenttype = CQuark.AppDomain.GetITypeByCQValue(parent);
                parenttype._class.IndexSet(content, obj, key.GetObject(), left.GetObject());

                CQ_Expression_GetValue g = f._expressions[0] as CQ_Expression_GetValue;
                content.Set(g.value_name, parent);
            }



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

            return(CQ_Value.Null);
        }
Ejemplo n.º 21
0
        public virtual CQ_Value Math2Value(char code, CQ_Value left, CQ_Value right)
        {
            //会走到这里说明不是简单的数学计算了
            Type rightType = right.m_type;

            if (rightType == typeof(string) && code == '+')
            {
                CQ_Value returnValue = new CQ_Value();
                returnValue.SetObject(typeof(string), left.ToString() + right.ToString());
                return(returnValue);
            }
            else
            {
                CQ_Value   returnValue = CQ_Value.Null;
                MethodInfo call        = null;

                //我们这里开始使用Wrap,如果再不行再走反射
                if (code == '+')
                {
                    if (Wrap.OpAddition(left, right, out returnValue))
                    {
                        return(returnValue);
                    }
                    else
                    {
                        call = _type.GetMethod("op_Addition", new Type[] { this.typeBridge, rightType });
                    }
                }

                else if (code == '-')
                {
                    if (Wrap.OpSubtraction(left, right, out returnValue))
                    {
                        return(returnValue);
                    }
                    else
                    {
                        call = _type.GetMethod("op_Subtraction", new Type[] { this.typeBridge, rightType });
                    }
                }
                else if (code == '*')
                {
                    if (Wrap.OpMultiply(left, right, out returnValue))
                    {
                        return(returnValue);
                    }
                    else
                    {
                        call = _type.GetMethod("op_Multiply", new Type[] { this.typeBridge, rightType });
                    }
                }
                else if (code == '/')
                {
                    if (Wrap.OpDivision(left, right, out returnValue))
                    {
                        return(returnValue);
                    }
                    else
                    {
                        call = _type.GetMethod("op_Division", new Type[] { this.typeBridge, rightType });
                    }
                }
                else if (code == '%')
                {
                    if (Wrap.OpModulus(left, right, out returnValue))
                    {
                        return(returnValue);
                    }
                    else
                    {
                        call = _type.GetMethod("op_Modulus", new Type[] { this.typeBridge, rightType });
                    }
                }

                //Wrap没走到,走反射
                returnValue = new CQ_Value();
                returnValue.SetObject(typeBridge.type, call.Invoke(null, new object[] { left.GetObject(), right.GetObject() }));
                //function.StaticCall(env,"op_Addtion",new List<ICL>{})
                return(returnValue);
            }
        }