示例#1
0
        public object ConvertTo(object src, CQ_Type targetType)
        {
            Type_Action dele = CQuark.AppDomain.GetType(targetType) as Type_Action;

            return(dele.CreateDelegate(src as DeleFunction));
            //throw new NotImplementedException();
        }
示例#2
0
 public object Math2Value(char code, object left, CQ_Value right, out CQ_Type returntype)
 {
     if ((Type)right.type == typeof(string))
     {
         returntype = typeof(String);
         return("null" + right.value);
     }
     throw new NotImplementedException();
 }
示例#3
0
 /// <summary>
 /// 类型转换.
 /// </summary>
 protected static object TryConvertTo <OriginalType> (object src, CQ_Type targetType, out bool convertSuccess) where OriginalType : struct
 {
     convertSuccess = true;
     try {
         double srcValue = GetDouble(typeof(OriginalType), src);
         return(Double2TargetType(targetType, srcValue));
     }
     catch (Exception) {
         convertSuccess = false;
         return(null);
     }
 }
示例#4
0
        public override object Math2Value(char code, object left, CQ_Value right, out CQ_Type returntype)
        {
            bool   math2ValueSuccess = false;
            object value             = Math2Value <long>(code, left, right, out returntype, out math2ValueSuccess);

            if (math2ValueSuccess)
            {
                return(value);
            }

            return(base.Math2Value(code, left, right, out returntype));
        }
示例#5
0
        public override object ConvertTo(object src, CQ_Type targetType)
        {
            bool   convertSuccess  = false;
            object convertedObject = TryConvertTo <long>(src, targetType, out convertSuccess);

            if (convertSuccess)
            {
                return(convertedObject);
            }

            return(base.ConvertTo(src, targetType));
        }
示例#6
0
        public IEnumerator CoroutineCompute(CQ_Content content, ICoroutine coroutine)
        {
#if CQUARK_DEBUG
            content.InStack(this);
#endif

            if (_expressions[0].hasCoroutine)
            {
                yield return(coroutine.StartNewCoroutine(_expressions[0].CoroutineCompute(content, coroutine)));
            }
            else
            {
                CQ_Value v = _expressions[0].ComputeValue(content);

                {
                    object  val        = v.value;
                    CQ_Type value_type = null;
                    if (content.values != null && content.values.ContainsKey(value_name))
                    {
                        value_type = content.values[value_name].type;
                    }
                    else
                    {
                        if (content.CallType != null)
                        {
                            if (content.CallType.members.ContainsKey(value_name))
                            {
                                if (content.CallType.members[value_name].bStatic)
                                {
                                    value_type = content.CallType.staticMemberInstance[value_name].type;
                                }
                                else
                                {
                                    value_type = content.CallThis.member[value_name].type;
                                }
                            }
                        }
                    }
                    //val = v.value;
                    if ((Type)value_type != typeof(Type_Var.var) && value_type != v.type)
                    {
                        val = v.ConvertTo(value_type);
                    }


                    content.Set(value_name, val);
                }
            }
#if CQUARK_DEBUG
            content.OutStack(this);
#endif
        }
示例#7
0
        public object ConvertTo(object src, CQ_Type targetType)
        {
            var type = CQuark.AppDomain.GetType(targetType);

            if (this.typeBridge == type || (Type)targetType == typeof(object))
            {
                return(src);
            }
            if (this.types.Contains(type))
            {
                return(src);
            }

            throw new NotImplementedException();
        }
示例#8
0
 public object Math2Value(char code, object left, CQ_Value right, out CQ_Type returntype)
 {
     returntype = typeof(string);
     if (code == '+')
     {
         if (right.value == null)
         {
             return((string)left + "null");
         }
         else
         {
             return((string)left + right.value.ToString());
         }
     }
     throw new NotImplementedException();
 }
示例#9
0
        public CQ_Value ComputeValue(CQ_Content content)
        {
#if CQUARK_DEBUG
            content.InStack(this);
#endif
            {
                CQ_Value v = _expressions[0].ComputeValue(content);

                {
                    object  val        = v.value;
                    CQ_Type value_type = null;
                    if (content.values != null && content.values.ContainsKey(value_name))
                    {
                        value_type = content.values[value_name].type;
                    }
                    else
                    {
                        if (content.CallType != null)
                        {
                            if (content.CallType.members.ContainsKey(value_name))
                            {
                                if (content.CallType.members[value_name].bStatic)
                                {
                                    value_type = content.CallType.staticMemberInstance[value_name].type;
                                }
                                else
                                {
                                    value_type = content.CallThis.member[value_name].type;
                                }
                            }
                        }
                    }
                    //val = v.value;
                    if ((Type)value_type != typeof(Type_Var.var) && value_type != v.type)
                    {
                        val = v.ConvertTo(value_type);
                    }


                    content.Set(value_name, val);
                }
            }
#if CQUARK_DEBUG
            content.OutStack(this);
#endif
            return(null);
        }
示例#10
0
        public static IType GetType(CQ_Type type)
        {
            if (type == null)
            {
                return(typess["null"]);
            }

            IType ret = null;

            if (types.TryGetValue(type, out ret) == false)
            {
                DebugUtil.LogWarning("(CQcript)类型未注册,将自动注册一份匿名:" + type.ToString());
                ret = MakeType(type, "");
                RegisterType(ret);
            }
            return(ret);
        }
示例#11
0
 public object ConvertTo(object src, CQ_Type targetType)
 {
     if ((Type)targetType == typeof(string))
     {
         return(src);
     }
     if ((Type)targetType == typeof(void))
     {
         return(null);
     }
     if (((Type)targetType).IsAssignableFrom(typeof(string)))
     //if((Type)targetType== typeof(object))
     {
         return(src);
     }
     return(null);
 }
示例#12
0
        public void Define(string name, CQ_Type type)
        {
            if (values == null)
            {
                values = new Dictionary <string, CQ_Value>();
            }
            else if (values.ContainsKey(name))
            {
                throw new Exception("已经定义过");
            }

            CQ_Value v = new CQ_Value();

            v.type       = type;
            values[name] = v;
            if (tvalues != null && tvalues.Count > 0)
            {
                tvalues.Peek().Add(name);//暂存临时变量
            }
        }
示例#13
0
        public virtual object Math2Value(char code, object left, CQ_Value right, out CQ_Type returntype)
        {
            returntype = typeBridge;
            MethodInfo call = null;

            //var m = ((Type)type).GetMembers();
            if ((Type)right.type == typeof(string) && code == '+')
            {
                returntype = typeof(string);
                return(left.ToString() + right.value as string);
            }

            if (code == '+')
            {
                call = _type.GetMethod("op_Addition", new Type[] { this.typeBridge, right.type });
            }
            else if (code == '-')//base = {CQcriptExt.Vector3 op_Subtraction(CQcriptExt.Vector3, CQcriptExt.Vector3)}
            {
                call = _type.GetMethod("op_Subtraction", new Type[] { this.typeBridge, right.type });
            }
            else if (code == '*')//[2] = {CQcriptExt.Vector3 op_Multiply(CQcriptExt.Vector3, CQcriptExt.Vector3)}
            {
                call = _type.GetMethod("op_Multiply", new Type[] { this.typeBridge, right.type });
            }
            else if (code == '/')//[3] = {CQcriptExt.Vector3 op_Division(CQcriptExt.Vector3, CQcriptExt.Vector3)}
            {
                call = _type.GetMethod("op_Division", new Type[] { this.typeBridge, right.type });
            }
            else if (code == '%')//[4] = {CQcriptExt.Vector3 op_Modulus(CQcriptExt.Vector3, CQcriptExt.Vector3)}
            {
                call = _type.GetMethod("op_Modulus", new Type[] { this.typeBridge, right.type });
            }

            var obj = call.Invoke(null, new object[] { left, right.value });

            //function.StaticCall(env,"op_Addtion",new List<ICL>{})
            return(obj);
        }
示例#14
0
 public object ConvertTo(object src, CQ_Type targetType)
 {
     return(null);
 }
示例#15
0
        public virtual object ConvertTo(object src, CQ_Type targetType)
        {
            Type targettype = (Type)targetType;

            if (this._type == targettype)
            {
                return(src);
            }

            //type.get

            if (_type.IsEnum)
            {
                if ((Type)targetType == typeof(int))
                {
                    return(System.Convert.ToInt32(src));
                }
                else if ((Type)targetType == typeof(uint))
                {
                    return(System.Convert.ToUInt32(src));
                }
                else if ((Type)targetType == typeof(short))
                {
                    return(System.Convert.ToInt16(src));
                }
                else if ((Type)targetType == typeof(ushort))
                {
                    return(System.Convert.ToUInt16(src));
                }
                else
                {
                    return(System.Convert.ToInt32(src));
                }
            }
            else if (targettype != null && targettype.IsEnum)
            {
                return(Enum.ToObject(targettype, src));
            }
            MethodInfo[] ms = _type.GetMethods();
            foreach (MethodInfo m in ms)
            {
                if ((m.Name == "op_Implicit" || m.Name == "op_Explicit") && m.ReturnType == targettype)
                {
                    return(m.Invoke(null, new object[] { src }));
                }
            }
            if (targettype != null)
            {
                if (targettype.IsAssignableFrom(_type))
                {
                    return(src);
                }
                if (src != null && targettype.IsInstanceOfType(src))
                {
                    return(src);
                }
            }
            else
            {
                return(src);
            }

            return(null);
        }
示例#16
0
        //快速计算
        protected static object Math2Value <LeftType> (char opCode, object left, CQ_Value right, out CQ_Type returntype, out bool math2ValueSuccess) where LeftType : struct
        {
            try {
                math2ValueSuccess = true;
                returntype        = GetReturnType_Math2Value(typeof(LeftType), right.type);
                double leftValue  = GetDouble(typeof(LeftType), left);
                double rightValue = GetDouble(right.type, right.value);
                double finalValue;

                switch (opCode)
                {
                case '+':
                    finalValue = leftValue + rightValue;
                    break;

                case '-':
                    finalValue = leftValue - rightValue;
                    break;

                case '*':
                    finalValue = leftValue * rightValue;
                    break;

                case '/':
                    finalValue = leftValue / rightValue;
                    break;

                case '%':
                    finalValue = leftValue % rightValue;
                    break;

                default:
                    throw new Exception("Invalid math operation::opCode = " + opCode);
                }

                return(Double2TargetType(returntype, finalValue));
            }
            catch (Exception e) {
                math2ValueSuccess = false;
                returntype        = null;
                return(null);
            }
        }
示例#17
0
 public virtual object Math2Value(char code, object left, CQ_Value right, out CQ_Type returntype)
 {
     throw new NotImplementedException();
 }
示例#18
0
 public virtual object ConvertTo(object src, CQ_Type targetType)
 {
     throw new NotImplementedException();
 }
示例#19
0
 public object Math2Value(char code, object left, CQ_Value right, out CQ_Type returntype)
 {
     throw new NotImplementedException("code:" + code + " right:+" + right.type.ToString() + "=" + right.value);
 }
示例#20
0
        public override object Math2Value(char code, object left, CQ_Value right, out CQ_Type returntype)
        {
            returntype = null;

            if (left is DeleEvent)
            {
                DeleEvent info     = left 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.value;
                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);
                    //}
                    return(info);
                }
                else if (code == '-')
                {
                    info._event.RemoveEventHandler(info.source, calldele);
                    //if (!(rightValue is Delegate)) {
                    //    Dele_Map_Delegate.Destroy(rightValue as IDeleBase);
                    //}
                    return(info);
                }
            }
            else if (left is Delegate || left == null)
            {
                Delegate info     = left as Delegate;
                Delegate calldele = null;
                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;
                }
                if (code == '+')
                {
                    return(Delegate.Combine(info, calldele));;
                }
                else if (code == '-')
                {
                    return(Delegate.Remove(info, calldele));
                }
            }
            return(new NotSupportedException());
        }
示例#21
0
        public static IType GetTypeByKeyword(string keyword)
        {
            IType ret = null;

            if (string.IsNullOrEmpty(keyword))
            {
                return(null);
            }
            if (typess.TryGetValue(keyword, out ret) == false)
            {
                if (keyword[keyword.Length - 1] == '>')
                {
                    int           iis    = keyword.IndexOf('<');
                    string        func   = keyword.Substring(0, iis);
                    List <string> _types = new List <string>();
                    int           istart = iis + 1;
                    int           inow   = istart;
                    int           dep    = 0;
                    while (inow < keyword.Length)
                    {
                        if (keyword[inow] == '<')
                        {
                            dep++;
                        }
                        if (keyword[inow] == '>')
                        {
                            dep--;
                            if (dep < 0)
                            {
                                _types.Add(keyword.Substring(istart, inow - istart));
                                break;
                            }
                        }

                        if (keyword[inow] == ',' && dep == 0)
                        {
                            _types.Add(keyword.Substring(istart, inow - istart));
                            istart = inow + 1;
                            inow   = istart;
                            continue;;
                        }

                        inow++;
                    }

                    //var funk = keyword.Split(new char[] { '<', '>', ',' }, StringSplitOptions.RemoveEmptyEntries);
                    if (typess.ContainsKey(func))
                    {
                        Type gentype = GetTypeByKeyword(func).typeBridge;
                        if (gentype.IsGenericTypeDefinition)
                        {
                            Type[] types = new Type[_types.Count];
                            for (int i = 0; i < types.Length; i++)
                            {
                                CQ_Type t  = GetTypeByKeyword(_types[i]).typeBridge;
                                Type    rt = t;
                                if (rt == null && t != null)
                                {
                                    rt = typeof(object);
                                }
                                types[i] = rt;
                            }
                            Type IType = gentype.MakeGenericType(types);
                            RegisterType(MakeType(IType, keyword));
                            return(GetTypeByKeyword(keyword));
                        }
                    }
                }
                DebugUtil.LogError("(CQcript)类型未注册:" + keyword);
            }

            return(ret);
        }