globle void DefruleRunTimeInitialize( void *theEnv, struct joinLink *rightPrime, struct joinLink *leftPrime) { struct defmodule *theModule; struct defrule *theRule, *theDisjunct; DefruleData(theEnv)->RightPrimeJoins = rightPrime; DefruleData(theEnv)->LeftPrimeJoins = leftPrime; SaveCurrentModule(theEnv); for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule)) { EnvSetCurrentModule(theEnv,(void *) theModule); for (theRule = EnvGetNextDefrule(theEnv,NULL); theRule != NULL; theRule = EnvGetNextDefrule(theEnv,theRule)) { for (theDisjunct = theRule; theDisjunct != NULL; theDisjunct = theDisjunct->disjunct) { AddBetaMemoriesToRule(theEnv,theDisjunct->lastJoin); } } } RestoreCurrentModule(theEnv); }
globle intBool EnvSetIncrementalReset( void *theEnv, int value) { int ov; struct defmodule *theModule; SaveCurrentModule(theEnv); for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule)) { EnvSetCurrentModule(theEnv,(void *) theModule); if (EnvGetNextDefrule(theEnv,NULL) != NULL) { RestoreCurrentModule(theEnv); return(-1); } } RestoreCurrentModule(theEnv); ov = EngineData(theEnv)->IncrementalResetFlag; EngineData(theEnv)->IncrementalResetFlag = value; return(ov); }
static void BsaveExpressions( void *theEnv, FILE *fp) { struct deffacts *theDeffacts; struct defmodule *theModule; /*===========================*/ /* Loop through each module. */ /*===========================*/ for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule)) { /*======================================================*/ /* Set the current module to the module being examined. */ /*======================================================*/ EnvSetCurrentModule(theEnv,(void *) theModule); /*==================================================*/ /* Loop through each deffacts in the current module */ /* and save the assertion list expression. */ /*==================================================*/ for (theDeffacts = (struct deffacts *) EnvGetNextDeffacts(theEnv,NULL); theDeffacts != NULL; theDeffacts = (struct deffacts *) EnvGetNextDeffacts(theEnv,theDeffacts)) { BsaveExpression(theEnv,theDeffacts->assertList,fp); } } }
static void DeallocateDeffactsData( void *theEnv) { #if ! RUN_TIME struct deffactsModule *theModuleItem; void *theModule; #if BLOAD || BLOAD_AND_BSAVE if (Bloaded(theEnv)) return; #endif DoForAllConstructs(theEnv,DestroyDeffactsAction,DeffactsData(theEnv)->DeffactsModuleIndex,FALSE,NULL); for (theModule = EnvGetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = EnvGetNextDefmodule(theEnv,theModule)) { theModuleItem = (struct deffactsModule *) GetModuleItem(theEnv,(struct defmodule *) theModule, DeffactsData(theEnv)->DeffactsModuleIndex); rtn_struct(theEnv,deffactsModule,theModuleItem); } #else #if MAC_MCW || WIN_MCW || MAC_XCD #pragma unused(theEnv) #endif #endif }
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 void *CreateDeftemplateScopeMap( void *theEnv, struct deftemplate *theDeftemplate) { unsigned scopeMapSize; char *scopeMap; char *templateName; struct defmodule *matchModule, *theModule; int moduleID,count; void *theBitMap; templateName = ValueToString(theDeftemplate->header.name); matchModule = theDeftemplate->header.whichModule->theModule; scopeMapSize = (sizeof(char) * ((GetNumberOfDefmodules(theEnv) / BITS_PER_BYTE) + 1)); scopeMap = (char *) gm2(theEnv,scopeMapSize); ClearBitString((void *) scopeMap,scopeMapSize); SaveCurrentModule(theEnv); for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL) ; theModule != NULL ; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,(void *) theModule)) { EnvSetCurrentModule(theEnv,(void *) theModule); moduleID = (int) theModule->bsaveID; if (FindImportedConstruct(theEnv,"deftemplate",matchModule, templateName,&count,TRUE,NULL) != NULL) SetBitMap(scopeMap,moduleID); } RestoreCurrentModule(theEnv); theBitMap = EnvAddBitMap(theEnv,scopeMap,scopeMapSize); IncrementBitMapCount(theBitMap); rm(theEnv,(void *) scopeMap,scopeMapSize); return(theBitMap); }
globle int SetIncrementalResetCommand( void *theEnv, EXEC_STATUS) { int oldValue; DATA_OBJECT argPtr; struct defmodule *theModule; oldValue = EnvGetIncrementalReset(theEnv,execStatus); /*============================================*/ /* Check for the correct number of arguments. */ /*============================================*/ if (EnvArgCountCheck(theEnv,execStatus,"set-incremental-reset",EXACTLY,1) == -1) { return(oldValue); } /*=========================================*/ /* The incremental reset behavior can't be */ /* changed when rules are loaded. */ /*=========================================*/ SaveCurrentModule(theEnv,execStatus); for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,execStatus,NULL); theModule != NULL; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,execStatus,theModule)) { EnvSetCurrentModule(theEnv,execStatus,(void *) theModule); if (EnvGetNextDefrule(theEnv,execStatus,NULL) != NULL) { RestoreCurrentModule(theEnv,execStatus); PrintErrorID(theEnv,execStatus,"INCRRSET",1,FALSE); EnvPrintRouter(theEnv,execStatus,WERROR,"The incremental reset behavior cannot be changed with rules loaded.\n"); SetEvaluationError(theEnv,execStatus,TRUE); return(oldValue); } } RestoreCurrentModule(theEnv,execStatus); /*==================================================*/ /* The symbol FALSE disables incremental reset. Any */ /* other value enables incremental reset. */ /*==================================================*/ EnvRtnUnknown(theEnv,execStatus,1,&argPtr); if ((argPtr.value == EnvFalseSymbol(theEnv,execStatus)) && (argPtr.type == SYMBOL)) { EnvSetIncrementalReset(theEnv,execStatus,FALSE); } else { EnvSetIncrementalReset(theEnv,execStatus,TRUE); } /*=======================*/ /* Return the old value. */ /*=======================*/ return(oldValue); }
globle int EnvSave( void *theEnv, EXEC_STATUS, char *fileName) { struct callFunctionItem *saveFunction; FILE *filePtr; void *defmodulePtr; /*=====================*/ /* Open the save file. */ /*=====================*/ if ((filePtr = GenOpen(theEnv,execStatus,fileName,"w")) == NULL) { return(FALSE); } /*===========================*/ /* Bypass the router system. */ /*===========================*/ SetFastSave(theEnv,execStatus,filePtr); /*======================*/ /* Save the constructs. */ /*======================*/ for (defmodulePtr = EnvGetNextDefmodule(theEnv,execStatus,NULL); defmodulePtr != NULL; defmodulePtr = EnvGetNextDefmodule(theEnv,execStatus,defmodulePtr)) { for (saveFunction = ConstructData(theEnv,execStatus)->ListOfSaveFunctions; saveFunction != NULL; saveFunction = saveFunction->next) { ((* (void (*)(void *,EXEC_STATUS,void *,char *)) saveFunction->func))(theEnv,execStatus,defmodulePtr,(char *) filePtr); } } /*======================*/ /* Close the save file. */ /*======================*/ GenClose(theEnv,execStatus,filePtr); /*===========================*/ /* Remove the router bypass. */ /*===========================*/ SetFastSave(theEnv,execStatus,NULL); /*=========================*/ /* Return TRUE to indicate */ /* successful completion. */ /*=========================*/ return(TRUE); }
static void BsaveExpressions( void *theEnv, FILE *fp) { struct defrule *theDefrule, *theDisjunct; struct defmodule *theModule; /*===========================*/ /* Loop through each module. */ /*===========================*/ for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule)) { /*======================================================*/ /* Set the current module to the module being examined. */ /*======================================================*/ EnvSetCurrentModule(theEnv,(void *) theModule); /*==================================================*/ /* Loop through each defrule in the current module. */ /*==================================================*/ for (theDefrule = (struct defrule *) EnvGetNextDefrule(theEnv,NULL); theDefrule != NULL; theDefrule = (struct defrule *) EnvGetNextDefrule(theEnv,theDefrule)) { /*===========================================*/ /* Save the dynamic salience of the defrule. */ /*===========================================*/ BsaveExpression(theEnv,theDefrule->dynamicSalience,fp); /*===================================*/ /* Loop through each disjunct of the */ /* defrule and save its RHS actions. */ /*===================================*/ for (theDisjunct = theDefrule; theDisjunct != NULL; theDisjunct = theDisjunct->disjunct) { BsaveExpression(theEnv,theDisjunct->actions,fp); } } } /*==============================*/ /* Set the marked flag for each */ /* join in the join network. */ /*==============================*/ MarkRuleNetwork(theEnv,1); }
static void BeforeDefmodulesToCode( void *theEnv) { int value = 0; struct defmodule *theModule; for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule)) { theModule->bsaveID = value++; } }
static void BsaveFind( void *theEnv, EXEC_STATUS) { struct defglobal *defglobalPtr; struct defmodule *theModule; /*=======================================================*/ /* If a binary image is already loaded, then temporarily */ /* save the count values since these will be overwritten */ /* in the process of saving the binary image. */ /*=======================================================*/ SaveBloadCount(theEnv,execStatus,DefglobalBinaryData(theEnv,execStatus)->NumberOfDefglobalModules); SaveBloadCount(theEnv,execStatus,DefglobalBinaryData(theEnv,execStatus)->NumberOfDefglobals); /*============================================*/ /* Set the count of defglobals and defglobals */ /* module data structures to zero. */ /*============================================*/ DefglobalBinaryData(theEnv,execStatus)->NumberOfDefglobals = 0; DefglobalBinaryData(theEnv,execStatus)->NumberOfDefglobalModules = 0; for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,execStatus,NULL); theModule != NULL; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,execStatus,theModule)) { /*================================================*/ /* Set the current module to the module being */ /* examined and increment the number of defglobal */ /* modules encountered. */ /*================================================*/ EnvSetCurrentModule(theEnv,execStatus,(void *) theModule); DefglobalBinaryData(theEnv,execStatus)->NumberOfDefglobalModules++; /*====================================================*/ /* Loop through each defglobal in the current module. */ /*====================================================*/ for (defglobalPtr = (struct defglobal *) EnvGetNextDefglobal(theEnv,execStatus,NULL); defglobalPtr != NULL; defglobalPtr = (struct defglobal *) EnvGetNextDefglobal(theEnv,execStatus,defglobalPtr)) { /*======================================================*/ /* Initialize the construct header for the binary save. */ /*======================================================*/ MarkConstructHeaderNeededItems(&defglobalPtr->header,DefglobalBinaryData(theEnv,execStatus)->NumberOfDefglobals++); } } }
globle void MarkModulesAsUnvisited( void *theEnv, EXEC_STATUS) { struct defmodule *theModule; DefmoduleData(theEnv,execStatus)->CurrentModule->visitedFlag = FALSE; for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,execStatus,NULL); theModule != NULL; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,execStatus,theModule)) { theModule->visitedFlag = FALSE; } }
static void DeallocateDefruleData( void *theEnv) { struct defruleModule *theModuleItem; void *theModule; struct activation *theActivation, *tmpActivation; struct salienceGroup *theGroup, *tmpGroup; #if BLOAD || BLOAD_AND_BSAVE if (Bloaded(theEnv)) { return; } #endif DoForAllConstructs(theEnv,DestroyDefruleAction,DefruleData(theEnv)->DefruleModuleIndex,FALSE,NULL); for (theModule = EnvGetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = EnvGetNextDefmodule(theEnv,theModule)) { theModuleItem = (struct defruleModule *) GetModuleItem(theEnv,(struct defmodule *) theModule, DefruleData(theEnv)->DefruleModuleIndex); theActivation = theModuleItem->agenda; while (theActivation != NULL) { tmpActivation = theActivation->next; rtn_struct(theEnv,activation,theActivation); theActivation = tmpActivation; } theGroup = theModuleItem->groupings; while (theGroup != NULL) { tmpGroup = theGroup->next; rtn_struct(theEnv,salienceGroup,theGroup); theGroup = tmpGroup; } #if ! RUN_TIME rtn_struct(theEnv,defruleModule,theModuleItem); #endif } rm3(theEnv,DefruleData(theEnv)->AlphaMemoryTable,sizeof (ALPHA_MEMORY_HASH *) * ALPHA_MEMORY_HASH_SIZE); }
static void BsaveFind( void *theEnv, EXEC_STATUS) { struct deftemplate *theDeftemplate; struct defmodule *theModule; /*=======================================================*/ /* If a binary image is already loaded, then temporarily */ /* save the count values since these will be overwritten */ /* in the process of saving the binary image. */ /*=======================================================*/ SaveBloadCount(theEnv,execStatus,FactBinaryData(theEnv,execStatus)->NumberOfPatterns); /*=======================================*/ /* Set the count of fact pattern network */ /* data structures to zero. */ /*=======================================*/ FactBinaryData(theEnv,execStatus)->NumberOfPatterns = 0L; /*===========================*/ /* Loop through each module. */ /*===========================*/ for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,execStatus,NULL); theModule != NULL; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,execStatus,theModule)) { /*===============================*/ /* Set the current module to the */ /* module being examined. */ /*===============================*/ EnvSetCurrentModule(theEnv,execStatus,(void *) theModule); /*=====================================================*/ /* Loop through each deftemplate in the current module */ /* and count the number of data structures which must */ /* be saved for its pattern network. */ /*=====================================================*/ for (theDeftemplate = (struct deftemplate *) EnvGetNextDeftemplate(theEnv,execStatus,NULL); theDeftemplate != NULL; theDeftemplate = (struct deftemplate *) EnvGetNextDeftemplate(theEnv,execStatus,theDeftemplate)) { BsaveDriver(theEnv,execStatus,BSAVE_FIND,NULL,theDeftemplate->patternNetwork); } } }
globle long DoForAllModules( void *theEnv, EXEC_STATUS, void (*actionFunction)(struct defmodule *,void *), int interruptable, void *userBuffer) { void *theModule; long moduleCount = 0L; /*==========================*/ /* Save the current module. */ /*==========================*/ SaveCurrentModule(theEnv,execStatus); /*==================================*/ /* Loop through all of the modules. */ /*==================================*/ for (theModule = EnvGetNextDefmodule(theEnv,execStatus,NULL); theModule != NULL; theModule = EnvGetNextDefmodule(theEnv,execStatus,theModule), moduleCount++) { EnvSetCurrentModule(theEnv,execStatus,(void *) theModule); if ((interruptable) && GetHaltExecution(theEnv,execStatus)) { RestoreCurrentModule(theEnv,execStatus); return(-1L); } (*actionFunction)((struct defmodule *) theModule,userBuffer); } /*=============================*/ /* Restore the current module. */ /*=============================*/ RestoreCurrentModule(theEnv,execStatus); /*=========================================*/ /* Return the number of modules traversed. */ /*=========================================*/ return(moduleCount); }
static void BsaveFactPatterns( void *theEnv, EXEC_STATUS, FILE *fp) { size_t space; struct deftemplate *theDeftemplate; struct defmodule *theModule; /*========================================*/ /* Write out the amount of space taken up */ /* by the factPatternNode data structures */ /* in the binary image. */ /*========================================*/ space = FactBinaryData(theEnv,execStatus)->NumberOfPatterns * sizeof(struct bsaveFactPatternNode); GenWrite(&space,sizeof(size_t),fp); /*===========================*/ /* Loop through each module. */ /*===========================*/ for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,execStatus,NULL); theModule != NULL; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,execStatus,theModule)) { /*=====================================================*/ /* Loop through each deftemplate in the current module */ /* and save its fact pattern network to the file. */ /*=====================================================*/ EnvSetCurrentModule(theEnv,execStatus,(void *) theModule); for (theDeftemplate = (struct deftemplate *) EnvGetNextDeftemplate(theEnv,execStatus,NULL); theDeftemplate != NULL; theDeftemplate = (struct deftemplate *) EnvGetNextDeftemplate(theEnv,execStatus,theDeftemplate)) { BsaveDriver(theEnv,execStatus,BSAVE_PATTERNS,fp,theDeftemplate->patternNetwork); } } /*=============================================================*/ /* If a binary image was already loaded when the bsave command */ /* was issued, then restore the counts indicating the number */ /* of factPatternNode data structures in the binary image */ /* (these were overwritten by the binary save). */ /*=============================================================*/ RestoreBloadCount(theEnv,execStatus,&FactBinaryData(theEnv,execStatus)->NumberOfPatterns); }
void EnvGetDefmoduleList( void *theEnv, CLIPSValue *returnValue) { void *theConstruct; unsigned long count = 0; struct multifield *theList; /*====================================*/ /* Determine the number of constructs */ /* of the specified type. */ /*====================================*/ for (theConstruct = EnvGetNextDefmodule(theEnv,NULL); theConstruct != NULL; theConstruct = EnvGetNextDefmodule(theEnv,theConstruct)) { count++; } /*===========================*/ /* Create a multifield large */ /* enough to store the list. */ /*===========================*/ SetpType(returnValue,MULTIFIELD); SetpDOBegin(returnValue,1); SetpDOEnd(returnValue,(long) count); theList = (struct multifield *) EnvCreateMultifield(theEnv,count); SetpValue(returnValue,(void *) theList); /*====================================*/ /* Store the names in the multifield. */ /*====================================*/ for (theConstruct = EnvGetNextDefmodule(theEnv,NULL), count = 1; theConstruct != NULL; theConstruct = EnvGetNextDefmodule(theEnv,theConstruct), count++) { if (EvaluationData(theEnv)->HaltExecution == true) { EnvSetMultifieldErrorValue(theEnv,returnValue); return; } SetMFType(theList,count,SYMBOL); SetMFValue(theList,count,EnvAddSymbol(theEnv,EnvGetDefmoduleName(theEnv,theConstruct))); } }
globle void EnvListDefmodules( void *theEnv, char *logicalName) { void *theModule; int count = 0; for (theModule = EnvGetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = EnvGetNextDefmodule(theEnv,theModule)) { EnvPrintRouter(theEnv,logicalName,EnvGetDefmoduleName(theEnv,theModule)); EnvPrintRouter(theEnv,logicalName,"\n"); count++; } PrintTally(theEnv,logicalName,count,"defmodule","defmodules"); }
static void BsaveJoins( void *theEnv, FILE *fp) { struct defrule *rulePtr; struct joinNode *joinPtr; struct defmodule *theModule; /*===========================*/ /* Loop through each module. */ /*===========================*/ for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule)) { EnvSetCurrentModule(theEnv,(void *) theModule); /*===========================================*/ /* Loop through each rule and its disjuncts. */ /*===========================================*/ rulePtr = (struct defrule *) EnvGetNextDefrule(theEnv,NULL); while (rulePtr != NULL) { /*=========================================*/ /* Loop through each join of the disjunct. */ /*=========================================*/ for (joinPtr = rulePtr->lastJoin; joinPtr != NULL; joinPtr = GetPreviousJoin(joinPtr)) { if (joinPtr->marked) BsaveJoin(theEnv,fp,joinPtr); } /*=======================================*/ /* Move on to the next rule or disjunct. */ /*=======================================*/ if (rulePtr->disjunct != NULL) rulePtr = rulePtr->disjunct; else rulePtr = (struct defrule *) EnvGetNextDefrule(theEnv,rulePtr); } } }
/***************************************************** NAME : BeforeObjectPatternsToCode DESCRIPTION : Marks all object pattern intermediate and alpha memory nodes with a unique integer id prior to the constructs-to-c execution INPUTS : None RETURNS : Nothing useful SIDE EFFECTS : bsaveIDs of nodes set NOTES : None *****************************************************/ static void BeforeObjectPatternsToCode( void *theEnv) { long whichPattern; OBJECT_PATTERN_NODE *intermediateNode; OBJECT_ALPHA_NODE *alphaNode; struct defmodule *theModule; DEFCLASS *theDefclass; CLASS_ALPHA_LINK *theLink; whichPattern = 0L; intermediateNode = ObjectNetworkPointer(theEnv); while (intermediateNode != NULL) { intermediateNode->bsaveID = whichPattern++; intermediateNode = GetNextObjectPatternNode(intermediateNode); } whichPattern = 0L; alphaNode = ObjectNetworkTerminalPointer(theEnv); while (alphaNode != NULL) { alphaNode->bsaveID = whichPattern++; alphaNode = alphaNode->nxtTerminal; } whichPattern = 0L; for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule)) { EnvSetCurrentModule(theEnv,(void *) theModule); for (theDefclass = (DEFCLASS *) EnvGetNextDefclass(theEnv,NULL) ; theDefclass != NULL ; theDefclass = (DEFCLASS *) EnvGetNextDefclass(theEnv,(void *) theDefclass)) { for (theLink = theDefclass->relevant_terminal_alpha_nodes; theLink != NULL; theLink = theLink->next) { theLink->bsaveID = whichPattern++; } } } }
static void DeallocateDefruleData( void *theEnv) { struct defruleModule *theModuleItem; void *theModule; struct activation *theActivation, *tmpActivation; #if BLOAD || BLOAD_AND_BSAVE if (Bloaded(theEnv)) return; #endif DoForAllConstructs(theEnv,DestroyDefruleAction,DefruleData(theEnv)->DefruleModuleIndex,FALSE,NULL); for (theModule = EnvGetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = EnvGetNextDefmodule(theEnv,theModule)) { theModuleItem = (struct defruleModule *) GetModuleItem(theEnv,(struct defmodule *) theModule, DefruleData(theEnv)->DefruleModuleIndex); theActivation = theModuleItem->agenda; while (theActivation != NULL) { tmpActivation = theActivation->next; #if CONFLICT_RESOLUTION_STRATEGIES if (theActivation->sortedBasis != NULL) { DestroyPartialMatch(theEnv,theActivation->sortedBasis); } #endif rtn_struct(theEnv,activation,theActivation); theActivation = tmpActivation; } #if ! RUN_TIME rtn_struct(theEnv,defruleModule,theModuleItem); #endif } }
void UpdateDeftemplateScope( void *theEnv) { struct deftemplate *theDeftemplate; int moduleCount; struct defmodule *theModule; struct defmoduleItemHeader *theItem; /*==================================*/ /* Loop through all of the modules. */ /*==================================*/ for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule)) { /*======================================================*/ /* Loop through each of the deftemplates in the module. */ /*======================================================*/ theItem = (struct defmoduleItemHeader *) GetModuleItem(theEnv,theModule,DeftemplateData(theEnv)->DeftemplateModuleIndex); for (theDeftemplate = (struct deftemplate *) theItem->firstItem; theDeftemplate != NULL ; theDeftemplate = (struct deftemplate *) EnvGetNextDeftemplate(theEnv,theDeftemplate)) { /*=======================================*/ /* If the deftemplate can be seen by the */ /* current module, then it is in scope. */ /*=======================================*/ if (FindImportedConstruct(theEnv,"deftemplate",theModule, ValueToString(theDeftemplate->header.name), &moduleCount,true,NULL) != NULL) { theDeftemplate->inScope = true; } else { theDeftemplate->inScope = false; } } } }
globle void RemoveAllBreakpoints( void *theEnv) { void *theRule; void *theDefmodule = NULL; while ((theDefmodule = EnvGetNextDefmodule(theEnv,theDefmodule)) != NULL) { theRule = NULL; while ((theRule = EnvGetNextDefrule(theEnv,theRule)) != NULL) { EnvRemoveBreak(theEnv,theRule); } } }
static void BloadBinaryItem( void *theEnv) { unsigned long int space; GenReadBinary(theEnv,&space,(unsigned long) sizeof(unsigned long int)); if (DefmoduleData(theEnv)->BNumberOfDefmodules == 0) return; BloadandRefresh(theEnv,DefmoduleData(theEnv)->BNumberOfDefmodules,(unsigned) sizeof(struct bsaveDefmodule),UpdateDefmodule); BloadandRefresh(theEnv,DefmoduleData(theEnv)->NumberOfPortItems,(unsigned) sizeof(struct bsavePortItem),UpdatePortItem); SetListOfDefmodules(theEnv,(void *) DefmoduleData(theEnv)->DefmoduleArray); EnvSetCurrentModule(theEnv,(void *) EnvGetNextDefmodule(theEnv,NULL)); }
/************************************************************************************* 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 : 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); }
globle intBool EnvSetIncrementalReset( void *theEnv, int value) { int ov; struct defmodule *theModule; /*============================================*/ /* The incremental reset behavior can only be */ /* changed if there are no existing rules. */ /*============================================*/ SaveCurrentModule(theEnv); for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule)) { EnvSetCurrentModule(theEnv,(void *) theModule); if (EnvGetNextDefrule(theEnv,NULL) != NULL) { RestoreCurrentModule(theEnv); return(-1); } } RestoreCurrentModule(theEnv); /*====================================*/ /* Change the incremental reset flag. */ /*====================================*/ ov = EngineData(theEnv)->IncrementalResetFlag; EngineData(theEnv)->IncrementalResetFlag = value; return(ov); }
static void InitDefmoduleCode( void *theEnv, FILE *initFP, int imageID, int maxIndices) { #if MAC_XCD #pragma unused(maxIndices) #endif if (EnvGetNextDefmodule(theEnv,NULL) != NULL) { fprintf(initFP," SetListOfDefmodules(theEnv,(void *) %s%d_1);\n",DefmodulePrefix(),imageID); } else { fprintf(initFP," SetListOfDefmodules(theEnv,NULL);\n"); } fprintf(initFP," EnvSetCurrentModule(theEnv,(void *) EnvGetNextDefmodule(theEnv,NULL));\n"); }
static CLASS_ALPHA_LINK *GetNextAlphaLink( void *theEnv, struct defmodule **theModule, DEFCLASS **theClass, CLASS_ALPHA_LINK *theLink) { while (TRUE) { if (theLink != NULL) { theLink = theLink->next; if (theLink != NULL) { return theLink; } } else if (*theClass != NULL) { *theClass = EnvGetNextDefclass(theEnv,*theClass); if (*theClass != NULL) { theLink = (*theClass)->relevant_terminal_alpha_nodes; } if (theLink != NULL) { return theLink; } } else { *theModule = EnvGetNextDefmodule(theEnv,*theModule); if (*theModule == NULL) { return NULL; } EnvSetCurrentModule(theEnv,(void *) *theModule); *theClass = EnvGetNextDefclass(theEnv,*theClass); if (*theClass != NULL) { theLink = (*theClass)->relevant_terminal_alpha_nodes; if (theLink != NULL) { return theLink; } } } } return NULL; }
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); }