📄 symblcmp.c
字号:
int numberOfEntries;
struct floatHashNode **floatTable;
int newHeader = TRUE;
FILE *fp;
int arrayVersion = 1;
/*====================================*/
/* Count the total number of entries. */
/*====================================*/
floatTable = GetFloatTable(theEnv);
count = numberOfEntries = 0;
for (i = 0; i < FLOAT_HASH_SIZE; i++)
{
for (hashPtr = floatTable[i];
hashPtr != NULL;
hashPtr = hashPtr->next)
{ numberOfEntries++; }
}
if (numberOfEntries == 0) return(version);
for (i = 1; i <= (numberOfEntries / ConstructCompilerData(theEnv)->MaxIndices) + 1 ; i++)
{ fprintf(ConstructCompilerData(theEnv)->HeaderFP,"extern struct floatHashNode F%d_%d[];\n",ConstructCompilerData(theEnv)->ImageID,i); }
/*==================*/
/* Create the file. */
/*==================*/
if ((fp = NewCFile(theEnv,fileName,1,version,FALSE)) == NULL) return(-1);
/*===================*/
/* List the entries. */
/*===================*/
j = 0;
for (i = 0; i < FLOAT_HASH_SIZE; i++)
{
for (hashPtr = floatTable[i];
hashPtr != NULL;
hashPtr = hashPtr->next)
{
if (newHeader)
{
fprintf(fp,"struct floatHashNode F%d_%d[] = {\n",ConstructCompilerData(theEnv)->ImageID,arrayVersion);
newHeader = FALSE;
}
if (hashPtr->next == NULL)
{ fprintf(fp,"{NULL,"); }
else
{
if ((j + 1) >= ConstructCompilerData(theEnv)->MaxIndices)
{ fprintf(fp,"{&F%d_%d[%d],",ConstructCompilerData(theEnv)->ImageID,arrayVersion + 1,0); }
else
{ fprintf(fp,"{&F%d_%d[%d],",ConstructCompilerData(theEnv)->ImageID,arrayVersion,j + 1); }
}
fprintf(fp,"%ld,0,1,0,0,%d,",hashPtr->count + 1,i);
fprintf(fp,"%s",FloatToString(theEnv,hashPtr->contents));
count++;
j++;
if ((count == numberOfEntries) || (j >= ConstructCompilerData(theEnv)->MaxIndices))
{
fprintf(fp,"}};\n");
GenClose(theEnv,fp);
j = 0;
version++;
arrayVersion++;
if (count < numberOfEntries)
{
if ((fp = NewCFile(theEnv,fileName,1,version,FALSE)) == NULL) return(0);
newHeader = TRUE;
}
}
else
{ fprintf(fp,"},\n"); }
}
}
return(version);
}
/******************************************************/
/* IntegerHashNodesToCode: Produces the code for the */
/* integer hash table entries for a run-time module */
/* created using the constructs-to-c function. */
/******************************************************/
static int IntegerHashNodesToCode(
void *theEnv,
char *fileName,
int version)
{
int i, j;
struct integerHashNode *hashPtr;
int count;
int numberOfEntries;
struct integerHashNode **integerTable;
int newHeader = TRUE;
FILE *fp;
int arrayVersion = 1;
/*====================================*/
/* Count the total number of entries. */
/*====================================*/
integerTable = GetIntegerTable(theEnv);
count = numberOfEntries = 0;
for (i = 0; i < INTEGER_HASH_SIZE; i++)
{
for (hashPtr = integerTable[i];
hashPtr != NULL;
hashPtr = hashPtr->next)
{ numberOfEntries++; }
}
if (numberOfEntries == 0) return(version);
for (i = 1; i <= (numberOfEntries / ConstructCompilerData(theEnv)->MaxIndices) + 1 ; i++)
{ fprintf(ConstructCompilerData(theEnv)->HeaderFP,"extern struct integerHashNode I%d_%d[];\n",ConstructCompilerData(theEnv)->ImageID,i); }
/*==================*/
/* Create the file. */
/*==================*/
if ((fp = NewCFile(theEnv,fileName,1,version,FALSE)) == NULL) return(-1);
/*===================*/
/* List the entries. */
/*===================*/
j = 0;
for (i = 0; i < INTEGER_HASH_SIZE; i++)
{
for (hashPtr = integerTable[i];
hashPtr != NULL;
hashPtr = hashPtr->next)
{
if (newHeader)
{
fprintf(fp,"struct integerHashNode I%d_%d[] = {\n",ConstructCompilerData(theEnv)->ImageID,arrayVersion);
newHeader = FALSE;
}
if (hashPtr->next == NULL)
{ fprintf(fp,"{NULL,"); }
else
{
if ((j + 1) >= ConstructCompilerData(theEnv)->MaxIndices)
{ fprintf(fp,"{&I%d_%d[%d],",ConstructCompilerData(theEnv)->ImageID,arrayVersion + 1,0); }
else
{ fprintf(fp,"{&I%d_%d[%d],",ConstructCompilerData(theEnv)->ImageID,arrayVersion,j + 1); }
}
fprintf(fp,"%ld,0,1,0,0,%d,",hashPtr->count + 1,i);
fprintf(fp,"%ld",hashPtr->contents);
count++;
j++;
if ((count == numberOfEntries) || (j >= ConstructCompilerData(theEnv)->MaxIndices))
{
fprintf(fp,"}};\n");
GenClose(theEnv,fp);
j = 0;
version++;
arrayVersion++;
if (count < numberOfEntries)
{
if ((fp = NewCFile(theEnv,fileName,1,version,FALSE)) == NULL) return(0);
newHeader = TRUE;
}
}
else
{ fprintf(fp,"},\n"); }
}
}
return(version);
}
/****************************************************************/
/* HashTablesToCode: Produces the code for the symbol, integer, */
/* float, and bitmap hash tables for a run-time module */
/* created using the constructs-to-c function. */
/****************************************************************/
static int HashTablesToCode(
void *theEnv,
char *fileName)
{
unsigned long i;
FILE *fp;
struct symbolHashNode **symbolTable;
struct floatHashNode **floatTable;
struct integerHashNode **integerTable;
struct bitMapHashNode **bitMapTable;
/*======================================*/
/* Write the code for the symbol table. */
/*======================================*/
symbolTable = GetSymbolTable(theEnv);
if ((fp = NewCFile(theEnv,fileName,1,1,FALSE)) == NULL) return(0);
fprintf(ConstructCompilerData(theEnv)->HeaderFP,"extern struct symbolHashNode *sht%d[];\n",ConstructCompilerData(theEnv)->ImageID);
fprintf(fp,"struct symbolHashNode *sht%d[%ld] = {\n",ConstructCompilerData(theEnv)->ImageID,SYMBOL_HASH_SIZE);
for (i = 0; i < SYMBOL_HASH_SIZE; i++)
{
PrintSymbolReference(theEnv,fp,symbolTable[i]);
if (i + 1 != SYMBOL_HASH_SIZE) fprintf(fp,",\n");
}
fprintf(fp,"};\n");
GenClose(theEnv,fp);
/*=====================================*/
/* Write the code for the float table. */
/*=====================================*/
floatTable = GetFloatTable(theEnv);
if ((fp = NewCFile(theEnv,fileName,1,2,FALSE)) == NULL) return(0);
fprintf(ConstructCompilerData(theEnv)->HeaderFP,"extern struct floatHashNode *fht%d[];\n",ConstructCompilerData(theEnv)->ImageID);
fprintf(fp,"struct floatHashNode *fht%d[%d] = {\n",ConstructCompilerData(theEnv)->ImageID,FLOAT_HASH_SIZE);
for (i = 0; i < FLOAT_HASH_SIZE; i++)
{
if (floatTable[i] == NULL) { fprintf(fp,"NULL"); }
else PrintFloatReference(theEnv,fp,floatTable[i]);
if (i + 1 != FLOAT_HASH_SIZE) fprintf(fp,",\n");
}
fprintf(fp,"};\n");
GenClose(theEnv,fp);
/*=======================================*/
/* Write the code for the integer table. */
/*=======================================*/
integerTable = GetIntegerTable(theEnv);
if ((fp = NewCFile(theEnv,fileName,1,3,FALSE)) == NULL) return(0);
fprintf(ConstructCompilerData(theEnv)->HeaderFP,"extern struct integerHashNode *iht%d[];\n",ConstructCompilerData(theEnv)->ImageID);
fprintf(fp,"struct integerHashNode *iht%d[%d] = {\n",ConstructCompilerData(theEnv)->ImageID,INTEGER_HASH_SIZE);
for (i = 0; i < INTEGER_HASH_SIZE; i++)
{
if (integerTable[i] == NULL) { fprintf(fp,"NULL"); }
else PrintIntegerReference(theEnv,fp,integerTable[i]);
if (i + 1 != INTEGER_HASH_SIZE) fprintf(fp,",\n");
}
fprintf(fp,"};\n");
GenClose(theEnv,fp);
/*======================================*/
/* Write the code for the bitmap table. */
/*======================================*/
bitMapTable = GetBitMapTable(theEnv);
if ((fp = NewCFile(theEnv,fileName,1,4,FALSE)) == NULL) return(0);
fprintf(ConstructCompilerData(theEnv)->HeaderFP,"extern struct bitMapHashNode *bmht%d[];\n",ConstructCompilerData(theEnv)->ImageID);
fprintf(fp,"struct bitMapHashNode *bmht%d[%d] = {\n",ConstructCompilerData(theEnv)->ImageID,BITMAP_HASH_SIZE);
for (i = 0; i < BITMAP_HASH_SIZE; i++)
{
PrintBitMapReference(theEnv,fp,bitMapTable[i]);
if (i + 1 != BITMAP_HASH_SIZE) fprintf(fp,",\n");
}
fprintf(fp,"};\n");
GenClose(theEnv,fp);
return(1);
}
/*****************************************************/
/* PrintSymbolReference: Prints the C code reference */
/* address to the specified symbol (also used for */
/* strings and instance names). */
/*****************************************************/
globle void PrintSymbolReference(
void *theEnv,
FILE *theFile,
struct symbolHashNode *theSymbol)
{
if (theSymbol == NULL) fprintf(theFile,"NULL");
else fprintf(theFile,"&S%d_%d[%d]",
ConstructCompilerData(theEnv)->ImageID,
(int) (theSymbol->bucket / ConstructCompilerData(theEnv)->MaxIndices) + 1,
(int) theSymbol->bucket % ConstructCompilerData(theEnv)->MaxIndices);
}
/****************************************************/
/* PrintFloatReference: Prints the C code reference */
/* address to the specified float. */
/****************************************************/
globle void PrintFloatReference(
void *theEnv,
FILE *theFile,
struct floatHashNode *theFloat)
{
fprintf(theFile,"&F%d_%d[%d]",
ConstructCompilerData(theEnv)->ImageID,
(int) (theFloat->bucket / ConstructCompilerData(theEnv)->MaxIndices) + 1,
(int) theFloat->bucket % ConstructCompilerData(theEnv)->MaxIndices);
}
/******************************************************/
/* PrintIntegerReference: Prints the C code reference */
/* address to the specified integer. */
/******************************************************/
globle void PrintIntegerReference(
void *theEnv,
FILE *theFile,
struct integerHashNode *theInteger)
{
fprintf(theFile,"&I%d_%d[%d]",
ConstructCompilerData(theEnv)->ImageID,
(int) (theInteger->bucket / ConstructCompilerData(theEnv)->MaxIndices) + 1,
(int) theInteger->bucket % ConstructCompilerData(theEnv)->MaxIndices);
}
/*****************************************************/
/* PrintBitMapReference: Prints the C code reference */
/* address to the specified bit map. */
/*****************************************************/
globle void PrintBitMapReference(
void *theEnv,
FILE *theFile,
struct bitMapHashNode *theBitMap)
{
if (theBitMap == NULL) fprintf(theFile,"NULL");
else fprintf(theFile,"&B%d_%d[%d]",
ConstructCompilerData(theEnv)->ImageID,
(int) (theBitMap->bucket / ConstructCompilerData(theEnv)->MaxIndices) + 1,
(int) theBitMap->bucket % ConstructCompilerData(theEnv)->MaxIndices);
}
/*********************************************************/
/* PrintCString: Prints KB strings in the appropriate */
/* format for C (the " and \ characters are preceeded */
/* by a \ and carriage returns are replaced with \n). */
/*********************************************************/
static void PrintCString(
FILE *theFile,
char *str)
{
unsigned i;
size_t slen;
/*============================================*/
/* Print the string's opening quotation mark. */
/*============================================*/
fprintf(theFile,"\"");
/*===============================================*/
/* Convert and write each character to the file. */
/*===============================================*/
slen = strlen(str);
for (i = 0 ; i < slen ; i++)
{
/*====================================*/
/* Preceed " and \ with the \ escape. */
/*====================================*/
if ((str[i] == '"') || (str[i] == '\\'))
{
fputc('\\',theFile);
fputc(str[i],theFile);
}
/*====================================*/
/* Replace a carriage return with \n. */
/*====================================*/
else if (str[i] == '\n')
{
fputc('\\',theFile);
fputc('n',theFile);
}
/*===============================*/
/* All other characters can be */
/* printed without modification. */
/*===============================*/
else
{ fputc(str[i],theFile); }
}
/*============================================*/
/* Print the string's closing quotation mark. */
/*============================================*/
fprintf(theFile,"\"");
}
#endif /* CONSTRUCT_COMPILER && (! RUN_TIME) */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -