public CLS_Content.Value ComputeValue(CLS_Content content) { content.InStack(this); //var parent = listParam[0].ComputeValue(content); //var type = content.environment.GetType(parent.type); List <CLS_Content.Value> _params = new List <CLS_Content.Value>(); for (int i = 0; i < listParam.Count; i++) { _params.Add(listParam[i].ComputeValue(content)); } CLS_Content.Value value = null; if (cache == null || cache.cachefail) { cache = new MethodCache(); value = type.function.StaticCall(content, functionName, _params, cache); } else { value = type.function.StaticCallCache(content, _params, cache); } content.OutStack(this); return(value); //做数学计算 //从上下文取值 //_value = null; //return null; }
public CLS_Content.Value ComputeValue(CLS_Content content) { content.InStack(this); //var parent = listParam[0].ComputeValue(content); //var type = content.environment.GetType(parent.type); List<CLS_Content.Value> _params = new List<CLS_Content.Value>(); for (int i = 0; i < listParam.Count; i++) { _params.Add(listParam[i].ComputeValue(content)); } CLS_Content.Value value = null; if (cache == null || cache.cachefail) { cache = new MethodCache(); value = type.function.StaticCall(content, functionName, _params, cache); } else { value = type.function.StaticCallCache(content, _params, cache); } content.OutStack(this); return value; //做数学计算 //从上下文取值 //_value = null; //return null; }
public CLS_Content.Value ComputeValue(CLS_Content content) { content.InStack(this); var parent = listParam[0].ComputeValue(content); var typefunction = content.environment.GetType(parent.type).function; if(parent.type is object) { SInstance s = parent.value as SInstance; if(s!=null) { typefunction = s.type; } } List<CLS_Content.Value> _params = new List<CLS_Content.Value>(); for (int i = 1; i < listParam.Count; i++) { _params.Add(listParam[i].ComputeValue(content)); } CLS_Content.Value value = null; if (cache == null||cache.cachefail) { cache = new MethodCache(); value = typefunction.MemberCall(content, parent.value, functionName, _params,cache); } else { value = typefunction.MemberCallCache(content, parent.value, _params, cache); } content.OutStack(this); return value; //做数学计算 //从上下文取值 //_value = null; //return null; }
public CLS_Content.Value ComputeValue(CLS_Content content) { content.InStack(this); var parent = listParam[0].ComputeValue(content); if (parent == null) { throw new Exception("调用空对象的方法:" + listParam[0].ToString() + ":" + ToString()); } var typefunction = content.environment.GetType(parent.type).function; if (parent.type is object) { SInstance s = parent.value as SInstance; if (s != null) { typefunction = s.type; } } List <CLS_Content.Value> _params = new List <CLS_Content.Value>(); for (int i = 1; i < listParam.Count; i++) { _params.Add(listParam[i].ComputeValue(content)); } CLS_Content.Value value = null; if (cache == null || cache.cachefail) { cache = new MethodCache(); value = typefunction.MemberCall(content, parent.value, functionName, _params, cache); } else { value = typefunction.MemberCallCache(content, parent.value, _params, cache); } content.OutStack(this); return(value); //做数学计算 //从上下文取值 //_value = null; //return null; }
public CLS_Content.Value StaticCallCache(CLS_Content environment, IList<CLS_Content.Value> _params, MethodCache cache) { throw new NotImplementedException(); }
public CLS_Content.Value MemberCall(CLS_Content contentParent, object object_this, string func, IList<CLS_Content.Value> _params,MethodCache cache=null) { if (cache != null) { cache.cachefail = true; } if (this.functions.ContainsKey(func)) { if (this.functions[func].bStatic == false) { CLS_Content content = new CLS_Content(contentParent.environment, true); contentParent.InStack(content);//把这个上下文推给上层的上下文,这样如果崩溃是可以一层层找到原因的 content.CallType = this; content.CallThis = object_this as SInstance; content.function = func; for (int i = 0; i < this.functions[func]._paramtypes.Count; i++) //int i = 0; //foreach (var p in this.functions[func]._params) { content.DefineAndSet(this.functions[func]._paramnames[i], this.functions[func]._paramtypes[i].type, _params[i].value); //i++; } CLS_Content.Value value = null; var funcobj = this.functions[func]; if (this.bInterface) { content.CallType = (object_this as SInstance).type; funcobj = (object_this as SInstance).type.functions[func]; } if (funcobj.expr_runtime != null) { value = funcobj.expr_runtime.ComputeValue(content); if (value != null) value.breakBlock = 0; } contentParent.OutStack(content); return value; } } else if (this.members.ContainsKey(func)) { if (this.members[func].bStatic == false) { Delegate dele = (object_this as SInstance).member[func].value as Delegate; if (dele != null) { CLS_Content.Value value = new CLS_Content.Value(); value.type = null; object[] objs = new object[_params.Count]; for (int i = 0; i < _params.Count; 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(); }
public CLS_Content.Value StaticCall(CLS_Content contentParent, string function, IList<CLS_Content.Value> _params, MethodCache cache = null) { if(cache!=null) { cache.cachefail = true; } NewStatic(contentParent.environment); if (this.functions.ContainsKey(function)) { if (this.functions[function].bStatic == true) { CLS_Content content = new CLS_Content(contentParent.environment, true); contentParent.InStack(content);//把这个上下文推给上层的上下文,这样如果崩溃是可以一层层找到原因的 content.CallType = this; content.CallThis = null; content.function = function; // int i = 0; for (int i = 0; i < functions[function]._paramtypes.Count; i++) //foreach (var p in this.functions[function]._params) { content.DefineAndSet(functions[function]._paramnames[i], functions[function]._paramtypes[i].type, _params[i].value); //i++; } //var value = this.functions[function].expr_runtime.ComputeValue(content); CLS_Content.Value value = null; if (this.functions[function].expr_runtime != null) { value = this.functions[function].expr_runtime.ComputeValue(content); if(value!=null) value.breakBlock = 0; } else { } contentParent.OutStack(content); return value; } } else if (this.members.ContainsKey(function)) { if (this.members[function].bStatic == true) { Delegate dele = this.staticMemberInstance[function].value as Delegate; if (dele != null) { CLS_Content.Value value = new CLS_Content.Value(); value.type = null; object[] objs = new object[_params.Count]; for (int i = 0; i < _params.Count; 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(); }
public virtual CLS_Content.Value MemberCallCache(CLS_Content content, object object_this, IList<CLS_Content.Value> _params, MethodCache cache) { List<Type> types = new List<Type>(); List<object> _oparams = new List<object>(); foreach (var p in _params) { { _oparams.Add(p.value); } if ((SType)p.type != null) { types.Add(typeof(object)); } else { types.Add(p.type); } } var targetop = cache.info; CLS_Content.Value v = new CLS_Content.Value(); if (cache.slow) { var pp = targetop.GetParameters(); for (int i = 0; i < pp.Length; i++) { if (i >= _params.Count) { _oparams.Add(pp[i].DefaultValue); } else { if (pp[i].ParameterType != (Type)_params[i].type) { _oparams[i] = content.environment.GetType(_params[i].type).ConvertTo(content, _oparams[i], pp[i].ParameterType); } } } } v.value = targetop.Invoke(object_this, _oparams.ToArray()); v.type = targetop.ReturnType; return v; }
public virtual CLS_Content.Value StaticCall(CLS_Content environment, string function, IList<CLS_Content.Value> _params, MethodCache cache = null) { bool needConvert = false; List<object> _oparams = new List<object>(); List<Type> types = new List<Type>(); bool bEm = false; foreach (var p in _params) { _oparams.Add(p.value); if ((SType)p.type != null) { types.Add(typeof(object)); } else { if (p.type == null) { bEm = true; } types.Add(p.type); } } System.Reflection.MethodInfo targetop = null; if (!bEm) targetop = type.GetMethod(function, types.ToArray()); //if (targetop == null && type.BaseType != null)//加上父类型静态函数查找,典型的现象是 GameObject.Destory //{ // targetop = type.BaseType.GetMethod(function, types.ToArray()); //} if (targetop == null) { if (function[function.Length - 1] == '>')//这是一个临时的模板函数调用 { int sppos = function.IndexOf('<', 0); string tfunc = function.Substring(0, sppos); string strparam = function.Substring(sppos + 1, function.Length - sppos - 2); string[] sf = strparam.Split(','); //string tfunc = sf[0]; Type[] gtypes = new Type[sf.Length]; for (int i = 0; i < sf.Length; i++) { gtypes[i] = environment.environment.GetTypeByKeyword(sf[i]).type; } targetop = FindTMethod(type, tfunc, _params, gtypes); } if (targetop == null) { Type ptype = type.BaseType; while (ptype != null) { targetop = ptype.GetMethod(function, types.ToArray()); if (targetop != null) break; var t = environment.environment.GetType(ptype); try { return t.function.StaticCall(environment, function, _params, cache); } catch { } ptype = ptype.BaseType; } } } if (targetop == null) {//因为有cache的存在,可以更慢更多的查找啦,哈哈哈哈 targetop = GetMethodSlow(environment, true, function, types, _oparams); needConvert = true; } if (targetop == null) { throw new Exception("函数不存在function:" + type.ToString() + "." + function); } if (cache != null) { cache.info = targetop; cache.slow = needConvert; } CLS_Content.Value v = new CLS_Content.Value(); v.value = targetop.Invoke(null, _oparams.ToArray()); v.type = targetop.ReturnType; return v; }
public virtual CLS_Content.Value MemberCall(CLS_Content environment, object object_this, string function, IList<CLS_Content.Value> _params, MethodCache cache = null) { bool needConvert = false; List<Type> types = new List<Type>(); List<object> _oparams = new List<object>(); bool bEm = false; foreach (var p in _params) { { _oparams.Add(p.value); } if ((SType)p.type != null) { types.Add(typeof(object)); } else { if (p.type == null) { bEm = true; } types.Add(p.type); } } System.Reflection.MethodInfo targetop = null; if (!bEm) { targetop = type.GetMethod(function, types.ToArray()); } CLS_Content.Value v = new CLS_Content.Value(); if (targetop == null) { if (function[function.Length - 1] == '>')//这是一个临时的模板函数调用 { int sppos = function.IndexOf('<', 0); string tfunc = function.Substring(0, sppos); string strparam = function.Substring(sppos + 1, function.Length - sppos - 2); string[] sf = strparam.Split(','); //string tfunc = sf[0]; Type[] gtypes = new Type[sf.Length]; for (int i = 0; i < sf.Length; i++) { gtypes[i] = environment.environment.GetTypeByKeyword(sf[i]).type; } targetop = FindTMethod(type, tfunc, _params, gtypes); } else { if (!bEm) { foreach (var s in type.GetInterfaces()) { targetop = s.GetMethod(function, types.ToArray()); if (targetop != null) break; } } if (targetop == null) {//因为有cache的存在,可以更慢更多的查找啦,哈哈哈哈 targetop = GetMethodSlow(environment, false, function, types, _oparams); needConvert = true; } if (targetop == null) { throw new Exception("函数不存在function:" + type.ToString() + "." + function); } } } if (cache != null) { cache.info = targetop; cache.slow = needConvert; } if (targetop == null) { throw new Exception("函数不存在function:" + type.ToString() + "." + function); } v.value = targetop.Invoke(object_this, _oparams.ToArray()); v.type = targetop.ReturnType; return v; }
public CLS_Content.Value StaticCallCache(CLS_Content environment, IList <CLS_Content.Value> _params, MethodCache cache) { throw new NotImplementedException(); }
public CLS_Content.Value MemberCall(CLS_Content contentParent, object object_this, string func, IList <CLS_Content.Value> _params, MethodCache cache = null) { if (cache != null) { cache.cachefail = true; } if (this.functions.ContainsKey(func)) { if (this.functions[func].bStatic == false) { CLS_Content content = new CLS_Content(contentParent.environment, true); contentParent.InStack(content);//把这个上下文推给上层的上下文,这样如果崩溃是可以一层层找到原因的 content.CallType = this; content.CallThis = object_this as SInstance; content.function = func; for (int i = 0; i < this.functions[func]._paramtypes.Count; i++) //int i = 0; //foreach (var p in this.functions[func]._params) { content.DefineAndSet(this.functions[func]._paramnames[i], this.functions[func]._paramtypes[i].type, _params[i].value); //i++; } CLS_Content.Value value = null; var funcobj = this.functions[func]; if (this.bInterface) { content.CallType = (object_this as SInstance).type; funcobj = (object_this as SInstance).type.functions[func]; } if (funcobj.expr_runtime != null) { value = funcobj.expr_runtime.ComputeValue(content); if (value != null) { value.breakBlock = 0; } } contentParent.OutStack(content); return(value); } } else if (this.members.ContainsKey(func)) { if (this.members[func].bStatic == false) { Delegate dele = (object_this as SInstance).member[func].value as Delegate; if (dele != null) { CLS_Content.Value value = new CLS_Content.Value(); value.type = null; object[] objs = new object[_params.Count]; for (int i = 0; i < _params.Count; 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(); }
public CLS_Content.Value StaticCall(CLS_Content contentParent, string function, IList <CLS_Content.Value> _params, MethodCache cache = null) { if (cache != null) { cache.cachefail = true; } NewStatic(contentParent.environment); if (this.functions.ContainsKey(function)) { if (this.functions[function].bStatic == true) { CLS_Content content = new CLS_Content(contentParent.environment, true); contentParent.InStack(content);//把这个上下文推给上层的上下文,这样如果崩溃是可以一层层找到原因的 content.CallType = this; content.CallThis = null; content.function = function; // int i = 0; for (int i = 0; i < functions[function]._paramtypes.Count; i++) //foreach (var p in this.functions[function]._params) { content.DefineAndSet(functions[function]._paramnames[i], functions[function]._paramtypes[i].type, _params[i].value); //i++; } //var value = this.functions[function].expr_runtime.ComputeValue(content); CLS_Content.Value value = null; if (this.functions[function].expr_runtime != null) { value = this.functions[function].expr_runtime.ComputeValue(content); if (value != null) { value.breakBlock = 0; } } else { } contentParent.OutStack(content); return(value); } } else if (this.members.ContainsKey(function)) { if (this.members[function].bStatic == true) { Delegate dele = this.staticMemberInstance[function].value as Delegate; if (dele != null) { CLS_Content.Value value = new CLS_Content.Value(); value.type = null; object[] objs = new object[_params.Count]; for (int i = 0; i < _params.Count; 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(); }
public virtual CLS_Content.Value MemberCallCache(CLS_Content content, object object_this, IList <CLS_Content.Value> _params, MethodCache cache) { List <Type> types = new List <Type>(); List <object> _oparams = new List <object>(); foreach (var p in _params) { { _oparams.Add(p.value); } if ((SType)p.type != null) { types.Add(typeof(object)); } else { types.Add(p.type); } } var targetop = cache.info; CLS_Content.Value v = new CLS_Content.Value(); if (cache.slow) { var pp = targetop.GetParameters(); for (int i = 0; i < pp.Length; i++) { if (i >= _params.Count) { _oparams.Add(pp[i].DefaultValue); } else { if (pp[i].ParameterType != (Type)_params[i].type) { _oparams[i] = content.environment.GetType(_params[i].type).ConvertTo(content, _oparams[i], pp[i].ParameterType); } } } } v.value = targetop.Invoke(object_this, _oparams.ToArray()); v.type = targetop.ReturnType; return(v); }
public virtual CLS_Content.Value StaticCall(CLS_Content environment, string function, IList <CLS_Content.Value> _params, MethodCache cache = null) { bool needConvert = false; List <object> _oparams = new List <object>(); List <Type> types = new List <Type>(); bool bEm = false; foreach (var p in _params) { _oparams.Add(p.value); if ((SType)p.type != null) { types.Add(typeof(object)); } else { if (p.type == null) { bEm = true; } types.Add(p.type); } } System.Reflection.MethodInfo targetop = null; if (!bEm) { targetop = type.GetMethod(function, types.ToArray()); } //if (targetop == null && type.BaseType != null)//加上父类型静态函数查找,典型的现象是 GameObject.Destory //{ // targetop = type.BaseType.GetMethod(function, types.ToArray()); //} if (targetop == null) { if (function[function.Length - 1] == '>')//这是一个临时的模板函数调用 { int sppos = function.IndexOf('<', 0); string tfunc = function.Substring(0, sppos); string strparam = function.Substring(sppos + 1, function.Length - sppos - 2); string[] sf = strparam.Split(','); //string tfunc = sf[0]; Type[] gtypes = new Type[sf.Length]; for (int i = 0; i < sf.Length; i++) { gtypes[i] = environment.environment.GetTypeByKeyword(sf[i]).type; } targetop = FindTMethod(type, tfunc, _params, gtypes); } if (targetop == null) { Type ptype = type.BaseType; while (ptype != null) { targetop = ptype.GetMethod(function, types.ToArray()); if (targetop != null) { break; } var t = environment.environment.GetType(ptype); try { return(t.function.StaticCall(environment, function, _params, cache)); } catch { } ptype = ptype.BaseType; } } } if (targetop == null) {//因为有cache的存在,可以更慢更多的查找啦,哈哈哈哈 targetop = GetMethodSlow(environment, true, function, types, _oparams); needConvert = true; } if (targetop == null) { throw new Exception("函数不存在function:" + type.ToString() + "." + function); } if (cache != null) { cache.info = targetop; cache.slow = needConvert; } CLS_Content.Value v = new CLS_Content.Value(); v.value = targetop.Invoke(null, _oparams.ToArray()); v.type = targetop.ReturnType; return(v); }
public CLS_Content.Value MemberCallCache(CLS_Content environment, object object_this, IList<CLS_Content.Value> _params, MethodCache cache) { throw new NotImplementedException(); }
public CLS_Content.Value MemberCallCache(CLS_Content environment, object object_this, IList <CLS_Content.Value> _params, MethodCache cache) { throw new NotImplementedException(); }
public virtual CLS_Content.Value MemberCall(CLS_Content environment, object object_this, string function, IList <CLS_Content.Value> _params, MethodCache cache) { bool needConvert = false; List <Type> types = new List <Type>(); List <object> _oparams = new List <object>(); bool bEm = false; foreach (CLS_Content.Value p in _params) { { _oparams.Add(p.value); } if ((SType)p.type != null) { types.Add(typeof(object)); } else { if (p.type == null) { bEm = true; } types.Add(p.type); } } System.Reflection.MethodInfo targetop = null; if (!bEm) { targetop = type.GetMethod(function, types.ToArray()); } CLS_Content.Value v = new CLS_Content.Value(); if (targetop == null) { if (function[function.Length - 1] == '>')//这是一个临时的模板函数调用 { int sppos = function.IndexOf('<', 0); string tfunc = function.Substring(0, sppos); string strparam = function.Substring(sppos + 1, function.Length - sppos - 2); string[] sf = strparam.Split(','); //string tfunc = sf[0]; Type[] gtypes = new Type[sf.Length]; for (int i = 0; i < sf.Length; i++) { gtypes[i] = environment.environment.GetTypeByKeyword(sf[i]).type; } targetop = FindTMethod(type, tfunc, _params, gtypes); var ps = targetop.GetParameters(); for (int i = 0; i < Math.Min(ps.Length, _oparams.Count); i++) { if (ps[i].ParameterType != (Type)_params[i].type) { _oparams[i] = environment.environment.GetType(_params[i].type).ConvertTo(environment, _oparams[i], ps[i].ParameterType); } } } else { if (!bEm) { foreach (var s in type.GetInterfaces()) { targetop = s.GetMethod(function, types.ToArray()); if (targetop != null) { break; } } } if (targetop == null) {//因为有cache的存在,可以更慢更多的查找啦,哈哈哈哈 targetop = GetMethodSlow(environment, false, function, types, _oparams); needConvert = true; } if (targetop == null) { throw new Exception("函数不存在function:" + type.ToString() + "." + function); } } } if (cache != null) { cache.info = targetop; cache.slow = needConvert; } if (targetop == null) { throw new Exception("函数不存在function:" + type.ToString() + "." + function); } v.value = targetop.Invoke(object_this, _oparams.ToArray()); v.type = targetop.ReturnType; return(v); }