static void CopyToBsaveConstraintRecord( void *theEnv, CONSTRAINT_RECORD *constraints, BSAVE_CONSTRAINT_RECORD *bsaveConstraints) { bsaveConstraints->anyAllowed = constraints->anyAllowed; bsaveConstraints->symbolsAllowed = constraints->symbolsAllowed; bsaveConstraints->stringsAllowed = constraints->stringsAllowed; bsaveConstraints->floatsAllowed = constraints->floatsAllowed; bsaveConstraints->integersAllowed = constraints->integersAllowed; bsaveConstraints->instanceNamesAllowed = constraints->instanceNamesAllowed; bsaveConstraints->instanceAddressesAllowed = constraints->instanceAddressesAllowed; bsaveConstraints->externalAddressesAllowed = constraints->externalAddressesAllowed; bsaveConstraints->multifieldsAllowed = constraints->multifieldsAllowed; bsaveConstraints->singlefieldsAllowed = constraints->singlefieldsAllowed; bsaveConstraints->factAddressesAllowed = constraints->factAddressesAllowed; bsaveConstraints->anyRestriction = constraints->anyRestriction; bsaveConstraints->symbolRestriction = constraints->symbolRestriction; bsaveConstraints->stringRestriction = constraints->stringRestriction; bsaveConstraints->floatRestriction = constraints->floatRestriction; bsaveConstraints->integerRestriction = constraints->integerRestriction; bsaveConstraints->instanceNameRestriction = constraints->instanceNameRestriction; bsaveConstraints->restrictionList = HashedExpressionIndex(theEnv,constraints->restrictionList); bsaveConstraints->minValue = HashedExpressionIndex(theEnv,constraints->minValue); bsaveConstraints->maxValue = HashedExpressionIndex(theEnv,constraints->maxValue); bsaveConstraints->minFields = HashedExpressionIndex(theEnv,constraints->minFields); bsaveConstraints->maxFields = HashedExpressionIndex(theEnv,constraints->maxFields); }
static void BsaveJoin( FILE *fp, struct joinNode *joinPtr) { struct bsaveJoinNode tempJoin; joinPtr->marked = 0; tempJoin.depth = joinPtr->depth; tempJoin.rhsType = joinPtr->rhsType; tempJoin.firstJoin = joinPtr->firstJoin; tempJoin.logicalJoin = joinPtr->logicalJoin; tempJoin.joinFromTheRight = joinPtr->joinFromTheRight; tempJoin.patternIsNegated = joinPtr->patternIsNegated; if (joinPtr->joinFromTheRight) { tempJoin.rightSideEntryStructure = BsaveJoinIndex(joinPtr->rightSideEntryStructure); } else { tempJoin.rightSideEntryStructure = -1L; } tempJoin.lastLevel = BsaveJoinIndex(joinPtr->lastLevel); tempJoin.nextLevel = BsaveJoinIndex(joinPtr->nextLevel); tempJoin.rightMatchNode = BsaveJoinIndex(joinPtr->rightMatchNode); tempJoin.rightDriveNode = BsaveJoinIndex(joinPtr->rightDriveNode); tempJoin.networkTest = HashedExpressionIndex(joinPtr->networkTest); if (joinPtr->ruleToActivate != NULL) { tempJoin.ruleToActivate = GetDisjunctIndex(joinPtr->ruleToActivate); } else { tempJoin.ruleToActivate = -1L; } GenWrite(&tempJoin,(unsigned long) sizeof(struct bsaveJoinNode),fp); }
globle void PrintHashedExpressionReference( FILE *theFile, struct expr *theExpression, int imageID, int maxIndices) { long theIDValue; if (theExpression == NULL) { fprintf(theFile,"NULL"); } else { theIDValue = HashedExpressionIndex(theExpression); fprintf(theFile,"&E%d_%ld[%ld]", imageID, theIDValue / maxIndices, theIDValue % maxIndices); } }
static void BsavePatternNode( void *theEnv, struct factPatternNode *thePattern, FILE *fp) { struct bsaveFactPatternNode tempNode; AssignBsavePatternHeaderValues(theEnv,&tempNode.header,&thePattern->header); tempNode.whichField = thePattern->whichField; tempNode.leaveFields = thePattern->leaveFields; tempNode.whichSlot = thePattern->whichSlot; tempNode.networkTest = HashedExpressionIndex(theEnv,thePattern->networkTest); tempNode.nextLevel = BsaveFactPatternIndex(thePattern->nextLevel); tempNode.lastLevel = BsaveFactPatternIndex(thePattern->lastLevel); tempNode.leftNode = BsaveFactPatternIndex(thePattern->leftNode); tempNode.rightNode = BsaveFactPatternIndex(thePattern->rightNode); GenWrite(&tempNode,(unsigned long) sizeof(struct bsaveFactPatternNode),fp); }
/*************************************************** NAME : BsaveObjectPatterns DESCRIPTION : Writes ouyt object pattern data structures to binary save file INPUTS : Bsave file stream pointer RETURNS : Nothing useful SIDE EFFECTS : Data structures written NOTES : Extra padding written with alpha node bitmaps to ensure correct alignment of structues on bload ***************************************************/ static void BsaveObjectPatterns( void *theEnv, EXEC_STATUS, FILE *fp) { size_t space; OBJECT_ALPHA_NODE *alphaPtr; OBJECT_PATTERN_NODE *patternPtr; BSAVE_OBJECT_ALPHA_NODE dummyAlpha; BSAVE_OBJECT_PATTERN_NODE dummyPattern; space = (sizeof(BSAVE_OBJECT_ALPHA_NODE) * ObjectReteBinaryData(theEnv,execStatus)->AlphaNodeCount) + (sizeof(BSAVE_OBJECT_PATTERN_NODE) * ObjectReteBinaryData(theEnv,execStatus)->PatternNodeCount); GenWrite(&space,sizeof(size_t),fp); /* ========================================== Write out the alpha terminal pattern nodes ========================================== */ alphaPtr = ObjectNetworkTerminalPointer(theEnv,execStatus); while (alphaPtr != NULL) { AssignBsavePatternHeaderValues(theEnv,execStatus,&dummyAlpha.header,&alphaPtr->header); dummyAlpha.classbmp = (long) alphaPtr->classbmp->bucket; if (alphaPtr->slotbmp != NULL) dummyAlpha.slotbmp = (long) alphaPtr->slotbmp->bucket; else dummyAlpha.slotbmp = -1L; dummyAlpha.patternNode = BsaveObjectPatternIndex(alphaPtr->patternNode); dummyAlpha.nxtInGroup = BsaveObjectAlphaIndex(alphaPtr->nxtInGroup); dummyAlpha.nxtTerminal = BsaveObjectAlphaIndex(alphaPtr->nxtTerminal); GenWrite(&dummyAlpha,sizeof(BSAVE_OBJECT_ALPHA_NODE),fp); alphaPtr = alphaPtr->nxtTerminal; } /* ======================================== Write out the intermediate pattern nodes ======================================== */ patternPtr = ObjectNetworkPointer(theEnv,execStatus); while (patternPtr != NULL) { dummyPattern.multifieldNode = patternPtr->multifieldNode; dummyPattern.whichField = patternPtr->whichField; dummyPattern.leaveFields = patternPtr->leaveFields; dummyPattern.endSlot = patternPtr->endSlot; dummyPattern.selector = patternPtr->selector; dummyPattern.slotNameID = patternPtr->slotNameID; dummyPattern.networkTest = HashedExpressionIndex(theEnv,execStatus,patternPtr->networkTest); dummyPattern.nextLevel = BsaveObjectPatternIndex(patternPtr->nextLevel); dummyPattern.lastLevel = BsaveObjectPatternIndex(patternPtr->lastLevel); dummyPattern.leftNode = BsaveObjectPatternIndex(patternPtr->leftNode); dummyPattern.rightNode = BsaveObjectPatternIndex(patternPtr->rightNode); dummyPattern.alphaNode = BsaveObjectAlphaIndex(patternPtr->alphaNode); GenWrite(&dummyPattern,sizeof(BSAVE_OBJECT_PATTERN_NODE),fp); if (patternPtr->nextLevel == NULL) { while (patternPtr->rightNode == NULL) { patternPtr = patternPtr->lastLevel; if (patternPtr == NULL) { RestoreBloadCount(theEnv,execStatus,&ObjectReteBinaryData(theEnv,execStatus)->AlphaNodeCount); RestoreBloadCount(theEnv,execStatus,&ObjectReteBinaryData(theEnv,execStatus)->PatternNodeCount); return; } } patternPtr = patternPtr->rightNode; } else patternPtr = patternPtr->nextLevel; } RestoreBloadCount(theEnv,execStatus,&ObjectReteBinaryData(theEnv,execStatus)->AlphaNodeCount); RestoreBloadCount(theEnv,execStatus,&ObjectReteBinaryData(theEnv,execStatus)->PatternNodeCount); }
static void BsaveBinaryItem( Environment *theEnv, FILE *fp) { size_t space; Deftemplate *theDeftemplate; struct bsaveDeftemplate tempDeftemplate; struct templateSlot *theSlot; struct bsaveTemplateSlot tempTemplateSlot; struct bsaveDeftemplateModule tempTemplateModule; Defmodule *theModule; struct deftemplateModule *theModuleItem; /*============================================================*/ /* Write out the amount of space taken up by the deftemplate, */ /* deftemplateModule, and templateSlot data structures in the */ /* binary image. */ /*============================================================*/ space = (DeftemplateBinaryData(theEnv)->NumberOfDeftemplates * sizeof(struct bsaveDeftemplate)) + (DeftemplateBinaryData(theEnv)->NumberOfTemplateSlots * sizeof(struct bsaveTemplateSlot)) + (DeftemplateBinaryData(theEnv)->NumberOfTemplateModules * sizeof(struct bsaveDeftemplateModule)); GenWrite(&space,sizeof(size_t),fp); /*===================================================*/ /* Write out each deftemplate module data structure. */ /*===================================================*/ DeftemplateBinaryData(theEnv)->NumberOfDeftemplates = 0; for (theModule = GetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = GetNextDefmodule(theEnv,theModule)) { SetCurrentModule(theEnv,theModule); theModuleItem = (struct deftemplateModule *) GetModuleItem(theEnv,NULL,FindModuleItem(theEnv,"deftemplate")->moduleIndex); AssignBsaveDefmdlItemHdrVals(&tempTemplateModule.header, &theModuleItem->header); GenWrite(&tempTemplateModule,sizeof(struct bsaveDeftemplateModule),fp); } /*============================================*/ /* Write out each deftemplate data structure. */ /*============================================*/ DeftemplateBinaryData(theEnv)->NumberOfTemplateSlots = 0; for (theModule = GetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = GetNextDefmodule(theEnv,theModule)) { SetCurrentModule(theEnv,theModule); for (theDeftemplate = GetNextDeftemplate(theEnv,NULL); theDeftemplate != NULL; theDeftemplate = GetNextDeftemplate(theEnv,theDeftemplate)) { AssignBsaveConstructHeaderVals(&tempDeftemplate.header, &theDeftemplate->header); tempDeftemplate.implied = theDeftemplate->implied; tempDeftemplate.numberOfSlots = theDeftemplate->numberOfSlots; tempDeftemplate.patternNetwork = BsaveFactPatternIndex(theDeftemplate->patternNetwork); if (theDeftemplate->slotList != NULL) { tempDeftemplate.slotList = DeftemplateBinaryData(theEnv)->NumberOfTemplateSlots; } else { tempDeftemplate.slotList = ULONG_MAX; } GenWrite(&tempDeftemplate,sizeof(struct bsaveDeftemplate),fp); DeftemplateBinaryData(theEnv)->NumberOfTemplateSlots += theDeftemplate->numberOfSlots; } } /*=============================================*/ /* Write out each templateSlot data structure. */ /*=============================================*/ for (theModule = GetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = GetNextDefmodule(theEnv,theModule)) { SetCurrentModule(theEnv,theModule); for (theDeftemplate = GetNextDeftemplate(theEnv,NULL); theDeftemplate != NULL; theDeftemplate = GetNextDeftemplate(theEnv,theDeftemplate)) { for (theSlot = theDeftemplate->slotList; theSlot != NULL; theSlot = theSlot->next) { tempTemplateSlot.constraints = ConstraintIndex(theSlot->constraints); tempTemplateSlot.slotName = theSlot->slotName->bucket; tempTemplateSlot.multislot = theSlot->multislot; tempTemplateSlot.noDefault = theSlot->noDefault; tempTemplateSlot.defaultPresent = theSlot->defaultPresent; tempTemplateSlot.defaultDynamic = theSlot->defaultDynamic; tempTemplateSlot.defaultList = HashedExpressionIndex(theEnv,theSlot->defaultList); tempTemplateSlot.facetList = HashedExpressionIndex(theEnv,theSlot->facetList); if (theSlot->next != NULL) tempTemplateSlot.next = 0L; else tempTemplateSlot.next = ULONG_MAX; GenWrite(&tempTemplateSlot,sizeof(struct bsaveTemplateSlot),fp); } } } /*=============================================================*/ /* If a binary image was already loaded when the bsave command */ /* was issued, then restore the counts indicating the number */ /* of deftemplates, deftemplate modules, and deftemplate slots */ /* in the binary image (these were overwritten by the binary */ /* save). */ /*=============================================================*/ RestoreBloadCount(theEnv,&DeftemplateBinaryData(theEnv)->NumberOfDeftemplates); RestoreBloadCount(theEnv,&DeftemplateBinaryData(theEnv)->NumberOfTemplateSlots); RestoreBloadCount(theEnv,&DeftemplateBinaryData(theEnv)->NumberOfTemplateModules); }
static void BsaveBinaryItem( FILE *fp) { unsigned long int space; struct defglobal *theDefglobal; struct bsaveDefglobal newDefglobal; struct defmodule *theModule; struct bsaveDefglobalModule tempDefglobalModule; struct defglobalModule *theModuleItem; /*==========================================================*/ /* Write out the amount of space taken up by the defglobal */ /* and defglobalModule data structures in the binary image. */ /*==========================================================*/ space = NumberOfDefglobals * sizeof(struct bsaveDefglobal) + (NumberOfDefglobalModules * sizeof(struct bsaveDefglobalModule)); GenWrite(&space,(unsigned long) sizeof(unsigned long int),fp); /*=================================================*/ /* Write out each defglobal module data structure. */ /*=================================================*/ NumberOfDefglobals = 0; for (theModule = (struct defmodule *) GetNextDefmodule(NULL); theModule != NULL; theModule = (struct defmodule *) GetNextDefmodule(theModule)) { SetCurrentModule((void *) theModule); theModuleItem = (struct defglobalModule *) GetModuleItem(NULL,FindModuleItem("defglobal")->moduleIndex); AssignBsaveDefmdlItemHdrVals(&tempDefglobalModule.header, &theModuleItem->header); GenWrite(&tempDefglobalModule,(unsigned long) sizeof(struct bsaveDefglobalModule),fp); } /*===========================*/ /* Write out each defglobal. */ /*===========================*/ NumberOfDefglobals = 0; for (theModule = (struct defmodule *) GetNextDefmodule(NULL); theModule != NULL; theModule = (struct defmodule *) GetNextDefmodule(theModule)) { SetCurrentModule((void *) theModule); for (theDefglobal = (struct defglobal *) GetNextDefglobal(NULL); theDefglobal != NULL; theDefglobal = (struct defglobal *) GetNextDefglobal(theDefglobal)) { AssignBsaveConstructHeaderVals(&newDefglobal.header, &theDefglobal->header); newDefglobal.initial = HashedExpressionIndex(theDefglobal->initial); GenWrite(&newDefglobal,(unsigned long) sizeof(struct bsaveDefglobal),fp); } } /*=============================================================*/ /* If a binary image was already loaded when the bsave command */ /* was issued, then restore the counts indicating the number */ /* of defglobals and defglobal modules in the binary image */ /* (these were overwritten by the binary save). */ /*=============================================================*/ if (Bloaded()) { RestoreBloadCount(&NumberOfDefglobalModules); RestoreBloadCount(&NumberOfDefglobals); } }
static void BsaveBinaryItem( void *theEnv, EXEC_STATUS, FILE *fp) { size_t space; struct defglobal *theDefglobal; struct bsaveDefglobal newDefglobal; struct defmodule *theModule; struct bsaveDefglobalModule tempDefglobalModule; struct defglobalModule *theModuleItem; /*==========================================================*/ /* Write out the amount of space taken up by the defglobal */ /* and defglobalModule data structures in the binary image. */ /*==========================================================*/ space = DefglobalBinaryData(theEnv,execStatus)->NumberOfDefglobals * sizeof(struct bsaveDefglobal) + (DefglobalBinaryData(theEnv,execStatus)->NumberOfDefglobalModules * sizeof(struct bsaveDefglobalModule)); GenWrite(&space,sizeof(size_t),fp); /*=================================================*/ /* Write out each defglobal module data structure. */ /*=================================================*/ DefglobalBinaryData(theEnv,execStatus)->NumberOfDefglobals = 0; for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,execStatus,NULL); theModule != NULL; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,execStatus,theModule)) { EnvSetCurrentModule(theEnv,execStatus,(void *) theModule); theModuleItem = (struct defglobalModule *) GetModuleItem(theEnv,execStatus,NULL,FindModuleItem(theEnv,execStatus,"defglobal")->moduleIndex); AssignBsaveDefmdlItemHdrVals(&tempDefglobalModule.header, &theModuleItem->header); GenWrite(&tempDefglobalModule,sizeof(struct bsaveDefglobalModule),fp); } /*===========================*/ /* Write out each defglobal. */ /*===========================*/ DefglobalBinaryData(theEnv,execStatus)->NumberOfDefglobals = 0; for (theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,execStatus,NULL); theModule != NULL; theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,execStatus,theModule)) { EnvSetCurrentModule(theEnv,execStatus,(void *) theModule); for (theDefglobal = (struct defglobal *) EnvGetNextDefglobal(theEnv,execStatus,NULL); theDefglobal != NULL; theDefglobal = (struct defglobal *) EnvGetNextDefglobal(theEnv,execStatus,theDefglobal)) { AssignBsaveConstructHeaderVals(&newDefglobal.header, &theDefglobal->header); newDefglobal.initial = HashedExpressionIndex(theEnv,execStatus,theDefglobal->initial); GenWrite(&newDefglobal,sizeof(struct bsaveDefglobal),fp); } } /*=============================================================*/ /* If a binary image was already loaded when the bsave command */ /* was issued, then restore the counts indicating the number */ /* of defglobals and defglobal modules in the binary image */ /* (these were overwritten by the binary save). */ /*=============================================================*/ RestoreBloadCount(theEnv,execStatus,&DefglobalBinaryData(theEnv,execStatus)->NumberOfDefglobalModules); RestoreBloadCount(theEnv,execStatus,&DefglobalBinaryData(theEnv,execStatus)->NumberOfDefglobals); }
/*************************************************** NAME : BsaveObjectPatterns DESCRIPTION : Writes ouyt object pattern data structures to binary save file INPUTS : Bsave file stream pointer RETURNS : Nothing useful SIDE EFFECTS : Data structures written NOTES : Extra padding written with alpha node bitmaps to ensure correct alignment of structues on bload ***************************************************/ static void BsaveObjectPatterns( FILE *fp) { UNLN space; OBJECT_ALPHA_NODE *alphaPtr; OBJECT_PATTERN_NODE *patternPtr; BSAVE_OBJECT_ALPHA_NODE dummyAlpha; BSAVE_OBJECT_PATTERN_NODE dummyPattern; space = (sizeof(BSAVE_OBJECT_ALPHA_NODE) * AlphaNodeCount) + (sizeof(BSAVE_OBJECT_PATTERN_NODE) * PatternNodeCount); GenWrite(&space,(UNLN) sizeof(UNLN),fp); /* ========================================== Write out the alpha terminal pattern nodes ========================================== */ alphaPtr = ObjectNetworkTerminalPointer(); while (alphaPtr != NULL) { AssignBsavePatternHeaderValues(&dummyAlpha.header,&alphaPtr->header); dummyAlpha.classbmp = alphaPtr->classbmp->bucket; if (alphaPtr->slotbmp != NULL) dummyAlpha.slotbmp = alphaPtr->slotbmp->bucket; else dummyAlpha.slotbmp = -1L; dummyAlpha.patternNode = BsaveObjectPatternIndex(alphaPtr->patternNode); dummyAlpha.nxtInGroup = BsaveObjectAlphaIndex(alphaPtr->nxtInGroup); dummyAlpha.nxtTerminal = BsaveObjectAlphaIndex(alphaPtr->nxtTerminal); GenWrite(&dummyAlpha,(UNLN) sizeof(BSAVE_OBJECT_ALPHA_NODE),fp); alphaPtr = alphaPtr->nxtTerminal; } /* ======================================== Write out the intermediate pattern nodes ======================================== */ patternPtr = ObjectNetworkPointer(); while (patternPtr != NULL) { dummyPattern.multifieldNode = patternPtr->multifieldNode; dummyPattern.whichField = patternPtr->whichField; dummyPattern.leaveFields = patternPtr->leaveFields; dummyPattern.endSlot = patternPtr->endSlot; dummyPattern.slotNameID = patternPtr->slotNameID; dummyPattern.networkTest = HashedExpressionIndex(patternPtr->networkTest); dummyPattern.nextLevel = BsaveObjectPatternIndex(patternPtr->nextLevel); dummyPattern.lastLevel = BsaveObjectPatternIndex(patternPtr->lastLevel); dummyPattern.leftNode = BsaveObjectPatternIndex(patternPtr->leftNode); dummyPattern.rightNode = BsaveObjectPatternIndex(patternPtr->rightNode); dummyPattern.alphaNode = BsaveObjectAlphaIndex(patternPtr->alphaNode); GenWrite(&dummyPattern,(UNLN) sizeof(BSAVE_OBJECT_PATTERN_NODE),fp); if (patternPtr->nextLevel == NULL) { while (patternPtr->rightNode == NULL) { patternPtr = patternPtr->lastLevel; if (patternPtr == NULL) return; } patternPtr = patternPtr->rightNode; } else patternPtr = patternPtr->nextLevel; } if (Bloaded()) { RestoreBloadCount(&AlphaNodeCount); RestoreBloadCount(&PatternNodeCount); } }