Exemplo n.º 1
0
        public object Math2Value(CLS_Content env, char code, object left, CLS_Content.Value right, out CLType returntype)
        {
            returntype = typeof(float);
            if ((Type)right.type == typeof(int))
            {
                if (code == '+')
                    return (float)left + (float)(int)right.value;
                else if (code == '-')
                    return (float)left - (float)(int)right.value;
                else if (code == '*')
                    return (float)left * (float)(int)right.value;
                else if (code == '/')
                    return (float)left / (float)(int)right.value;
                else if (code == '%')
                    return (float)left % (float)(int)right.value;
            }
            else if ((Type)right.type == typeof(uint))
            {
                if (code == '+')
                    return (float)left + (float)(uint)right.value;
                else if (code == '-')
                    return (float)left - (float)(uint)right.value;
                else if (code == '*')
                    return (float)left * (float)(uint)right.value;
                else if (code == '/')
                    return (float)left / (float)(uint)right.value;
                else if (code == '%')
                    return (float)left % (float)(uint)right.value;
            }
            else if ((Type)right.type == typeof(double))
            {
                returntype = typeof(double);

                if (code == '+')
                    return (double)(float)left + (double)right.value;
                else if (code == '-')
                    return (double)(float)left - (double)right.value;
                else if (code == '*')
                    return (double)(float)left * (double)right.value;
                else if (code == '/')
                    return (double)(float)left / (double)right.value;
                else if (code == '%')
                    return (double)(float)left % (double)right.value;
            }
            else if ((Type)right.type == typeof(float))
            {
                returntype = typeof(float);
                if (code == '+')
                    return (float)left + (float)right.value;
                else if (code == '-')
                    return (float)left - (float)right.value;
                else if (code == '*')
                    return (float)left * (float)right.value;
                else if (code == '/')
                    return (float)left / (float)right.value;
                else if (code == '%')
                    return (float)left % (float)right.value;
            }
            throw new NotImplementedException();
        }
        public CLS_Content.Value ComputeValue(CLS_Content content)
        {
            content.InStack(this);

            {
                CLS_Content.Value v = listParam[0].ComputeValue(content);

                {
                    object val = v.value;
                    if (content.values.ContainsKey(value_name))
                    {
                        CLType value_type = content.values[value_name].type;

                        val = v.value;
                        if ((Type)value_type != typeof(CLS_Type_Var.var) && value_type != v.type)
                        {
                            val = content.environment.GetType(v.type).ConvertTo(content, v.value, value_type);
                        }
                    }
                    content.Set(value_name, val);
                }
            }
            content.OutStack(this);
            return(null);
        }
Exemplo n.º 3
0
        public virtual object ConvertTo(CLS_Content env, object src, CLType targetType)
        {
            //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);
                }
            }
            var ms = _type.GetMethods();
            foreach (var m in ms)
            {
                if ((m.Name == "op_Implicit" || m.Name == "op_Explicit") && m.ReturnType == (Type)targetType)
                {
                    return m.Invoke(null, new object[] { src });
                }
            }

            return src;
        }
Exemplo n.º 4
0
        public object ConvertTo(CLS_Content content, object src, CLType targetType)
        {
            Type targetSysType = (Type)targetType;

            if (targetSysType.IsEnum)
            {
                return(Enum.ToObject(targetSysType, src));
            }
            else if (targetSysType == typeof(int))
            {
                return(System.Convert.ToInt32(src));
            }
            else if (targetSysType == typeof(uint))
            {
                return(System.Convert.ToUInt32(src));
            }
            else if (targetSysType == typeof(short))
            {
                return(System.Convert.ToInt16(src));
            }
            else if (targetSysType == typeof(ushort))
            {
                return(System.Convert.ToUInt16(src));
            }
            else if (targetSysType == typeof(long))
            {
                return(System.Convert.ToInt64(src));
            }
            else if (targetSysType == typeof(ulong))
            {
                return(System.Convert.ToUInt64(src));
            }

            throw new NotImplementedException();
        }
Exemplo n.º 5
0
        public object ConvertTo(CLS_Content env, object src, CLType targetType)
        {
            ICLS_Type_Dele dele = env.environment.GetType(targetType) as ICLS_Type_Dele;

            return(dele.CreateDelegate(env.environment, src as DeleFunction));
            //throw new NotImplementedException();
        }
Exemplo n.º 6
0
        public override object Math2Value(CLS_Content env, char code, object left, CLS_Content.Value right, out CLType returntype)
        {
            returntype = null;

            Delegate rightDele = null;
            if (right.value is DeleFunction)
                rightDele = CreateDelegate(env.environment, right.value as DeleFunction);
            else if (right.value is DeleLambda)
                rightDele = CreateDelegate(env.environment, right.value as DeleLambda);
            else if (right.value is Delegate)
                rightDele = right.value as Delegate;

            if (rightDele != null)
            {
                Delegate leftDele = left as Delegate;
                if (left == null)
                    return rightDele;

                if (code == '+')
                    return Delegate.Combine(leftDele, rightDele);
                if (code == '-')
                    return Delegate.Remove(leftDele, rightDele);
            }

            throw new NotSupportedException("" + right.value);
        }
Exemplo n.º 7
0
    public override object Math2Value(CLS_Content content, char code, object left, CLS_Content.Value right, out CLType returntype)
    {
        if (code == '+')
        {
            if (right.value is Vector3)
            {
                returntype = typeof(Vector3);
                return ((Vector3)left) + ((Vector3)right.value);
            }
        }
        if (code == '-')
        {
            returntype = typeof(Vector3);
            return ((Vector3)left) - ((Vector3)right.value);
        }
        if (code == '*')
        {
            returntype = typeof(Vector3);
            return ((Vector3)left) * Convert.ToSingle(right.value);
        }
        if (code == '/')
        {
            returntype = typeof(Vector3);
            return ((Vector3)left) / Convert.ToSingle(right.value);
        }

        return base.Math2Value(content, code, left, right, out returntype);
    }
Exemplo n.º 8
0
 public override object ConvertTo(CLS_Content env, object src, CLType targetType)
 {
     Type t = targetType;
     if (t == typeof(double))
         return (double)(long)(src);
     if (t == typeof(float))
         return (float)(long)(src);
     if (t == typeof(long))
         return src;
     if (t == typeof(ulong))
         return (ulong)(long)(src);
     if (t == typeof(int))
         return (int)(long)(src);
     if (t == typeof(uint))
         return (uint)(long)(src);
     if (t == typeof(short))
         return (short)(long)(src);
     if (t == typeof(ushort))
         return (ushort)(long)(src);
     if (t == typeof(sbyte))
         return (sbyte)(long)(src);
     if (t == typeof(byte))
         return (byte)(long)(src);
     if (t == typeof(char))
         return (char)(long)(src);
     if (t == typeof(int?))
         return (int?)(long)(src);
     if (t == typeof(uint?))
         return (uint?)(long)(src);
     return base.ConvertTo(env, src, targetType);
 }
Exemplo n.º 9
0
        public virtual object ConvertTo(CLS_Content env, object src, CLType targetType)
        {
            if (this._type == (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));
                }
            }
            var ms = _type.GetMethods();

            foreach (var m in ms)
            {
                if ((m.Name == "op_Implicit" || m.Name == "op_Explicit") && m.ReturnType == (Type)targetType)
                {
                    return(m.Invoke(null, new object[] { src }));
                }
            }
            if ((Type)targetType != null)

            {
                if (((Type)targetType).IsAssignableFrom(_type))
                {
                    return(src);
                }
                if (src != null && ((Type)targetType).IsInstanceOfType(src))
                {
                    return(src);
                }
            }
            else
            {
                return(src);
            }

            return(null);
        }
Exemplo n.º 10
0
        public override object Math2Value(CLS_Content env, char code, object left, CLS_Content.Value right, out CLType returntype)
        {
            returntype = typeof(double);
            if ((Type)right.type == typeof(int))
            {
                if (code == '+')
                    return (double)left + (double)(int)right.value;
                else if (code == '-')
                    return (double)left - (double)(int)right.value;
                else if (code == '*')
                    return (double)left * (double)(int)right.value;
                else if (code == '/')
                    return (double)left / (double)(int)right.value;
                else if (code == '%')
                    return (double)left % (double)(int)right.value;
            }
            else if ((Type)right.type == typeof(uint))
            {
                if (code == '+')
                    return (double)left + (double)(uint)right.value;
                else if (code == '-')
                    return (double)left - (double)(uint)right.value;
                else if (code == '*')
                    return (double)left * (double)(uint)right.value;
                else if (code == '/')
                    return (double)left / (double)(uint)right.value;
                else if (code == '%')
                    return (double)left % (double)(uint)right.value;
            }
            else if ((Type)right.type == typeof(double))
            {
                returntype = typeof(double);

                if (code == '+')
                    return (double)left + (double)right.value;
                else if (code == '-')
                    return (double)left - (double)right.value;
                else if (code == '*')
                    return (double)left * (double)right.value;
                else if (code == '/')
                    return (double)left / (double)right.value;
                else if (code == '%')
                    return (double)left % (double)right.value;
            }
            else if ((Type)right.type == typeof(float))
            {
                returntype = typeof(double);
                if (code == '+')
                    return (double)left + (double)(float)right.value;
                else if (code == '-')
                    return (double)left - (double)(float)right.value;
                else if (code == '*')
                    return (double)left * (double)(float)right.value;
                else if (code == '/')
                    return (double)left / (double)(float)right.value;
                else if (code == '%')
                    return (double)left % (double)(float)right.value;
            }
            return base.Math2Value(env, code, left, right, out returntype);
        }
Exemplo n.º 11
0
 public object Math2Value(CLS_Content env, char code, object left, CLS_Content.Value right, out CLType returntype)
 {
     returntype = typeof(string);
     if (code == '+')
         return (string)left + right.value.ToString();
  
     throw new NotImplementedException();
 }
Exemplo n.º 12
0
        public override object ConvertTo(CLS_Content env, object src, CLType targetType)
        {
            Type t = targetType;

            if (t == typeof(double))
            {
                return((double)(long)(src));
            }
            if (t == typeof(float))
            {
                return((float)(long)(src));
            }
            if (t == typeof(long))
            {
                return(src);
            }
            if (t == typeof(ulong))
            {
                return((ulong)(long)(src));
            }
            if (t == typeof(int))
            {
                return((int)(long)(src));
            }
            if (t == typeof(uint))
            {
                return((uint)(long)(src));
            }
            if (t == typeof(short))
            {
                return((short)(long)(src));
            }
            if (t == typeof(ushort))
            {
                return((ushort)(long)(src));
            }
            if (t == typeof(sbyte))
            {
                return((sbyte)(long)(src));
            }
            if (t == typeof(byte))
            {
                return((byte)(long)(src));
            }
            if (t == typeof(char))
            {
                return((char)(long)(src));
            }
            if (t == typeof(int?))
            {
                return((int?)(long)(src));
            }
            if (t == typeof(uint?))
            {
                return((uint?)(long)(src));
            }
            return(base.ConvertTo(env, src, targetType));
        }
Exemplo n.º 13
0
 public object ConvertTo(CLS_Content env, object src, CLType targetType)
 {
     if (targetType == type) return src;
     if ((Type)targetType == typeof(void))
     {
         return null;
     }
     throw new NotImplementedException();
 }
Exemplo n.º 14
0
 public object ConvertTo(CLS_Content env, object src, CLType targetType)
 {
     var type = env.environment.GetType(targetType);
     if (this.types.Contains(type))
     {
         return src;
     }
     throw new NotImplementedException();
 }
Exemplo n.º 15
0
 public object Math2Value(CLS_Content env, char code, object left, CLS_Content.Value right, out CLType returntype)
 {
    
     if ((Type)right.type == typeof(string))
     {
         returntype = typeof(String);
         return "null" + right.value;
     }
     throw new NotImplementedException();
 }
Exemplo n.º 16
0
        public override object Math2Value(CLS_Content env, char code, object left, CLS_Content.Value right, out CLType returntype)
        {
            bool math2ValueSuccess = false;
            object value = NumericTypeUtils.Math2Value<byte>(code, left, right, out returntype, out math2ValueSuccess);
            if (math2ValueSuccess) {
                return value;
            }

            return base.Math2Value(env, code, left, right, out returntype);
        }
Exemplo n.º 17
0
 public ICLS_Type GetType(CLType type)
 {
     if (type == null)
         return typess["null"];
     if (types.ContainsKey(type) == false)
     {
         logger.Log_Error("(CLScript)类型未注册:" + type.ToString());
     }
     return types[type];
 }
Exemplo n.º 18
0
        public override object ConvertTo(CLS_Content env, object src, CLType targetType)
        {
            bool convertSuccess = false;
            object convertedObject = NumericTypeUtils.TryConvertTo<byte>(src, targetType, out convertSuccess);
            if (convertSuccess) {
                return convertedObject;
            }

            return base.ConvertTo(env, src, targetType);
        }
Exemplo n.º 19
0
        public object ConvertTo(CLS_Content env, object src, CLType targetType)
        {
            var type = env.environment.GetType(targetType);

            if (this.types.Contains(type))
            {
                return(src);
            }
            throw new NotImplementedException();
        }
Exemplo n.º 20
0
 public ICLS_Type GetType(CLType type)
 {
     if (type == null)
     {
         return(typess["null"]);
     }
     if (types.ContainsKey(type) == false)
     {
         logger.Log_Error("(CLScript)类型未注册:" + type.ToString());
     }
     return(types[type]);
 }
Exemplo n.º 21
0
        /// <summary>
        /// 类型转换.
        /// </summary>
        /// <typeparam name="OriginalType"></typeparam>
        /// <param name="src"></param>
        /// <param name="targetType"></param>
        /// <returns></returns>
        public static object TryConvertTo <OriginalType>(object src, CLType targetType, out bool convertSuccess) where OriginalType : struct
        {
            convertSuccess = true;

            try {
                decimal srcValue = GetDecimalValue(typeof(OriginalType), src);
                return(Decimal2TargetType(targetType, srcValue));
            } catch (Exception) {
                convertSuccess = false;
                return(null);
            }
        }
Exemplo n.º 22
0
        public void Define(string name, CLType type)
        {
            Value val = new Value();

            val.type         = type;
            dictValues[name] = val;

            if (stackTempValueName.size > 0)
            {
                stackTempValueName[stackTempValueName.size - 1].Add(name);//暂存临时变量
            }
        }
Exemplo n.º 23
0
 public object ConvertTo(CLS_Content env, object src, CLType targetType)
 {
     if (targetType == type)
     {
         return(src);
     }
     if ((Type)targetType == typeof(void))
     {
         return(null);
     }
     throw new NotImplementedException();
 }
Exemplo n.º 24
0
        public override object ConvertTo(CLS_Content env, object src, CLType targetType)
        {
            bool   convertSuccess  = false;
            object convertedObject = NumericTypeUtils.TryConvertTo <int>(src, targetType, out convertSuccess);

            if (convertSuccess)
            {
                return(convertedObject);
            }

            return(base.ConvertTo(env, src, targetType));
        }
Exemplo n.º 25
0
        public virtual object ConvertTo(CLS_Content env, object src, CLType targetType)
        {
            Type targetSysType = (Type)targetType;

            if (sysType == targetSysType)
                return src;

            if (targetSysType == null)
                return src;

            return src;
        }
Exemplo n.º 26
0
 public object ConvertTo(CLS_Content env, object src, CLType 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;
 }
Exemplo n.º 27
0
        public ICLS_Type GetType(CLType type)
        {
            if (type == null)
            {
                return(typess["null"]);
            }
            if (types.ContainsKey(type) == false)
            {
                logger.Log_Warn("(CLScript)类型未注册,将自动注册一份匿名:" + type.ToString());
                RegType(new RegHelper_Type(type, ""));
            }

            return(types[type]);
        }
Exemplo n.º 28
0
        public void DefineAndSet(string name, CLType type, object value)
        {
            Value val = new Value();

            val.type  = type;
            val.value = value;
            val.FixValueType(this);
            dictValues[name] = val;

            if (stackTempValueName.size > 0)
            {
                stackTempValueName[stackTempValueName.size - 1].Add(name);//暂存临时变量
            }
        }
Exemplo n.º 29
0
        public void Define(string name, CLType type)
        {
            if (values.ContainsKey(name))
            {
                throw new Exception("已经定义过");
            }
            Value v = new Value();

            v.type       = type;
            values[name] = v;
            if (tvalues.Count > 0)
            {
                tvalues.Peek().Add(name);//暂存临时变量
            }
        }
Exemplo n.º 30
0
        public void DefineAndSet(string name, CLType type, object value)
        {
            if (values.ContainsKey(name))
            {
                throw new Exception(type.ToString() + ":" + name + "已经定义过");
            }
            Value v = new Value();

            v.type       = type;
            v.value      = value;
            values[name] = v;
            if (tvalues.Count > 0)
            {
                tvalues.Peek().Add(name);//暂存临时变量
            }
        }
Exemplo n.º 31
0
        public virtual object ConvertTo(CLS_Content env, object src, CLType targetType)
        {
            Type targetSysType = (Type)targetType;

            if (sysType == targetSysType)
            {
                return(src);
            }

            if (targetSysType == null)
            {
                return(src);
            }

            return(src);
        }
Exemplo n.º 32
0
        public virtual object ConvertTo(CLS_Content env, object src, CLType targetType)
        {
            //type.get
            //var m =type.GetMembers();
            var ms = _type.GetMethods();

            foreach (var m in ms)
            {
                if ((m.Name == "op_Implicit" || m.Name == "op_Explicit") && m.ReturnType == (Type)targetType)
                {
                    return(m.Invoke(null, new object[] { src }));
                }
            }

            return(src);
        }
Exemplo n.º 33
0
        public virtual object Math2Value(CLS_Content env, char code, object left, CLS_Content.Value right, out CLType returnType)
        {
            if (code == '+')
            {
                returnType = typeof(string);

                if (left == null)
                    return "null" + right.value;

                if (right.value == null)
                    return left.ToString() + "null";

                return left.ToString() + right.value;
            }

            throw new NotImplementedException("未实现算术运算: " + code);
        }
Exemplo n.º 34
0
        public ICLS_Type GetType(CLType type)
        {
            if (type == null)
            {
                return(typess["null"]);
            }

            ICLS_Type ret = null;

            if (types.TryGetValue(type, out ret) == false)
            {
                logger.Log_Warn("(CLScript)类型未注册,将自动注册一份匿名:" + type.ToString());
                ret = RegHelper_Type.MakeType(type, "");
                RegType(ret);
            }
            return(ret);
        }
Exemplo n.º 35
0
 public object ConvertTo(CLS_Content env, object src, CLType 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);
 }
Exemplo n.º 36
0
    public override object Math2Value(CLS_Content content, char code, object left, CLS_Content.Value right, out CLType returntype)
    {
        if (code == '*')
        {
            if (right.value is Quaternion)
            {
                returntype = typeof(Quaternion);
                return ((Quaternion)left) * ((Quaternion)right.value);
            }
            if (right.value is Vector3)
            {
                returntype = typeof(Vector3);
                return ((Quaternion)left) * ((Vector3)right.value);
            }
        }

        return base.Math2Value(content, code, left, right, out returntype);
    }
Exemplo n.º 37
0
 public override object ConvertTo(CLS_Content env, object src, CLType targetType)
 {
     if ((Type)targetType == typeof(uint))
     {
         return (uint)(byte)src;
     }
     else if ((Type)targetType == typeof(int))
     {
         return (int)(byte)src;
     }
     else if ((Type)targetType == typeof(double))
     {
         return (double)(byte)src;
     }
     else if ((Type)targetType == typeof(float))
     {
         return (float)(byte)src;
     }
     else if ((Type)targetType == typeof(ushort))
     {
         return (ushort)(byte)src;
     }
     else if ((Type)targetType == typeof(byte))
     {
         return (byte)(byte)src;
     }
     else if ((Type)targetType == typeof(char))
     {
         return (char)(byte)src;
     }
     else if ((Type)targetType == typeof(ushort))
     {
         return (ushort)(byte)src;
     }
     else if ((Type)targetType == typeof(sbyte))
     {
         return (sbyte)(byte)src;
     }
     else if ((Type)targetType == typeof(short))
     {
         return (short)(byte)src;
     }
     return base.ConvertTo(env, src, targetType);
 }
Exemplo n.º 38
0
        public CLS_Content.Value ComputeValue(CLS_Content content)
        {
            content.InStack(this);

            {
                CLS_Content.Value v = listParam[0].ComputeValue(content);

                {
                    object val        = v.value;
                    CLType value_type = null;
                    if (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(CLS_Type_Var.var) && value_type != v.type)
                    {
                        val = content.environment.GetType(v.type).ConvertTo(content, v.value, value_type);
                    }


                    content.Set(value_name, val);
                }
            }
            content.OutStack(this);
            return(null);
        }
Exemplo n.º 39
0
 public override object ConvertTo(CLS_Content env, object src, CLType targetType)
 {
     if ((Type)targetType == typeof(uint))
     {
         return((uint)(byte)src);
     }
     else if ((Type)targetType == typeof(int))
     {
         return((int)(byte)src);
     }
     else if ((Type)targetType == typeof(double))
     {
         return((double)(byte)src);
     }
     else if ((Type)targetType == typeof(float))
     {
         return((float)(byte)src);
     }
     else if ((Type)targetType == typeof(ushort))
     {
         return((ushort)(byte)src);
     }
     else if ((Type)targetType == typeof(byte))
     {
         return((byte)(byte)src);
     }
     else if ((Type)targetType == typeof(char))
     {
         return((char)(byte)src);
     }
     else if ((Type)targetType == typeof(ushort))
     {
         return((ushort)(byte)src);
     }
     else if ((Type)targetType == typeof(sbyte))
     {
         return((sbyte)(byte)src);
     }
     else if ((Type)targetType == typeof(short))
     {
         return((short)(byte)src);
     }
     return(base.ConvertTo(env, src, targetType));
 }
        public override object Math2Value(CLS_Content env, char code, object left, CLS_Content.Value right, out CLType returntype)
        {
            returntype = null;

            if (left is DeleEvent)
            {
                DeleEvent info = left as DeleEvent;
                Delegate calldele = null;
                if (right.value is DeleFunction) calldele = CreateDelegate(env.environment, right.value as DeleFunction);
                else if (right.value is DeleLambda) calldele = CreateDelegate(env.environment, right.value as DeleLambda);
                else if (right.value is Delegate) calldele = right.value as Delegate;

                if (code == '+')
                {
                    info._event.AddEventHandler(info.source, calldele);
                    return null;
                }
                else if (code == '-')
                {
                    info._event.AddEventHandler(info.source, calldele);
                    return null;
                }

            }
            else if(left is Delegate)
            {
                Delegate info = left as Delegate;
                Delegate calldele = null;
                if (right.value is DeleFunction) calldele = CreateDelegate(env.environment, right.value as DeleFunction);
                else if (right.value is DeleLambda) calldele = CreateDelegate(env.environment, right.value as DeleLambda);
                else if (right.value is Delegate) calldele = right.value as Delegate;
                if (code == '+')
                {
                    Delegate.Combine(info, calldele);
                    return null;
                }
                else if (code == '-')
                {
                    Delegate.Remove(info, calldele);
                }
            }
            return new NotSupportedException();
        }
Exemplo n.º 41
0
        public ICLS_Type GetType(CLType type)
        {
            if (type == null)
            {
                return(dictTypeKeywords["null"]);
            }

            ICLS_Type iType;

            if (dictTypes.TryGetValue(type, out iType))
            {
                return(iType);
            }

            logger.Log_Warn("类型未注册, 这里将自动注册一份匿名:" + type.ToString());
            RegType(new RegHelper_Type(type, ""));

            return(dictTypes[type]);
        }
Exemplo n.º 42
0
 public object ConvertTo(CLS_Content env, object src, CLType targetType)
 {
     if ((Type)targetType == typeof(uint))
     {
         return((uint)src);
     }
     else if ((Type)targetType == typeof(int))
     {
         return((int)(uint)src);
     }
     else if ((Type)targetType == typeof(double))
     {
         return((double)(uint)src);
     }
     else if ((Type)targetType == typeof(float))
     {
         return((float)(uint)src);
     }
     throw new NotImplementedException();
 }
Exemplo n.º 43
0
 public object ConvertTo(CLS_Content env, object src, CLType targetType)
 {
     if ((Type)targetType == typeof(int))
     {
         return (int)(float)src;
     }
     else if ((Type)targetType == typeof(uint))
     {
         return (uint)(float)src;
     }
     else if ((Type)targetType == typeof(double))
     {
         return (double)(float)src;
     }
     else if ((Type)targetType == typeof(float))
     {
         return (float)src;
     }
     throw new NotImplementedException();
 }
Exemplo n.º 44
0
        public object ConvertTo(CLS_Content content, object src, CLType targetType)
        {
            Type targetSysType = (Type)targetType;

            if (targetSysType.IsEnum)
                return Enum.ToObject(targetSysType, src);
            else if (targetSysType == typeof(int))
                return System.Convert.ToInt32(src);
            else if (targetSysType == typeof(uint))
                return System.Convert.ToUInt32(src);
            else if (targetSysType == typeof(short))
                return System.Convert.ToInt16(src);
            else if (targetSysType == typeof(ushort))
                return System.Convert.ToUInt16(src);
            else if (targetSysType == typeof(long))
                return System.Convert.ToInt64(src);
            else if (targetSysType == typeof(ulong))
                return System.Convert.ToUInt64(src);

            throw new NotImplementedException();
        }
Exemplo n.º 45
0
        public object Math2Value(CLS_Content content, char code, object left, CLS_Content.Value right, out CLType returnType)
        {
            returnType = type;

            int tLeft = System.Convert.ToInt32(left);
            int tRight = System.Convert.ToInt32(right.value);

            switch (code)
            {
                case '+':
                    return tLeft + tRight;
                case '-':
                    return tLeft - tRight;
                case '*':
                    return tLeft * tRight;
                case '/':
                    return tLeft / tRight;
                case '%':
                    return tLeft % tRight;
                case '<':
                    return tLeft << tRight;
                case '>':
                    return tLeft >> tRight;
                case '&':
                    return tLeft & tRight;
                case '|':
                    return tLeft | tRight;
                case '~':
                    return ~tLeft;
                case '^':
                    return tLeft ^ tRight;
            }

            throw new NotImplementedException();
        }
Exemplo n.º 46
0
 public object Math2Value(CLS_Content env, char code, object left, CLS_Content.Value right, out CLType returntype)
 {
     returntype = typeof(string);
     if (code == '+')
     {
         if (right.value == null)
         {
             return((string)left + "null");
         }
         else
         {
             return((string)left + right.value.ToString());
         }
     }
     throw new NotImplementedException();
 }
Exemplo n.º 47
0
 public object ConvertTo(CLS_Content env, object src, CLType targetType)
 {
     return src;
 }
Exemplo n.º 48
0
        public override object Math2Value(CLS_Content env, char code, object left, CLS_Content.Value right, out CLType returntype)
        {
            bool   math2ValueSuccess = false;
            object value             = NumericTypeUtils.Math2Value <int>(code, left, right, out returntype, out math2ValueSuccess);

            if (math2ValueSuccess)
            {
                return(value);
            }

            return(base.Math2Value(env, code, left, right, out returntype));
        }
Exemplo n.º 49
0
 public object Math2Value(CLS_Content env, char code, object left, CLS_Content.Value right, out CLType returntype)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 50
0
 public override object ConvertTo(CLS_Content env, object src, CLType targetType)
 {
     return((KeyValuePair <TKey, TValue>)src);
 }
Exemplo n.º 51
0
 public override object ConvertTo(CLS_Content content, object src, CLType targetType)
 {
     return ((Time)src);
 }
Exemplo n.º 52
0
 public object Math2Value(CLS_Content env, char code, object left, CLS_Content.Value right, out CLType returntype)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 53
0
 public object ConvertTo(CLS_Content env, object src, CLType targetType)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 54
0
        public override object Math2Value(CLS_Content env, char code, object left, CLS_Content.Value right, out CLType returntype)
        {
            returntype = typeof(float);
            if ((Type)right.type == typeof(int))
            {
                if (code == '+')
                {
                    return((float)left + (float)(int)right.value);
                }
                else if (code == '-')
                {
                    return((float)left - (float)(int)right.value);
                }
                else if (code == '*')
                {
                    return((float)left * (float)(int)right.value);
                }
                else if (code == '/')
                {
                    return((float)left / (float)(int)right.value);
                }
                else if (code == '%')
                {
                    return((float)left % (float)(int)right.value);
                }
            }
            else if ((Type)right.type == typeof(uint))
            {
                if (code == '+')
                {
                    return((float)left + (float)(uint)right.value);
                }
                else if (code == '-')
                {
                    return((float)left - (float)(uint)right.value);
                }
                else if (code == '*')
                {
                    return((float)left * (float)(uint)right.value);
                }
                else if (code == '/')
                {
                    return((float)left / (float)(uint)right.value);
                }
                else if (code == '%')
                {
                    return((float)left % (float)(uint)right.value);
                }
            }
            else if ((Type)right.type == typeof(double))
            {
                returntype = typeof(double);

                if (code == '+')
                {
                    return((double)(float)left + (double)right.value);
                }
                else if (code == '-')
                {
                    return((double)(float)left - (double)right.value);
                }
                else if (code == '*')
                {
                    return((double)(float)left * (double)right.value);
                }
                else if (code == '/')
                {
                    return((double)(float)left / (double)right.value);
                }
                else if (code == '%')
                {
                    return((double)(float)left % (double)right.value);
                }
            }
            else if ((Type)right.type == typeof(float))
            {
                returntype = typeof(float);
                if (code == '+')
                {
                    return((float)left + (float)right.value);
                }
                else if (code == '-')
                {
                    return((float)left - (float)right.value);
                }
                else if (code == '*')
                {
                    return((float)left * (float)right.value);
                }
                else if (code == '/')
                {
                    return((float)left / (float)right.value);
                }
                else if (code == '%')
                {
                    return((float)left % (float)right.value);
                }
            }
            return(base.Math2Value(env, code, left, right, out returntype));
        }
Exemplo n.º 55
0
        public override object Math2Value(CLS_Content env, char code, object left, CLS_Content.Value right, out CLType returntype)
        {
            returntype = null;

            if (left is DeleEvent)
            {
                DeleEvent info     = left as DeleEvent;
                Delegate  calldele = null;

                //!--exist bug.

                /*if (right.value is DeleFunction) calldele = CreateDelegate(env.environment, right.value as DeleFunction);
                 * else if (right.value is DeleLambda) calldele = CreateDelegate(env.environment, 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(env.environment, rightValue as DeleFunction);
                    }
                    else if (code == '-')
                    {
                        calldele = CreateDelegate(env.environment, rightValue as DeleFunction);
                    }
                }
                else if (rightValue is DeleLambda)
                {
                    if (code == '+')
                    {
                        calldele = CreateDelegate(env.environment, rightValue as DeleLambda);
                    }
                    else if (code == '-')
                    {
                        calldele = CreateDelegate(env.environment, 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(env.environment, right.value as DeleFunction);
                }
                else if (right.value is DeleLambda)
                {
                    calldele = CreateDelegate(env.environment, 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());
        }
Exemplo n.º 56
0
 public object ConvertTo(CLS_Content env, object src, CLType targetType)
 {
     ICLS_Type_Dele dele =  env.environment.GetType(targetType) as ICLS_Type_Dele;
     return dele.CreateDelegate(env.environment, src as DeleFunction);
     //throw new NotImplementedException();
 }
Exemplo n.º 57
0
        public override object Math2Value(CLS_Content env, char code, object left, CLS_Content.Value right, out CLType returntype)
        {
            returntype = typeof(int);
            if ((Type)right.type == typeof(uint))
            {
                if (code == '+')
                    return (byte)left + (uint)right.value;
                else if (code == '-')
                    return (byte)left - (uint)right.value;
                else if (code == '*')
                    return (byte)left * (uint)right.value;
                else if (code == '/')
                    return (byte)left / (uint)right.value;
                else if (code == '%')
                    return (byte)left % (uint)right.value;
            }
            else if ((Type)right.type == typeof(ushort))
            {
                if (code == '+')
                    return (byte)left + (ushort)right.value;
                else if (code == '-')
                    return (byte)left - (ushort)right.value;
                else if (code == '*')
                    return (byte)left * (ushort)right.value;
                else if (code == '/')
                    return (byte)left / (ushort)right.value;
                else if (code == '%')
                    return (byte)left % (ushort)right.value;
            }
            else if ((Type)right.type == typeof(char))
            {
                if (code == '+')
                    return (byte)left + (char)right.value;
                else if (code == '-')
                    return (byte)left - (char)right.value;
                else if (code == '*')
                    return (byte)left * (char)right.value;
                else if (code == '/')
                    return (byte)left / (char)right.value;
                else if (code == '%')
                    return (byte)left % (char)right.value;
            }
            else if ((Type)right.type == typeof(byte))
            {

                if (code == '+')
                    return (byte)left + (byte)right.value;
                else if (code == '-')
                    return (byte)left - (byte)right.value;
                else if (code == '*')
                    return (byte)left * (byte)right.value;
                else if (code == '/')
                    return (byte)left / (byte)right.value;
                else if (code == '%')
                    return (byte)left % (byte)right.value;
            }
            else if ((Type)right.type == typeof(int))
            {
                returntype = typeof(int);
                if (code == '+')
                    return (int)(byte)left + (int)right.value;
                else if (code == '-')
                    return (int)(byte)left - (int)right.value;
                else if (code == '*')
                    return (int)(byte)left * (int)right.value;
                else if (code == '/')
                    return (int)(byte)left / (int)right.value;
                else if (code == '%')
                    return (int)(byte)left % (int)right.value;
            }
            else if ((Type)right.type == typeof(short))
            {
                returntype = typeof(int);
                if (code == '+')
                    return (int)(byte)left + (short)right.value;
                else if (code == '-')
                    return (int)(byte)left - (short)right.value;
                else if (code == '*')
                    return (int)(byte)left * (short)right.value;
                else if (code == '/')
                    return (int)(byte)left / (short)right.value;
                else if (code == '%')
                    return (int)(byte)left % (short)right.value;
            }
            else if ((Type)right.type == typeof(sbyte))
            {
                returntype = typeof(int);
                if (code == '+')
                    return (int)(byte)left + (sbyte)right.value;
                else if (code == '-')
                    return (int)(byte)left - (sbyte)right.value;
                else if (code == '*')
                    return (int)(byte)left * (sbyte)right.value;
                else if (code == '/')
                    return (int)(byte)left / (sbyte)right.value;
                else if (code == '%')
                    return (int)(byte)left % (sbyte)right.value;
            }
            else if ((Type)right.type == typeof(double))
            {
                returntype = typeof(double);

                if (code == '+')
                    return (double)(byte)left + (double)right.value;
                else if (code == '-')
                    return (double)(byte)left - (double)right.value;
                else if (code == '*')
                    return (double)(byte)left * (double)right.value;
                else if (code == '/')
                    return (double)(byte)left / (double)right.value;
                else if (code == '%')
                    return (double)(byte)left % (double)right.value;
            }
            else if ((Type)right.type == typeof(float))
            {
                returntype = typeof(float);
                if (code == '+')
                    return (float)(byte)left + (float)right.value;
                else if (code == '-')
                    return (float)(byte)left - (float)right.value;
                else if (code == '*')
                    return (float)(byte)left * (float)right.value;
                else if (code == '/')
                    return (float)(byte)left / (float)right.value;
                else if (code == '%')
                    return (float)(byte)left % (float)right.value;
            }
            return base.Math2Value(env, code, left, right, out returntype);
        }
Exemplo n.º 58
0
        public object Math2Value(CLS_Content env, char code, object left, CLS_Content.Value right, out CLType returntype)
        {

            throw new NotImplementedException("code:"+code +" right:+"+right.type.ToString()+"="+ right.value);
        }
Exemplo n.º 59
0
 public override object Math2Value(CLS_Content env, char code, object left, CLS_Content.Value right, out CLType returntype)
 {
     if (code == '+')
     {
         if (right.value is long)
         {
             returntype = type;
             return (long)left + (long)right.value;
         }
         else if (right.value is int)
         {
             returntype = type;
             return (long)left + (int)right.value;
         }
         else if (right.value is double)
         {
             returntype = typeof(double);
             return (long)left + (double)right.value;
         }
         else if (right.value is float)
         {
             returntype = typeof(float);
             return (long)left + (float)right.value;
         }
         else if (right.value is uint)
         {
             returntype = type;
             return (long)left + (uint)right.value;
         }
         else if (right.value is string)
         {
             returntype = typeof(string);
             return Convert.ToString(left) + Convert.ToString(right.value);
         }
         else if (right.value is IConvertible)
         {
             returntype = type;
             return (long)left + Convert.ToInt64(right.value);
         }
     }
     else if (code == '-')
     {
         if (right.value is long)
         {
             returntype = type;
             return (long)left - (long)right.value;
         }
         else if (right.value is int)
         {
             returntype = type;
             return (long)left - (int)right.value;
         }
         else if (right.value is double)
         {
             returntype = typeof(double);
             return (long)left - (double)right.value;
         }
         else if (right.value is float)
         {
             returntype = typeof(float);
             return (long)left - (float)right.value;
         }
         else if (right.value is uint)
         {
             returntype = type;
             return (long)left - (uint)right.value;
         }
         else if (right.value is IConvertible)
         {
             returntype = type;
             return (long)left - Convert.ToInt64(right.value);
         }
     }
     else if (code == '*')
     {
         if (right.value is long)
         {
             returntype = type;
             return (long)left * (long)right.value;
         }
         else if (right.value is int)
         {
             returntype = type;
             return (long)left * (int)right.value;
         }
         else if (right.value is double)
         {
             returntype = typeof(double);
             return (long)left * (double)right.value;
         }
         else if (right.value is float)
         {
             returntype = typeof(float);
             return (long)left * (float)right.value;
         }
         else if (right.value is uint)
         {
             returntype = type;
             return (long)left * (uint)right.value;
         }
         else if (right.value is IConvertible)
         {
             returntype = type;
             return (long)left * Convert.ToInt64(right.value);
         }
     }
     else if (code == '/')
     {
         if (right.value is long)
         {
             returntype = type;
             return (long)left / (long)right.value;
         }
         else if (right.value is int)
         {
             returntype = type;
             return (long)left / (int)right.value;
         }
         else if (right.value is double)
         {
             returntype = typeof(double);
             return (long)left / (double)right.value;
         }
         else if (right.value is float)
         {
             returntype = typeof(float);
             return (long)left / (float)right.value;
         }
         else if (right.value is uint)
         {
             returntype = type;
             return (long)left / (uint)right.value;
         }
         else if (right.value is IConvertible)
         {
             returntype = type;
             return (long)left / Convert.ToInt64(right.value);
         }
     }
     else if (code == '%')
     {
         if (right.value is long)
         {
             returntype = type;
             return (long)left % (long)right.value;
         }
         else if (right.value is int)
         {
             returntype = type;
             return (long)left % (int)right.value;
         }
         else if (right.value is double)
         {
             returntype = typeof(double);
             return (long)left % (double)right.value;
         }
         else if (right.value is float)
         {
             returntype = typeof(float);
             return (long)left % (float)right.value;
         }
         else if (right.value is uint)
         {
             returntype = type;
             return (long)left % (uint)right.value;
         }
         else if (right.value is IConvertible)
         {
             returntype = type;
             return (long)left % Convert.ToInt64(right.value);
         }
     }
     else if (code == '<')
     {
         if (right.value is int)
         {
             returntype = type;
             return (long)left << (int)right.value;
         }
         else if (right.value is IConvertible)
         {
             returntype = type;
             return (long)left << Convert.ToInt32(right.value);
         }
     }
     else if (code == '>')
     {
         if (right.value is int)
         {
             returntype = type;
             return (long)left >> (int)right.value;
         }
         else if (right.value is IConvertible)
         {
             returntype = type;
             return (long)left >> Convert.ToInt32(right.value);
         }
     }
     else if (code == '&')
     {
         if (right.value is long)
         {
             returntype = type;
             return (long)left & (long)right.value;
         }
         else if (right.value is int)
         {
             returntype = type;
             return (long)left & (int)right.value;
         }
         else if (right.value is uint)
         {
             returntype = type;
             return (long)left & (uint)right.value;
         }
         else if (right.value is IConvertible)
         {
             returntype = type;
             return (long)left & Convert.ToInt64(right.value);
         }
     }
     else if (code == '|')
     {
         if (right.value is long)
         {
             returntype = type;
             return (long)left | (long)right.value;
         }
         else if (right.value is IConvertible)
         {
             returntype = type;
             return (long)left | Convert.ToInt64(right.value);
         }
     }
     else if (code == '~')
     {
         returntype = type;
         return ~(long)left;
     }
     else if (code == '^')
     {
         if (right.value is long)
         {
             returntype = type;
             return (long)left ^ (long)right.value;
         }
         else if (right.value is int)
         {
             returntype = type;
             return (long)left ^ (int)right.value;
         }
         else if (right.value is uint)
         {
             returntype = type;
             return (long)left ^ (uint)right.value;
         }
         else if (right.value is IConvertible)
         {
             returntype = type;
             return (long)left ^ Convert.ToInt64(right.value);
         }
     }
     return base.Math2Value(env, code, left, right, out returntype);
 }
Exemplo n.º 60
0
 public object ConvertTo(CLS_Content env, object src, CLType targetType)
 {
     return(src);
 }