示例#1
0
        public CLS_Content Clone()
        {
            CLS_Content content = CLS_Content.NewContent(environment);

            content.CallThis = this.CallThis;
            content.CallType = this.CallType;
            foreach (var pair in this.dictValues)
            {
                content.dictValues.Add(pair.Key, pair.Value);
            }
            return(content);
        }
示例#2
0
        public ICLS_Expression Optimize(ICLS_Expression value, ICLS_Environment env)
        {
            ICLS_Expression expr = value as ICLS_Expression;

            if (expr == null)
            {
                return(value);
            }
            else
            {
                return(OptimizeDepth(expr, CLS_Content.NewContent(env)));
            }
        }
示例#3
0
        public override Delegate CreateDelegate(ICLS_Environment env, DeleFunction delefunc)
        {
            Delegate _dele = delefunc.cacheFunction(null);

            if (_dele != null)
            {
                return(_dele);
            }

            var func = delefunc.calltype.functions[delefunc.function];
            Action <T, T1, T2> dele;

            if (func.expr_runtime != null)
            {
                dele = (T param0, T1 param1, T2 param2) =>
                {
                    CLS_Content content = CLS_Content.NewContent(env);
#if UNITY_EDITOR
                    try{
#endif
                    content.CallThis = delefunc.callthis;
                    content.CallType = delefunc.calltype;
                    content.DefineAndSet(func._paramnames[0], func._paramtypes[0].type, param0);
                    content.DefineAndSet(func._paramnames[1], func._paramtypes[1].type, param1);
                    content.DefineAndSet(func._paramnames[2], func._paramtypes[2].type, param2);
                    func.expr_runtime.ComputeValue(content);
                    CLS_Content.PoolContent(content);
#if UNITY_EDITOR
                }catch (System.Exception ex) { content.environment.logger.Log_Error(ex.Message + "\n" + content.DumpStack() + ex); }
#endif
                };
            }
            else
            {
                dele = (T param0, T1 param1, T2 param2) => { };
            }

            if (this.sysType != typeof(Action <T, T1, T2>))
            {
                _dele = Delegate.CreateDelegate(this.sysType, dele.Target, dele.Method);
            }
            else
            {
                _dele = dele;
            }
            return(delefunc.cacheFunction(_dele));
        }
        public override Delegate CreateDelegate(ICLS_Environment env, DeleFunction delefunc)
        {
            Delegate _dele = delefunc.cacheFunction(null);

            if (_dele != null)
            {
                return(_dele);
            }

            var             func = delefunc.calltype.functions[delefunc.function];
            NonVoidDelegate dele;

            if (func.expr_runtime != null)
            {
                dele = delegate(T param, T1 param1)
                {
                    CLS_Content content = CLS_Content.NewContent(env);
#if UNITY_EDITOR
                    try{
#endif
                    content.CallThis = delefunc.callthis;
                    content.CallType = delefunc.calltype;
                    content.DefineAndSet(func._paramnames[0], func._paramtypes[0].type, param);
                    content.DefineAndSet(func._paramnames[1], func._paramtypes[1].type, param1);
                    CLS_Content.Value retValue = func.expr_runtime.ComputeValue(content);
                    CLS_Content.PoolContent(content);
                    return((ReturnType)retValue.value);

#if UNITY_EDITOR
                }catch (System.Exception ex) { content.environment.logger.Log_Error(ex.Message + "\n" + content.DumpStack() + ex); return(default(ReturnType)); }
#endif
                };
            }
            else
            {
                dele = delegate(T param, T1 param1) { return(default(ReturnType)); };
            }

            _dele = Delegate.CreateDelegate(this.type, dele.Target, dele.Method);
            return(delefunc.cacheFunction(_dele));
        }
示例#5
0
 public CLS_Content CreateContent()
 {
     return(CLS_Content.NewContent(this));
 }
示例#6
0
        public CLS_Content.Value New(CLS_Content content, BetterList <CLS_Content.Value> _params)
        {
            if (staticMemberContent == null)
            {
                NewStatic(content.environment);
            }

            SInstance scriptInstance = new SInstance();

            scriptInstance.type = this;

            foreach (var pair in this.members)
            {
                Member member = pair.Value;
                if (!member.bStatic)
                {
                    CLS_Content.Value val = new CLS_Content.Value();
                    val.type = member.type.type;
                    if (member.expr_defvalue == null)
                    {
                        val.value = member.type.DefValue;
                    }
                    else
                    {
                        CLS_Content.Value value = member.expr_defvalue.ComputeValue(staticMemberContent);
                        if (member.type.type != value.type)
                        {
                            val.value = content.environment.GetType(value.type).ConvertTo(content, value.value, member.type.type);
                        }
                        else
                        {
                            val.value = value.value;
                        }
                    }
                    scriptInstance.member[pair.Key] = val;
                }
            }

            CLS_Content.Value thisVal = new CLS_Content.Value()
            {
                type = this, value = scriptInstance
            };

            // 加入this关键字
            scriptInstance.member["this"] = thisVal;

            // 加入base关键字
            if (BaseType != null)
            {
                scriptInstance.member["base"] = new CLS_Content.Value()
                {
                    type = BaseType, value = scriptInstance, breakBlock = 255
                }
            }
            ;

            // 调用构造函数
            if (this.functions.ContainsKey(this.Name))
            {
                MemberCall(content, scriptInstance, this.Name, _params);
            }

            return(thisVal);
        }

        void NewStatic(ICLS_Environment env)
        {
            staticMemberContent = CLS_Content.NewContent(env);
            staticMemberValues  = new Dictionary <string, CLS_Content.Value>();

            // 先初始化基类静态数据
            if (BaseType != null)
            {
                BaseType.NewStatic(env);

                // 拷贝基类的静态数据
                foreach (var pair in BaseType.staticMemberValues)
                {
                    staticMemberValues.Add(pair.Key, pair.Value);
                }
            }

            // 添加自身的静态成员数据
            foreach (var pair in this.members)
            {
                if (pair.Value.bStatic && !staticMemberValues.ContainsKey(pair.Key))
                {
                    CLS_Content.Value val = new CLS_Content.Value();
                    val.type = pair.Value.type.type;
                    if (pair.Value.expr_defvalue == null)
                    {
                        val.value = pair.Value.type.DefValue;
                    }
                    else
                    {
                        CLS_Content.Value value = pair.Value.expr_defvalue.ComputeValue(staticMemberContent);
                        if (pair.Value.type.type != value.type)
                        {
                            val.value = env.GetType(value.type).ConvertTo(staticMemberContent, value.value, pair.Value.type.type);
                        }
                        else
                        {
                            val.value = value.value;
                        }
                    }
                    staticMemberValues[pair.Key] = val;
                }
            }
        }
示例#7
0
        public CLS_Content.Value MemberCall(CLS_Content contentParent, object object_this, string func, BetterList <CLS_Content.Value> _params, bool isBaseCall = false)
        {
            SInstance callThis = object_this as SInstance;

            // 成员函数判断
            Function fun;

            if (this.functions.TryGetValue(func, out fun))
            {
#if UNITY_EDITOR
                if (fun.bStatic)
                {
                    throw new Exception("不能通过实例来调用静态函数: " + this.Name + "." + func);
                }
#endif
                CLS_Content.Value value = null;

                SType callType = this;

                if (isBaseCall)
                {
                    SType          tempType = contentParent.CallType.BaseType;
                    SType.Function tempFun;
                    while (tempType != null)
                    {
                        if (tempType.functions.TryGetValue(func, out tempFun))
                        {
                            if (tempFun.ownerType == null || tempFun.ownerType == tempType)
                            {
                                callType = tempType;
                                fun      = tempFun;
                                break;
                            }
                        }
                        tempType = tempType.BaseType;
                    }
                }
                else
                {
                    if (callType != callThis.type)
                    {
                        SType    tempType = callThis.type;
                        Function tempFun;
                        while (tempType != null)
                        {
                            if (tempType.functions.TryGetValue(func, out tempFun))
                            {
                                if (tempFun.ownerType == null || tempFun.ownerType == tempType)
                                {
                                    callType = tempType;
                                    fun      = tempFun;
                                    break;
                                }
                            }
                            tempType = tempType.BaseType;
                        }
                    }
                    else if (fun.ownerType != null && fun.ownerType != callType)
                    {
                        callType = fun.ownerType;
                    }
                }

                if (fun.expr_runtime != null)
                {
                    CLS_Content content = CLS_Content.NewContent(contentParent.environment);
#if UNITY_EDITOR
                    contentParent.InStackContent(content);//把这个上下文推给上层的上下文,这样如果崩溃是可以一层层找到原因的
#endif
                    content.CallType = callType;
                    content.CallThis = callThis;

                    for (int i = 0, count = fun._paramtypes.Count; i < count; i++)
                    {
                        content.DefineAndSet(fun._paramnames[i], fun._paramtypes[i].type, _params[i].value);
                    }

                    value = fun.expr_runtime.ComputeValue(content);
                    if (value != null)
                    {
                        value.breakBlock = 0;
                    }
#if UNITY_EDITOR
                    contentParent.OutStackContent(content);
#endif
                    CLS_Content.PoolContent(content);
                }

                return(value);
            }

            // 委托判断
            CLS_Content.Value mDeleVal;
            if (callThis.member.TryGetValue(func, out mDeleVal))
            {
                Delegate dele = mDeleVal.value as Delegate;
                if (dele != null)
                {
                    CLS_Content.Value value = new CLS_Content.Value();
                    value.type = null;
                    object[] objs = CLS_Content.ParamObjsArray[_params.size];
                    for (int i = 0; i < _params.size; i++)
                    {
                        objs[i] = _params[i].value;
                    }
                    value.value = dele.DynamicInvoke(objs);
                    if (value.value != null)
                    {
                        value.type = value.value.GetType();
                    }
                    value.breakBlock = 0;
                    return(value);
                }
            }
            throw new NotImplementedException("未实现成员函数: " + this.Name + "." + func);
        }
示例#8
0
        public CLS_Content.Value StaticCall(CLS_Content contentParent, string func, BetterList <CLS_Content.Value> _params)
        {
            if (staticMemberContent == null)
            {
                NewStatic(contentParent.environment);
            }

            // 静态函数判断
            Function fun;

            if (this.functions.TryGetValue(func, out fun))
            {
#if UNITY_EDITOR
                if (!fun.bStatic)
                {
                    throw new Exception("成员函数必须通过实例来调用: " + this.Name + "." + func);
                }
#endif
                CLS_Content.Value value = null;
                if (fun.expr_runtime != null)
                {
                    CLS_Content content = CLS_Content.NewContent(contentParent.environment);
#if UNITY_EDITOR
                    contentParent.InStackContent(content);//把这个上下文推给上层的上下文,这样如果崩溃是可以一层层找到原因的
#endif
                    content.CallType = this;
                    content.CallThis = null;

                    for (int i = 0, count = fun._paramtypes.Count; i < count; i++)
                    {
                        content.DefineAndSet(fun._paramnames[i], fun._paramtypes[i].type, _params[i].value);
                    }

                    value = fun.expr_runtime.ComputeValue(content);
                    if (value != null)
                    {
                        value.breakBlock = 0;
                    }
#if UNITY_EDITOR
                    contentParent.OutStackContent(content);
#endif
                    CLS_Content.PoolContent(content);
                }
                return(value);
            }

            // 委托判断
            CLS_Content.Value smDeleVal;
            if (this.staticMemberValues.TryGetValue(func, out smDeleVal))
            {
                Delegate dele = smDeleVal.value as Delegate;
                if (dele != null)
                {
                    CLS_Content.Value value = new CLS_Content.Value();
                    value.type = null;
                    object[] objs = CLS_Content.ParamObjsArray[_params.size];
                    for (int i = 0; i < _params.size; i++)
                    {
                        objs[i] = _params[i].value;
                    }
                    value.value = dele.DynamicInvoke(objs);
                    if (value.value != null)
                    {
                        value.type = value.value.GetType();
                    }
                    value.breakBlock = 0;
                    return(value);
                }
            }

            throw new NotImplementedException("未实现静态函数: " + this.Name + "." + func);
        }