public override Func <T> CreateSetFunction <T>(object value, CompilerData cdata) { if (CompilerUtility.IsFunc(value)) { Func <T> valueFunc = (Func <T>)value; return(() => { T ob = valueFunc(); //Type checking Type refType = cdata._environment[_environmentIndex].type; if (refType != typeof(Object) && refType != ob.GetType()) { throw new RuntimeException("data type does not match: " + refType.Name + " is not " + ob.GetType().Name); } //Assign data cdata._environment[_environmentIndex].data = ob; return (T)(cdata._environment[_environmentIndex].data); }); } else { T val = (T)value; return(() => { //Type checking Type refType = cdata._environment[_environmentIndex].type; if (refType != typeof(Object) && refType != val.GetType()) { throw new RuntimeException("data type does not match"); } //Assign data cdata._environment[_environmentIndex].data = val; return val; }); } }
protected virtual Func <T[]> CreateArrayLiteral <T>(object[] elements, CompilerData cdata) { Type elemType = typeof(T); return((Func <T[]>)(() => { int length = elements.Length; IList output = Array.CreateInstance(type, length); for (int i = 0; i < length; i += 1) { var func = elements[i] as Func <T>; if (func != null) { output[i] = func(); } else { output[i] = (T)elements[i]; } } return (T[])output; })); }
public override Func <T> CreateSetFunction <T>(object value, CompilerData cdata) { Func <object> targetFunc = CompilerUtility.ForceGetFunction <object>(_targetObject, cdata); Func <T> valueFunc = CompilerUtility.ForceGetFunction <T>(value, cdata); if (targetFunc == null && valueFunc == null) { T val = (T)value; return(() => { return (T)RunTimeUtility.SetMemberValue(_targetObject, _identifer, cdata, val); }); } else if (targetFunc == null && valueFunc != null) { return(() => { return (T)RunTimeUtility.SetMemberValue(_targetObject, _identifer, cdata, valueFunc()); }); } else if (targetFunc != null && valueFunc == null) { T val = (T)value; return(() => { return (T)RunTimeUtility.SetMemberValue(targetFunc(), _identifer, cdata, val); }); } else { return(() => { return (T)RunTimeUtility.SetMemberValue(targetFunc(), _identifer, cdata, valueFunc()); }); } }
public virtual object CreateArrayLiteral(object[] elements, CompilerData cdata) { return(CreateArrayLiteral <object>(elements, cdata)); }
public virtual object CastArray(object arg, CompilerData _internal) { return((Func <object[]>)(() => { return (object[])arg; })); }
public MethodCall(MethodInfo methodInfo, object target, object[] argumentNodes, CompilerData cdata) : base(DelegateUtility.GetMethodType(methodInfo), methodInfo.Name, target, methodInfo.DeclaringType) { _method = methodInfo; _returnType = CompilerUtility.GetReturnType(DelegateUtility.GetMethodType(methodInfo)); _cdata = cdata; _argNodeBuffer = (argumentNodes != null) ? argumentNodes : new object[0]; _argBuffer = new object[_argNodeBuffer.Length]; if (!ValidateArguments()) { throw new Exception("Arguments suppied do not match the spefied signaure: " + _identifer + _type.ToString()); } }
public override Func <T> CreateSetFunction <T>(object value, CompilerData cdata) { Func <object> accessorFunc = CompilerUtility.ForceGetFunction(_accessor, cdata); Func <object> targetFunc = CompilerUtility.ForceGetFunction(_targetObject, cdata); Func <object> valueFunc = CompilerUtility.ForceGetFunction(value, cdata); if (valueFunc == null && targetFunc == null && accessorFunc == null) { IList list = _accessor as IList; int accessorCount = list.Count; return(() => { for (int i = 0; i < accessorCount; i += 1) { ((IList)_targetObject)[(int)list[i]] = value; } return (T)value; }); } else if (valueFunc == null && targetFunc == null && accessorFunc != null) { return(() => { IList list = accessorFunc() as IList; int accessorCount = list.Count; for (int i = 0; i < accessorCount; i += 1) { ((IList)_targetObject)[(int)list[i]] = value; } return (T)value; }); } else if (valueFunc == null && targetFunc != null && accessorFunc == null) { IList list = _accessor as IList; int accessorCount = list.Count; return(() => { IList targetObject = (IList)targetFunc(); for (int i = 0; i < accessorCount; i += 1) { targetObject[(int)list[i]] = value; } return (T)value; }); } else if (valueFunc == null && targetFunc != null && accessorFunc != null) { return(() => { IList targetObject = (IList)targetFunc(); IList list = accessorFunc() as IList; int accessorCount = list.Count; for (int i = 0; i < accessorCount; i += 1) { targetObject[(int)list[i]] = value; } return (T)value; }); } else if (valueFunc != null && targetFunc == null && accessorFunc == null) { IList targetObject = (IList)targetFunc(); IList list = _accessor as IList; int accessorCount = list.Count; return(() => { T val = (T)valueFunc(); for (int i = 0; i < accessorCount; i += 1) { targetObject[(int)list[i]] = val; } return (T)val; }); } else if (valueFunc != null && targetFunc == null && accessorFunc != null) { return(() => { T val = (T)valueFunc(); IList list = accessorFunc() as IList; int accessorCount = list.Count; for (int i = 0; i < accessorCount; i += 1) { ((IList)_targetObject)[(int)list[i]] = val; } return (T)val; }); } else if (valueFunc != null && targetFunc != null && accessorFunc == null) { IList targetObject = (IList)targetFunc(); IList list = _accessor as IList; int accessorCount = list.Count; return(() => { T val = (T)valueFunc(); for (int i = 0; i < accessorCount; i += 1) { targetObject[(int)list[i]] = val; } return (T)val; }); } else { return(() => { IList targetObject = (IList)targetFunc(); T val = (T)valueFunc(); IList list = accessorFunc() as IList; int accessorCount = list.Count; for (int i = 0; i < accessorCount; i += 1) { targetObject[(int)list[i]] = val; } return (T)val; }); } }
public override Func <T> CreateGetFunction <T>(CompilerData cdata) { Func <object> accessorFunc = CompilerUtility.ForceGetFunction(_accessor, cdata); Func <object> targetFunc = (CompilerUtility.IsFunc(_targetObject)) ? (Func <object>)_targetObject : null; if (targetFunc == null && accessorFunc == null) { IList list = _accessor as IList; int accessorCount = list.Count; return(() => { Type et = (_elemType != typeof(object)) ? _elemType : _targetObject.GetType().GetElementType(); IList arr = System.Array.CreateInstance(et, accessorCount); for (int i = 0; i < accessorCount; i += 1) { arr[i] = ((IList)_targetObject)[(int)list[i]]; } return (T)arr; }); } else if (targetFunc == null && accessorFunc != null) { return(() => { IList list = accessorFunc() as IList; int accessorCount = list.Count; Type et = (_elemType != typeof(object)) ? _elemType : _targetObject.GetType().GetElementType(); IList arr = System.Array.CreateInstance(et, accessorCount); for (int i = 0; i < accessorCount; i += 1) { arr[i] = ((IList)_targetObject)[(int)list[i]]; } return (T)arr; }); } else if (targetFunc != null && accessorFunc == null) { IList list = _accessor as IList; int accessorCount = list.Count; return(() => { object targetObject = targetFunc(); Type et = (_elemType != typeof(object)) ? _elemType : targetObject.GetType().GetElementType(); IList arr = System.Array.CreateInstance(et, accessorCount); for (int i = 0; i < accessorCount; i += 1) { arr[i] = ((IList)targetObject)[(int)list[i]]; } return (T)arr; }); } else { return(() => { IList list = accessorFunc() as IList; int accessorCount = list.Count; object targetObject = targetFunc(); Type et = (_elemType != typeof(object)) ? _elemType : targetObject.GetType().GetElementType(); IList arr = System.Array.CreateInstance(et, accessorCount); for (int i = 0; i < accessorCount; i += 1) { arr[i] = ((IList)targetObject)[(int)list[i]]; } return (T)arr; }); } }
public virtual Func <object> CreateGetFunction(CompilerData cdata) { return(CreateGetFunction <object>(cdata)); }
public abstract Func <T> CreateGetFunction <T>(CompilerData cdata);
public CompiledScript(Func <object> function, CompilerData cdata) { _function = function; _cdata = cdata; }
public override Func <T> CreateModifyFunction <T>(object value, CompilerData cdata, Token.Type operation) { Type rtype = CompilerUtility.GetReturnType(value); Operation.BinaryOperationDelegate del = cdata._assembly.GetBinaryOperation(operation, type, rtype); // This section was made for runtime type inference // May cause some weird issues, definitely check this out if there are problems if (del == null && type != typeof(Object) && rtype == typeof(Object)) { del = cdata._assembly.GetBinaryOperation(operation, type, type); } if (del == null && type == typeof(Object) && rtype != typeof(Object)) { del = cdata._assembly.GetBinaryOperation(operation, rtype, rtype); } if (del == null) { throw new CompilationException("Cannot perform the operation " + operation.ToString() + " on " + type.Name + " and " + rtype.Name); } Func <object> targetFunc = CompilerUtility.ForceGetFunction <object>(_targetObject, cdata); Func <object> accessorFunc = CompilerUtility.ForceGetFunction <object>(_accessor, cdata); object func = del(this, value, cdata); Type returnType = CompilerUtility.GetReturnType(func); TypeDef returnTypeDef = cdata._assembly.GetTypeDef(returnType); if (targetFunc == null && accessorFunc == null) { return(() => { object ob = returnTypeDef.CallFunction(func); ((IList)(_targetObject))[(int)_accessor] = ob; return (T)ob; }); } if (targetFunc == null && accessorFunc != null) { return(() => { object ob = returnTypeDef.CallFunction(func); ((IList)(_targetObject))[(int)accessorFunc()] = ob; return (T)ob; }); } if (targetFunc != null && accessorFunc == null) { return(() => { object ob = returnTypeDef.CallFunction(func); ((IList)(targetFunc()))[(int)_accessor] = ob; return (T)ob; }); } else { return(() => { object ob = returnTypeDef.CallFunction(func); ((IList)(targetFunc()))[(int)accessorFunc()] = ob; return (T)ob; }); } }
public override Func <T> CreateSetFunction <T>(object value, CompilerData cdata) { Func <object> accessorFunc = CompilerUtility.ForceGetFunction(_accessor, cdata); Func <object> targetFunc = CompilerUtility.ForceGetFunction(_targetObject, cdata); Func <object> valueFunc = CompilerUtility.ForceGetFunction(value, cdata); if (valueFunc == null && targetFunc == null && accessorFunc == null) { return(() => { ((IList)(_targetObject))[(int)_accessor] = value; return (T)value; }); } else if (valueFunc == null && targetFunc == null && accessorFunc != null) { return(() => { ((IList)(_targetObject))[(int)accessorFunc()] = value; return (T)value; }); } else if (valueFunc == null && targetFunc != null && accessorFunc == null) { return(() => { ((IList)(targetFunc()))[(int)_accessor] = value; return (T)value; }); } else if (valueFunc == null && targetFunc != null && accessorFunc != null) { return(() => { ((IList)(targetFunc()))[(int)accessorFunc()] = value; return (T)value; }); } else if (valueFunc != null && targetFunc == null && accessorFunc == null) { return(() => { object val = valueFunc(); ((IList)(_targetObject))[(int)_accessor] = val; return (T)val; }); } else if (valueFunc != null && targetFunc == null && accessorFunc != null) { return(() => { object val = valueFunc(); ((IList)(_targetObject))[(int)accessorFunc()] = val; return (T)val; }); } else if (valueFunc != null && targetFunc != null && accessorFunc == null) { return(() => { object val = valueFunc(); ((IList)(targetFunc()))[(int)_accessor] = val; return (T)val; }); } else { return(() => { object val = valueFunc(); ((IList)(targetFunc()))[(int)accessorFunc()] = val; return (T)val; }); } }
public static Func <object> ForceGetFunction(object refOrFunc, CompilerData cdata) { return(ForceGetFunction <object>(refOrFunc, cdata)); }
public override Func <T> CreateSetFunction <T>(object value, CompilerData cdata) { Func <object> accessorFunc = CompilerUtility.ForceGetFunction(_accessor, cdata); Func <T> valueFunc = CompilerUtility.ForceGetFunction <T>(value, cdata); if (valueFunc == null && accessorFunc == null) { T val = (T)value; IList list = _accessor as IList; int accessorCount = list.Count; return(() => { for (int i = 0; i < accessorCount; i += 1) { ((IList)cdata._environment[_environmentIndex].data)[(int)list[i]] = val; } return (T)val; }); } else if (valueFunc == null && accessorFunc != null) { T val = (T)value; return(() => { IList list = accessorFunc() as IList; int accessorCount = list.Count; for (int i = 0; i < accessorCount; i += 1) { ((IList)cdata._environment[_environmentIndex].data)[(int)list[i]] = val; } return (T)val; }); } if (valueFunc != null && accessorFunc == null) { T val = valueFunc(); IList list = _accessor as IList; int accessorCount = list.Count; return(() => { for (int i = 0; i < accessorCount; i += 1) { ((IList)cdata._environment[_environmentIndex].data)[(int)list[i]] = val; } return (T)val; }); } else { return(() => { T val = valueFunc(); IList list = accessorFunc() as IList; int accessorCount = list.Count; for (int i = 0; i < accessorCount; i += 1) { ((IList)cdata._environment[_environmentIndex].data)[(int)list[i]] = val; } return (T)val; }); } }
public virtual Func <T> CreateModifyFunction <T>(object value, CompilerData cdata, Token.Type operation) { throw new System.NotImplementedException(); }
public abstract Func <T> CreateSetFunction <T>(object value, CompilerData cdata);
public FunctionCall(Type t, string identifier, int envIndex, object[] argumentNodes, CompilerData cdata) : base(t, identifier, envIndex) { UnityEngine.Debug.Log("Creating Function"); _returnType = (t != null) ? CompilerUtility.GetReturnType(t) : typeof(object); _cdata = cdata; _argNodeBuffer = (argumentNodes != null) ? argumentNodes : new object[0]; _typeDef = _cdata._assembly.GetTypeDef(CompilerUtility.GetReturnType(t)); _argBuffer = new object[0]; //always zero, on a function call the variables are injected right into the envrionment array if (!ValidateArguments()) { throw new Exception("Arguments suppied do not match the spefied signaure: " + _identifer + _type.ToString()); } }
public virtual Func <object> CreateSetFunction(object value, CompilerData cdata) { return(CreateSetFunction <object>(value, cdata)); }
public override Func <T> CreateModifyFunction <T>(object value, CompilerData cdata, Token.Type operation) { throw new System.InvalidOperationException("Cannot modify array indexed results"); }
public virtual object Cast(object arg, CompilerData _internal) { return((Func <object>)(() => { return arg; })); }
public static object SubtractFromMemberValue(object target, string identifier, CompilerData cdata, object value) { Type t = target.GetType(); MethodCache.CachedMember cached = cdata._methodCache.GetCached(t, identifier); if (cached == null) { cached = cdata._methodCache.CacheMember(t, identifier); } switch (cached.memberType) { case MemberTypes.Field: FieldInfo field = (FieldInfo)cached.main; if (field.FieldType == typeof(int)) { int mod = ((int)field.GetValue(target) - (int)value); field.SetValue(target, mod); return(mod); } else if (field.FieldType == typeof(float)) { float mod = ((float)field.GetValue(target) - (float)value); field.SetValue(target, mod); return(mod); } throw new Exception("Runtime Error: Cannot cast"); case MemberTypes.Property: PropertyInfo prop = (PropertyInfo)cached.main; if (prop.PropertyType == typeof(int)) { int mod = ((int)prop.GetValue(target) - (int)value); prop.SetValue(target, mod); return(mod); } else if (prop.PropertyType == typeof(float)) { float mod = ((float)prop.GetValue(target) - (float)value); prop.SetValue(target, mod); return(mod); } throw new Exception("Runtime Error: Cannot cast"); default: throw new Exception("Runtime Error: No Setter for " + cached.name + " " + cached.memberType.ToString()); } }
public MethodCall(Type t, string identifier, object target, object[] argumentNodes, CompilerData cdata, Type targetType) : base(t, identifier, target, targetType) { _returnType = (t != null) ? CompilerUtility.GetReturnType(t) : typeof(object); _cdata = cdata; _argNodeBuffer = (argumentNodes != null) ? argumentNodes : new object[0]; //_method = targetType.GetMethod(identifier); _argBuffer = new object[_argNodeBuffer.Length]; if (!ValidateArguments()) { throw new Exception("Arguments suppied do not match the spefied signaure: " + _identifer + _type.ToString()); } }