static void DeallocateDefglobalData( void *theEnv) { #if ! RUN_TIME struct defglobalModule *theModuleItem; void *theModule; #if BLOAD || BLOAD_AND_BSAVE if (Bloaded(theEnv)) return; #endif DoForAllConstructs(theEnv,DestroyDefglobalAction,DefglobalData(theEnv)->DefglobalModuleIndex,FALSE,NULL); for (theModule = EnvGetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = EnvGetNextDefmodule(theEnv,theModule)) { theModuleItem = (struct defglobalModule *) GetModuleItem(theEnv,(struct defmodule *) theModule, DefglobalData(theEnv)->DefglobalModuleIndex); rtn_struct(theEnv,defglobalModule,theModuleItem); } #else DoForAllConstructs(theEnv,DestroyDefglobalAction,DefglobalData(theEnv)->DefglobalModuleIndex,FALSE,NULL); #endif }
globle intBool EnvSetResetGlobals( void *theEnv, int value) { int ov; ov = DefglobalData(theEnv)->ResetGlobals; DefglobalData(theEnv)->ResetGlobals = value; return(ov); }
static void ReturnModule( void *theEnv, void *theItem) { FreeConstructHeaderModule(theEnv,(struct defmoduleItemHeader *) theItem,DefglobalData(theEnv)->DefglobalConstruct); rtn_struct(theEnv,defglobalModule,theItem); }
globle void DefglobalBasicCommands( void *theEnv) { AddSaveFunction(theEnv,"defglobal",SaveDefglobals,40); EnvAddResetFunction(theEnv,"defglobal",ResetDefglobals,50); #if ! RUN_TIME EnvDefineFunction2(theEnv,"get-defglobal-list",'m',PTIEF GetDefglobalListFunction,"GetDefglobalListFunction","01w"); EnvDefineFunction2(theEnv,"undefglobal",'v',PTIEF UndefglobalCommand,"UndefglobalCommand","11w"); EnvDefineFunction2(theEnv,"defglobal-module",'w',PTIEF DefglobalModuleFunction,"DefglobalModuleFunction","11w"); #if DEBUGGING_FUNCTIONS EnvDefineFunction2(theEnv,"list-defglobals",'v', PTIEF ListDefglobalsCommand,"ListDefglobalsCommand","01w"); EnvDefineFunction2(theEnv,"ppdefglobal",'v',PTIEF PPDefglobalCommand,"PPDefglobalCommand","11w"); AddWatchItem(theEnv,"globals",0,&DefglobalData(theEnv)->WatchGlobals,0,DefglobalWatchAccess,DefglobalWatchPrint); #endif #if (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) DefglobalBinarySetup(theEnv); #endif #if CONSTRUCT_COMPILER && (! RUN_TIME) DefglobalCompilerSetup(theEnv); #endif #endif }
globle int PPDefglobal( void *theEnv, const char *defglobalName, const char *logicalName) { return(PPConstruct(theEnv,defglobalName,logicalName,DefglobalData(theEnv)->DefglobalConstruct)); }
globle void EnvGetDefglobalList( void *theEnv, DATA_OBJECT_PTR returnValue, void *theModule) { GetConstructList(theEnv,returnValue,DefglobalData(theEnv)->DefglobalConstruct,(struct defmodule *) theModule); }
static void SaveDefglobals( void *theEnv, void *theModule, const char *logicalName) { SaveConstruct(theEnv,theModule,logicalName,DefglobalData(theEnv)->DefglobalConstruct); }
globle void DefglobalCompilerSetup( void *theEnv) { DefglobalData(theEnv)->DefglobalCodeItem = AddCodeGeneratorItem(theEnv,"defglobal",0,BeforeDefglobalsToCode, InitDefglobalsCode,ConstructToCode,2); }
globle void DefglobalCompilerSetup( void *theEnv, EXEC_STATUS) { DefglobalData(theEnv,execStatus)->DefglobalCodeItem = AddCodeGeneratorItem(theEnv,execStatus,"defglobal",0,BeforeDefglobalsToCode, InitDefglobalsCode,ConstructToCode,2); }
globle void EnvListDefglobals( void *theEnv, const char *logicalName, void *vTheModule) { struct defmodule *theModule = (struct defmodule *) vTheModule; ListConstruct(theEnv,DefglobalData(theEnv)->DefglobalConstruct,logicalName,theModule); }
static void DefglobalToCode( void *theEnv, EXEC_STATUS, FILE *theFile, struct defglobal *theDefglobal, int imageID, int maxIndices, int moduleCount) { /*==================*/ /* Defglobal Header */ /*==================*/ fprintf(theFile,"{"); ConstructHeaderToCode(theEnv,execStatus,theFile,&theDefglobal->header,imageID,maxIndices, moduleCount,ModulePrefix(DefglobalData(theEnv,execStatus)->DefglobalCodeItem), ConstructPrefix(DefglobalData(theEnv,execStatus)->DefglobalCodeItem)); fprintf(theFile,","); /*============================================*/ /* Watch Flag, In Scope Flag, and Busy Count. */ /*============================================*/ fprintf(theFile,"0,0,%ld,",theDefglobal->busyCount); /*================*/ /* Current Value. */ /*================*/ fprintf(theFile,"{NULL,RVOID}"); /*=====================*/ /* Initial Expression. */ /*=====================*/ fprintf(theFile,","); PrintHashedExpressionReference(theEnv,execStatus,theFile,theDefglobal->initial,imageID,maxIndices); fprintf(theFile,"}"); }
static void DefglobalToCode( Environment *theEnv, FILE *theFile, Defglobal *theDefglobal, unsigned int imageID, unsigned int maxIndices, unsigned int moduleCount) { /*==================*/ /* Defglobal Header */ /*==================*/ fprintf(theFile,"{"); ConstructHeaderToCode(theEnv,theFile,&theDefglobal->header,imageID,maxIndices, moduleCount,ModulePrefix(DefglobalData(theEnv)->DefglobalCodeItem), ConstructPrefix(DefglobalData(theEnv)->DefglobalCodeItem)); fprintf(theFile,","); /*============================================*/ /* Watch Flag, In Scope Flag, and Busy Count. */ /*============================================*/ fprintf(theFile,"0,0,%ld,",theDefglobal->busyCount); /*================*/ /* Current Value. */ /*================*/ fprintf(theFile,"{ { NULL } }"); /*=====================*/ /* Initial Expression. */ /*=====================*/ fprintf(theFile,","); PrintHashedExpressionReference(theEnv,theFile,theDefglobal->initial,imageID,maxIndices); fprintf(theFile,"}"); }
static unsigned DefglobalWatchPrint( void *theEnv, const char *logName, int code, EXPRESSION *argExprs) { #if MAC_XCD #pragma unused(code) #endif return(ConstructPrintWatchAccess(theEnv,DefglobalData(theEnv)->DefglobalConstruct,logName,argExprs, EnvGetDefglobalWatch,EnvSetDefglobalWatch)); }
static unsigned DefglobalWatchAccess( void *theEnv, int code, unsigned newState, EXPRESSION *argExprs) { #if MAC_XCD #pragma unused(code) #endif return(ConstructSetWatchAccess(theEnv,DefglobalData(theEnv)->DefglobalConstruct,newState,argExprs, EnvGetDefglobalWatch,EnvSetDefglobalWatch)); }
void DefglobalCModuleReference( Environment *theEnv, FILE *theFile, unsigned long count, unsigned int imageID, unsigned int maxIndices) { fprintf(theFile,"MIHS &%s%u_%lu[%lu]", ModulePrefix(DefglobalData(theEnv)->DefglobalCodeItem), imageID, (count / maxIndices) + 1, (count % maxIndices)); }
globle void DefglobalCModuleReference( void *theEnv, FILE *theFile, int count, int imageID, int maxIndices) { fprintf(theFile,"MIHS &%s%d_%d[%d]", ModulePrefix(DefglobalData(theEnv)->DefglobalCodeItem), imageID, (count / maxIndices) + 1, (count % maxIndices)); }
void InitializeDefglobals( Environment *theEnv) { struct entityRecord globalInfo = { "GBL_VARIABLE", GBL_VARIABLE,0,0,0, NULL, NULL, NULL, (EntityEvaluationFunction *) EntityGetDefglobalValue, NULL,NULL, NULL,NULL,NULL,NULL,NULL,NULL }; struct entityRecord defglobalPtrRecord = { "DEFGLOBAL_PTR", DEFGLOBAL_PTR,0,0,0, NULL,NULL,NULL, (EntityEvaluationFunction *) QGetDefglobalUDFValue, NULL, (EntityBusyCountFunction *) DecrementDefglobalBusyCount, (EntityBusyCountFunction *) IncrementDefglobalBusyCount, NULL,NULL,NULL,NULL,NULL }; AllocateEnvironmentData(theEnv,DEFGLOBAL_DATA,sizeof(struct defglobalData),DeallocateDefglobalData); memcpy(&DefglobalData(theEnv)->GlobalInfo,&globalInfo,sizeof(struct entityRecord)); memcpy(&DefglobalData(theEnv)->DefglobalPtrRecord,&defglobalPtrRecord,sizeof(struct entityRecord)); DefglobalData(theEnv)->ResetGlobals = true; DefglobalData(theEnv)->LastModuleIndex = -1; InstallPrimitive(theEnv,&DefglobalData(theEnv)->GlobalInfo,GBL_VARIABLE); InstallPrimitive(theEnv,&DefglobalData(theEnv)->GlobalInfo,MF_GBL_VARIABLE); InstallPrimitive(theEnv,&DefglobalData(theEnv)->DefglobalPtrRecord,DEFGLOBAL_PTR); InitializeDefglobalModules(theEnv); DefglobalBasicCommands(theEnv); DefglobalCommandDefinitions(theEnv); DefglobalData(theEnv)->DefglobalConstruct = AddConstruct(theEnv,"defglobal","defglobals",ParseDefglobal, (FindConstructFunction *) FindDefglobal, GetConstructNamePointer,GetConstructPPForm, GetConstructModuleItem, (GetNextConstructFunction *) GetNextDefglobal, SetNextConstruct, (IsConstructDeletableFunction *) DefglobalIsDeletable, (DeleteConstructFunction *) Undefglobal, (FreeConstructFunction *) ReturnDefglobal); }
static void ReturnDefglobal( void *theEnv, void *vTheDefglobal) { #if (MAC_MCW || IBM_MCW) && (RUN_TIME || BLOAD_ONLY) #pragma unused(theEnv,vTheDefglobal) #endif #if (! BLOAD_ONLY) && (! RUN_TIME) struct defglobal *theDefglobal = (struct defglobal *) vTheDefglobal; if (theDefglobal == NULL) return; /*====================================*/ /* Return the global's current value. */ /*====================================*/ ValueDeinstall(theEnv,&theDefglobal->current); if (theDefglobal->current.type == MULTIFIELD) { ReturnMultifield(theEnv,(struct multifield *) theDefglobal->current.value); } /*================================================*/ /* Return the expression representing the initial */ /* value of the defglobal when it was defined. */ /*================================================*/ RemoveHashedExpression(theEnv,theDefglobal->initial); /*===============================*/ /* Release items stored in the */ /* defglobal's construct header. */ /*===============================*/ DeinstallConstructHeader(theEnv,&theDefglobal->header); /*======================================*/ /* Return the defglobal data structure. */ /*======================================*/ rtn_struct(theEnv,defglobal,theDefglobal); /*===========================================*/ /* Set the variable indicating that a change */ /* has been made to a global variable. */ /*===========================================*/ DefglobalData(theEnv)->ChangeToGlobals = TRUE; #endif }
static void ReturnDefglobal( Environment *theEnv, Defglobal *theDefglobal) { #if (! BLOAD_ONLY) && (! RUN_TIME) if (theDefglobal == NULL) return; /*====================================*/ /* Return the global's current value. */ /*====================================*/ Release(theEnv,theDefglobal->current.header); if (theDefglobal->current.header->type == MULTIFIELD_TYPE) { if (theDefglobal->current.multifieldValue->busyCount == 0) { ReturnMultifield(theEnv,theDefglobal->current.multifieldValue); } else { AddToMultifieldList(theEnv,theDefglobal->current.multifieldValue); } } /*================================================*/ /* Return the expression representing the initial */ /* value of the defglobal when it was defined. */ /*================================================*/ RemoveHashedExpression(theEnv,theDefglobal->initial); /*===============================*/ /* Release items stored in the */ /* defglobal's construct header. */ /*===============================*/ DeinstallConstructHeader(theEnv,&theDefglobal->header); /*======================================*/ /* Return the defglobal data structure. */ /*======================================*/ rtn_struct(theEnv,defglobal,theDefglobal); /*===========================================*/ /* Set the variable indicating that a change */ /* has been made to a global variable. */ /*===========================================*/ DefglobalData(theEnv)->ChangeToGlobals = true; #endif }
static void DefglobalModuleToCode( void *theEnv, FILE *theFile, struct defmodule *theModule, int imageID, int maxIndices, int moduleCount) { fprintf(theFile,"{"); ConstructModuleToCode(theEnv,theFile,theModule,imageID,maxIndices, DefglobalData(theEnv)->DefglobalModuleIndex,ConstructPrefix(DefglobalData(theEnv)->DefglobalCodeItem)); fprintf(theFile,"}"); }
void DefglobalCConstructReference( Environment *theEnv, FILE *theFile, Defglobal *theGlobal, unsigned int imageID, unsigned int maxIndices) { if (theGlobal == NULL) { fprintf(theFile,"NULL"); } else { fprintf(theFile,"&%s%u_%lu[%lu]",ConstructPrefix(DefglobalData(theEnv)->DefglobalCodeItem), imageID, (theGlobal->header.bsaveID / maxIndices) + 1, theGlobal->header.bsaveID % maxIndices); } }
static void DefglobalModuleToCode( Environment *theEnv, FILE *theFile, Defmodule *theModule, unsigned int imageID, unsigned int maxIndices, unsigned int moduleCount) { #if MAC_XCD #pragma unused(moduleCount) #endif fprintf(theFile,"{"); ConstructModuleToCode(theEnv,theFile,theModule,imageID,maxIndices, DefglobalData(theEnv)->DefglobalModuleIndex,ConstructPrefix(DefglobalData(theEnv)->DefglobalCodeItem)); fprintf(theFile,"}"); }
static void DefglobalModuleToCode( void *theEnv, FILE *theFile, struct defmodule *theModule, int imageID, int maxIndices, int moduleCount) { #if MAC_MCW || WIN_MCW || MAC_XCD #pragma unused(moduleCount) #endif fprintf(theFile,"{"); ConstructModuleToCode(theEnv,theFile,theModule,imageID,maxIndices, DefglobalData(theEnv)->DefglobalModuleIndex,ConstructPrefix(DefglobalData(theEnv)->DefglobalCodeItem)); fprintf(theFile,"}"); }
void UpdateDefglobalScope( Environment *theEnv) { Defglobal *theDefglobal; unsigned int moduleCount; Defmodule *theModule; struct defmoduleItemHeader *theItem; /*============================*/ /* Loop through every module. */ /*============================*/ for (theModule = GetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = GetNextDefmodule(theEnv,theModule)) { /*============================================================*/ /* Loop through every defglobal in the module being examined. */ /*============================================================*/ theItem = (struct defmoduleItemHeader *) GetModuleItem(theEnv,theModule,DefglobalData(theEnv)->DefglobalModuleIndex); for (theDefglobal = (Defglobal *) theItem->firstItem; theDefglobal != NULL ; theDefglobal = GetNextDefglobal(theEnv,theDefglobal)) { /*====================================================*/ /* If the defglobal is visible to the current module, */ /* then mark it as being in scope, otherwise mark it */ /* as being out of scope. */ /*====================================================*/ if (FindImportedConstruct(theEnv,"defglobal",theModule, theDefglobal->header.name->contents, &moduleCount,true,NULL) != NULL) { theDefglobal->inScope = true; } else { theDefglobal->inScope = false; } } } }
globle void DefglobalCConstructReference( void *theEnv, FILE *theFile, void *vTheGlobal, int imageID, int maxIndices) { struct defglobal *theGlobal = (struct defglobal *) vTheGlobal; if (theGlobal == NULL) { fprintf(theFile,"NULL"); } else { fprintf(theFile,"&%s%d_%ld[%ld]",ConstructPrefix(DefglobalData(theEnv)->DefglobalCodeItem), imageID, (theGlobal->header.bsaveID / maxIndices) + 1, theGlobal->header.bsaveID % maxIndices); } }
static void InitializeDefglobalModules( void *theEnv) { DefglobalData(theEnv)->DefglobalModuleIndex = RegisterModuleItem(theEnv,"defglobal", AllocateModule, ReturnModule, #if BLOAD_AND_BSAVE || BLOAD || BLOAD_ONLY BloadDefglobalModuleReference, #else NULL, #endif #if CONSTRUCT_COMPILER && (! RUN_TIME) DefglobalCModuleReference, #else NULL, #endif EnvFindDefglobal); #if (! BLOAD_ONLY) && (! RUN_TIME) && DEFMODULE_CONSTRUCT AddPortConstructItem(theEnv,"defglobal",SYMBOL); #endif }
globle void InitializeDefglobals( void *theEnv) { struct entityRecord globalInfo = { "GBL_VARIABLE", GBL_VARIABLE,0,0,0, NULL, NULL, NULL, GetDefglobalValue2, NULL,NULL, NULL,NULL,NULL }; struct entityRecord defglobalPtrRecord = { "DEFGLOBAL_PTR", DEFGLOBAL_PTR,0,0,0, NULL,NULL,NULL, QGetDefglobalValue, NULL, DecrementDefglobalBusyCount, IncrementDefglobalBusyCount, NULL,NULL,NULL,NULL }; AllocateEnvironmentData(theEnv,DEFGLOBAL_DATA,sizeof(struct defglobalData),DeallocateDefglobalData); memcpy(&DefglobalData(theEnv)->GlobalInfo,&globalInfo,sizeof(struct entityRecord)); memcpy(&DefglobalData(theEnv)->DefglobalPtrRecord,&defglobalPtrRecord,sizeof(struct entityRecord)); DefglobalData(theEnv)->ResetGlobals = TRUE; DefglobalData(theEnv)->LastModuleIndex = -1; InstallPrimitive(theEnv,&DefglobalData(theEnv)->GlobalInfo,GBL_VARIABLE); InstallPrimitive(theEnv,&DefglobalData(theEnv)->DefglobalPtrRecord,DEFGLOBAL_PTR); InitializeDefglobalModules(theEnv); DefglobalBasicCommands(theEnv); DefglobalCommandDefinitions(theEnv); DefglobalData(theEnv)->DefglobalConstruct = AddConstruct(theEnv,"defglobal","defglobals",ParseDefglobal,EnvFindDefglobal, GetConstructNamePointer,GetConstructPPForm, GetConstructModuleItem,EnvGetNextDefglobal,SetNextConstruct, EnvIsDefglobalDeletable,EnvUndefglobal,ReturnDefglobal); }
static int ConstructToCode( void *theEnv, char *fileName, char *pathName, char *fileNameBuffer, int fileID, FILE *headerFP, int imageID, int maxIndices) { int fileCount = 1; struct defmodule *theModule; struct defglobal *theDefglobal; int moduleCount = 0, moduleArrayCount = 0, moduleArrayVersion = 1; int defglobalArrayCount = 0, defglobalArrayVersion = 1; FILE *moduleFile = NULL, *defglobalFile = NULL; /*================================================*/ /* Include the appropriate defglobal header file. */ /*================================================*/ fprintf(headerFP,"#include \"globldef.h\"\n"); /*===================================================================*/ /* Loop through all the modules and all the defglobals writing their */ /* C code representation to the file as they are traversed. */ /*===================================================================*/ for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule)) { EnvSetCurrentModule(theEnv,(void *) theModule); moduleFile = OpenFileIfNeeded(theEnv,moduleFile,fileName,pathName,fileNameBuffer,fileID,imageID,&fileCount, moduleArrayVersion,headerFP, "struct defglobalModule",ModulePrefix(DefglobalData(theEnv)->DefglobalCodeItem), FALSE,NULL); if (moduleFile == NULL) { CloseDefglobalFiles(theEnv,moduleFile,defglobalFile,maxIndices); return(0); } DefglobalModuleToCode(theEnv,moduleFile,theModule,imageID,maxIndices,moduleCount); moduleFile = CloseFileIfNeeded(theEnv,moduleFile,&moduleArrayCount,&moduleArrayVersion, maxIndices,NULL,NULL); for (theDefglobal = (struct defglobal *) EnvGetNextDefglobal(theEnv,NULL); theDefglobal != NULL; theDefglobal = (struct defglobal *) EnvGetNextDefglobal(theEnv,theDefglobal)) { defglobalFile = OpenFileIfNeeded(theEnv,defglobalFile,fileName,pathName,fileNameBuffer,fileID,imageID,&fileCount, defglobalArrayVersion,headerFP, "struct defglobal",ConstructPrefix(DefglobalData(theEnv)->DefglobalCodeItem), FALSE,NULL); if (defglobalFile == NULL) { CloseDefglobalFiles(theEnv,moduleFile,defglobalFile,maxIndices); return(0); } DefglobalToCode(theEnv,defglobalFile,theDefglobal,imageID,maxIndices,moduleCount); defglobalArrayCount++; defglobalFile = CloseFileIfNeeded(theEnv,defglobalFile,&defglobalArrayCount, &defglobalArrayVersion,maxIndices,NULL,NULL); } moduleCount++; moduleArrayCount++; } CloseDefglobalFiles(theEnv,moduleFile,defglobalFile,maxIndices); return(1); }
static void BeforeDefglobalsToCode( void *theEnv) { MarkConstructBsaveIDs(theEnv,DefglobalData(theEnv)->DefglobalModuleIndex); }
globle void EnvSetGlobalsChanged( void *theEnv, int value) { DefglobalData(theEnv)->ChangeToGlobals = value; }