📄 rulebin.c
字号:
/*=================================================*/ GenRead(&space,(unsigned long) sizeof(unsigned long int)); GenRead(&NumberOfDefruleModules,(unsigned long) sizeof(long int)); GenRead(&NumberOfDefrules,(unsigned long) sizeof(long int)); GenRead(&NumberOfJoins,(unsigned long) sizeof(long int)); /*===================================*/ /* Allocate the space needed for the */ /* defruleModule data structures. */ /*===================================*/ if (NumberOfDefruleModules == 0) { ModuleArray = NULL; DefruleArray = NULL; JoinArray = NULL; } space = NumberOfDefruleModules * sizeof(struct defruleModule); ModuleArray = (struct defruleModule HUGE_ADDR *) genlongalloc(space); /*===============================*/ /* Allocate the space needed for */ /* the defrule data structures. */ /*===============================*/ if (NumberOfDefrules == 0) { DefruleArray = NULL; JoinArray = NULL; return; } space = NumberOfDefrules * sizeof(struct defrule); DefruleArray = (struct defrule *) genlongalloc(space); /*===============================*/ /* Allocate the space needed for */ /* the joinNode data structures. */ /*===============================*/ space = NumberOfJoins * sizeof(struct joinNode); JoinArray = (struct joinNode *) genlongalloc(space); }/****************************************************//* BloadBinaryItem: Loads and refreshes the defrule *//* constructs used by this binary image. *//****************************************************/static VOID BloadBinaryItem() { unsigned long space; /*======================================================*/ /* Read in the amount of space used by the binary image */ /* (this is used to skip the construct in the event it */ /* is not available in the version of CLIPS being run). */ /*======================================================*/ GenRead(&space,(unsigned long) sizeof(unsigned long int)); /*===========================================*/ /* Read in the defruleModule data structures */ /* and refresh the pointers. */ /*===========================================*/ BloadandRefresh(NumberOfDefruleModules,(unsigned) sizeof(struct bsaveDefruleModule), UpdateDefruleModule); /*=====================================*/ /* Read in the defrule data structures */ /* and refresh the pointers. */ /*=====================================*/ BloadandRefresh(NumberOfDefrules,(unsigned) sizeof(struct bsaveDefrule), UpdateDefrule); /*======================================*/ /* Read in the joinNode data structures */ /* and refresh the pointers. */ /*======================================*/ BloadandRefresh(NumberOfJoins,(unsigned) sizeof(struct bsaveJoinNode), UpdateJoin); } /**********************************************//* UpdateDefruleModule: Bload refresh routine *//* for defrule module data structures. *//**********************************************/static VOID UpdateDefruleModule(buf,obji) VOID *buf; long obji; { struct bsaveDefruleModule *bdmPtr; bdmPtr = (struct bsaveDefruleModule *) buf; UpdateDefmoduleItemHeader(&bdmPtr->header,&ModuleArray[obji].header, (int) sizeof(struct defrule), (VOID *) DefruleArray); ModuleArray[obji].agenda = NULL; } /****************************************//* UpdateDefrule: Bload refresh routine *//* for defrule data structures. *//****************************************/static VOID UpdateDefrule(buf,obji) VOID *buf; long obji; { struct bsaveDefrule *br; br = (struct bsaveDefrule *) buf; UpdateConstructHeader(&br->header,&DefruleArray[obji].header, (int) sizeof(struct defruleModule),(VOID *) ModuleArray, (int) sizeof(struct defrule),(VOID *) DefruleArray);#if DYNAMIC_SALIENCE DefruleArray[obji].dynamicSalience = ExpressionPointer(br->dynamicSalience);#endif DefruleArray[obji].actions = ExpressionPointer(br->actions);#if LOGICAL_DEPENDENCIES DefruleArray[obji].logicalJoin = BloadJoinPointer(br->logicalJoin);#endif DefruleArray[obji].lastJoin = BloadJoinPointer(br->lastJoin); DefruleArray[obji].disjunct = BloadDefrulePointer(DefruleArray,br->disjunct); DefruleArray[obji].salience = br->salience; DefruleArray[obji].localVarCnt = br->localVarCnt; DefruleArray[obji].complexity = br->complexity; DefruleArray[obji].autoFocus = br->autoFocus; DefruleArray[obji].executing = 0; DefruleArray[obji].afterBreakpoint = 0;#if DEBUGGING_FUNCTIONS DefruleArray[obji].watchActivation = WatchActivations; DefruleArray[obji].watchFiring = WatchRules;#endif } /*************************************//* UpdateJoin: Bload refresh routine *//* for joinNode data structures. *//*************************************/static VOID UpdateJoin(buf,obji) VOID *buf; long obji; { struct bsaveJoinNode *bj; bj = (struct bsaveJoinNode *) buf; JoinArray[obji].firstJoin = bj->firstJoin; JoinArray[obji].logicalJoin = bj->logicalJoin; JoinArray[obji].joinFromTheRight = bj->joinFromTheRight; JoinArray[obji].patternIsNegated = bj->patternIsNegated; JoinArray[obji].depth = bj->depth; JoinArray[obji].rhsType = bj->rhsType; JoinArray[obji].networkTest = HashedExpressionPointer(bj->networkTest); JoinArray[obji].nextLevel = BloadJoinPointer(bj->nextLevel); JoinArray[obji].lastLevel = BloadJoinPointer(bj->lastLevel); if (bj->joinFromTheRight == CLIPS_TRUE) { JoinArray[obji].rightSideEntryStructure = (VOID *) BloadJoinPointer(bj->rightSideEntryStructure); } JoinArray[obji].rightMatchNode = BloadJoinPointer(bj->rightMatchNode); JoinArray[obji].rightDriveNode = BloadJoinPointer(bj->rightDriveNode); JoinArray[obji].ruleToActivate = BloadDefrulePointer(DefruleArray,bj->ruleToActivate); JoinArray[obji].initialize = 0; JoinArray[obji].marked = 0; JoinArray[obji].bsaveID = 0L; JoinArray[obji].beta = NULL; }/************************************************************//* UpdatePatternNodeHeader: Refreshes the values in pattern *//* node headers from the loaded binary image. *//************************************************************/globle VOID UpdatePatternNodeHeader(theHeader,theBsaveHeader) struct patternNodeHeader *theHeader; struct bsavePatternNodeHeader *theBsaveHeader; { struct joinNode *theJoin; theHeader->singlefieldNode = theBsaveHeader->singlefieldNode; theHeader->multifieldNode = theBsaveHeader->multifieldNode; theHeader->stopNode = theBsaveHeader->stopNode; theHeader->beginSlot = theBsaveHeader->beginSlot; theHeader->endSlot = theBsaveHeader->endSlot; theHeader->initialize = 0; theHeader->marked = 0; theHeader->alphaMemory = NULL; theHeader->endOfQueue = NULL; theJoin = BloadJoinPointer(theBsaveHeader->entryJoin); theHeader->entryJoin = theJoin; while (theJoin != NULL) { theJoin->rightSideEntryStructure = (VOID *) theHeader; theJoin = theJoin->rightMatchNode; } }/**************************************//* ClearBload: Defrule clear routine *//* when a binary load is in effect. *//**************************************/static VOID ClearBload() { unsigned long int space; long i; struct patternParser *theParser = NULL; struct patternEntity *theEntity = NULL; VOID *theModule; /*===========================================*/ /* Delete all known entities before removing */ /* the defrule data structures. */ /*===========================================*/ GetNextPatternEntity(&theParser,&theEntity); while (theEntity != NULL) { (*theEntity->theInfo->base.deleteFunction)(theEntity); theEntity = NULL; GetNextPatternEntity(&theParser,&theEntity); } /*=========================================*/ /* Remove all activations from the agenda. */ /*=========================================*/ SaveCurrentModule(); for (theModule = GetNextDefmodule(NULL); theModule != NULL; theModule = GetNextDefmodule(theModule)) { SetCurrentModule(theModule); RemoveAllActivations(); } RestoreCurrentModule(); ClearFocusStack(); /*==========================================================*/ /* Remove all partial matches from the beta memories in the */ /* join network. Alpha memories do not need to be examined */ /* since all pattern entities have been deleted by now. */ /*==========================================================*/ for (i = 0; i < NumberOfJoins; i++) { FlushAlphaBetaMemory(JoinArray[i].beta); } /*================================================*/ /* Decrement the symbol count for each rule name. */ /*================================================*/ for (i = 0; i < NumberOfDefrules; i++) { UnmarkConstructHeader(&DefruleArray[i].header); } /*==================================================*/ /* Return the space allocated for the bload arrays. */ /*==================================================*/ space = NumberOfDefruleModules * sizeof(struct defruleModule); if (space != 0) genlongfree((VOID *) ModuleArray,space); space = NumberOfDefrules * sizeof(struct defrule); if (space != 0) genlongfree((VOID *) DefruleArray,space); space = NumberOfJoins * sizeof(struct joinNode); if (space != 0) genlongfree((VOID *) JoinArray,space); }/*******************************************************//* BloadDefruleModuleReference: Returns the defrule *//* module pointer for using with the bload function. *//*******************************************************/globle VOID *BloadDefruleModuleReference(index) int index; { return ((VOID *) &ModuleArray[index]); }#endif /* DEFRULE_CONSTRUCT && (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) && (! RUN_TIME) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -