static void DeallocateDeffunctionData( void *theEnv) { #if ! RUN_TIME struct deffunctionModule *theModuleItem; void *theModule; #if BLOAD || BLOAD_AND_BSAVE if (Bloaded(theEnv)) return; #endif DoForAllConstructs(theEnv,DestroyDeffunctionAction,DeffunctionData(theEnv)->DeffunctionModuleIndex,FALSE,NULL); for (theModule = EnvGetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = EnvGetNextDefmodule(theEnv,theModule)) { theModuleItem = (struct deffunctionModule *) GetModuleItem(theEnv,(struct defmodule *) theModule, DeffunctionData(theEnv)->DeffunctionModuleIndex); rtn_struct(theEnv,deffunctionModule,theModuleItem); } #else #endif }
/*************************************************** NAME : SingleDeffunctionToCode DESCRIPTION : Writes out a single deffunction's data to the file INPUTS : 1) The output file 2) The deffunction 3) The compile image id 4) The maximum number of elements in an array 5) The module index RETURNS : Nothing useful SIDE EFFECTS : Deffunction data written NOTES : None ***************************************************/ static void SingleDeffunctionToCode( void *theEnv, FILE *theFile, DEFFUNCTION *theDeffunction, int imageID, int maxIndices, int moduleCount) { /* ================== Deffunction Header ================== */ fprintf(theFile,"{"); ConstructHeaderToCode(theEnv,theFile,&theDeffunction->header,imageID,maxIndices,moduleCount, ModulePrefix(DeffunctionData(theEnv)->DeffunctionCodeItem), ConstructPrefix(DeffunctionData(theEnv)->DeffunctionCodeItem)); /* ========================= Deffunction specific data ========================= */ fprintf(theFile,",0,0,0,"); ExpressionToCode(theEnv,theFile,theDeffunction->code); fprintf(theFile,",%d,%d,%d", theDeffunction->minNumberOfParameters, theDeffunction->maxNumberOfParameters, theDeffunction->numberOfLocalVars); fprintf(theFile,"}"); }
static void DeallocateDeffunctionData( void *theEnv, EXEC_STATUS) { #if ! RUN_TIME struct deffunctionModule *theModuleItem; void *theModule; #if BLOAD || BLOAD_AND_BSAVE if (Bloaded(theEnv,execStatus)) return; #endif DoForAllConstructs(theEnv,execStatus,DestroyDeffunctionAction,DeffunctionData(theEnv,execStatus)->DeffunctionModuleIndex,FALSE,NULL); for (theModule = EnvGetNextDefmodule(theEnv,execStatus,NULL); theModule != NULL; theModule = EnvGetNextDefmodule(theEnv,execStatus,theModule)) { theModuleItem = (struct deffunctionModule *) GetModuleItem(theEnv,execStatus,(struct defmodule *) theModule, DeffunctionData(theEnv,execStatus)->DeffunctionModuleIndex); rtn_struct(theEnv,execStatus,deffunctionModule,theModuleItem); } #else #if MAC_MCW || WIN_MCW || MAC_XCD #pragma unused(theEnv,execStatus) #endif #endif }
/*************************************************************** NAME : GetDeffunctionListFunction DESCRIPTION : Groups all deffunction 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-deffunction-list [<module>]) ***************************************************************/ globle void GetDeffunctionListFunction( void *theEnv, EXEC_STATUS, DATA_OBJECT *returnValue) { GetConstructListFunction(theEnv,execStatus,"get-deffunction-list",returnValue,DeffunctionData(theEnv,execStatus)->DeffunctionConstruct); }
/*************************************************** NAME : LookupDeffunctionInScope DESCRIPTION : Finds a deffunction in current or imported modules (module specifier is not allowed) INPUTS : The deffunction name RETURNS : The deffunction (NULL if not found) SIDE EFFECTS : Error message printed on ambiguous references NOTES : None ***************************************************/ globle DEFFUNCTION *LookupDeffunctionInScope( void *theEnv, EXEC_STATUS, char *deffunctionName) { return((DEFFUNCTION *) LookupConstruct(theEnv,execStatus,DeffunctionData(theEnv,execStatus)->DeffunctionConstruct,deffunctionName,FALSE)); }
/*************************************************** NAME : BsaveDeffunctionExpressions 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 BsaveDeffunctionExpressions( void *theEnv, FILE *fp) { DoForAllConstructs(theEnv,BsaveDeffunctionExpression,DeffunctionData(theEnv)->DeffunctionModuleIndex, FALSE,(void *) fp); }
/*************************************************** NAME : EnvListDeffunctions DESCRIPTION : Displays all deffunction names INPUTS : 1) The logical name of the output 2) The module RETURNS : Nothing useful SIDE EFFECTS : Deffunction name sprinted NOTES : C Interface ***************************************************/ globle void EnvListDeffunctions( void *theEnv, char *logicalName, struct defmodule *theModule) { ListConstruct(theEnv,DeffunctionData(theEnv)->DeffunctionConstruct,logicalName,theModule); }
/*************************************************** NAME : UpdateDeffunction DESCRIPTION : Updates deffunction with binary load data - sets pointers from offset information INPUTS : 1) A pointer to the bloaded data 2) The index of the binary array element to update RETURNS : Nothing useful SIDE EFFECTS : Deffunction pointers upadted NOTES : None ***************************************************/ static void UpdateDeffunction( void *theEnv, void *buf, long obji) { BSAVE_DEFFUNCTION *bdptr; DEFFUNCTION *dptr; bdptr = (BSAVE_DEFFUNCTION *) buf; dptr = (DEFFUNCTION *) &DeffunctionBinaryData(theEnv)->DeffunctionArray[obji]; UpdateConstructHeader(theEnv,&bdptr->header,&dptr->header, (int) sizeof(DEFFUNCTION_MODULE),(void *) DeffunctionBinaryData(theEnv)->ModuleArray, (int) sizeof(DEFFUNCTION),(void *) DeffunctionBinaryData(theEnv)->DeffunctionArray); dptr->code = ExpressionPointer(bdptr->code); dptr->busy = 0; dptr->executing = 0; #if DEBUGGING_FUNCTIONS dptr->trace = (unsigned short) DeffunctionData(theEnv)->WatchDeffunctions; #endif dptr->minNumberOfParameters = bdptr->minNumberOfParameters; dptr->maxNumberOfParameters = bdptr->maxNumberOfParameters; dptr->numberOfLocalVars = bdptr->numberOfLocalVars; }
/*************************************************************** NAME : EnvGetDeffunctionList DESCRIPTION : Groups all deffunction names into a multifield list INPUTS : 1) A data object buffer to hold the multifield result 2) The module from which to obtain deffunctions RETURNS : Nothing useful SIDE EFFECTS : Multifield allocated and filled NOTES : External C access ***************************************************************/ globle void EnvGetDeffunctionList( void *theEnv, DATA_OBJECT *returnValue, struct defmodule *theModule) { GetConstructList(theEnv,returnValue,DeffunctionData(theEnv)->DeffunctionConstruct,theModule); }
/*************************************************** NAME : SaveDeffunctions DESCRIPTION : Writes out deffunctions for (save) command INPUTS : The logical output name RETURNS : Nothing useful SIDE EFFECTS : Writes out deffunctions NOTES : None ***************************************************/ static void SaveDeffunctions( void *theEnv, void *theModule, char *logicalName) { SaveConstruct(theEnv,theModule,logicalName,DeffunctionData(theEnv)->DeffunctionConstruct); }
/******************************************************* NAME : UnboundDeffunctionErr DESCRIPTION : Print out a synopis of the currently executing deffunction for unbound variable errors INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : Error synopsis printed to WERROR NOTES : None *******************************************************/ static void UnboundDeffunctionErr( void *theEnv) { EnvPrintRouter(theEnv,WERROR,"deffunction "); EnvPrintRouter(theEnv,WERROR,EnvGetDeffunctionName(theEnv,(void *) DeffunctionData(theEnv)->ExecutingDeffunction)); EnvPrintRouter(theEnv,WERROR,".\n"); }
/*************************************************** NAME : EnvFindDeffunction DESCRIPTION : Searches for a deffunction INPUTS : The name of the deffunction (possibly including a module name) RETURNS : Pointer to the deffunction if found, otherwise NULL SIDE EFFECTS : None NOTES : None ***************************************************/ globle void *EnvFindDeffunction( void *theEnv, EXEC_STATUS, char *dfnxModuleAndName) { return(FindNamedConstruct(theEnv,execStatus,dfnxModuleAndName,DeffunctionData(theEnv,execStatus)->DeffunctionConstruct)); }
/*************************************************************** NAME : EnvGetDeffunctionList DESCRIPTION : Groups all deffunction names into a multifield list INPUTS : 1) A data object buffer to hold the multifield result 2) The module from which to obtain deffunctions RETURNS : Nothing useful SIDE EFFECTS : Multifield allocated and filled NOTES : External C access ***************************************************************/ globle void EnvGetDeffunctionList( void *theEnv, EXEC_STATUS, DATA_OBJECT *returnValue, struct defmodule *theModule) { GetConstructList(theEnv,execStatus,returnValue,DeffunctionData(theEnv,execStatus)->DeffunctionConstruct,theModule); }
/*************************************************** NAME : WatchDeffunction DESCRIPTION : Displays a message indicating when a deffunction began and ended execution INPUTS : The beginning or end trace string to print when deffunction starts or finishes respectively RETURNS : Nothing useful SIDE EFFECTS : Watch message printed NOTES : None ***************************************************/ static void WatchDeffunction( void *theEnv, char *tstring) { EnvPrintRouter(theEnv,WTRACE,"DFN "); EnvPrintRouter(theEnv,WTRACE,tstring); if (DeffunctionData(theEnv)->ExecutingDeffunction->header.whichModule->theModule != ((struct defmodule *) EnvGetCurrentModule(theEnv))) { EnvPrintRouter(theEnv,WTRACE,EnvGetDefmoduleName(theEnv,(void *) DeffunctionData(theEnv)->ExecutingDeffunction->header.whichModule->theModule)); EnvPrintRouter(theEnv,WTRACE,"::"); } EnvPrintRouter(theEnv,WTRACE,ValueToString(DeffunctionData(theEnv)->ExecutingDeffunction->header.name)); EnvPrintRouter(theEnv,WTRACE," ED:"); PrintLongInteger(theEnv,WTRACE,(long long) EvaluationData(theEnv)->CurrentEvaluationDepth); PrintProcParamArray(theEnv,WTRACE); }
/*************************************************** NAME : EnvListDeffunctions DESCRIPTION : Displays all deffunction names INPUTS : 1) The logical name of the output 2) The module RETURNS : Nothing useful SIDE EFFECTS : Deffunction name sprinted NOTES : C Interface ***************************************************/ globle void EnvListDeffunctions( void *theEnv, EXEC_STATUS, char *logicalName, struct defmodule *theModule) { ListConstruct(theEnv,execStatus,DeffunctionData(theEnv,execStatus)->DeffunctionConstruct,logicalName,theModule); }
/*************************************************** NAME : SaveDeffunctions DESCRIPTION : Writes out deffunctions for (save) command INPUTS : The logical output name RETURNS : Nothing useful SIDE EFFECTS : Writes out deffunctions NOTES : None ***************************************************/ static void SaveDeffunctions( void *theEnv, EXEC_STATUS, void *theModule, char *logicalName) { SaveConstruct(theEnv,execStatus,theModule,logicalName,DeffunctionData(theEnv,execStatus)->DeffunctionConstruct); }
/*************************************************** NAME : ReturnModule DESCRIPTION : Removes a deffunction module and all associated deffunctions INPUTS : The deffunction module RETURNS : Nothing useful SIDE EFFECTS : Module and deffunctions deleted NOTES : None ***************************************************/ static void ReturnModule( void *theEnv, void *theItem) { #if (! BLOAD_ONLY) FreeConstructHeaderModule(theEnv,(struct defmoduleItemHeader *) theItem,DeffunctionData(theEnv)->DeffunctionConstruct); #endif rtn_struct(theEnv,deffunctionModule,theItem); }
/*************************************************** NAME : SaveDeffunctionHeaders DESCRIPTION : Writes out deffunction forward declarations for (save) command INPUTS : The logical output name RETURNS : Nothing useful SIDE EFFECTS : Writes out deffunctions with no body of actions NOTES : Used for deffunctions which are mutually recursive with other constructs ***************************************************/ static void SaveDeffunctionHeaders( void *theEnv, void *theModule, char *logicalName) { DoForAllConstructsInModule(theEnv,theModule,SaveDeffunctionHeader, DeffunctionData(theEnv)->DeffunctionModuleIndex, FALSE,(void *) logicalName); }
/*********************************************************************** NAME : DeffunctionWatchPrint DESCRIPTION : Parses a list of deffunction names passed by AddWatchItem() and displays the traces accordingly INPUTS : 1) The logical name of the output 2) A code indicating which trace flag is to be examined Ignored 3) A list of expressions containing the names of the deffunctions for which to examine traces RETURNS : TRUE if all OK, FALSE otherwise SIDE EFFECTS : Watch flags displayed for specified deffunctions NOTES : Accessory function for AddWatchItem() ***********************************************************************/ static unsigned DeffunctionWatchPrint( void *theEnv, char *logName, int code, EXPRESSION *argExprs) { return(ConstructPrintWatchAccess(theEnv,DeffunctionData(theEnv)->DeffunctionConstruct,logName,argExprs, EnvGetDeffunctionWatch,EnvSetDeffunctionWatch)); }
/****************************************************************** NAME : DeffunctionWatchAccess DESCRIPTION : Parses a list of deffunction names passed by AddWatchItem() and sets the traces accordingly INPUTS : 1) A code indicating which trace flag is to be set Ignored 2) The value to which to set the trace flags 3) A list of expressions containing the names of the deffunctions for which to set traces RETURNS : TRUE if all OK, FALSE otherwise SIDE EFFECTS : Watch flags set in specified deffunctions NOTES : Accessory function for AddWatchItem() ******************************************************************/ static unsigned DeffunctionWatchAccess( void *theEnv, int code, unsigned newState, EXPRESSION *argExprs) { return(ConstructSetWatchAccess(theEnv,DeffunctionData(theEnv)->DeffunctionConstruct,newState,argExprs, EnvGetDeffunctionWatch,EnvSetDeffunctionWatch)); }
/*************************************************************************** NAME : BsaveDeffunctionFind DESCRIPTION : For all deffunctions, this routine marks all the needed symbols. Also, it also counts the number of expression structures needed. Also, counts total number of deffunctions. 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 deffunction (assumes deffunctions will be bsaved in order of binary list) ***************************************************************************/ static void BsaveDeffunctionFind( void *theEnv) { SaveBloadCount(theEnv,DeffunctionBinaryData(theEnv)->ModuleCount); SaveBloadCount(theEnv,DeffunctionBinaryData(theEnv)->DeffunctionCount); DeffunctionBinaryData(theEnv)->DeffunctionCount = 0L; DeffunctionBinaryData(theEnv)->ModuleCount = DoForAllConstructs(theEnv,MarkDeffunctionItems,DeffunctionData(theEnv)->DeffunctionModuleIndex, FALSE,NULL); }
/*************************************************** NAME : DeffunctionModuleToCode DESCRIPTION : Writes out the C values for a deffunction module item INPUTS : 1) The output file 2) The module for the deffunctions 3) The compile image id 4) The maximum number of elements in an array RETURNS : Nothing useful SIDE EFFECTS : Deffunction module item written NOTES : None ***************************************************/ static void DeffunctionModuleToCode( void *theEnv, FILE *theFile, struct defmodule *theModule, int imageID, int maxIndices) { fprintf(theFile,"{"); ConstructModuleToCode(theEnv,theFile,theModule,imageID,maxIndices, DeffunctionData(theEnv)->DeffunctionModuleIndex,ConstructPrefix(DeffunctionData(theEnv)->DeffunctionCodeItem)); fprintf(theFile,"}"); }
/**************************************************** NAME : DeffunctionCModuleReference DESCRIPTION : Prints out a reference to a deffunction 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 : Deffunction module reference printed NOTES : None ****************************************************/ void DeffunctionCModuleReference( void *theEnv, FILE *theFile, int count, int imageID, int maxIndices) { fprintf(theFile,"MIHS &%s%d_%d[%d]", ModulePrefix(DeffunctionData(theEnv)->DeffunctionCodeItem), imageID, (count / maxIndices) + 1, (count % maxIndices)); }
/*************************************************** NAME : PrintDeffunctionReference DESCRIPTION : Prints a reference to the run-time deffunction array for the construct compiler INPUTS : 1) The file output destination 2) A pointer to the deffunction 3) The id of the run-time image 4) The maximum number of indices in any array RETURNS : Nothing useful SIDE EFFECTS : Reference printed NOTES : None ***************************************************/ void PrintDeffunctionReference( void *theEnv, FILE *fp, DEFFUNCTION *dfPtr, int imageID, int maxIndices) { if (dfPtr == NULL) fprintf(fp,"NULL"); else fprintf(fp,"&%s%d_%d[%d]",ConstructPrefix(DeffunctionData(theEnv)->DeffunctionCodeItem),imageID, (int) ((dfPtr->header.bsaveID / maxIndices) + 1), (int) (dfPtr->header.bsaveID % maxIndices)); }
static unsigned DeffunctionWatchAccess( void *theEnv, EXEC_STATUS, int code, unsigned newState, EXPRESSION *argExprs) { #if MAC_MCW || WIN_MCW || MAC_XCD #pragma unused(code) #endif return(ConstructSetWatchAccess(theEnv,execStatus,DeffunctionData(theEnv,execStatus)->DeffunctionConstruct,newState,argExprs, EnvGetDeffunctionWatch,EnvSetDeffunctionWatch)); }
/************************************************************************************* NAME : BsaveDeffunctions DESCRIPTION : Writes out deffunction in binary format Space required (unsigned long) All deffunctions (sizeof(DEFFUNCTION) * Number of deffunctions) INPUTS : File pointer of binary file RETURNS : Nothing useful SIDE EFFECTS : Binary file adjusted NOTES : None *************************************************************************************/ static void BsaveDeffunctions( void *theEnv, FILE *fp) { size_t space; struct defmodule *theModule; DEFFUNCTION_MODULE *theModuleItem; BSAVE_DEFFUNCTION_MODULE dummy_mitem; space = ((sizeof(BSAVE_DEFFUNCTION_MODULE) * DeffunctionBinaryData(theEnv)->ModuleCount) + (sizeof(BSAVE_DEFFUNCTION) * DeffunctionBinaryData(theEnv)->DeffunctionCount)); GenWrite((void *) &space,sizeof(size_t),fp); /* ================================= Write out each deffunction module ================================= */ DeffunctionBinaryData(theEnv)->DeffunctionCount = 0L; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); while (theModule != NULL) { theModuleItem = (DEFFUNCTION_MODULE *) GetModuleItem(theEnv,theModule,FindModuleItem(theEnv,"deffunction")->moduleIndex); AssignBsaveDefmdlItemHdrVals(&dummy_mitem.header,&theModuleItem->header); GenWrite((void *) &dummy_mitem,sizeof(BSAVE_DEFFUNCTION_MODULE),fp); theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,(void *) theModule); } /* ========================== Write out each deffunction ========================== */ DoForAllConstructs(theEnv,BsaveDeffunction,DeffunctionData(theEnv)->DeffunctionModuleIndex, FALSE,(void *) fp); RestoreBloadCount(theEnv,&DeffunctionBinaryData(theEnv)->ModuleCount); RestoreBloadCount(theEnv,&DeffunctionBinaryData(theEnv)->DeffunctionCount); }
/*************************************************** NAME : ClearDeffunctionsReady DESCRIPTION : Determines if it is safe to remove all deffunctions Assumes *all* constructs will be deleted - only checks to see if any deffunctions are currently executing INPUTS : None RETURNS : TRUE if no deffunctions are executing, FALSE otherwise SIDE EFFECTS : None NOTES : Used by (clear) and (bload) ***************************************************/ static intBool ClearDeffunctionsReady( void *theEnv) { return((DeffunctionData(theEnv)->ExecutingDeffunction != NULL) ? FALSE : TRUE); }
/*************************************************************** NAME : GetDeffunctionListFunction DESCRIPTION : Groups all deffunction 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-deffunction-list [<module>]) ***************************************************************/ globle void GetDeffunctionListFunction( void *theEnv, DATA_OBJECT *returnValue) { GetConstructListFunction(theEnv,(char*)"get-deffunction-list",returnValue,DeffunctionData(theEnv)->DeffunctionConstruct); }
/*************************************************** NAME : ListDeffunctionsCommand DESCRIPTION : Displays all deffunction names INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : Deffunction name sprinted NOTES : H/L Interface ***************************************************/ globle void ListDeffunctionsCommand( void *theEnv) { ListConstructCommand(theEnv,(char*)"list-deffunctions",DeffunctionData(theEnv)->DeffunctionConstruct); }
/**************************************************** NAME : PPDeffunctionCommand DESCRIPTION : Displays the pretty-print form of a deffunction INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : Pretty-print form displayed to WDISPLAY logical name NOTES : H/L Syntax: (ppdeffunction <name>) ****************************************************/ globle void PPDeffunctionCommand( void *theEnv) { PPConstructCommand(theEnv,(char*)"ppdeffunction",DeffunctionData(theEnv)->DeffunctionConstruct); }