static void DeallocateDefinstancesData( void *theEnv) { #if ! RUN_TIME struct definstancesModule *theModuleItem; void *theModule; #if BLOAD || BLOAD_AND_BSAVE if (Bloaded(theEnv)) return; #endif DoForAllConstructs(theEnv,DestroyDefinstancesAction,DefinstancesData(theEnv)->DefinstancesModuleIndex,FALSE,NULL); for (theModule = EnvGetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = EnvGetNextDefmodule(theEnv,theModule)) { theModuleItem = (struct definstancesModule *) GetModuleItem(theEnv,(struct defmodule *) theModule, DefinstancesData(theEnv)->DefinstancesModuleIndex); rtn_struct(theEnv,definstancesModule,theModuleItem); } #else #if MAC_MCW || WIN_MCW || MAC_XCD #pragma unused(theEnv) #endif #endif }
/*************************************************** NAME : EnvListDefinstances DESCRIPTION : Displays all definstances names INPUTS : 1) The logical name of the output 2) The module RETURNS : Nothing useful SIDE EFFECTS : Definstances names printed NOTES : C Interface ***************************************************/ globle void EnvListDefinstances( void *theEnv, char *logicalName, struct defmodule *theModule) { ListConstruct(theEnv,DefinstancesData(theEnv)->DefinstancesConstruct,logicalName,theModule); }
/*************************************************** NAME : BsaveDefinstancesExpressions DESCRIPTION : Writes out all expressions needed by deffunctyions INPUTS : The file pointer of the binary file RETURNS : Nothing useful SIDE EFFECTS : File updated NOTES : None ***************************************************/ static void BsaveDefinstancesExpressions( void *theEnv, FILE *fp) { DoForAllConstructs(theEnv,BsaveDefinstancesExpression,DefinstancesData(theEnv)->DefinstancesModuleIndex, FALSE,(void *) fp); }
/*********************************************************** NAME : EnvGetNextDefinstances DESCRIPTION : Finds first or next definstances INPUTS : The address of the current definstances RETURNS : The address of the next definstances (NULL if none) SIDE EFFECTS : None NOTES : If ptr == NULL, the first definstances is returned. ***********************************************************/ globle void *EnvGetNextDefinstances( void *theEnv, void *ptr) { return((void *) GetNextConstructItem(theEnv,(struct constructHeader *) ptr, DefinstancesData(theEnv)->DefinstancesModuleIndex)); }
/*************************************************************** NAME : EnvGetDefinstancesList DESCRIPTION : Groups all definstances names into a multifield list INPUTS : 1) A data object buffer to hold the multifield result 2) The module from which to obtain definstances RETURNS : Nothing useful SIDE EFFECTS : Multifield allocated and filled NOTES : External C access ***************************************************************/ globle void EnvGetDefinstancesList( void *theEnv, DATA_OBJECT *returnValue, struct defmodule *theModule) { GetConstructList(theEnv,returnValue,DefinstancesData(theEnv)->DefinstancesConstruct,theModule); }
/*************************************************** NAME : SaveDefinstances DESCRIPTION : Prints pretty print form of definstances to specified output INPUTS : The logical name of the output RETURNS : Nothing useful SIDE EFFECTS : None NOTES : None ***************************************************/ static void SaveDefinstances( void *theEnv, void *theModule, char *logName) { SaveConstruct(theEnv,theModule,logName,DefinstancesData(theEnv)->DefinstancesConstruct); }
/*************************************************** NAME : ReturnModule DESCRIPTION : Removes a definstances module and all associated definstances INPUTS : The definstances module RETURNS : Nothing useful SIDE EFFECTS : Module and definstances deleted NOTES : None ***************************************************/ static void ReturnModule( void *theEnv, void *theItem) { #if (! BLOAD_ONLY) FreeConstructHeaderModule(theEnv,(struct defmoduleItemHeader *) theItem,DefinstancesData(theEnv)->DefinstancesConstruct); #endif rtn_struct(theEnv,definstancesModule,theItem); }
/*************************************************** NAME : ClearDefinstancesReady DESCRIPTION : Determines if it is safe to remove all definstances Assumes *all* constructs will be deleted INPUTS : None RETURNS : TRUE if all definstances can be deleted, FALSE otherwise SIDE EFFECTS : None NOTES : Used by (clear) and (bload) ***************************************************/ static intBool ClearDefinstancesReady( void *theEnv) { int flagBuffer = TRUE; DoForAllConstructs(theEnv,CheckDefinstancesBusy,DefinstancesData(theEnv)->DefinstancesModuleIndex, FALSE,(void *) &flagBuffer); return(flagBuffer); }
/*************************************************************************** NAME : BsaveDefinstancesFind DESCRIPTION : For all definstances, this routine marks all the needed symbols. Also, it also counts the number of expression structures needed. Also, counts total number of definstances. INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : ExpressionCount (a global from BSAVE.C) is incremented for every expression needed Symbols are marked in their structures NOTES : Also sets bsaveIndex for each definstances (assumes definstances will be bsaved in order of binary list) ***************************************************************************/ static void BsaveDefinstancesFind( void *theEnv) { SaveBloadCount(theEnv,DefinstancesBinaryData(theEnv)->ModuleCount); SaveBloadCount(theEnv,DefinstancesBinaryData(theEnv)->DefinstancesCount); DefinstancesBinaryData(theEnv)->DefinstancesCount = 0L; DefinstancesBinaryData(theEnv)->ModuleCount = DoForAllConstructs(theEnv,MarkDefinstancesItems,DefinstancesData(theEnv)->DefinstancesModuleIndex, FALSE,NULL); }
/*************************************************** NAME : DefinstancesModuleToCode DESCRIPTION : Writes out the C values for a definstances module item INPUTS : 1) The output file 2) The module for the definstances 3) The compile image id 4) The maximum number of elements in an array RETURNS : Nothing useful SIDE EFFECTS : Definstances module item written NOTES : None ***************************************************/ static void DefinstancesModuleToCode( void *theEnv, FILE *theFile, struct defmodule *theModule, int imageID, int maxIndices) { fprintf(theFile,"{"); ConstructModuleToCode(theEnv,theFile,theModule,imageID,maxIndices, DefinstancesData(theEnv)->DefinstancesModuleIndex,ConstructPrefix(DefinstancesData(theEnv)->DefinstancesCodeItem)); fprintf(theFile,"}"); }
/**************************************************** NAME : DefinstancesCModuleReference DESCRIPTION : Prints out a reference to a definstances module INPUTS : 1) The output file 2) The id of the module item 3) The id of the image 4) The maximum number of elements allowed in an array RETURNS : Nothing useful SIDE EFFECTS : Definstances module reference printed NOTES : None ****************************************************/ globle void DefinstancesCModuleReference( void *theEnv, FILE *theFile, int count, int imageID, int maxIndices) { fprintf(theFile,"MIHS &%s%d_%d[%d]", ModulePrefix(DefinstancesData(theEnv)->DefinstancesCodeItem), imageID, (count / maxIndices) + 1, (count % maxIndices)); }
/*************************************************** NAME : SingleDefinstancesToCode DESCRIPTION : Writes out a single definstances' data to the file INPUTS : 1) The output file 2) The definstances 3) The compile image id 4) The maximum number of elements in an array 5) The module index RETURNS : Nothing useful SIDE EFFECTS : Definstances data written NOTES : None ***************************************************/ static void SingleDefinstancesToCode( void *theEnv, FILE *theFile, DEFINSTANCES *theDefinstances, int imageID, int maxIndices, int moduleCount) { /* =================== Definstances Header =================== */ fprintf(theFile,"{"); ConstructHeaderToCode(theEnv,theFile,&theDefinstances->header,imageID,maxIndices,moduleCount, ModulePrefix(DefinstancesData(theEnv)->DefinstancesCodeItem), ConstructPrefix(DefinstancesData(theEnv)->DefinstancesCodeItem)); /* ========================== Definstances specific data ========================== */ fprintf(theFile,",0,"); ExpressionToCode(theEnv,theFile,theDefinstances->mkinstance); fprintf(theFile,"}"); }
/************************************************************************************* NAME : BsaveDefinstancesDriver DESCRIPTION : Writes out definstances in binary format Space required (unsigned long) All definstances (sizeof(DEFINSTANCES) * Number of definstances) INPUTS : File pointer of binary file RETURNS : Nothing useful SIDE EFFECTS : Binary file adjusted NOTES : None *************************************************************************************/ static void BsaveDefinstancesDriver( void *theEnv, FILE *fp) { unsigned long space; struct defmodule *theModule; DEFINSTANCES_MODULE *theModuleItem; BSAVE_DEFINSTANCES_MODULE dummy_mitem; space = (unsigned long) ((sizeof(BSAVE_DEFINSTANCES_MODULE) * DefinstancesBinaryData(theEnv)->ModuleCount) + (sizeof(BSAVE_DEFINSTANCES) * DefinstancesBinaryData(theEnv)->DefinstancesCount)); GenWrite((void *) &space,(unsigned long) sizeof(unsigned long),fp); /* ================================= Write out each definstances module ================================= */ DefinstancesBinaryData(theEnv)->DefinstancesCount = 0L; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); while (theModule != NULL) { theModuleItem = (DEFINSTANCES_MODULE *) GetModuleItem(theEnv,theModule,FindModuleItem(theEnv,"definstances")->moduleIndex); AssignBsaveDefmdlItemHdrVals(&dummy_mitem.header,&theModuleItem->header); GenWrite((void *) &dummy_mitem,(unsigned long) sizeof(BSAVE_DEFINSTANCES_MODULE),fp); theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,(void *) theModule); } /* ========================== Write out each definstances ========================== */ DoForAllConstructs(theEnv,BsaveDefinstances,DefinstancesData(theEnv)->DefinstancesModuleIndex, FALSE,(void *) fp); RestoreBloadCount(theEnv,&DefinstancesBinaryData(theEnv)->ModuleCount); RestoreBloadCount(theEnv,&DefinstancesBinaryData(theEnv)->DefinstancesCount); }
/***************************************************************** NAME : GetDefinstancesModuleCommand DESCRIPTION : Determines to which module a definstances belongs INPUTS : None RETURNS : The symbolic name of the module SIDE EFFECTS : None NOTES : H/L Syntax: (definstances-module <defins-name>) *****************************************************************/ globle SYMBOL_HN *GetDefinstancesModuleCommand( void *theEnv) { return(GetConstructModuleCommand(theEnv,"definstances-module",DefinstancesData(theEnv)->DefinstancesConstruct)); }
/*************************************************** NAME : SetupDefinstancesCompiler DESCRIPTION : Initializes the construct compiler item for definstances INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : Code generator item initialized NOTES : None ***************************************************/ globle void SetupDefinstancesCompiler( void *theEnv) { DefinstancesData(theEnv)->DefinstancesCodeItem = AddCodeGeneratorItem(theEnv,(char*)"definstances",0,ReadyDefinstancesForCode, NULL,DefinstancesToCode,2); }
/*************************************************** NAME : EnvFindDefinstances DESCRIPTION : Looks up a definstance construct by name-string INPUTS : The symbolic name RETURNS : The definstance address, or NULL if not found SIDE EFFECTS : None NOTES : None ***************************************************/ globle void *EnvFindDefinstances( void *theEnv, char *name) { return(FindNamedConstruct(theEnv,name,DefinstancesData(theEnv)->DefinstancesConstruct)); }
/******************************************************* NAME : DefinstancesToCode DESCRIPTION : Writes out static array code for definstances INPUTS : 1) The base name of the construct set 2) The base id for this construct 3) The file pointer for the header file 4) The base id for the construct set 5) The max number of indices allowed in an array RETURNS : -1 if no definstances, 0 on errors, 1 if definstances written SIDE EFFECTS : Code written to files NOTES : None *******************************************************/ static int DefinstancesToCode( void *theEnv, char *fileName, char *pathName, char *fileNameBuffer, int fileID, FILE *headerFP, int imageID, int maxIndices) { int fileCount = 1; struct defmodule *theModule; DEFINSTANCES *theDefinstances; int moduleCount = 0, moduleArrayCount = 0, moduleArrayVersion = 1; int definstancesArrayCount = 0, definstancesArrayVersion = 1; FILE *moduleFile = NULL, *definstancesFile = NULL; /* ================================================ Include the appropriate definstances header file ================================================ */ fprintf(headerFP,"#include \"defins.h\"\n"); /* ============================================================= Loop through all the modules and all the definstances writing their C code representation to the file as they are traversed ============================================================= */ theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); while (theModule != NULL) { EnvSetCurrentModule(theEnv,(void *) theModule); moduleFile = OpenFileIfNeeded(theEnv,moduleFile,fileName,pathName,fileNameBuffer,fileID,imageID,&fileCount, moduleArrayVersion,headerFP, (char*)"DEFINSTANCES_MODULE",ModulePrefix(DefinstancesData(theEnv)->DefinstancesCodeItem), FALSE,NULL); if (moduleFile == NULL) { CloseDefinstancesFiles(theEnv,moduleFile,definstancesFile,maxIndices); return(0); } DefinstancesModuleToCode(theEnv,moduleFile,theModule,imageID,maxIndices); moduleFile = CloseFileIfNeeded(theEnv,moduleFile,&moduleArrayCount,&moduleArrayVersion, maxIndices,NULL,NULL); theDefinstances = (DEFINSTANCES *) EnvGetNextDefinstances(theEnv,NULL); while (theDefinstances != NULL) { definstancesFile = OpenFileIfNeeded(theEnv,definstancesFile,fileName,pathName,fileNameBuffer,fileID,imageID,&fileCount, definstancesArrayVersion,headerFP, (char*)"DEFINSTANCES",ConstructPrefix(DefinstancesData(theEnv)->DefinstancesCodeItem), FALSE,NULL); if (definstancesFile == NULL) { CloseDefinstancesFiles(theEnv,moduleFile,definstancesFile,maxIndices); return(0); } SingleDefinstancesToCode(theEnv,definstancesFile,theDefinstances,imageID, maxIndices,moduleCount); definstancesArrayCount++; definstancesFile = CloseFileIfNeeded(theEnv,definstancesFile,&definstancesArrayCount, &definstancesArrayVersion,maxIndices,NULL,NULL); theDefinstances = (DEFINSTANCES *) EnvGetNextDefinstances(theEnv,theDefinstances); } theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule); moduleCount++; moduleArrayCount++; } CloseDefinstancesFiles(theEnv,moduleFile,definstancesFile,maxIndices); return(1); }
/*************************************************** NAME : ReadyDefinstancesForCode DESCRIPTION : Sets index of deffunctions for use in compiled expressions INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : BsaveIndices set NOTES : None ***************************************************/ static void ReadyDefinstancesForCode( void *theEnv) { MarkConstructBsaveIDs(theEnv,DefinstancesData(theEnv)->DefinstancesModuleIndex); }
/***************************************************************** NAME : GetDefinstancesModuleCommand DESCRIPTION : Determines to which module a definstances belongs INPUTS : None RETURNS : The symbolic name of the module SIDE EFFECTS : None NOTES : H/L Syntax: (definstances-module <defins-name>) *****************************************************************/ globle void *GetDefinstancesModuleCommand( void *theEnv) { return(GetConstructModuleCommand(theEnv,(char*)"definstances-module",DefinstancesData(theEnv)->DefinstancesConstruct)); }
/*********************************************************** NAME : UndefinstancesCommand DESCRIPTION : Removes a definstance INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : Definstance deallocated NOTES : H/L Syntax : (undefinstances <name> | *) ***********************************************************/ globle void UndefinstancesCommand( void *theEnv) { UndefconstructCommand(theEnv,(char*)"undefinstances",DefinstancesData(theEnv)->DefinstancesConstruct); }
/*************************************************** NAME : ResetDefinstances DESCRIPTION : Calls EvaluateExpression for each of the make-instance calls in all of the definstances constructs INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : All instances in the definstances are evaluated (and created if there are no errors) Any previously existing instances are deleted first. NOTES : None ***************************************************/ static void ResetDefinstances( void *theEnv) { DoForAllConstructs(theEnv,ResetDefinstancesAction,DefinstancesData(theEnv)->DefinstancesModuleIndex,TRUE,NULL); }
/*************************************************************** NAME : PPDefinstancesCommand DESCRIPTION : Prints out the pretty-print form of a definstance INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : None NOTES : H/L Syntax : (ppdefinstances <name>) ***************************************************************/ globle void PPDefinstancesCommand( void *theEnv) { PPConstructCommand(theEnv,(char*)"ppdefinstances",DefinstancesData(theEnv)->DefinstancesConstruct); }
/*************************************************** NAME : ListDefinstancesCommand DESCRIPTION : Displays all definstances names INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : Definstances name sprinted NOTES : H/L Interface ***************************************************/ globle void ListDefinstancesCommand( void *theEnv) { ListConstructCommand(theEnv,(char*)"list-definstances",DefinstancesData(theEnv)->DefinstancesConstruct); }
/*************************************************** NAME : SetupDefinstances DESCRIPTION : Adds the definstance support routines to the Kernel INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : Appropriate function lists modified NOTES : None ***************************************************/ globle void SetupDefinstances( void *theEnv) { AllocateEnvironmentData(theEnv,DEFINSTANCES_DATA,sizeof(struct definstancesData),DeallocateDefinstancesData); DefinstancesData(theEnv)->DefinstancesModuleIndex = RegisterModuleItem(theEnv,(char*)"definstances", #if (! RUN_TIME) AllocateModule,ReturnModule, #else NULL,NULL, #endif #if BLOAD_AND_BSAVE || BLOAD || BLOAD_ONLY BloadDefinstancesModuleRef, #else NULL, #endif #if CONSTRUCT_COMPILER && (! RUN_TIME) DefinstancesCModuleReference, #else NULL, #endif EnvFindDefinstances); DefinstancesData(theEnv)->DefinstancesConstruct = AddConstruct(theEnv,(char*)"definstances",(char*)"definstances", #if (! BLOAD_ONLY) && (! RUN_TIME) ParseDefinstances, #else NULL, #endif EnvFindDefinstances, GetConstructNamePointer,GetConstructPPForm, GetConstructModuleItem,EnvGetNextDefinstances,SetNextConstruct, EnvIsDefinstancesDeletable,EnvUndefinstances, #if (! BLOAD_ONLY) && (! RUN_TIME) RemoveDefinstances #else NULL #endif ); #if ! RUN_TIME AddClearReadyFunction(theEnv,(char*)"definstances",ClearDefinstancesReady,0); #if ! BLOAD_ONLY EnvDefineFunction2(theEnv,(char*)"undefinstances",'v',PTIEF UndefinstancesCommand,(char*)"UndefinstancesCommand",(char*)"11w"); AddSaveFunction(theEnv,(char*)"definstances",SaveDefinstances,0); #if DEFRULE_CONSTRUCT EnvAddClearFunction(theEnv,(char*)"definstances",CreateInitialDefinstances,-1000); #endif #endif #if DEBUGGING_FUNCTIONS EnvDefineFunction2(theEnv,(char*)"ppdefinstances",'v',PTIEF PPDefinstancesCommand ,(char*)"PPDefinstancesCommand",(char*)"11w"); EnvDefineFunction2(theEnv,(char*)"list-definstances",'v',PTIEF ListDefinstancesCommand,(char*)"ListDefinstancesCommand",(char*)"01"); #endif EnvDefineFunction2(theEnv,(char*)"get-definstances-list",'m',PTIEF GetDefinstancesListFunction, (char*)"GetDefinstancesListFunction",(char*)"01"); EnvDefineFunction2(theEnv,(char*)"definstances-module",'w',PTIEF GetDefinstancesModuleCommand, (char*)"GetDefinstancesModuleCommand",(char*)"11w"); #endif EnvAddResetFunction(theEnv,(char*)"definstances",(void (*)(void *)) ResetDefinstances,0); #if BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE SetupDefinstancesBload(theEnv); #endif #if CONSTRUCT_COMPILER && (! RUN_TIME) SetupDefinstancesCompiler(theEnv); #endif }
/**************************************************************** NAME : GetDefinstancesListFunction DESCRIPTION : Groups all definstances names into a multifield list INPUTS : A data object buffer to hold the multifield result RETURNS : Nothing useful SIDE EFFECTS : Multifield allocated and filled NOTES : H/L Syntax: (get-definstances-list [<module>]) ****************************************************************/ globle void GetDefinstancesListFunction( void *theEnv, DATA_OBJECT*returnValue) { GetConstructListFunction(theEnv,(char*)"get-definstances-list",returnValue,DefinstancesData(theEnv)->DefinstancesConstruct); }