public override IChelaType InstanceGeneric(GenericInstance args, ChelaModule instModule) { GenericPrototype prototype = args.GetPrototype(); for (int i = 0; i < args.GetParameterCount(); ++i) { if (prototype.GetPlaceHolder(i) == this) { IChelaType type = args.GetParameter(i); if (type.IsPassedByReference()) { return(ReferenceType.Create(type)); } else { return(type); } } } return(this); }
public GenericInstance GetFullGenericInstance() { // Return the cached instance. if (fullGenericInstance != null) { return(fullGenericInstance); } // Get the full prototype. GenericPrototype fullProto = GetFullGenericPrototype(); if (fullProto == null) { return(null); } // Get the parent full generic instance. GenericInstance parentFull = null; Scope parent = GetParentScope(); if (parent != null) { parentFull = parent.GetFullGenericInstance(); } // Get my generic instance. GenericInstance myInstance = GetGenericInstance(); if (myInstance == null || myInstance.GetParameterCount() == 0) { fullGenericInstance = parentFull; } else if (parentFull == null || parentFull.GetParameterCount() == 0) { fullGenericInstance = myInstance; } else { // Merge both instances int parentSize = parentFull.GetParameterCount(); int mySize = myInstance.GetParameterCount(); IChelaType[] newInstance = new IChelaType[parentSize + mySize]; // Add the parent prototype components. for (int i = 0; i < parentSize; ++i) { newInstance[i] = parentFull.GetParameter(i); } // Add my prototype components. for (int i = 0; i < mySize; ++i) { newInstance[i + parentSize] = myInstance.GetParameter(i); } // Store the new complete generic instance. fullGenericInstance = new GenericInstance(fullProto, newInstance); } return(fullGenericInstance); }