public bool MathLogic(LogicToken code, CQ_Value left, CQ_Value right) { if (code == LogicToken.equal)//[6] = {Boolean op_Equality(CQcriptExt.Vector3, CQcriptExt.Vector3)} { if (left.GetObject() == null || right.TypeIsEmpty) { return(left.GetObject() == right.GetObject()); } else { return(left.GetObject() == right.GetObject()); } } else if (code == LogicToken.not_equal)//[7] = {Boolean op_Inequality(CQcriptExt.Vector3, CQcriptExt.Vector3)} { if (left.GetObject() == null || right.TypeIsEmpty) { return(left.GetObject() != right.GetObject()); } else { return(left.GetObject() != right.GetObject()); } } throw new NotImplementedException(); }
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 CQ_Value ComputeValue(CQ_Content content) { #if CQUARK_DEBUG content.InStack(this); #endif if (__expressions != null && __expressions.Count > 0) { CQ_Value v = __expressions[0].ComputeValue(content); object val = v.value; if ((Type)value_type == typeof(Type_Var.var)) { if (v.type != null) { value_type = v.type; } } else if (v.type != value_type) { val = v.ConvertTo(value_type); } content.DefineAndSet(value_name, value_type, val); } else { content.Define(value_name, value_type); } #if CQUARK_DEBUG content.OutStack(this); #endif return(null); }
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 CQ_Value ComputeValue(CQ_Content content) { #if CQUARK_DEBUG content.InStack(this); #endif CQ_Value v = _expressions[0].ComputeValue(content); CQ_Value oldVal = CQ_Value.Null; if (content.values != null && content.values.ContainsKey(value_name)) { oldVal = content.values[value_name]; } else if (content.CallType != null && content.CallType.members.ContainsKey(value_name)) { if (content.CallType.members[value_name].bStatic) { oldVal = content.CallType.staticMemberInstance[value_name]; } else { oldVal = content.CallThis.member[value_name]; } } oldVal.UsingValue(v); content.Set(value_name, oldVal); #if CQUARK_DEBUG content.OutStack(this); #endif return(CQ_Value.Null); }
public CQ_Value ComputeValue(CQ_Content content) { #if CQUARK_DEBUG content.InStack(this); #endif if (__expressions != null && __expressions.Count > 0) { CQ_Value v = __expressions[0].ComputeValue(content); //object val = v.GetValue(); //if((Type)value_type == typeof(Type_Var.var)) { // if(!v.TypeIsEmpty) // value_type = v.typeBridge; //} //else if(v.typeBridge != value_type) { // val = v.ConvertTo(value_type); //} content.DefineAndSet(value_name, value_type, v); } else { content.Define(value_name, value_type); } #if CQUARK_DEBUG content.OutStack(this); #endif return(CQ_Value.Null); }
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 value = CQ_Value.Null; //这几行是为了快速获取Unity的静态变量,而不需要反射 if (!Wrap.StaticCall(type.typeBridge.type, functionName, parameters, out value)) { if (cache == null || cache.cachefail) { cache = new MethodCache(); value = type._class.StaticCall(content, functionName, parameters, cache); } else { value = type._class.StaticCallCache(content, parameters, cache); } } #if CQUARK_DEBUG content.OutStack(this); #endif CQ_ObjPool.PushArray(parameters); return(value); }
public CQ_Value ComputeValue(CQ_Content content) { #if CQUARK_DEBUG content.InStack(this); #endif CQ_Value getvalue = CQ_Value.Null; //这几行是为了快速获取Unity的静态变量,而不需要反射 if (!Wrap.StaticValueGet(type.typeBridge.type, staticmembername, out getvalue)) { getvalue = type._class.StaticValueGet(content, staticmembername); } CQ_Value vright = CQ_Value.One; if (_expressions.Count > 0) { vright = _expressions[0].ComputeValue(content); } var mtype = CQuark.AppDomain.GetITypeByCQValue(getvalue); CQ_Value vout = mtype.Math2Value(mathop, getvalue, vright); //这几行是为了快速获取Unity的静态变量,而不需要反射 if (!Wrap.StaticValueSet(type.typeBridge.type, staticmembername, vout)) { type._class.StaticValueSet(content, staticmembername, vout); } #if CQUARK_DEBUG content.OutStack(this); #endif return(vout); }
public void DefineAndSet(string name, TypeBridge type, CQ_Value value) { if (values == null) { values = new Dictionary <string, CQ_Value>(); } else if (values.ContainsKey(name)) { throw new Exception(name + "已经定义过"); } CQ_Value v = new CQ_Value(); if (type.type != null) { v.m_type = type.type; } else if (type.stype != null) { v.m_stype = type.stype; } v.UsingValue(value); values[name] = v; int newdepth = tvalueDepth.Pop() + 1; tvalueDepth.Push(newdepth); tvalues.Push(name); }
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 ComputeValue(CQ_Content content) { #if CQUARK_DEBUG content.InStack(this); #endif CQ_Value parent = _expressions[0].ComputeValue(content); object obj = parent.GetObject(); if (parent == CQ_Value.Null) { throw new Exception("调用空对象的方法:" + _expressions[0].ToString() + ":" + ToString()); } var key = _expressions[1].ComputeValue(content); CQ_Value value = CQ_Value.Null; //这几行是为了快速获取Unity的静态变量,而不需要反射 if (!Wrap.IndexGet(parent.m_type, obj, key, out value)) { IType type = CQuark.AppDomain.GetITypeByCQValue(parent); value = type._class.IndexGet(content, obj, key.GetObject()); } #if CQUARK_DEBUG content.OutStack(this); #endif return(value); }
public static bool UnityEngineVector3MSet(object objSelf, string memberName, CQ_Value param) { UnityEngine.Vector3 obj = (UnityEngine.Vector3)objSelf; switch (memberName) { case "x": if (param.EqualOrImplicateType(typeof(float))) { obj.x = (float)param.ConvertTo(typeof(float)); return(true); } break; case "y": if (param.EqualOrImplicateType(typeof(float))) { obj.y = (float)param.ConvertTo(typeof(float)); return(true); } break; case "z": if (param.EqualOrImplicateType(typeof(float))) { obj.z = (float)param.ConvertTo(typeof(float)); return(true); } break; } return(false); }
public static bool UnityEngineVector3MCall(object objSelf, string functionName, List <CQ_Value> param, out CQ_Value returnValue, bool mustEqual) { UnityEngine.Vector3 obj = (UnityEngine.Vector3)objSelf; if (param.Count == 3 && functionName == "Set" && MatchType(param, new Type[] { typeof(float), typeof(float), typeof(float) }, mustEqual)) { returnValue = null; obj.Set((float)param[0].ConvertTo(typeof(float)), (float)param[1].ConvertTo(typeof(float)), (float)param[2].ConvertTo(typeof(float))); return(true); } if (param.Count == 1 && functionName == "Scale" && MatchType(param, new Type[] { typeof(UnityEngine.Vector3) }, mustEqual)) { returnValue = null; obj.Scale((UnityEngine.Vector3)param[0].ConvertTo(typeof(UnityEngine.Vector3))); return(true); } if (param.Count == 0 && functionName == "GetHashCode") { returnValue = new CQ_Value(); returnValue.type = typeof(int); returnValue.value = obj.GetHashCode(); return(true); } if (param.Count == 1 && functionName == "Equals" && MatchType(param, new Type[] { typeof(object) }, mustEqual)) { returnValue = new CQ_Value(); returnValue.type = typeof(bool); returnValue.value = obj.Equals((object)param[0].ConvertTo(typeof(object))); return(true); } if (param.Count == 0 && functionName == "Normalize") { returnValue = null; obj.Normalize(); return(true); } if (param.Count == 0 && functionName == "ToString") { returnValue = new CQ_Value(); returnValue.type = typeof(string); returnValue.value = obj.ToString(); return(true); } if (param.Count == 1 && functionName == "ToString" && MatchType(param, new Type[] { typeof(string) }, mustEqual)) { returnValue = new CQ_Value(); returnValue.type = typeof(string); returnValue.value = obj.ToString((string)param[0].ConvertTo(typeof(string))); return(true); } if (param.Count == 0 && functionName == "GetType") { returnValue = new CQ_Value(); returnValue.type = typeof(System.Type); returnValue.value = obj.GetType(); return(true); } returnValue = null; return(false); }
public IEnumerator CoroutineCompute(CQ_Content content, ICoroutine coroutine) { #if CQUARK_DEBUG content.InStack(this); #endif content.DepthAdd(); CQ_Value value = null; foreach (ICQ_Expression i in _expressions) { ICQ_Expression e = i as ICQ_Expression; if (e != null) { if (e.hasCoroutine) { yield return(coroutine.StartNewCoroutine(e.CoroutineCompute(content, coroutine))); } else { value = e.ComputeValue(content); if (value != null && value.breakBlock != 0) { break; } } } } content.DepthRemove(); #if CQUARK_DEBUG content.OutStack(this); #endif yield break; }
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 value = CQ_Value.Null; //这几行是为了快速获取Unity的静态变量,而不需要反射 if (!Wrap.New(type.typeBridge.type, parameters, out value)) { value = type._class.New(content, parameters); } #if CQUARK_DEBUG content.OutStack(this); #endif CQ_ObjPool.PushArray(parameters); return(value); }
public CQ_Value ComputeValue(CQ_Content content) { #if CQUARK_DEBUG content.InStack(this); #endif CQ_Value parent = _expressions[0].ComputeValue(content); if (parent == null) { throw new Exception("调用空对象的方法:" + _expressions[0].ToString() + ":" + ToString()); } CQ_Value value = null; //这几行是为了快速获取Unity的静态变量,而不需要反射 if (!Wrap.MemberValueGet(parent.type.type, parent.value, membername, out value)) { IClass iclass = CQuark.AppDomain.GetType(parent.type)._class; CQClassInstance s = parent.value as CQClassInstance; if (s != null) { iclass = s.type; } value = iclass.MemberValueGet(content, parent.value, membername); } #if CQUARK_DEBUG content.OutStack(this); #endif return(value); //做数学计算 //从上下文取值 //_value = null; //return null; }
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 IEnumerator CoroutineCompute(CQ_Content content, UnityEngine.MonoBehaviour coroutine) { #if CQUARK_DEBUG content.InStack(this); #endif content.DepthAdd(); CQ_Value value = new CQ_Value(); foreach (ICQ_Expression e in _expressions) { if (e != null) { if (e.hasCoroutine) { yield return(coroutine.StartCoroutine(e.CoroutineCompute(content, coroutine))); } else { value = e.ComputeValue(content); if (value.m_breakBlock != 0) { break; } } } } content.DepthRemove(); #if CQUARK_DEBUG content.OutStack(this); #endif yield break; }
public bool MathLogic(LogicToken code, object left, CQ_Value right) { if (code == LogicToken.equal)//[6] = {Boolean op_Equality(CQcriptExt.Vector3, CQcriptExt.Vector3)} { if (left == null || right.type == null) { return(left == right.value); } else { return(left == right.value); } } else if (code == LogicToken.not_equal)//[7] = {Boolean op_Inequality(CQcriptExt.Vector3, CQcriptExt.Vector3)} { if (left == null || right.type == null) { return(left != right.value); } else { return(left != right.value); } } throw new NotImplementedException(); }
public CQ_Value Call(CQ_Content content, IList <CQ_Value> param) { CQ_Value v = new CQ_Value(); List <object> objs = new List <object>(); for (int i = 0; i < this.defvalues.Count; i++) { if (i >= param.Count) { objs.Add(defvalues[i]); } else { if (this.paramtype[i] == (Type)param[i].type) { objs.Add(param[i].value); } else { object conv = param[i].ConvertTo(paramtype[i]); objs.Add(conv); } } } v.type = this.returntype; v.value = dele.DynamicInvoke(objs.ToArray()); return(v); }
public CQ_Value ComputeValue(CQ_Content content) { #if CQUARK_DEBUG content.InStack(this); #endif var parent = _expressions[0].ComputeValue(content); if (parent == null) { throw new Exception("调用空对象的方法:" + _expressions[0].ToString() + ":" + ToString()); } var key = _expressions[1].ComputeValue(content); CQ_Value value = null; //这几行是为了快速获取Unity的静态变量,而不需要反射 if (!Wrap.IndexGet(parent.type.type, parent.value, key, out value)) { var type = CQuark.AppDomain.GetType(parent.type); value = type._class.IndexGet(content, parent.value, key.value); } #if CQUARK_DEBUG content.OutStack(this); #endif //IndexGet返回的值类型是 System.Object. //在这里需要将类型明确化. //value.type = value.value.GetType(); return(value); //return type.function.MemberValueGet(CQuark.AppDomain, parent.value, membername); //做数学计算 //从上下文取值 //_value = null; //return null; }
public CQ_Value ComputeValue(CQ_Content content) { #if CQUARK_DEBUG content.InStack(this); #endif List <CQ_Value> param = new List <CQ_Value>(); //TODO 这些_expressions一开始就做非空判断,那么List全部可以换成数组了 foreach (ICQ_Expression p in _expressions) { if (p != null) { param.Add(p.ComputeValue(content)); } } CQ_Value value = null; //这几行是为了快速获取Unity的静态变量,而不需要反射 if (!Wrap.New(type.typeBridge.type, param, out value)) { value = type._class.New(content, param); } #if CQUARK_DEBUG content.OutStack(this); #endif return(value); }
public CQ_Value ComputeValue(CQ_Content content) { #if CQUARK_DEBUG content.InStack(this); #endif CQ_Value result = CQ_Value.Null; { result = new CQ_Value(); var value = _expressions[0].ComputeValue(content); if (value.m_type != typeof(bool)) { throw new Exception("三元表达式要求条件为bool型"); } bool bv = value.GetBool(); if (bv) { result = _expressions[1].ComputeValue(content); } else { result = _expressions[2].ComputeValue(content); } } #if CQUARK_DEBUG content.OutStack(this); #endif return(result); }
//这个函数展示最简单的计算 void Eval1() { CQuarkParagraph block = new CQuarkParagraph(); CQuark.CQ_Value ret = block.Execute("1+2"); Debug.Log("return = " + ret); }
public static bool UnityEngineTimeMCall(object objSelf, string functionName, List <CQ_Value> param, out CQ_Value returnValue, bool mustEqual) { UnityEngine.Time obj = (UnityEngine.Time)objSelf; if (param.Count == 1 && functionName == "Equals" && MatchType(param, new Type[] { typeof(object) }, mustEqual)) { returnValue = new CQ_Value(); returnValue.type = typeof(bool); returnValue.value = obj.Equals((object)param[0].ConvertTo(typeof(object))); return(true); } if (param.Count == 0 && functionName == "GetHashCode") { returnValue = new CQ_Value(); returnValue.type = typeof(int); returnValue.value = obj.GetHashCode(); return(true); } if (param.Count == 0 && functionName == "GetType") { returnValue = new CQ_Value(); returnValue.type = typeof(System.Type); returnValue.value = obj.GetType(); return(true); } if (param.Count == 0 && functionName == "ToString") { returnValue = new CQ_Value(); returnValue.type = typeof(string); returnValue.value = obj.ToString(); return(true); } returnValue = null; return(false); }
public IEnumerator CoroutineCompute(CQ_Content content, UnityEngine.MonoBehaviour coroutine) { #if CQUARK_DEBUG content.InStack(this); #endif CQ_Value rv = new CQ_Value(); if (_expressions.Count > 0 && _expressions[0] != null) { rv = _expressions[0].ComputeValue(content); } else { rv.m_type = typeof(void); } rv.m_breakBlock = BreakType.YieldReturn; #if CQUARK_DEBUG content.OutStack(this); #endif if (rv == CQ_Value.Null) { yield return(null); } else if (rv.m_type == typeof(IEnumerator)) { yield return(coroutine.StartCoroutine(rv.GetObject() as IEnumerator)); } else { yield return(rv.GetObject());//这里Unity会非常智能的自动去转型 } }
public CQ_Value ComputeValue(CQ_Content content) { #if CQUARK_DEBUG content.InStack(this); #endif content.DepthAdd(); CQ_Value value = null; foreach (ICQ_Expression i in _expressions) { ICQ_Expression e = i as ICQ_Expression; if (e != null) { value = e.ComputeValue(content); } if (value != null && value.breakBlock != 0) { break; } } content.DepthRemove(); #if CQUARK_DEBUG content.OutStack(this); #endif return(value); }
public CQ_Value ComputeValue(CQ_Content content) { #if CQUARK_DEBUG content.InStack(this); #endif List <CQ_Value> _params = new List <CQ_Value>(); for (int i = 0; i < _expressions.Count; i++) { _params.Add(_expressions[i].ComputeValue(content)); } CQ_Value value = null; //这几行是为了快速获取Unity的静态变量,而不需要反射 if (!Wrap.StaticCall(type.typeBridge.type, functionName, _params, out value)) { if (cache == null || cache.cachefail) { cache = new MethodCache(); value = type._class.StaticCall(content, functionName, _params, cache); } else { value = type._class.StaticCallCache(content, _params, cache); } } #if CQUARK_DEBUG content.OutStack(this); #endif return(value); }
public CQ_Value StaticCallCache(CQ_Content content, IList <CQ_Value> _params, MethodCache cache) { List <object> _oparams = new List <object>(); foreach (var p in _params) { _oparams.Add(p.value); } System.Reflection.MethodInfo methodInfo = cache.info; if (cache.needConvert) { var pp = methodInfo.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] = CQuark.AppDomain.GetType(_params[i].type).ConvertTo(_oparams[i], pp[i].ParameterType); } } } } CQ_Value v = new CQ_Value(); v.value = methodInfo.Invoke(null, _oparams.ToArray()); v.type = methodInfo.ReturnType; 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); } }