コード例 #1
0
ファイル: Type_Delegate.cs プロジェクト: liuruoyu1981/CQuark
        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
ファイル: Type_Null.cs プロジェクト: liuruoyu1981/CQuark
 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
ファイル: Type_Numeric.cs プロジェクト: liuruoyu1981/CQuark
 /// <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
ファイル: Type_Long.cs プロジェクト: liuruoyu1981/CQuark
        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
ファイル: Type_Long.cs プロジェクト: liuruoyu1981/CQuark
        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
ファイル: Type_String.cs プロジェクト: liuruoyu1981/CQuark
 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
ファイル: AppDomain.cs プロジェクト: liuruoyu1981/CQuark
        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
ファイル: Type_String.cs プロジェクト: liuruoyu1981/CQuark
 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
ファイル: CQ_Content.cs プロジェクト: liuruoyu1981/CQuark
        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
ファイル: Type_Numeric.cs プロジェクト: liuruoyu1981/CQuark
        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
ファイル: Type_Null.cs プロジェクト: liuruoyu1981/CQuark
 public object ConvertTo(object src, CQ_Type targetType)
 {
     return(null);
 }
コード例 #15
0
ファイル: Type_Numeric.cs プロジェクト: liuruoyu1981/CQuark
        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
ファイル: Type_Numeric.cs プロジェクト: liuruoyu1981/CQuark
        //快速计算
        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
ファイル: Type_Action.cs プロジェクト: liuruoyu1981/CQuark
 public virtual object Math2Value(char code, object left, CQ_Value right, out CQ_Type returntype)
 {
     throw new NotImplementedException();
 }
コード例 #18
0
ファイル: Type_Action.cs プロジェクト: liuruoyu1981/CQuark
 public virtual object ConvertTo(object src, CQ_Type targetType)
 {
     throw new NotImplementedException();
 }
コード例 #19
0
ファイル: Type_Delegate.cs プロジェクト: liuruoyu1981/CQuark
 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
ファイル: AppDomain.cs プロジェクト: liuruoyu1981/CQuark
        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);
        }