Esempio n. 1
0
 public bool MathLogic(LogicToken code, CQ_Value left, CQ_Value right)
 {
     if (code == LogicToken.equal)
     {
         return(left.ToString() == right.ToString());
     }
     else if (code == LogicToken.not_equal)
     {
         return(left.ToString() != right.ToString());
     }
     throw new NotImplementedException();
 }
Esempio n. 2
0
 public CQ_Value Math2Value(char code, CQ_Value left, CQ_Value right)
 {
     if (code == '+')
     {
         CQ_Value returnValue = new CQ_Value();
         returnValue.SetObject(typeof(string), left.ToString() + right.ToString());
         return(returnValue);
     }
     throw new NotImplementedException();
 }
Esempio n. 3
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());
            }
        }
Esempio n. 4
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);
            }
        }