static void DeffactsToCode( void *theEnv, FILE *theFile, struct deffacts *theDeffacts, int imageID, int maxIndices, int moduleCount) { /*=================*/ /* Deffacts Header */ /*=================*/ fprintf(theFile,"{"); ConstructHeaderToCode(theEnv,theFile,&theDeffacts->header,imageID,maxIndices, moduleCount,ModulePrefix(DeffactsData(theEnv)->DeffactsCodeItem), ConstructPrefix(DeffactsData(theEnv)->DeffactsCodeItem)); fprintf(theFile,","); /*=============*/ /* Assert List */ /*=============*/ ExpressionToCode(theEnv,theFile,theDeffacts->assertList); fprintf(theFile,"}"); }
/**************************************************************** NAME : SingleDefgenericToCode DESCRIPTION : Writes out a single defgeneric's data to the file INPUTS : 1) The output file 2) The compile image id 3) The maximum number of elements in an array 4) The defgeneric 5) The module index 6) The partition holding the generic methods 7) The relative index of the generics methods in the partition RETURNS : Nothing useful SIDE EFFECTS : Defgeneric data written NOTES : None ***************************************************************/ static void SingleDefgenericToCode( FILE *theFile, int imageID, int maxIndices, DEFGENERIC *theDefgeneric, int moduleCount, int methodArrayVersion, int methodArrayCount) { /* ================== Defgeneric Header ================== */ fprintf(theFile,"{"); ConstructHeaderToCode(theFile,&theDefgeneric->header,imageID,maxIndices,moduleCount, ModulePrefix(DefgenericCodeItem), ConstructPrefix(DefgenericCodeItem)); /* ========================= Defgeneric specific data ========================= */ fprintf(theFile,",0,0,"); if (theDefgeneric->methods == NULL) fprintf(theFile,"NULL"); else { fprintf(theFile,"&%s%d_%d[%d]",MethodPrefix(),imageID, methodArrayVersion,methodArrayCount); } fprintf(theFile,",%u,0}",theDefgeneric->mcnt); }
/*************************************************** NAME : SingleDeffunctionToCode DESCRIPTION : Writes out a single deffunction's data to the file INPUTS : 1) The output file 2) The deffunction 3) The compile image id 4) The maximum number of elements in an array 5) The module index RETURNS : Nothing useful SIDE EFFECTS : Deffunction data written NOTES : None ***************************************************/ static void SingleDeffunctionToCode( void *theEnv, FILE *theFile, DEFFUNCTION *theDeffunction, int imageID, int maxIndices, int moduleCount) { /* ================== Deffunction Header ================== */ fprintf(theFile,"{"); ConstructHeaderToCode(theEnv,theFile,&theDeffunction->header,imageID,maxIndices,moduleCount, ModulePrefix(DeffunctionData(theEnv)->DeffunctionCodeItem), ConstructPrefix(DeffunctionData(theEnv)->DeffunctionCodeItem)); /* ========================= Deffunction specific data ========================= */ fprintf(theFile,",0,0,0,"); ExpressionToCode(theEnv,theFile,theDeffunction->code); fprintf(theFile,",%d,%d,%d", theDeffunction->minNumberOfParameters, theDeffunction->maxNumberOfParameters, theDeffunction->numberOfLocalVars); fprintf(theFile,"}"); }
static void DeftemplateToCode( void *theEnv, FILE *theFile, struct deftemplate *theTemplate, int imageID, int maxIndices, int moduleCount, int slotCount) { /*====================*/ /* Deftemplate Header */ /*====================*/ fprintf(theFile,"{"); ConstructHeaderToCode(theEnv,theFile,&theTemplate->header,imageID,maxIndices, moduleCount,ModulePrefix(DeftemplateData(theEnv)->DeftemplateCodeItem), ConstructPrefix(DeftemplateData(theEnv)->DeftemplateCodeItem)); fprintf(theFile,","); /*===========*/ /* Slot List */ /*===========*/ if (theTemplate->slotList == NULL) { fprintf(theFile,"NULL,"); } else { fprintf(theFile,"&%s%d_%d[%d],",SlotPrefix(), imageID, (slotCount / maxIndices) + 1, slotCount % maxIndices); } /*==========================================*/ /* Implied Flag, Watch Flag, In Scope Flag, */ /* Number of Slots, and Busy Count. */ /*==========================================*/ fprintf(theFile,"%d,0,0,%d,%ld,",theTemplate->implied,theTemplate->numberOfSlots,theTemplate->busyCount); /*=================*/ /* Pattern Network */ /*=================*/ if (theTemplate->patternNetwork == NULL) { fprintf(theFile,"NULL"); } else { FactPatternNodeReference(theEnv,theTemplate->patternNetwork,theFile,imageID,maxIndices); } /*============================================*/ /* Print the factList and lastFact references */ /* and close the structure. */ /*============================================*/ fprintf(theFile,",NULL,NULL}"); }
globle void DeftemplateCModuleReference( FILE *theFile, int count, int imageID, int maxIndices) { fprintf(theFile,"MIHS &%s%d_%d[%d]",ModulePrefix(DeftemplateCodeItem), imageID, (count / maxIndices) + 1, (count % maxIndices)); }
globle void DefruleCModuleReference( void *theEnv, FILE *theFile, int count, int imageID, int maxIndices) { fprintf(theFile,"MIHS &%s%d_%d[%d]",ModulePrefix(DefruleData(theEnv)->DefruleCodeItem), imageID, (count / maxIndices) + 1, (count % maxIndices)); }
void DefglobalCModuleReference( Environment *theEnv, FILE *theFile, unsigned long count, unsigned int imageID, unsigned int maxIndices) { fprintf(theFile,"MIHS &%s%u_%lu[%lu]", ModulePrefix(DefglobalData(theEnv)->DefglobalCodeItem), imageID, (count / maxIndices) + 1, (count % maxIndices)); }
globle void DefglobalCModuleReference( void *theEnv, EXEC_STATUS, FILE *theFile, int count, int imageID, int maxIndices) { fprintf(theFile,"MIHS &%s%d_%d[%d]", ModulePrefix(DefglobalData(theEnv,execStatus)->DefglobalCodeItem), imageID, (count / maxIndices) + 1, (count % maxIndices)); }
static void DefglobalToCode( void *theEnv, EXEC_STATUS, FILE *theFile, struct defglobal *theDefglobal, int imageID, int maxIndices, int moduleCount) { /*==================*/ /* Defglobal Header */ /*==================*/ fprintf(theFile,"{"); ConstructHeaderToCode(theEnv,execStatus,theFile,&theDefglobal->header,imageID,maxIndices, moduleCount,ModulePrefix(DefglobalData(theEnv,execStatus)->DefglobalCodeItem), ConstructPrefix(DefglobalData(theEnv,execStatus)->DefglobalCodeItem)); fprintf(theFile,","); /*============================================*/ /* Watch Flag, In Scope Flag, and Busy Count. */ /*============================================*/ fprintf(theFile,"0,0,%ld,",theDefglobal->busyCount); /*================*/ /* Current Value. */ /*================*/ fprintf(theFile,"{NULL,RVOID}"); /*=====================*/ /* Initial Expression. */ /*=====================*/ fprintf(theFile,","); PrintHashedExpressionReference(theEnv,execStatus,theFile,theDefglobal->initial,imageID,maxIndices); fprintf(theFile,"}"); }
static void DefglobalToCode( Environment *theEnv, FILE *theFile, Defglobal *theDefglobal, unsigned int imageID, unsigned int maxIndices, unsigned int moduleCount) { /*==================*/ /* Defglobal Header */ /*==================*/ fprintf(theFile,"{"); ConstructHeaderToCode(theEnv,theFile,&theDefglobal->header,imageID,maxIndices, moduleCount,ModulePrefix(DefglobalData(theEnv)->DefglobalCodeItem), ConstructPrefix(DefglobalData(theEnv)->DefglobalCodeItem)); fprintf(theFile,","); /*============================================*/ /* Watch Flag, In Scope Flag, and Busy Count. */ /*============================================*/ fprintf(theFile,"0,0,%ld,",theDefglobal->busyCount); /*================*/ /* Current Value. */ /*================*/ fprintf(theFile,"{ { NULL } }"); /*=====================*/ /* Initial Expression. */ /*=====================*/ fprintf(theFile,","); PrintHashedExpressionReference(theEnv,theFile,theDefglobal->initial,imageID,maxIndices); fprintf(theFile,"}"); }
/*************************************************** NAME : SingleDefinstancesToCode DESCRIPTION : Writes out a single definstances' data to the file INPUTS : 1) The output file 2) The definstances 3) The compile image id 4) The maximum number of elements in an array 5) The module index RETURNS : Nothing useful SIDE EFFECTS : Definstances data written NOTES : None ***************************************************/ static void SingleDefinstancesToCode( FILE *theFile, DEFINSTANCES *theDefinstances, int imageID, int maxIndices, int moduleCount) { /* =================== Definstances Header =================== */ fprintf(theFile,"{"); ConstructHeaderToCode(theFile,&theDefinstances->header,imageID,maxIndices,moduleCount, ModulePrefix(DefinstancesCodeItem), ConstructPrefix(DefinstancesCodeItem)); /* ========================== Definstances specific data ========================== */ fprintf(theFile,",0,"); ExpressionToCode(theFile,theDefinstances->mkinstance); fprintf(theFile,"}"); }
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); }
/******************************************************* NAME : DefinstancesToCode DESCRIPTION : Writes out static array code for definstances INPUTS : 1) The base name of the construct set 2) The base id for this construct 3) The file pointer for the header file 4) The base id for the construct set 5) The max number of indices allowed in an array RETURNS : -1 if no definstances, 0 on errors, 1 if definstances written SIDE EFFECTS : Code written to files NOTES : None *******************************************************/ static int DefinstancesToCode( void *theEnv, char *fileName, char *pathName, char *fileNameBuffer, int fileID, FILE *headerFP, int imageID, int maxIndices) { int fileCount = 1; struct defmodule *theModule; DEFINSTANCES *theDefinstances; int moduleCount = 0, moduleArrayCount = 0, moduleArrayVersion = 1; int definstancesArrayCount = 0, definstancesArrayVersion = 1; FILE *moduleFile = NULL, *definstancesFile = NULL; /* ================================================ Include the appropriate definstances header file ================================================ */ fprintf(headerFP,"#include \"defins.h\"\n"); /* ============================================================= Loop through all the modules and all the definstances writing their C code representation to the file as they are traversed ============================================================= */ theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); while (theModule != NULL) { EnvSetCurrentModule(theEnv,(void *) theModule); moduleFile = OpenFileIfNeeded(theEnv,moduleFile,fileName,pathName,fileNameBuffer,fileID,imageID,&fileCount, moduleArrayVersion,headerFP, (char*)"DEFINSTANCES_MODULE",ModulePrefix(DefinstancesData(theEnv)->DefinstancesCodeItem), FALSE,NULL); if (moduleFile == NULL) { CloseDefinstancesFiles(theEnv,moduleFile,definstancesFile,maxIndices); return(0); } DefinstancesModuleToCode(theEnv,moduleFile,theModule,imageID,maxIndices); moduleFile = CloseFileIfNeeded(theEnv,moduleFile,&moduleArrayCount,&moduleArrayVersion, maxIndices,NULL,NULL); theDefinstances = (DEFINSTANCES *) EnvGetNextDefinstances(theEnv,NULL); while (theDefinstances != NULL) { definstancesFile = OpenFileIfNeeded(theEnv,definstancesFile,fileName,pathName,fileNameBuffer,fileID,imageID,&fileCount, definstancesArrayVersion,headerFP, (char*)"DEFINSTANCES",ConstructPrefix(DefinstancesData(theEnv)->DefinstancesCodeItem), FALSE,NULL); if (definstancesFile == NULL) { CloseDefinstancesFiles(theEnv,moduleFile,definstancesFile,maxIndices); return(0); } SingleDefinstancesToCode(theEnv,definstancesFile,theDefinstances,imageID, maxIndices,moduleCount); definstancesArrayCount++; definstancesFile = CloseFileIfNeeded(theEnv,definstancesFile,&definstancesArrayCount, &definstancesArrayVersion,maxIndices,NULL,NULL); theDefinstances = (DEFINSTANCES *) EnvGetNextDefinstances(theEnv,theDefinstances); } theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule); moduleCount++; moduleArrayCount++; } CloseDefinstancesFiles(theEnv,moduleFile,definstancesFile,maxIndices); return(1); }
static bool ConstructToCode( Environment *theEnv, const char *fileName, const char *pathName, char *fileNameBuffer, unsigned int fileID, FILE *headerFP, unsigned int imageID, unsigned int maxIndices) { unsigned int fileCount = 1; Defmodule *theModule; Deffacts *theDeffacts; unsigned int moduleCount = 0, moduleArrayCount = 0, moduleArrayVersion = 1; unsigned int deffactsArrayCount = 0, deffactsArrayVersion = 1; FILE *moduleFile = NULL, *deffactsFile = NULL; /*===============================================*/ /* Include the appropriate deffacts header file. */ /*===============================================*/ fprintf(headerFP,"#include \"dffctdef.h\"\n"); /*=================================================================*/ /* Loop through all the modules and all the deffacts writing their */ /* C code representation to the file as they are traversed. */ /*=================================================================*/ for (theModule = GetNextDefmodule(theEnv,NULL); theModule != NULL; theModule = GetNextDefmodule(theEnv,theModule)) { SetCurrentModule(theEnv,theModule); moduleFile = OpenFileIfNeeded(theEnv,moduleFile,fileName,pathName,fileNameBuffer,fileID,imageID,&fileCount, moduleArrayVersion,headerFP, "struct deffactsModule",ModulePrefix(DeffactsData(theEnv)->DeffactsCodeItem), false,NULL); if (moduleFile == NULL) { CloseDeffactsFiles(theEnv,moduleFile,deffactsFile,maxIndices); return false; } DeffactsModuleToCode(theEnv,moduleFile,theModule,imageID,maxIndices,moduleCount); moduleFile = CloseFileIfNeeded(theEnv,moduleFile,&moduleArrayCount,&moduleArrayVersion, maxIndices,NULL,NULL); /*===================================================*/ /* Loop through each of the deffacts in this module. */ /*===================================================*/ for (theDeffacts = GetNextDeffacts(theEnv,NULL); theDeffacts != NULL; theDeffacts = GetNextDeffacts(theEnv,theDeffacts)) { deffactsFile = OpenFileIfNeeded(theEnv,deffactsFile,fileName,pathName,fileNameBuffer,fileID,imageID,&fileCount, deffactsArrayVersion,headerFP, "Deffacts",ConstructPrefix(DeffactsData(theEnv)->DeffactsCodeItem), false,NULL); if (deffactsFile == NULL) { CloseDeffactsFiles(theEnv,moduleFile,deffactsFile,maxIndices); return false; } DeffactsToCode(theEnv,deffactsFile,theDeffacts,imageID,maxIndices,moduleCount); deffactsArrayCount++; deffactsFile = CloseFileIfNeeded(theEnv,deffactsFile,&deffactsArrayCount, &deffactsArrayVersion,maxIndices,NULL,NULL); } moduleCount++; moduleArrayCount++; } CloseDeffactsFiles(theEnv,moduleFile,deffactsFile,maxIndices); return true; }
/******************************************************* NAME : DefgenericsToCode DESCRIPTION : Writes out static array code for generic functions, methods, etc. INPUTS : 1) The base name of the construct set 2) The base id for this construct 3) The file pointer for the header file 4) The base id for the construct set 5) The max number of indices allowed in an array RETURNS : -1 if no generic functions, 0 on errors, 1 if generic functions written SIDE EFFECTS : Code written to files NOTES : None *******************************************************/ static int DefgenericsToCode( char *fileName, int fileID, FILE *headerFP, int imageID, int maxIndices) { int fileCount = 1; struct defmodule *theModule; DEFGENERIC *theDefgeneric; DEFMETHOD *theMethod; RESTRICTION *theRestriction; register unsigned i,j,k; int moduleCount = 0; int itemArrayCounts[SAVE_ITEMS]; int itemArrayVersions[SAVE_ITEMS]; FILE *itemFiles[SAVE_ITEMS]; int itemReopenFlags[SAVE_ITEMS]; struct CodeGeneratorFile itemCodeFiles[SAVE_ITEMS]; for (i = 0 ; i < SAVE_ITEMS ; i++) { itemArrayCounts[i] = 0; itemArrayVersions[i] = 1; itemFiles[i] = NULL; itemReopenFlags[i] = FALSE; itemCodeFiles[i].filePrefix = NULL; } /* =========================================== Include the appropriate generic header file =========================================== */ fprintf(headerFP,"#include \"genrcfun.h\"\n"); /* ============================================================= Loop through all the modules and all the defgenerics writing their C code representation to the file as they are traversed ============================================================= */ theModule = (struct defmodule *) GetNextDefmodule(NULL); while (theModule != NULL) { SetCurrentModule((void *) theModule); itemFiles[MODULEI] = OpenFileIfNeeded(itemFiles[MODULEI],fileName,fileID,imageID,&fileCount, itemArrayVersions[MODULEI],headerFP, "DEFGENERIC_MODULE",ModulePrefix(DefgenericCodeItem), itemReopenFlags[MODULEI],&itemCodeFiles[MODULEI]); if (itemFiles[MODULEI] == NULL) goto GenericCodeError; DefgenericModuleToCode(itemFiles[MODULEI],theModule,imageID,maxIndices); itemFiles[MODULEI] = CloseFileIfNeeded(itemFiles[MODULEI],&itemArrayCounts[MODULEI], &itemArrayVersions[MODULEI],maxIndices, &itemReopenFlags[MODULEI],&itemCodeFiles[MODULEI]); theDefgeneric = (DEFGENERIC *) GetNextDefgeneric(NULL); while (theDefgeneric != NULL) { itemFiles[GENERICI] = OpenFileIfNeeded(itemFiles[GENERICI],fileName,fileID,imageID,&fileCount, itemArrayVersions[GENERICI],headerFP, "DEFGENERIC",ConstructPrefix(DefgenericCodeItem), itemReopenFlags[GENERICI],&itemCodeFiles[GENERICI]); if (itemFiles[GENERICI] == NULL) goto GenericCodeError; SingleDefgenericToCode(itemFiles[GENERICI],imageID,maxIndices,theDefgeneric, moduleCount,itemArrayVersions[METHODI], itemArrayCounts[METHODI]); itemArrayCounts[GENERICI]++; itemFiles[GENERICI] = CloseFileIfNeeded(itemFiles[GENERICI],&itemArrayCounts[GENERICI], &itemArrayVersions[GENERICI],maxIndices, &itemReopenFlags[GENERICI],&itemCodeFiles[GENERICI]); if (theDefgeneric->mcnt > 0) { /* =========================================== Make sure that all methods for a particular generic function go into the same array =========================================== */ itemFiles[METHODI] = OpenFileIfNeeded(itemFiles[METHODI],fileName,fileID,imageID,&fileCount, itemArrayVersions[METHODI],headerFP, "DEFMETHOD",MethodPrefix(), itemReopenFlags[METHODI],&itemCodeFiles[METHODI]); if (itemFiles[METHODI] == NULL) goto GenericCodeError; for (i = 0 ; i < theDefgeneric->mcnt ; i++) { theMethod = &theDefgeneric->methods[i]; if (i > 0) fprintf(itemFiles[METHODI],",\n"); MethodToCode(itemFiles[METHODI],imageID,theMethod, itemArrayVersions[RESTRICTIONI],itemArrayCounts[RESTRICTIONI]); if (theMethod->restrictionCount > 0) { /* ======================================== Make sure that all restrictions for a particular method go into the same array ======================================== */ itemFiles[RESTRICTIONI] = OpenFileIfNeeded(itemFiles[RESTRICTIONI],fileName,fileID, imageID,&fileCount, itemArrayVersions[RESTRICTIONI],headerFP, "RESTRICTION",RestrictionPrefix(), itemReopenFlags[RESTRICTIONI],&itemCodeFiles[RESTRICTIONI]); if (itemFiles[RESTRICTIONI] == NULL) goto GenericCodeError; for (j = 0 ; j < theMethod->restrictionCount ; j++) { theRestriction = &theMethod->restrictions[j]; if (j > 0) fprintf(itemFiles[RESTRICTIONI],",\n"); RestrictionToCode(itemFiles[RESTRICTIONI],imageID,theRestriction, itemArrayVersions[TYPEI],itemArrayCounts[TYPEI]); if (theRestriction->tcnt > 0) { /* ========================================= Make sure that all types for a particular restriction go into the same array ========================================= */ itemFiles[TYPEI] = OpenFileIfNeeded(itemFiles[TYPEI],fileName,fileID, imageID,&fileCount, itemArrayVersions[TYPEI],headerFP, "void *",TypePrefix(), itemReopenFlags[TYPEI],&itemCodeFiles[TYPEI]); if (itemFiles[TYPEI] == NULL) goto GenericCodeError; for (k = 0 ; k < theRestriction->tcnt ; k++) { if (k > 0) fprintf(itemFiles[TYPEI],",\n"); TypeToCode(itemFiles[TYPEI],imageID, theRestriction->types[k],maxIndices); } itemArrayCounts[TYPEI] += theRestriction->tcnt; itemFiles[TYPEI] = CloseFileIfNeeded(itemFiles[TYPEI],&itemArrayCounts[TYPEI], &itemArrayVersions[TYPEI],maxIndices, &itemReopenFlags[TYPEI],&itemCodeFiles[TYPEI]); } } itemArrayCounts[RESTRICTIONI] += theMethod->restrictionCount; itemFiles[RESTRICTIONI] = CloseFileIfNeeded(itemFiles[RESTRICTIONI],&itemArrayCounts[RESTRICTIONI], &itemArrayVersions[RESTRICTIONI],maxIndices, &itemReopenFlags[RESTRICTIONI],&itemCodeFiles[RESTRICTIONI]); } } itemArrayCounts[METHODI] += theDefgeneric->mcnt; itemFiles[METHODI] = CloseFileIfNeeded(itemFiles[METHODI],&itemArrayCounts[METHODI], &itemArrayVersions[METHODI],maxIndices, &itemReopenFlags[METHODI],&itemCodeFiles[METHODI]); } theDefgeneric = (DEFGENERIC *) GetNextDefgeneric(theDefgeneric); } theModule = (struct defmodule *) GetNextDefmodule(theModule); moduleCount++; itemArrayCounts[MODULEI]++; } CloseDefgenericFiles(itemFiles,itemReopenFlags,itemCodeFiles,maxIndices); return(1); GenericCodeError: CloseDefgenericFiles(itemFiles,itemReopenFlags,itemCodeFiles,maxIndices); return(0); }
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 defrule *theDefrule; int joinArrayCount = 0, joinArrayVersion = 1; int linkArrayCount = 0, linkArrayVersion = 1; int moduleCount = 0, moduleArrayCount = 0, moduleArrayVersion = 1; int defruleArrayCount = 0, defruleArrayVersion = 1; FILE *joinFile = NULL, *moduleFile = NULL, *defruleFile = NULL, *linkFile = NULL; /*==============================================*/ /* Include the appropriate defrule header file. */ /*==============================================*/ fprintf(headerFP,"#include \"ruledef.h\"\n"); /*======================================*/ /* Save the left and right prime links. */ /*======================================*/ if (! TraverseJoinLinks(theEnv,DefruleData(theEnv)->LeftPrimeJoins,fileName,pathName,fileNameBuffer,fileID,headerFP,imageID, maxIndices,&linkFile,&fileCount,&linkArrayVersion,&linkArrayCount)) { CloseDefruleFiles(theEnv,moduleFile,defruleFile,joinFile,linkFile,maxIndices); return(0); } if (! TraverseJoinLinks(theEnv,DefruleData(theEnv)->RightPrimeJoins,fileName,pathName,fileNameBuffer,fileID,headerFP,imageID, maxIndices,&linkFile,&fileCount,&linkArrayVersion,&linkArrayCount)) { CloseDefruleFiles(theEnv,moduleFile,defruleFile,joinFile,linkFile,maxIndices); return(0); } /*=========================================================*/ /* Loop through all the modules, all the defrules, and all */ /* the join nodes 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)) { /*=========================*/ /* Set the current module. */ /*=========================*/ EnvSetCurrentModule(theEnv,(void *) theModule); /*==========================*/ /* Save the defrule module. */ /*==========================*/ moduleFile = OpenFileIfNeeded(theEnv,moduleFile,fileName,pathName,fileNameBuffer,fileID,imageID,&fileCount, moduleArrayVersion,headerFP, (char*)"struct defruleModule",ModulePrefix(DefruleData(theEnv)->DefruleCodeItem), FALSE,NULL); if (moduleFile == NULL) { CloseDefruleFiles(theEnv,moduleFile,defruleFile,joinFile,linkFile,maxIndices); return(0); } DefruleModuleToCode(theEnv,moduleFile,theModule,imageID,maxIndices,moduleCount); moduleFile = CloseFileIfNeeded(theEnv,moduleFile,&moduleArrayCount,&moduleArrayVersion, maxIndices,NULL,NULL); /*=========================================*/ /* Loop through all of the defrules (and */ /* their disjuncts) in the current module. */ /*=========================================*/ theDefrule = (struct defrule *) EnvGetNextDefrule(theEnv,NULL); while (theDefrule != NULL) { /*===================================*/ /* Save the defrule data structures. */ /*===================================*/ defruleFile = OpenFileIfNeeded(theEnv,defruleFile,fileName,pathName,fileNameBuffer,fileID,imageID,&fileCount, defruleArrayVersion,headerFP, (char*)"struct defrule",ConstructPrefix(DefruleData(theEnv)->DefruleCodeItem), FALSE,NULL); if (defruleFile == NULL) { CloseDefruleFiles(theEnv,moduleFile,defruleFile,joinFile,linkFile,maxIndices); return(0); } DefruleToCode(theEnv,defruleFile,theDefrule,imageID,maxIndices, moduleCount); defruleArrayCount++; defruleFile = CloseFileIfNeeded(theEnv,defruleFile,&defruleArrayCount,&defruleArrayVersion, maxIndices,NULL,NULL); /*================================*/ /* Save the join data structures. */ /*================================*/ if (! RuleCompilerTraverseJoins(theEnv,theDefrule->lastJoin,fileName,pathName,fileNameBuffer,fileID,headerFP,imageID, maxIndices,&joinFile,&linkFile,&fileCount,&joinArrayVersion,&joinArrayCount, &linkArrayVersion,&linkArrayCount)) { CloseDefruleFiles(theEnv,moduleFile,defruleFile,joinFile,linkFile,maxIndices); return(0); } /*==========================================*/ /* Move on to the next disjunct or defrule. */ /*==========================================*/ if (theDefrule->disjunct != NULL) theDefrule = theDefrule->disjunct; else theDefrule = (struct defrule *) EnvGetNextDefrule(theEnv,theDefrule); } moduleCount++; moduleArrayCount++; } CloseDefruleFiles(theEnv,moduleFile,defruleFile,joinFile,linkFile,maxIndices); return(1); }
static void DefruleToCode( void *theEnv, FILE *theFile, struct defrule *theDefrule, int imageID, int maxIndices, int moduleCount) { /*==================*/ /* Construct Header */ /*==================*/ fprintf(theFile,"{"); ConstructHeaderToCode(theEnv,theFile,&theDefrule->header,imageID,maxIndices, moduleCount,ModulePrefix(DefruleData(theEnv)->DefruleCodeItem), ConstructPrefix(DefruleData(theEnv)->DefruleCodeItem)); /*==========================*/ /* Flags and Integer Values */ /*==========================*/ fprintf(theFile,",%d,%d,%d,%d,%d,%d,%d,%d,", theDefrule->salience,theDefrule->localVarCnt, theDefrule->complexity,theDefrule->afterBreakpoint, theDefrule->watchActivation,theDefrule->watchFiring, theDefrule->autoFocus,theDefrule->executing); /*==================*/ /* Dynamic Salience */ /*==================*/ ExpressionToCode(theEnv,theFile,theDefrule->dynamicSalience); fprintf(theFile,","); /*=============*/ /* RHS Actions */ /*=============*/ ExpressionToCode(theEnv,theFile,theDefrule->actions); fprintf(theFile,","); /*=========================*/ /* Logical Dependency Join */ /*=========================*/ if (theDefrule->logicalJoin != NULL) { fprintf(theFile,"&%s%d_%ld[%ld],",JoinPrefix(), imageID,(theDefrule->logicalJoin->bsaveID / maxIndices) + 1, theDefrule->logicalJoin->bsaveID % maxIndices); } else { fprintf(theFile,"NULL,"); } /*===========*/ /* Last Join */ /*===========*/ if (theDefrule->lastJoin != NULL) { fprintf(theFile,"&%s%d_%ld[%ld],",JoinPrefix(), imageID,(theDefrule->lastJoin->bsaveID / maxIndices) + 1, theDefrule->lastJoin->bsaveID % maxIndices); } else { fprintf(theFile,"NULL,"); } /*===============*/ /* Next Disjunct */ /*===============*/ if (theDefrule->disjunct != NULL) { fprintf(theFile,"&%s%d_%ld[%ld]}",ConstructPrefix(DefruleData(theEnv)->DefruleCodeItem), imageID,(theDefrule->disjunct->header.bsaveID / maxIndices) + 1, theDefrule->disjunct->header.bsaveID % maxIndices); } else { fprintf(theFile,"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 deftemplate *theTemplate; struct templateSlot *slotPtr; int slotCount = 0, slotArrayCount = 0, slotArrayVersion = 1; int moduleCount = 0, moduleArrayCount = 0, moduleArrayVersion = 1; int templateArrayCount = 0, templateArrayVersion = 1; FILE *slotFile = NULL, *moduleFile = NULL, *templateFile = NULL; /*==================================================*/ /* Include the appropriate deftemplate header file. */ /*==================================================*/ fprintf(headerFP,"#include \"tmpltdef.h\"\n"); /*=============================================================*/ /* Loop through all the modules, all the deftemplates, and all */ /* the deftemplate slots writing their C code representation */ /* to the file as they are traversed. */ /*=============================================================*/ theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); while (theModule != NULL) { EnvSetCurrentModule(theEnv,(void *) theModule); moduleFile = OpenFileIfNeeded(theEnv,moduleFile,fileName,pathName,fileNameBuffer,fileID,imageID,&fileCount, moduleArrayVersion,headerFP, (char*)"struct deftemplateModule",ModulePrefix(DeftemplateData(theEnv)->DeftemplateCodeItem), FALSE,NULL); if (moduleFile == NULL) { CloseDeftemplateFiles(theEnv,moduleFile,templateFile,slotFile,maxIndices); return(0); } DeftemplateModuleToCode(theEnv,moduleFile,theModule,imageID,maxIndices,moduleCount); moduleFile = CloseFileIfNeeded(theEnv,moduleFile,&moduleArrayCount,&moduleArrayVersion, maxIndices,NULL,NULL); /*=======================================================*/ /* Loop through each of the deftemplates in this module. */ /*=======================================================*/ theTemplate = (struct deftemplate *) EnvGetNextDeftemplate(theEnv,NULL); while (theTemplate != NULL) { templateFile = OpenFileIfNeeded(theEnv,templateFile,fileName,pathName,fileNameBuffer,fileID,imageID,&fileCount, templateArrayVersion,headerFP, (char*)"struct deftemplate",ConstructPrefix(DeftemplateData(theEnv)->DeftemplateCodeItem), FALSE,NULL); if (templateFile == NULL) { CloseDeftemplateFiles(theEnv,moduleFile,templateFile,slotFile,maxIndices); return(0); } DeftemplateToCode(theEnv,templateFile,theTemplate,imageID,maxIndices, moduleCount,slotCount); templateArrayCount++; templateFile = CloseFileIfNeeded(theEnv,templateFile,&templateArrayCount,&templateArrayVersion, maxIndices,NULL,NULL); /*======================================================*/ /* Loop through each of the slots for this deftemplate. */ /*======================================================*/ slotPtr = theTemplate->slotList; while (slotPtr != NULL) { slotFile = OpenFileIfNeeded(theEnv,slotFile,fileName,pathName,fileNameBuffer,fileID,imageID,&fileCount, slotArrayVersion,headerFP, (char*)"struct templateSlot",SlotPrefix(),FALSE,NULL); if (slotFile == NULL) { CloseDeftemplateFiles(theEnv,moduleFile,templateFile,slotFile,maxIndices); return(0); } SlotToCode(theEnv,slotFile,slotPtr,imageID,maxIndices,slotCount); slotCount++; slotArrayCount++; slotFile = CloseFileIfNeeded(theEnv,slotFile,&slotArrayCount,&slotArrayVersion, maxIndices,NULL,NULL); slotPtr = slotPtr->next; } theTemplate = (struct deftemplate *) EnvGetNextDeftemplate(theEnv,theTemplate); } theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule); moduleCount++; moduleArrayCount++; } CloseDeftemplateFiles(theEnv,moduleFile,templateFile,slotFile,maxIndices); return(1); }
static int ConstructToCode( char *fileName, int fileID, FILE *headerFP, int imageID, int maxIndices) { int fileCount = 1; struct defmodule *theModule; struct defrule *theDefrule; struct joinNode *theJoin; int joinArrayCount = 0, joinArrayVersion = 1; int moduleCount = 0, moduleArrayCount = 0, moduleArrayVersion = 1; int defruleArrayCount = 0, defruleArrayVersion = 1; FILE *joinFile = NULL, *moduleFile = NULL, *defruleFile = NULL; #if FUZZY_DEFTEMPLATES struct fzSlotLocator *thePatternFv; int patternFvArrayCount = 0, patternFvArrayVersion = 1; FILE *patternFvFile = NULL; #endif /*==============================================*/ /* Include the appropriate defrule header file. */ /*==============================================*/ fprintf(headerFP,"#include \"ruledef.h\"\n"); /*=========================================================*/ /* Loop through all the modules, all the defrules, and all */ /* the join nodes writing their C code representation to */ /* the file as they are traversed. */ /*=========================================================*/ #if FUZZY_DEFTEMPLATES /*=========================================================*/ /* ALSO write the patternFv arrays as required if Fuzzy */ /*=========================================================*/ #endif for (theModule = (struct defmodule *) GetNextDefmodule(NULL); theModule != NULL; theModule = (struct defmodule *) GetNextDefmodule(theModule)) { /*=========================*/ /* Set the current module. */ /*=========================*/ SetCurrentModule((void *) theModule); /*==========================*/ /* Save the defrule module. */ /*==========================*/ moduleFile = OpenFileIfNeeded(moduleFile,fileName,fileID,imageID,&fileCount, moduleArrayVersion,headerFP, "struct defruleModule",ModulePrefix(DefruleCodeItem), FALSE,NULL); if (moduleFile == NULL) { #if FUZZY_DEFTEMPLATES CloseDefruleFiles(moduleFile,defruleFile,joinFile,patternFvFile,maxIndices); #else CloseDefruleFiles(moduleFile,defruleFile,joinFile,maxIndices); #endif return(0); } DefruleModuleToCode(moduleFile,theModule,imageID,maxIndices,moduleCount); moduleFile = CloseFileIfNeeded(moduleFile,&moduleArrayCount,&moduleArrayVersion, maxIndices,NULL,NULL); /*=========================================*/ /* Loop through all of the defrules (and */ /* their disjuncts) in the current module. */ /*=========================================*/ theDefrule = (struct defrule *) GetNextDefrule(NULL); while (theDefrule != NULL) { /*===================================*/ /* Save the defrule data structures. */ /*===================================*/ defruleFile = OpenFileIfNeeded(defruleFile,fileName,fileID,imageID,&fileCount, defruleArrayVersion,headerFP, "struct defrule",ConstructPrefix(DefruleCodeItem), FALSE,NULL); if (defruleFile == NULL) { #if FUZZY_DEFTEMPLATES CloseDefruleFiles(moduleFile,defruleFile,joinFile,patternFvFile,maxIndices); #else CloseDefruleFiles(moduleFile,defruleFile,joinFile,maxIndices); #endif return(0); } #if FUZZY_DEFTEMPLATES DefruleToCode(defruleFile,theDefrule,imageID,maxIndices, moduleCount, patternFvArrayCount, patternFvArrayVersion); #else DefruleToCode(defruleFile,theDefrule,imageID,maxIndices, moduleCount); #endif defruleArrayCount++; defruleFile = CloseFileIfNeeded(defruleFile,&defruleArrayCount,&defruleArrayVersion, maxIndices,NULL,NULL); #if FUZZY_DEFTEMPLATES /* write out the patternFv array of fzSlotLocator structs */ thePatternFv = theDefrule->pattern_fv_arrayPtr; if (thePatternFv != NULL) { int i; int numFzSlots = theDefrule->numberOfFuzzySlots; patternFvFile = OpenFileIfNeeded(patternFvFile,fileName,fileID,imageID,&fileCount, patternFvArrayVersion,headerFP, "struct fzSlotLocator",PatternFvPrefix(),FALSE,NULL); if (patternFvFile == NULL) { CloseDefruleFiles(moduleFile,defruleFile,joinFile,patternFvFile,maxIndices); return(0); } for (i=0; i< numFzSlots; i++) { fprintf(patternFvFile, "{%d, %d, ", thePatternFv[i].patternNum, thePatternFv[i].slotNum); PrintFuzzyValueReference(patternFvFile,thePatternFv[i].fvhnPtr); fprintf(patternFvFile, "}"); if (i != numFzSlots-1) fprintf(patternFvFile, ","); } patternFvArrayCount += numFzSlots; patternFvFile = CloseFileIfNeeded(patternFvFile,&patternFvArrayCount,&patternFvArrayVersion, maxIndices,NULL,NULL); } #endif /*================================*/ /* Save the join data structures. */ /*================================*/ for (theJoin = theDefrule->lastJoin; theJoin != NULL; theJoin = GetPreviousJoin(theJoin)) { if (theJoin->marked) { joinFile = OpenFileIfNeeded(joinFile,fileName,fileID,imageID,&fileCount, joinArrayVersion,headerFP, "struct joinNode",JoinPrefix(),FALSE,NULL); if (joinFile == NULL) { #if FUZZY_DEFTEMPLATES CloseDefruleFiles(moduleFile,defruleFile,joinFile,patternFvFile,maxIndices); #else CloseDefruleFiles(moduleFile,defruleFile,joinFile,maxIndices); #endif return(0); } JoinToCode(joinFile,theJoin,imageID,maxIndices); joinArrayCount++; joinFile = CloseFileIfNeeded(joinFile,&joinArrayCount,&joinArrayVersion, maxIndices,NULL,NULL); } } /*==========================================*/ /* Move on to the next disjunct or defrule. */ /*==========================================*/ if (theDefrule->disjunct != NULL) theDefrule = theDefrule->disjunct; else theDefrule = (struct defrule *) GetNextDefrule(theDefrule); } moduleCount++; moduleArrayCount++; } #if FUZZY_DEFTEMPLATES CloseDefruleFiles(moduleFile,defruleFile,joinFile,patternFvFile,maxIndices); #else CloseDefruleFiles(moduleFile,defruleFile,joinFile,maxIndices); #endif return(1); }
/******************************************************* NAME : DeffunctionsToCode DESCRIPTION : Writes out static array code for deffunctions INPUTS : 1) The base name of the construct set 2) The base id for this construct 3) The file pointer for the header file 4) The base id for the construct set 5) The max number of indices allowed in an array RETURNS : 0 on errors, 1 if deffunctions written SIDE EFFECTS : Code written to files NOTES : None *******************************************************/ static bool DeffunctionsToCode( void *theEnv, const char *fileName, const char *pathName, char *fileNameBuffer, int fileID, FILE *headerFP, int imageID, int maxIndices) { int fileCount = 1; struct defmodule *theModule; DEFFUNCTION *theDeffunction; int moduleCount = 0, moduleArrayCount = 0, moduleArrayVersion = 1; int deffunctionArrayCount = 0, deffunctionArrayVersion = 1; FILE *moduleFile = NULL, *deffunctionFile = NULL; /* =============================================== Include the appropriate deffunction header file =============================================== */ fprintf(headerFP,"#include \"dffnxfun.h\"\n"); /* ============================================================= Loop through all the modules and all the deffunctions writing their C code representation to the file as they are traversed ============================================================= */ theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL); while (theModule != NULL) { EnvSetCurrentModule(theEnv,(void *) theModule); moduleFile = OpenFileIfNeeded(theEnv,moduleFile,fileName,pathName,fileNameBuffer,fileID,imageID,&fileCount, moduleArrayVersion,headerFP, "DEFFUNCTION_MODULE",ModulePrefix(DeffunctionData(theEnv)->DeffunctionCodeItem), false,NULL); if (moduleFile == NULL) { CloseDeffunctionFiles(theEnv,moduleFile,deffunctionFile,maxIndices); return(false); } DeffunctionModuleToCode(theEnv,moduleFile,theModule,imageID,maxIndices); moduleFile = CloseFileIfNeeded(theEnv,moduleFile,&moduleArrayCount,&moduleArrayVersion, maxIndices,NULL,NULL); theDeffunction = (DEFFUNCTION *) EnvGetNextDeffunction(theEnv,NULL); while (theDeffunction != NULL) { deffunctionFile = OpenFileIfNeeded(theEnv,deffunctionFile,fileName,pathName,fileNameBuffer,fileID,imageID,&fileCount, deffunctionArrayVersion,headerFP, "DEFFUNCTION",ConstructPrefix(DeffunctionData(theEnv)->DeffunctionCodeItem), false,NULL); if (deffunctionFile == NULL) { CloseDeffunctionFiles(theEnv,moduleFile,deffunctionFile,maxIndices); return(false); } SingleDeffunctionToCode(theEnv,deffunctionFile,theDeffunction,imageID, maxIndices,moduleCount); deffunctionArrayCount++; deffunctionFile = CloseFileIfNeeded(theEnv,deffunctionFile,&deffunctionArrayCount, &deffunctionArrayVersion,maxIndices,NULL,NULL); theDeffunction = (DEFFUNCTION *) EnvGetNextDeffunction(theEnv,theDeffunction); } theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,theModule); moduleCount++; moduleArrayCount++; } CloseDeffunctionFiles(theEnv,moduleFile,deffunctionFile,maxIndices); return(true); }