📄 rulebin.c
字号:
/* and joinNode data structures to be read. */
/*=================================================*/
GenReadBinary(theEnv,&space,(unsigned long) sizeof(unsigned long int));
GenReadBinary(theEnv,&DefruleBinaryData(theEnv)->NumberOfDefruleModules,(unsigned long) sizeof(long int));
GenReadBinary(theEnv,&DefruleBinaryData(theEnv)->NumberOfDefrules,(unsigned long) sizeof(long int));
GenReadBinary(theEnv,&DefruleBinaryData(theEnv)->NumberOfJoins,(unsigned long) sizeof(long int));
/*===================================*/
/* Allocate the space needed for the */
/* defruleModule data structures. */
/*===================================*/
if (DefruleBinaryData(theEnv)->NumberOfDefruleModules == 0)
{
DefruleBinaryData(theEnv)->ModuleArray = NULL;
DefruleBinaryData(theEnv)->DefruleArray = NULL;
DefruleBinaryData(theEnv)->JoinArray = NULL;
}
space = DefruleBinaryData(theEnv)->NumberOfDefruleModules * sizeof(struct defruleModule);
DefruleBinaryData(theEnv)->ModuleArray = (struct defruleModule *) genlongalloc(theEnv,space);
/*===============================*/
/* Allocate the space needed for */
/* the defrule data structures. */
/*===============================*/
if (DefruleBinaryData(theEnv)->NumberOfDefrules == 0)
{
DefruleBinaryData(theEnv)->DefruleArray = NULL;
DefruleBinaryData(theEnv)->JoinArray = NULL;
return;
}
space = DefruleBinaryData(theEnv)->NumberOfDefrules * sizeof(struct defrule);
DefruleBinaryData(theEnv)->DefruleArray = (struct defrule *) genlongalloc(theEnv,space);
/*===============================*/
/* Allocate the space needed for */
/* the joinNode data structures. */
/*===============================*/
space = DefruleBinaryData(theEnv)->NumberOfJoins * sizeof(struct joinNode);
DefruleBinaryData(theEnv)->JoinArray = (struct joinNode *) genlongalloc(theEnv,space);
}
/****************************************************/
/* BloadBinaryItem: Loads and refreshes the defrule */
/* constructs used by this binary image. */
/****************************************************/
static void BloadBinaryItem(
void *theEnv)
{
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 being run). */
/*======================================================*/
GenReadBinary(theEnv,&space,(unsigned long) sizeof(unsigned long int));
/*===========================================*/
/* Read in the defruleModule data structures */
/* and refresh the pointers. */
/*===========================================*/
BloadandRefresh(theEnv,DefruleBinaryData(theEnv)->NumberOfDefruleModules,(unsigned) sizeof(struct bsaveDefruleModule),
UpdateDefruleModule);
/*=====================================*/
/* Read in the defrule data structures */
/* and refresh the pointers. */
/*=====================================*/
BloadandRefresh(theEnv,DefruleBinaryData(theEnv)->NumberOfDefrules,(unsigned) sizeof(struct bsaveDefrule),
UpdateDefrule);
/*======================================*/
/* Read in the joinNode data structures */
/* and refresh the pointers. */
/*======================================*/
BloadandRefresh(theEnv,DefruleBinaryData(theEnv)->NumberOfJoins,(unsigned) sizeof(struct bsaveJoinNode),
UpdateJoin);
}
/**********************************************/
/* UpdateDefruleModule: Bload refresh routine */
/* for defrule module data structures. */
/**********************************************/
static void UpdateDefruleModule(
void *theEnv,
void *buf,
long obji)
{
struct bsaveDefruleModule *bdmPtr;
bdmPtr = (struct bsaveDefruleModule *) buf;
UpdateDefmoduleItemHeader(theEnv,&bdmPtr->header,&DefruleBinaryData(theEnv)->ModuleArray[obji].header,
(int) sizeof(struct defrule),
(void *) DefruleBinaryData(theEnv)->DefruleArray);
DefruleBinaryData(theEnv)->ModuleArray[obji].agenda = NULL;
}
/****************************************/
/* UpdateDefrule: Bload refresh routine */
/* for defrule data structures. */
/****************************************/
static void UpdateDefrule(
void *theEnv,
void *buf,
long obji)
{
struct bsaveDefrule *br;
br = (struct bsaveDefrule *) buf;
UpdateConstructHeader(theEnv,&br->header,&DefruleBinaryData(theEnv)->DefruleArray[obji].header,
(int) sizeof(struct defruleModule),(void *) DefruleBinaryData(theEnv)->ModuleArray,
(int) sizeof(struct defrule),(void *) DefruleBinaryData(theEnv)->DefruleArray);
DefruleBinaryData(theEnv)->DefruleArray[obji].dynamicSalience = ExpressionPointer(br->dynamicSalience);
DefruleBinaryData(theEnv)->DefruleArray[obji].actions = ExpressionPointer(br->actions);
DefruleBinaryData(theEnv)->DefruleArray[obji].logicalJoin = BloadJoinPointer(br->logicalJoin);
DefruleBinaryData(theEnv)->DefruleArray[obji].lastJoin = BloadJoinPointer(br->lastJoin);
DefruleBinaryData(theEnv)->DefruleArray[obji].disjunct = BloadDefrulePointer(DefruleBinaryData(theEnv)->DefruleArray,br->disjunct);
DefruleBinaryData(theEnv)->DefruleArray[obji].salience = br->salience;
DefruleBinaryData(theEnv)->DefruleArray[obji].localVarCnt = br->localVarCnt;
DefruleBinaryData(theEnv)->DefruleArray[obji].complexity = br->complexity;
DefruleBinaryData(theEnv)->DefruleArray[obji].autoFocus = br->autoFocus;
DefruleBinaryData(theEnv)->DefruleArray[obji].executing = 0;
DefruleBinaryData(theEnv)->DefruleArray[obji].afterBreakpoint = 0;
#if DEBUGGING_FUNCTIONS
DefruleBinaryData(theEnv)->DefruleArray[obji].watchActivation = AgendaData(theEnv)->WatchActivations;
DefruleBinaryData(theEnv)->DefruleArray[obji].watchFiring = DefruleData(theEnv)->WatchRules;
#endif
}
/*************************************/
/* UpdateJoin: Bload refresh routine */
/* for joinNode data structures. */
/*************************************/
static void UpdateJoin(
void *theEnv,
void *buf,
long obji)
{
struct bsaveJoinNode *bj;
bj = (struct bsaveJoinNode *) buf;
DefruleBinaryData(theEnv)->JoinArray[obji].firstJoin = bj->firstJoin;
DefruleBinaryData(theEnv)->JoinArray[obji].logicalJoin = bj->logicalJoin;
DefruleBinaryData(theEnv)->JoinArray[obji].joinFromTheRight = bj->joinFromTheRight;
DefruleBinaryData(theEnv)->JoinArray[obji].patternIsNegated = bj->patternIsNegated;
DefruleBinaryData(theEnv)->JoinArray[obji].depth = bj->depth;
DefruleBinaryData(theEnv)->JoinArray[obji].rhsType = bj->rhsType;
DefruleBinaryData(theEnv)->JoinArray[obji].networkTest = HashedExpressionPointer(bj->networkTest);
DefruleBinaryData(theEnv)->JoinArray[obji].nextLevel = BloadJoinPointer(bj->nextLevel);
DefruleBinaryData(theEnv)->JoinArray[obji].lastLevel = BloadJoinPointer(bj->lastLevel);
if (bj->joinFromTheRight == TRUE)
{ DefruleBinaryData(theEnv)->JoinArray[obji].rightSideEntryStructure = (void *) BloadJoinPointer(bj->rightSideEntryStructure); }
DefruleBinaryData(theEnv)->JoinArray[obji].rightMatchNode = BloadJoinPointer(bj->rightMatchNode);
DefruleBinaryData(theEnv)->JoinArray[obji].rightDriveNode = BloadJoinPointer(bj->rightDriveNode);
DefruleBinaryData(theEnv)->JoinArray[obji].ruleToActivate = BloadDefrulePointer(DefruleBinaryData(theEnv)->DefruleArray,bj->ruleToActivate);
DefruleBinaryData(theEnv)->JoinArray[obji].initialize = 0;
DefruleBinaryData(theEnv)->JoinArray[obji].marked = 0;
DefruleBinaryData(theEnv)->JoinArray[obji].bsaveID = 0L;
DefruleBinaryData(theEnv)->JoinArray[obji].beta = NULL;
}
/************************************************************/
/* UpdatePatternNodeHeader: Refreshes the values in pattern */
/* node headers from the loaded binary image. */
/************************************************************/
globle void UpdatePatternNodeHeader(
void *theEnv,
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(
void *theEnv)
{
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(theEnv,&theParser,&theEntity);
while (theEntity != NULL)
{
(*theEntity->theInfo->base.deleteFunction)(theEnv,theEntity);
theEntity = NULL;
GetNextPatternEntity(theEnv,&theParser,&theEntity);
}
/*=========================================*/
/* Remove all activations from the agenda. */
/*=========================================*/
SaveCurrentModule(theEnv);
for (theModule = EnvGetNextDefmodule(theEnv,NULL);
theModule != NULL;
theModule = EnvGetNextDefmodule(theEnv,theModule))
{
EnvSetCurrentModule(theEnv,theModule);
RemoveAllActivations(theEnv);
}
RestoreCurrentModule(theEnv);
EnvClearFocusStack(theEnv);
/*==========================================================*/
/* 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 < DefruleBinaryData(theEnv)->NumberOfJoins; i++)
{ FlushAlphaBetaMemory(theEnv,DefruleBinaryData(theEnv)->JoinArray[i].beta); }
/*================================================*/
/* Decrement the symbol count for each rule name. */
/*================================================*/
for (i = 0; i < DefruleBinaryData(theEnv)->NumberOfDefrules; i++)
{ UnmarkConstructHeader(theEnv,&DefruleBinaryData(theEnv)->DefruleArray[i].header); }
/*==================================================*/
/* Return the space allocated for the bload arrays. */
/*==================================================*/
space = DefruleBinaryData(theEnv)->NumberOfDefruleModules * sizeof(struct defruleModule);
if (space != 0) genlongfree(theEnv,(void *) DefruleBinaryData(theEnv)->ModuleArray,space);
DefruleBinaryData(theEnv)->NumberOfDefruleModules = 0;
space = DefruleBinaryData(theEnv)->NumberOfDefrules * sizeof(struct defrule);
if (space != 0) genlongfree(theEnv,(void *) DefruleBinaryData(theEnv)->DefruleArray,space);
DefruleBinaryData(theEnv)->NumberOfDefrules = 0;
space = DefruleBinaryData(theEnv)->NumberOfJoins * sizeof(struct joinNode);
if (space != 0) genlongfree(theEnv,(void *) DefruleBinaryData(theEnv)->JoinArray,space);
DefruleBinaryData(theEnv)->NumberOfJoins = 0;
}
/*******************************************************/
/* BloadDefruleModuleReference: Returns the defrule */
/* module pointer for using with the bload function. */
/*******************************************************/
globle void *BloadDefruleModuleReference(
void *theEnv,
int theIndex)
{
return ((void *) &DefruleBinaryData(theEnv)->ModuleArray[theIndex]);
}
#endif /* DEFRULE_CONSTRUCT && (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) && (! RUN_TIME) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -