public CQ_Value ComputeValue(CQ_Content content) { #if CQUARK_DEBUG content.InStack(this); #endif var right = _expressions[0].ComputeValue(content); IType type = CQuark.AppDomain.GetITypeByCQValue(right); CQ_Value value = new CQ_Value(); if (targettype.type != null) { value.SetObject(targettype.type, type.ConvertTo(right.GetObject(), targettype)); } else if (targettype.stype != null) { value.SetObject(targettype.stype, type.ConvertTo(right.GetObject(), targettype)); } #if CQUARK_DEBUG content.OutStack(this); #endif return(value); }
public CQ_Value MemberValueGet(CQ_Content content, object object_this, string valuename) { MemberValueCache c = null; if (!memberValueGetCaches.TryGetValue(valuename, out c)) { c = new MemberValueCache(); memberValueGetCaches[valuename] = c; c.finfo = type.GetField(valuename); if (c.finfo == null) { c.minfo = type.GetMethod("get_" + valuename); if (c.minfo == null) { c.einfo = type.GetEvent(valuename); if (c.einfo == null) { c.type = -1; return(CQ_Value.Null); } else { c.type = 3; } } else { c.type = 2; } } else { c.type = 1; } } if (c.type < 0) { return(CQ_Value.Null); } CQ_Value v = new CQ_Value(); switch (c.type) { case 1: v.SetObject(c.finfo.FieldType, c.finfo.GetValue(object_this)); break; case 2: v.SetObject(c.minfo.ReturnType, c.minfo.Invoke(object_this, null)); break; case 3: v.SetObject(c.einfo.EventHandlerType, new DeleEvent(object_this, c.einfo)); break; } return(v); }
public CQ_Value IndexGet(CQ_Content content, object object_this, object key) { //var m = type.GetMembers(); if (indexGetCache == null) { indexGetCache = type.GetMethod("get_Item"); if (indexGetCache != null) { indexGetCacheType = indexGetCache.ReturnType; } if (indexGetCache == null) { indexGetCache = type.GetMethod("GetValue", new Type[] { typeof(int) }); if (indexGetCache != null) { indexGetCacheType = type.GetElementType(); } } indexGetCachetypeindex = indexGetCache.GetParameters()[0].ParameterType; } //else { CQ_Value v = new CQ_Value(); if (key != null && key.GetType() != indexGetCachetypeindex) { key = CQuark.AppDomain.ConvertTo(key, (CQuark.TypeBridge)indexGetCachetypeindex); } v.SetObject(indexGetCacheType, indexGetCache.Invoke(object_this, new object[] { key })); return(v); } //throw new NotImplementedException(); }
public override Delegate CreateDelegate(DeleFunction delefunc) { DeleFunction _func = delefunc; Delegate _dele = delefunc.cacheFunction(this._type, null); if (_dele != null) { return(_dele); } Action <T> dele = (T param0) => { var func = _func.calltype.functions[_func.function]; if (func.expr_runtime != null) { CQ_Content content = CQ_ObjPool.PopContent(); try { content.CallThis = _func.callthis; content.CallType = _func.calltype; #if CQUARK_DEBUG content.function = _func.function; #endif CQ_Value p0 = new CQ_Value(); p0.SetObject(func._paramtypes[0].typeBridge, param0); content.DefineAndSet(func._paramnames[0], func._paramtypes[0].typeBridge, p0); func.expr_runtime.ComputeValue(content); content.DepthRemove(); } catch (Exception err) { string errinfo = "Dump Call in:"; if (_func.calltype != null) { errinfo += _func.calltype.Name + "::"; } if (_func.function != null) { errinfo += _func.function; } errinfo += "\n"; DebugUtil.Log(errinfo + content.Dump()); throw err; } CQ_ObjPool.PushContent(content); } }; Delegate d = dele as Delegate; if ((Type)this.typeBridge != typeof(Action)) { _dele = Delegate.CreateDelegate(this.typeBridge, d.Target, d.Method); } else { _dele = dele; } return(delefunc.cacheFunction(this._type, _dele)); }
public CQ_Value StaticCallCache(CQ_Content content, CQ_Value[] _params, MethodCache cache) { List <object> _oparams = new List <object>(); foreach (var p in _params) { _oparams.Add(p.GetObject()); } System.Reflection.MethodInfo methodInfo = cache.info; if (cache.needConvert) { var pp = methodInfo.GetParameters(); for (int i = 0; i < pp.Length; i++) { if (i >= _params.Length) { _oparams.Add(pp[i].DefaultValue); } else { if (pp[i].ParameterType != _params[i].m_type) { _oparams[i] = _params[i].ConvertTo(pp[i].ParameterType); } } } } CQ_Value v = new CQ_Value(); v.SetObject(methodInfo.ReturnType, methodInfo.Invoke(null, _oparams.ToArray())); return(v); }
public override Delegate CreateDelegate(DeleLambda lambda) { CQ_Content content = lambda.content.Clone(); var pnames = lambda.paramNames; var expr = lambda.expr_func; Action <T, T1, T2> dele = (T param0, T1 param1, T2 param2) => { if (expr != null) { try { content.DepthAdd(); CQ_Value p0 = new CQ_Value(); p0.SetObject(typeof(T), param0); content.DefineAndSet(pnames[0], typeof(T), p0); CQ_Value p1 = new CQ_Value(); p1.SetObject(typeof(T1), param1); content.DefineAndSet(pnames[1], typeof(T1), p1); CQ_Value p2 = new CQ_Value(); p2.SetObject(typeof(T2), param2); content.DefineAndSet(pnames[2], typeof(T2), p2); expr.ComputeValue(content); content.DepthRemove(); } catch (Exception err) { string errinfo = "Dump Call lambda in:"; if (content.CallType != null) { errinfo += content.CallType.Name + "::"; } #if CQUARK_DEBUG if (content.function != null) { errinfo += content.function; } #endif errinfo += "\n"; DebugUtil.Log(errinfo + content.Dump()); throw err; } } }; Delegate d = dele as Delegate; if ((Type)this.typeBridge != typeof(Action <T, T1, T2>)) { return(Delegate.CreateDelegate(this.typeBridge, d.Target, d.Method)); } else { return(dele); } }
public override Delegate CreateDelegate(DeleFunction delefunc) { DeleFunction _func = delefunc; Delegate _dele = delefunc.cacheFunction(this._type, null); if (_dele != null) { return(_dele); } NonVoidDelegate dele = delegate(T param, T1 param1) { var func = _func.calltype.functions[_func.function]; if (func.expr_runtime != null) { CQ_Content content = CQ_ObjPool.PopContent(); try { content.CallThis = _func.callthis; content.CallType = _func.calltype; #if CQUARK_DEBUG content.function = _func.function; #endif CQ_Value p0 = new CQ_Value(); p0.SetObject(func._paramtypes[0].typeBridge, param); content.DefineAndSet(func._paramnames[0], typeof(T), p0); CQ_Value p1 = new CQ_Value(); p1.SetObject(func._paramtypes[0].typeBridge, param1); content.DefineAndSet(func._paramnames[1], typeof(T1), p1); CQ_Value retValue = func.expr_runtime.ComputeValue(content); content.DepthRemove(); CQ_ObjPool.PushContent(content); return((ReturnType)retValue.GetObject()); } catch (Exception err) { string errinfo = "Dump Call in:"; if (_func.calltype != null) { errinfo += _func.calltype.Name + "::"; } if (_func.function != null) { errinfo += _func.function; } errinfo += "\n"; DebugUtil.Log(errinfo + content.Dump()); throw err; } } return(default(ReturnType)); }; _dele = Delegate.CreateDelegate(this.typeBridge, dele.Target, dele.Method); return(delefunc.cacheFunction(this._type, _dele)); }
public CQ_Value New(CQ_Content content, CQ_Value[] _params) { if (contentMemberCalc == null) { contentMemberCalc = CQ_ObjPool.PopContent(); } NewStatic(); CQ_ClassInstance c = new CQ_ClassInstance(); c.type = this; foreach (KeyValuePair <string, Member> i in this.members) { if (i.Value.bStatic == false) { if (i.Value.expr_defvalue == null) { CQ_Value val = new CQ_Value(); val.SetObject(i.Value.m_itype.typeBridge, i.Value.m_itype.defaultValue); c.member[i.Key] = val; //sv.value_value.member[i.Key] = new CQ_Value(); //sv.value_value.member[i.Key].SetCQType(i.Value.type.cqType); //sv.value_value.member[i.Key].value = i.Value.type.defaultValue; } else { var value = i.Value.expr_defvalue.ComputeValue(contentMemberCalc); if (i.Value.m_itype.typeBridge != value.typeBridge) { CQ_Value val = new CQ_Value(); val.SetObject(i.Value.m_itype.typeBridge, value.ConvertTo(i.Value.m_itype.typeBridge)); c.member[i.Key] = val; //sv.value_value.member[i.Key] = val; //sv.value_value.member[i.Key] = new CQ_Value(); //sv.value_value.member[i.Key].SetCQType(i.Value.type.cqType); //sv.value_value.member[i.Key].value = value.ConvertTo(i.Value.type.cqType); } else { c.member[i.Key] = value; } } } } if (this.functions.ContainsKey(this.Name))//有同名函数就调用 { MemberCall(content, c, this.Name, _params); } CQ_Value v = new CQ_Value(); v.SetObject(this, c); return(v); }
public CQ_Value Math2Value(char code, CQ_Value left, CQ_Value right) { if (code == '+') { CQ_Value returnValue = new CQ_Value(); returnValue.SetObject(typeof(string), left.ToString() + right.ToString()); return(returnValue); } throw new NotImplementedException(); }
public CQ_Value Math2Value(char code, CQ_Value left, CQ_Value right) { if (right.m_type == typeof(string)) { CQ_Value returnValue = new CQ_Value(); returnValue.SetObject(typeof(string), "null" + right.GetObject()); return(returnValue); } throw new NotImplementedException(); }
public CQ_Value GetQuiet(string name) { CQ_Value retV = new CQ_Value(); if (name == "this") { retV.SetObject(CallType, CallThis); return(retV); } if (values != null) { if (values.TryGetValue(name, out retV))//优先上下文变量 { return(retV); } } if (CallType != null) { Class_CQuark.Member retM = Class_CQuark.Member.Null; if (CallType.members.TryGetValue(name, out retM)) { if (retM.bStatic) { return(CallType.staticMemberInstance[name]); } else { return(CallThis.member[name]); } } if (CallType.functions.ContainsKey(name)) { //如果直接得到代理实例, DeleFunction dele = new DeleFunction(CallType, this.CallThis, name); retV.SetObject(typeof(DeleFunction), dele); return(retV); } } return(retV);//null }
public override Delegate CreateDelegate(DeleLambda lambda) { CQ_Content content = lambda.content.Clone(); var pnames = lambda.paramNames; var expr = lambda.expr_func; NonVoidDelegate dele = delegate(T param0, T1 param1) { if (expr != null) { try { content.DepthAdd(); CQ_Value p0 = new CQ_Value(); p0.SetObject(typeof(T), param0); content.DefineAndSet(pnames[0], typeof(T), p0); CQ_Value p1 = new CQ_Value(); p1.SetObject(typeof(T1), param1); content.DefineAndSet(pnames[1], typeof(T1), p1); CQ_Value retValue = expr.ComputeValue(content); content.DepthRemove(); return((ReturnType)retValue.GetObject()); } catch (Exception err) { string errinfo = "Dump Call lambda in:"; if (content.CallType != null) { errinfo += content.CallType.Name + "::"; } #if CQUARK_DEBUG if (content.function != null) { errinfo += content.function; } #endif errinfo += "\n"; DebugUtil.Log(errinfo + content.Dump()); throw err; } } return(default(ReturnType)); }; Delegate d = dele as Delegate; return(Delegate.CreateDelegate(this.typeBridge, d.Target, d.Method)); }
public CQ_Value ComputeValue(CQ_Content content) { #if CQUARK_DEBUG content.InStack(this); #endif int oldDepthCount = content.Record(); try { ICQ_Expression expr = _expressions[0]; if (expr is CQ_Expression_Block) { expr.ComputeValue(content); } else { content.DepthAdd(); expr.ComputeValue(content); content.DepthRemove(); } } catch (Exception err) { bool bParse = false; int i = 1; while (i < _expressions.Count) { CQ_Expression_Define def = _expressions[i] as CQ_Expression_Define; if (err.GetType() == (Type)def.value_type || err.GetType().IsSubclassOf((Type)def.value_type)) { content.DepthAdd(); CQ_Value errVal = new CQ_Value(); errVal.SetObject(def.value_type, err); content.DefineAndSet(def.value_name, def.value_type, errVal); _expressions[i + 1].ComputeValue(content); content.DepthRemove(); bParse = true; break; } i += 2; } if (!bParse) { throw err; } } content.Restore(oldDepthCount, this); //while((bool)expr_continue.value); #if CQUARK_DEBUG content.OutStack(this); #endif return(CQ_Value.Null); }
public CQ_Value New(CQ_Content content, CQ_Value[] _params) { Type[] types = new Type[_params.Length]; object[] objparams = new object[_params.Length]; for (int i = 0; i < _params.Length; i++) { types[i] = _params[i].m_type; objparams[i] = _params[i].GetObject(); } CQ_Value value = new CQ_Value(); ConstructorInfo con = this.type.GetConstructor(types); if (con == null) { value.SetObject(type, Activator.CreateInstance(this.type)); } else { value.SetObject(type, con.Invoke(objparams)); } return(value); }
public CQ_Value ComputeValue(CQ_Content content) { #if CQUARK_DEBUG content.InStack(this); #endif //List<CQ_Content.Value> list = new List<CQ_Content.Value>(); CQ_Value value = new CQ_Value(); DeleLambda dele = new DeleLambda(content, (this._expressions[0] as CQ_Expression_Block)._expressions, this._expressions[1]); value.SetObject(typeof(DeleLambda), dele); #if CQUARK_DEBUG content.OutStack(this); #endif return(value); }
void NewStatic() { if (this.staticMemberInstance == null) { staticMemberInstance = new Dictionary <string, CQ_Value>(); foreach (var i in this.members) { if (i.Value.bStatic == true) { if (i.Value.expr_defvalue == null) { CQ_Value val = new CQ_Value(); val.SetObject(i.Value.m_itype.typeBridge, i.Value.m_itype.defaultValue); staticMemberInstance[i.Key] = val; } else { CQ_Value value = i.Value.expr_defvalue.ComputeValue(contentMemberCalc); if (i.Value.m_itype.typeBridge != value.typeBridge) { CQ_Value val = new CQ_Value(); val.SetObject(i.Value.m_itype.typeBridge, value.ConvertTo(i.Value.m_itype.typeBridge)); staticMemberInstance[i.Key] = val; //staticMemberInstance[i.Key] = new CQ_Value(); //staticMemberInstance[i.Key].SetCQType( i.Value.type.cqType); //staticMemberInstance[i.Key].value = value.ConvertTo(i.Value.type.cqType); } else { staticMemberInstance[i.Key] = value; } } } } } }
public CQ_Value MemberCall(CQ_Content content, object object_this, string function, CQ_Value[] _params, MethodCache cache) { //TODO 这里应该优先匹配类型完全相同(含默认参),没有的话再匹配隐式 bool needConvert = false; List <Type> types = new List <Type>(); List <object> _oparams = new List <object>(); bool pIsEmpty = false; foreach (CQ_Value p in _params) { _oparams.Add(p.GetObject()); if (p.m_stype != null) { types.Add(typeof(object)); } else { if (p.m_type == null) { pIsEmpty = true; } types.Add(p.m_type); } } System.Reflection.MethodInfo methodInfo = null; if (!pIsEmpty) { methodInfo = type.GetMethod(function, types.ToArray()); } CQ_Value v = new CQ_Value(); if (methodInfo == 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] = CQuark.AppDomain.GetTypeByKeyword(sf[i]).typeBridge; } methodInfo = FindMethod(type, tfunc, _params, gtypes); var ps = methodInfo.GetParameters(); for (int i = 0; i < Math.Min(ps.Length, _oparams.Count); i++) { if (ps[i].ParameterType != _params[i].m_type) { _oparams[i] = _params[i].ConvertTo(ps[i].ParameterType); } } } else { if (!pIsEmpty) { foreach (var s in type.GetInterfaces()) { methodInfo = s.GetMethod(function, types.ToArray()); if (methodInfo != null) { break; } } } if (methodInfo == null) //因为有cache的存在,可以更慢更多的查找啦,哈哈哈哈 { methodInfo = GetMethodSlow(content, false, function, types, _oparams); needConvert = true; } if (methodInfo == null) { throw new Exception("函数不存在function:" + type.ToString() + "." + function); } } } if (cache != null) { cache.info = methodInfo; cache.needConvert = needConvert; } if (methodInfo == null) { throw new Exception("函数不存在function:" + type.ToString() + "." + function); } v.SetObject(methodInfo.ReturnType, methodInfo.Invoke(object_this, _oparams.ToArray())); return(v); }
public CQ_Value StaticCall(CQ_Content content, string function, CQ_Value[] _params, MethodCache cache) { //TODO 这里应该优先匹配类型完全相同(含默认参),没有的话再匹配隐式 bool needConvert = false; List <object> _oparams = new List <object>(); List <Type> types = new List <Type>(); bool pIsEmpty = false; foreach (CQ_Value p in _params) { _oparams.Add(p.GetObject()); if (p.m_stype != null) { types.Add(typeof(object)); } else { if (p.m_type == null) { pIsEmpty = true; } types.Add(p.m_type); } } System.Reflection.MethodInfo methodInfo = null; if (!pIsEmpty) { methodInfo = type.GetMethod(function, types.ToArray()); } //if (methodInfo == null && type.BaseType != null)//加上父类型静态函数查找,典型的现象是 GameObject.Destory //{ // methodInfo = type.BaseType.GetMethod(function, types.ToArray()); //} if (methodInfo == 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] = CQuark.AppDomain.GetTypeByKeyword(sf[i]).typeBridge; } methodInfo = FindMethod(type, tfunc, _params, gtypes); } if (methodInfo == null) { Type ptype = type.BaseType; while (ptype != null) { methodInfo = ptype.GetMethod(function, types.ToArray()); if (methodInfo != null) { break; } var t = CQuark.AppDomain.GetITypeByType(ptype); try { return(t._class.StaticCall(content, function, _params, cache)); } catch { } ptype = ptype.BaseType; } } } if (methodInfo == null) { methodInfo = GetMethodSlow(content, true, function, types, _oparams); needConvert = true; } if (methodInfo == null) { throw new Exception("函数不存在function:" + type.ToString() + "." + function); } if (cache != null) { cache.info = methodInfo; cache.needConvert = needConvert; } CQ_Value v = new CQ_Value(); v.SetObject(methodInfo.ReturnType, methodInfo.Invoke(null, _oparams.ToArray())); return(v); }
public CQ_Value ComputeValue(CQ_Content content) { #if CQUARK_DEBUG content.InStack(this); #endif content.DepthAdd(); CQ_Expression_Define define = _expressions[0] as CQ_Expression_Define; define.ComputeValue(content); System.Collections.IEnumerable emu = _expressions[1].ComputeValue(content).GetObject() as System.Collections.IEnumerable; ICQ_Expression expr_block = _expressions[2] as ICQ_Expression; var it = emu.GetEnumerator(); CQ_Value vrt = CQ_Value.Null; while (it.MoveNext()) { //content.Set(define.value_name, it.Current); CQ_Value val = new CQ_Value(); val.SetObject(define.value_type, it.Current); content.Set(define.value_name, val); if (expr_block != null) { if (expr_block is CQ_Expression_Block) { CQ_Value v = expr_block.ComputeValue(content); if (v.m_breakBlock == BreakType.Return) { vrt = v; } if (v.m_breakBlock == BreakType.Return || v.m_breakBlock == BreakType.Break) { break; } } else { content.DepthAdd(); bool bbreak = false; CQ_Value v = expr_block.ComputeValue(content); if (v.m_breakBlock == BreakType.Return) { vrt = v; } if (v.m_breakBlock == BreakType.Break || v.m_breakBlock == BreakType.Return) { bbreak = true; } content.DepthRemove(); if (bbreak) { break; } } } } content.DepthRemove(); #if CQUARK_DEBUG content.OutStack(this); #endif return(vrt); }
public virtual CQ_Value Math2Value(char code, CQ_Value left, CQ_Value right) { //会走到这里说明不是简单的数学计算了 Type rightType = right.m_type; if (rightType == typeof(string) && code == '+') { CQ_Value returnValue = new CQ_Value(); returnValue.SetObject(typeof(string), left.ToString() + right.ToString()); return(returnValue); } else { CQ_Value returnValue = CQ_Value.Null; MethodInfo call = null; //我们这里开始使用Wrap,如果再不行再走反射 if (code == '+') { if (Wrap.OpAddition(left, right, out returnValue)) { return(returnValue); } else { call = _type.GetMethod("op_Addition", new Type[] { this.typeBridge, rightType }); } } else if (code == '-') { if (Wrap.OpSubtraction(left, right, out returnValue)) { return(returnValue); } else { call = _type.GetMethod("op_Subtraction", new Type[] { this.typeBridge, rightType }); } } else if (code == '*') { if (Wrap.OpMultiply(left, right, out returnValue)) { return(returnValue); } else { call = _type.GetMethod("op_Multiply", new Type[] { this.typeBridge, rightType }); } } else if (code == '/') { if (Wrap.OpDivision(left, right, out returnValue)) { return(returnValue); } else { call = _type.GetMethod("op_Division", new Type[] { this.typeBridge, rightType }); } } else if (code == '%') { if (Wrap.OpModulus(left, right, out returnValue)) { return(returnValue); } else { call = _type.GetMethod("op_Modulus", new Type[] { this.typeBridge, rightType }); } } //Wrap没走到,走反射 returnValue = new CQ_Value(); returnValue.SetObject(typeBridge.type, call.Invoke(null, new object[] { left.GetObject(), right.GetObject() })); //function.StaticCall(env,"op_Addtion",new List<ICL>{}) return(returnValue); } }
public CQ_Value MemberCall(CQ_Content contentParent, object object_this, string func, CQ_Value[] _params, MethodCache cache) { if (cache != null) { cache.cachefail = true; } Function funccache = null; if (this.functions.TryGetValue(func, out funccache)) { if (funccache.bStatic == false) { CQ_Content content = CQ_ObjPool.PopContent(); content.CallType = this; content.CallThis = object_this as CQ_ClassInstance; #if CQUARK_DEBUG content.function = func; contentParent.InStack(content);//把这个上下文推给上层的上下文,这样如果崩溃是可以一层层找到原因的 #endif for (int i = 0; i < funccache._paramtypes.Count; i++) { //content.DefineAndSet(funccache._paramnames[i], funccache._paramtypes[i].typeBridge, _params[i].GetValue()); content.DefineAndSet(funccache._paramnames[i], _params[i].typeBridge, _params[i]); } //如果返回值是IEnumerator的话,这里把方法返回出来 if (funccache._returntype != null && funccache._returntype.typeBridge.type == typeof(IEnumerator)) { CQ_Value ienumerator = new CQ_Value(); CQ_Expression_Block funcCQ = funccache.expr_runtime as CQ_Expression_Block; funcCQ.callObj = content; ienumerator.SetObject(typeof(CQ_Expression_Block), funcCQ); return(ienumerator); } CQ_Value value = CQ_Value.Null; var funcobj = funccache; if (this.bInterface) { content.CallType = (object_this as CQ_ClassInstance).type; funcobj = (object_this as CQ_ClassInstance).type.functions[func]; } if (funcobj.expr_runtime != null) { value = funcobj.expr_runtime.ComputeValue(content); } #if CQUARK_DEBUG contentParent.OutStack(content); #endif CQ_ObjPool.PushContent(content); return(value); } } else if (this.members.ContainsKey(func)) { if (this.members[func].bStatic == false) { Delegate dele = (object_this as CQ_ClassInstance).member[func].GetObject() as Delegate; if (dele != null) { CQ_Value value = new CQ_Value(); object[] objs = new object[_params.Length]; for (int i = 0; i < _params.Length; i++) { objs[i] = _params[i].GetObject(); } object obj = dele.DynamicInvoke(objs); if (obj == null) { return(CQ_Value.Null); } else { value.SetObject(obj.GetType(), obj); return(value); } } } } throw new NotImplementedException(); }
public CQ_Value StaticCall(CQ_Content contentParent, string function, CQ_Value[] _params, MethodCache cache) { if (cache != null) { cache.cachefail = true; } NewStatic(); if (this.functions.ContainsKey(function)) { if (this.functions[function].bStatic == true) { CQ_Content content = CQ_ObjPool.PopContent(); content.CallType = this; content.CallThis = null; #if CQUARK_DEBUG content.function = function; contentParent.InStack(content);//把这个上下文推给上层的上下文,这样如果崩溃是可以一层层找到原因的 #endif // int i = 0; for (int i = 0; i < functions[function]._paramtypes.Count; i++) { //content.DefineAndSet(functions[function]._paramnames[i], functions[function]._paramtypes[i].typeBridge, _params[i].GetValue()); content.DefineAndSet(functions[function]._paramnames[i], _params[i].typeBridge, _params[i]); } CQ_Value value = CQ_Value.Null; if (this.functions[function].expr_runtime != null) { value = this.functions[function].expr_runtime.ComputeValue(content); } #if CQUARK_DEBUG contentParent.OutStack(content); #endif CQ_ObjPool.PushContent(content); return(value); } } else if (this.members.ContainsKey(function)) { if (this.members[function].bStatic == true) { Delegate dele = this.staticMemberInstance[function].GetObject() as Delegate; if (dele != null) { CQ_Value value = new CQ_Value(); object[] objs = new object[_params.Length]; for (int i = 0; i < _params.Length; i++) { objs[i] = _params[i].GetObject(); } object obj = dele.DynamicInvoke(objs); if (obj == null) { return(CQ_Value.Null); } else { value.SetObject(obj.GetType(), obj); return(value); } //value.breakBlock = BreakType.None; } } } throw new NotImplementedException(); }
public CQ_Value ComputeValue(CQ_Content content) { #if CQUARK_DEBUG content.InStack(this); #endif CQ_Value[] parameters = CQ_ObjPool.PopArray(_expressions.Count); for (int i = 0; i < _expressions.Count; i++) { parameters[i] = _expressions[i].ComputeValue(content); } CQ_Value v = CQ_Value.Null; Class_CQuark.Function retFunc = null; bool bFind = false; if (content.CallType != null) { bFind = content.CallType.functions.TryGetValue(funcname, out retFunc); } if (bFind) { if (retFunc.bStatic) { v = content.CallType.StaticCall(content, funcname, parameters); } else { v = content.CallType.MemberCall(content, content.CallThis, funcname, parameters); } } else { v = content.GetQuiet(funcname); if (v.IsDelegate) { Delegate d = v.GetObject() as Delegate; v = new CQ_Value(); object[] obja = new object[parameters.Length]; for (int i = 0; i < parameters.Length; i++) { obja[i] = parameters[i].GetObject(); } object obj = d.DynamicInvoke(obja); if (obj == null) { v.SetNoneTypeObject(null); } else { v.SetObject(obj.GetType(), obj); } } else { throw new Exception(funcname + "没有这样的方法"); //v = CQuark.AppDomain.GetMethod(funcname).Call(content, list); } } //操作变量之 //做数学计算 //从上下文取值 //_value = null; #if CQUARK_DEBUG content.OutStack(this); #endif CQ_ObjPool.PushArray(parameters); return(v); }
public CQ_Value ComputeValue(CQ_Content content) { #if CQUARK_DEBUG content.InStack(this); #endif CQ_Value parent = _expressions[0].ComputeValue(content); #if CQUARK_DEBUG if (parent == CQ_Value.Null) { throw new Exception("调用空对象的方法:" + _expressions[0].ToString() + ":" + ToString()); } #endif CQ_Value[] parameters = CQ_ObjPool.PopArray(_expressions.Count - 1); for (int i = 0; i < _expressions.Count - 1; i++) { parameters[i] = _expressions[i + 1].ComputeValue(content); } CQ_Value value = CQ_Value.Null; //这几行是为了快速获取Unity的静态变量,而不需要反射 object obj = parent.GetObject(); if (!Wrap.MemberCall(parent.m_type, obj, functionName, parameters, out value)) { //TODO 要么注册所有基本类型(bool,int,string...)要么这里特殊处理 if (functionName == "ToString" && parameters.Length == 0) { CQ_Value ret = new CQ_Value(); ret.SetObject(typeof(string), obj.ToString()); return(ret); } else if (obj is UnityEngine.MonoBehaviour && functionName == "StartCoroutine" && parameters.Length >= 1 && parameters[0].GetObject() is CQ_Expression_Block) { //从西瓜调用的ClassSystem.StartCoroutine(CquarkMethod());不需要走cache UnityEngine.MonoBehaviour mb = obj as UnityEngine.MonoBehaviour; CQ_Expression_Block call = parameters[0].GetObject() as CQ_Expression_Block; CQ_Value ret = new CQ_Value(); ret.SetObject(typeof(UnityEngine.Coroutine), mb.StartCoroutine(call.callObj.CallType.CoroutineCall(call, call.callObj, mb))); return(ret); } else { var iclass = CQuark.AppDomain.GetITypeByCQValue(parent)._class; if (cache == null || cache.cachefail) { cache = new MethodCache(); value = iclass.MemberCall(content, obj, functionName, parameters, cache); } else { value = iclass.MemberCallCache(content, obj, parameters, cache); } } } #if CQUARK_DEBUG content.OutStack(this); #endif CQ_ObjPool.PushArray(parameters); return(value); }