//This is just a sketch //TODO: implement customizable behavior, using dictionary type->type, to specify to which type to switch in case of overflow public virtual bool HandleOverflow(Exception ex, CallDispatcher dispatcher, DispatchRecord failedRecord, EvaluationContext context) { //get the common type and decide what to do... Type newType = null; switch (failedRecord.CommonType.Name) { case "Byte": case "SByte": case "Int16": case "UInt16": case "Int32": case "UInt32": newType = typeof(Int64); break; case "Int64": case "UInt64": newType = typeof(BigInteger); break; case "Single": newType = typeof(double); break; } if (newType == null) { throw ex; } context.CallArgs[0] = Convert.ChangeType(context.CallArgs[0], newType); context.CallArgs[1] = Convert.ChangeType(context.CallArgs[1], newType); return(true); }
public virtual CallDispatcher CreateDispatcher(string op) { CallDispatcher result = new CallDispatcher(this, op); CallDispatchers[op] = result; return(result); }
public virtual DispatchRecord CreateDispatchRecord(CallDispatcher dispatcher, TypePair forKey) { Type commonType = GetCommonType(dispatcher.MethodName, forKey.Arg1Type, forKey.Arg2Type); if (commonType == null) { return(null); } TypeConverter arg1Converter = GetConverter(forKey.Arg1Type, commonType); TypeConverter arg2Converter = GetConverter(forKey.Arg2Type, commonType); //Get base method for the operator and common type TypePair baseKey = new TypePair(commonType, commonType); DispatchRecord rec = dispatcher.GetRecord(baseKey); if (rec == null) { throw new RuntimeException("Operator or method " + dispatcher.MethodName + " is not defined for type " + commonType); } rec = new DispatchRecord(forKey, commonType, arg1Converter, arg2Converter, rec.ResultConverter, rec.Implementation); dispatcher.Add(rec); return(rec); }
public virtual bool HandleException(Exception ex, CallDispatcher dispatcher, DispatchRecord failedTarget, EvaluationContext context) { return(false); }