/// <summary> /// Build expression that creates an instance of GenericInstance with arguments from the given .NET generic instance. /// </summary> private static AstExpression CreateGenericInstance(ISourceLocation seqp, XReference member, MethodSource currentMethod, AssemblyCompiler compiler) { // Prepare var genericInstance = member as IXGenericInstance; if (genericInstance == null) { #if DEBUG //Debugger.Launch(); #endif throw new CompilerException(string.Format("{0} is not a generic instance", member)); } var count = genericInstance.GenericArguments.Count; var typeHelperType = compiler.GetDot42InternalType(InternalConstants.TypeHelperName).Resolve(); // Foreach type argument var typeExpressions = new List <AstExpression>(); for (var i = 0; i < count; i++) { var argType = genericInstance.GenericArguments[i]; var typeExpr = LoadTypeForGenericInstance(seqp, currentMethod, argType, typeHelperType, compiler.Module.TypeSystem); typeExpressions.Add(typeExpr); } var elementType = compiler.Module.TypeSystem.Type; return(new AstExpression(seqp, AstCode.InitArrayFromArguments, new XArrayType(elementType), typeExpressions) { ExpectedType = new XArrayType(elementType) }); }
/** Called by clients to register listener which are notified when the * weak object is dying. * * @param xReference a listener */ public void removeReference(XReference xReference) { lock (this) { m_XReference_dispose -= new XReference_dispose(xReference.dispose); } }
/** Called by clients to unregister listeners. * * @param xReference a listener */ public void addReference(XReference xReference) { lock (this) { m_XReference_dispose += new XReference_dispose(xReference.dispose); } }
/// <summary> /// Adds a new request to the table and returns the last removed request id. /// </summary> /// <param name="requestId"></param> /// <returns>Last remove request Id</returns> public long LogNewRequest(long requestId) { lock (_syncLock) { XReference sourceReferenceId = new XReference(requestId); _requestTable.AddSource(sourceReferenceId); long smallestRequestId; long smallestReferenceId = _requestTable.GetFirstReferenceId(_lastAcknowledgedReferenceId, out smallestRequestId); _lastAcknowledgedRequestId = smallestRequestId - 1; _lastAcknowledgedReferenceId = smallestReferenceId - 1; } return(_lastAcknowledgedRequestId); }
/// <summary> /// Expires the old requests /// </summary> /// <param name="expirationInterval">expiration interval in seconds</param> public void Expire(long expirationInterval) { XReference[] loggedRequests = new XReference[_requestTable.SourceIds.Count]; lock (_syncLock) { _requestTable.SourceIds.CopyTo(loggedRequests, 0); } foreach (XReference refernce in loggedRequests) { if (refernce != null && refernce.CreationTime.AddSeconds(expirationInterval) < DateTime.Now) { RemoveRequest(refernce.SourceId); } } }
/// <summary> /// Removes the request with specified Id. /// </summary> /// <param name="requestId"></param> /// <returns></returns> public bool RemoveRequest(long requestId) { lock (_syncLock) { XReference sourceReferenceId = new XReference(requestId); long referenceId = _requestTable.RemoveSource(sourceReferenceId); if (referenceId != -1) { if (_lastAcknowledgedReferenceId + 1 == referenceId) { _lastAcknowledgedReferenceId = referenceId; } } } return(true); }
/// <summary> /// Build expressions that are used when calling a .NET method with generic instance parameters, one expression for /// each required parameter. /// </summary> private static IList <AstExpression> CreateGenericInstanceCallArguments(ISourceLocation seqp, XReference member, MethodSource currentMethod, AssemblyCompiler compiler) { // Prepare var genericInstance = member as IXGenericInstance; if (genericInstance == null) { #if DEBUG //Debugger.Launch(); #endif throw new CompilerException(string.Format("{0} is not a generic instance", member)); } var count = genericInstance.GenericArguments.Count; var typeHelperType = compiler.GetDot42InternalType(InternalConstants.TypeHelperName).Resolve(); // Foreach type argument var typeExpressions = new List <AstExpression>(); for (var i = 0; i < count; i++) { var argType = genericInstance.GenericArguments[i]; var typeExpr = LoadTypeForGenericInstance(seqp, currentMethod, argType, compiler, typeHelperType, compiler.Module.TypeSystem, TypeConversion.EnsureTrueOrMarkerType); typeExpressions.Add(typeExpr); } bool isMethod = member is XMethodReference; bool buildArray = count > (isMethod ? InternalConstants.GenericMethodParametersAsArrayThreshold : InternalConstants.GenericTypeParametersAsArrayThreshold); if (buildArray) { //TODO: when we can determine that all expressions just load our classes generic instance (array) field, // and extract all values in sequence, we should shortcut and just return a load of the field, // instead of unpacking and re-packing each value, putting pressure on the garbage collector // in the process. This is not a huge problem any longer, as we do not use arrays as often // as we used to. Nevertheless, where arrays are used, possible re-use should be faily common, // e.g. when instatiating nested classes or invoking static methods. var elementType = compiler.Module.TypeSystem.Type; return(new [] { new AstExpression(seqp, AstCode.InitArrayFromArguments, new XArrayType(elementType), typeExpressions) { ExpectedType = new XArrayType(elementType) } }); } else { return(typeExpressions); } }
/** Called by clients to register listener which are notified when the weak object is dying. @param xReference a listener */ public void removeReference( XReference xReference ) { lock (this) { m_XReference_dispose -= new XReference_dispose( xReference.dispose ); } }
/** Called by clients to unregister listeners. @param xReference a listener */ public void addReference( XReference xReference ) { lock (this) { m_XReference_dispose += new XReference_dispose( xReference.dispose ); } }