static void DestroyDefglobal( Environment *theEnv, Defglobal *theDefglobal) { if (theDefglobal == NULL) return; /*====================================*/ /* Return the global's current value. */ /*====================================*/ if (theDefglobal->current.header->type == MULTIFIELD_TYPE) { if (theDefglobal->current.multifieldValue->busyCount == 0) { ReturnMultifield(theEnv,theDefglobal->current.multifieldValue); } else { AddToMultifieldList(theEnv,theDefglobal->current.multifieldValue); } } #if (! RUN_TIME) /*===============================*/ /* Release items stored in the */ /* defglobal's construct header. */ /*===============================*/ DeinstallConstructHeader(theEnv,&theDefglobal->header); /*======================================*/ /* Return the defglobal data structure. */ /*======================================*/ rtn_struct(theEnv,defglobal,theDefglobal); #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 }
globle void CopyDataObject( DATA_OBJECT *dst, DATA_OBJECT *src, int garbageMultifield) { if (src->type != MULTIFIELD) { dst->type = src->type; dst->value = src->value; } else { DuplicateMultifield(dst,src); if (garbageMultifield) { AddToMultifieldList((struct multifield *) dst->value); } } }
void QSetDefglobalValue( Environment *theEnv, Defglobal *theGlobal, UDFValue *vPtr, bool resetVar) { CLIPSValue newValue; /*====================================================*/ /* If the new value passed for the defglobal is NULL, */ /* then reset the defglobal to the initial value it */ /* had when it was defined. */ /*====================================================*/ if (resetVar) { EvaluateExpression(theEnv,theGlobal->initial,vPtr); if (EvaluationData(theEnv)->EvaluationError) { vPtr->value = FalseSymbol(theEnv); } } /*==========================================*/ /* If globals are being watch, then display */ /* the change to the global variable. */ /*==========================================*/ #if DEBUGGING_FUNCTIONS if (theGlobal->watch && (! ConstructData(theEnv)->ClearReadyInProgress) && (! ConstructData(theEnv)->ClearInProgress)) { WriteString(theEnv,STDOUT,":== ?*"); WriteString(theEnv,STDOUT,theGlobal->header.name->contents); WriteString(theEnv,STDOUT,"* ==> "); WriteUDFValue(theEnv,STDOUT,vPtr); WriteString(theEnv,STDOUT," <== "); WriteCLIPSValue(theEnv,STDOUT,&theGlobal->current); WriteString(theEnv,STDOUT,"\n"); } #endif /*==============================================*/ /* Retain the new value of the global variable. */ /*==============================================*/ NormalizeMultifield(theEnv,vPtr); if (vPtr->header->type != MULTIFIELD_TYPE) { newValue.value = vPtr->value; } else { newValue.value = CopyMultifield(theEnv,vPtr->multifieldValue); } Retain(theEnv,newValue.header); /*==============================================*/ /* Remove the old value of the global variable. */ /*==============================================*/ Release(theEnv,theGlobal->current.header); if (theGlobal->current.header->type == MULTIFIELD_TYPE) { if (theGlobal->current.multifieldValue->busyCount == 0) { ReturnMultifield(theEnv,theGlobal->current.multifieldValue); } else { AddToMultifieldList(theEnv,theGlobal->current.multifieldValue); } } /*===========================================*/ /* Set the new value of the global variable. */ /*===========================================*/ theGlobal->current.value = newValue.value; /*===========================================*/ /* Set the variable indicating that a change */ /* has been made to a global variable. */ /*===========================================*/ DefglobalData(theEnv)->ChangeToGlobals = true; if (EvaluationData(theEnv)->CurrentExpression == NULL) { CleanCurrentGarbageFrame(theEnv,NULL); CallPeriodicTasks(theEnv); } }