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); } object func = del(this, value, cdata); Type returnType = CompilerUtility.GetReturnType(func); TypeDef returnTypeDef = cdata._assembly.GetTypeDef(returnType); return(() => { object ob = returnTypeDef.CallFunction(func); cdata._environment[_environmentIndex].data = ob; return (T)ob; }); }
public Operation.BinaryOperationDelegate GetBinaryOperation(Token.Type op, Type t0, Type t1) { //Console.WriteLine(op.ToString()); Dictionary <ulong, Operation.BinaryOperationDelegate> operatorMap = null; if (_binaryOperators.TryGetValue(op, out operatorMap)) { //Console.WriteLine("Getting Hash " + Hashing.Hash(t0, t1)); Operation.BinaryOperationDelegate del = null; if (operatorMap.TryGetValue(Hashing.Hash(t0, t1), out del)) { return(del); } } return(null); }
private object CompileDefaultBinaryOperator(Func <object> nextFunc, params Token.Type[] tokenTypes) { object left = nextFunc(); object output = null; while (MatchToken(tokenTypes)) { Token op = previous; int line = UpdateLineNumber(); object right = nextFunc(); if (output == null) { output = left; } Type ltype = CompilerUtility.GetReturnType(output); Type rtype = CompilerUtility.GetReturnType(right); Operation.BinaryOperationDelegate del = _assembly.GetBinaryOperation(op.type, ltype, 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 && ltype != typeof(Object) && rtype == typeof(Object)) { del = _assembly.GetBinaryOperation(op.type, ltype, ltype); } if (del == null && ltype == typeof(Object) && rtype != typeof(Object)) { del = _assembly.GetBinaryOperation(op.type, rtype, rtype); } // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * if (del == null) { del = _assembly.GetBinaryOperation(op.type, typeof(Object), typeof(Object)); } if (del == null) { throw new CompilationException("[line " + line + "] Cannot perform the operation " + op.text + " on " + ltype.Name + " and " + rtype.Name); } output = del(output, right, _cdata); } return((output != null) ? (object)output : left); }
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); object func = del(this, value, cdata); Type returnType = CompilerUtility.GetReturnType(func); TypeDef returnTypeDef = cdata._assembly.GetTypeDef(returnType); if (targetFunc == null) { return(() => { object ob = returnTypeDef.CallFunction(func); return (T)RunTimeUtility.SetMemberValue(_targetObject, _identifer, cdata, ob); }); } else { return(() => { object ob = returnTypeDef.CallFunction(func); return (T)RunTimeUtility.SetMemberValue(targetFunc(), _identifer, cdata, ob); }); } }