00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #define _EXPRNBIN_SOURCE_
00024
00025 #include "setup.h"
00026
00027 #if (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE)
00028
00029 #include <stdio.h>
00030 #define _STDIO_INCLUDED_
00031
00032 #include "memalloc.h"
00033 #include "dffctdef.h"
00034 #include "moduldef.h"
00035 #include "constrct.h"
00036 #include "extnfunc.h"
00037 #include "bload.h"
00038 #include "bsave.h"
00039 #include "envrnmnt.h"
00040
00041 #if DEFRULE_CONSTRUCT
00042 #include "network.h"
00043 #endif
00044
00045 #if DEFGENERIC_CONSTRUCT
00046 #include "genrcbin.h"
00047 #endif
00048
00049 #if DEFFUNCTION_CONSTRUCT
00050 #include "dffnxbin.h"
00051 #endif
00052
00053 #if DEFTEMPLATE_CONSTRUCT
00054 #include "tmpltbin.h"
00055 #endif
00056
00057 #if DEFGLOBAL_CONSTRUCT
00058 #include "globlbin.h"
00059 #endif
00060
00061 #if OBJECT_SYSTEM
00062 #include "objbin.h"
00063 #include "insfun.h"
00064 #include "inscom.h"
00065 #endif
00066
00067 #include "exprnbin.h"
00068
00069
00070
00071
00072
00073 static void UpdateExpression(void *,void *,long);
00074
00075
00076
00077
00078
00079
00080 globle void AllocateExpressions(
00081 void *theEnv)
00082 {
00083 size_t space;
00084
00085 GenReadBinary(theEnv,(void *) &ExpressionData(theEnv)->NumberOfExpressions,sizeof(long));
00086 if (ExpressionData(theEnv)->NumberOfExpressions == 0L)
00087 ExpressionData(theEnv)->ExpressionArray = NULL;
00088 else
00089 {
00090 space = ExpressionData(theEnv)->NumberOfExpressions * sizeof(struct expr);
00091 ExpressionData(theEnv)->ExpressionArray = (struct expr *) genalloc(theEnv,space);
00092 }
00093 }
00094
00095
00096
00097
00098
00099 globle void RefreshExpressions(
00100 void *theEnv)
00101 {
00102 if (ExpressionData(theEnv)->ExpressionArray == NULL) return;
00103
00104 BloadandRefresh(theEnv,ExpressionData(theEnv)->NumberOfExpressions,
00105 (unsigned) sizeof(BSAVE_EXPRESSION),UpdateExpression);
00106 }
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119 static void UpdateExpression(
00120 void *theEnv,
00121 void *buf,
00122 long obji)
00123 {
00124 BSAVE_EXPRESSION *bexp;
00125 long theIndex;
00126
00127 bexp = (BSAVE_EXPRESSION *) buf;
00128 ExpressionData(theEnv)->ExpressionArray[obji].type = bexp->type;
00129 switch(bexp->type)
00130 {
00131 case FCALL:
00132 ExpressionData(theEnv)->ExpressionArray[obji].value = (void *) BloadData(theEnv)->FunctionArray[bexp->value];
00133 break;
00134
00135 case GCALL:
00136 #if DEFGENERIC_CONSTRUCT
00137 ExpressionData(theEnv)->ExpressionArray[obji].value = (void *) GenericPointer(bexp->value);
00138 #else
00139 ExpressionData(theEnv)->ExpressionArray[obji].value = NULL;
00140 #endif
00141 break;
00142
00143 case PCALL:
00144 #if DEFFUNCTION_CONSTRUCT
00145 ExpressionData(theEnv)->ExpressionArray[obji].value = (void *) DeffunctionPointer(bexp->value);
00146 #else
00147 ExpressionData(theEnv)->ExpressionArray[obji].value = NULL;
00148 #endif
00149 break;
00150
00151 case DEFTEMPLATE_PTR:
00152 #if DEFTEMPLATE_CONSTRUCT
00153 ExpressionData(theEnv)->ExpressionArray[obji].value = (void *) DeftemplatePointer(bexp->value);
00154 #else
00155 ExpressionData(theEnv)->ExpressionArray[obji].value = NULL;
00156 #endif
00157 break;
00158
00159 case DEFCLASS_PTR:
00160 #if OBJECT_SYSTEM
00161 ExpressionData(theEnv)->ExpressionArray[obji].value = (void *) DefclassPointer(bexp->value);
00162 #else
00163 ExpressionData(theEnv)->ExpressionArray[obji].value = NULL;
00164 #endif
00165 break;
00166
00167 case DEFGLOBAL_PTR:
00168
00169 #if DEFGLOBAL_CONSTRUCT
00170 ExpressionData(theEnv)->ExpressionArray[obji].value = (void *) DefglobalPointer(bexp->value);
00171 #else
00172 ExpressionData(theEnv)->ExpressionArray[obji].value = NULL;
00173 #endif
00174 break;
00175
00176
00177 case INTEGER:
00178 ExpressionData(theEnv)->ExpressionArray[obji].value = (void *) SymbolData(theEnv)->IntegerArray[bexp->value];
00179 IncrementIntegerCount((INTEGER_HN *) ExpressionData(theEnv)->ExpressionArray[obji].value);
00180 break;
00181
00182 case FLOAT:
00183 ExpressionData(theEnv)->ExpressionArray[obji].value = (void *) SymbolData(theEnv)->FloatArray[bexp->value];
00184 IncrementFloatCount((FLOAT_HN *) ExpressionData(theEnv)->ExpressionArray[obji].value);
00185 break;
00186
00187 case INSTANCE_NAME:
00188 #if ! OBJECT_SYSTEM
00189 ExpressionData(theEnv)->ExpressionArray[obji].type = SYMBOL;
00190 #endif
00191 case GBL_VARIABLE:
00192 case SYMBOL:
00193 case STRING:
00194 ExpressionData(theEnv)->ExpressionArray[obji].value = (void *) SymbolData(theEnv)->SymbolArray[bexp->value];
00195 IncrementSymbolCount((SYMBOL_HN *) ExpressionData(theEnv)->ExpressionArray[obji].value);
00196 break;
00197
00198 #if DEFTEMPLATE_CONSTRUCT
00199 case FACT_ADDRESS:
00200 ExpressionData(theEnv)->ExpressionArray[obji].value = (void *) &FactData(theEnv)->DummyFact;
00201 EnvIncrementFactCount(theEnv,ExpressionData(theEnv)->ExpressionArray[obji].value);
00202 break;
00203 #endif
00204
00205 #if OBJECT_SYSTEM
00206 case INSTANCE_ADDRESS:
00207 ExpressionData(theEnv)->ExpressionArray[obji].value = (void *) &InstanceData(theEnv)->DummyInstance;
00208 EnvIncrementInstanceCount(theEnv,ExpressionData(theEnv)->ExpressionArray[obji].value);
00209 break;
00210 #endif
00211
00212 case EXTERNAL_ADDRESS:
00213 ExpressionData(theEnv)->ExpressionArray[obji].value = NULL;
00214 break;
00215
00216 case RVOID:
00217 break;
00218
00219 default:
00220 if (EvaluationData(theEnv)->PrimitivesArray[bexp->type] == NULL) break;
00221 if (EvaluationData(theEnv)->PrimitivesArray[bexp->type]->bitMap)
00222 {
00223 ExpressionData(theEnv)->ExpressionArray[obji].value = (void *) SymbolData(theEnv)->BitMapArray[bexp->value];
00224 IncrementBitMapCount((BITMAP_HN *) ExpressionData(theEnv)->ExpressionArray[obji].value);
00225 }
00226 break;
00227 }
00228
00229 theIndex = (long int) bexp->nextArg;
00230 if (theIndex == -1L)
00231 { ExpressionData(theEnv)->ExpressionArray[obji].nextArg = NULL; }
00232 else
00233 { ExpressionData(theEnv)->ExpressionArray[obji].nextArg = (struct expr *) &ExpressionData(theEnv)->ExpressionArray[theIndex]; }
00234
00235 theIndex = (long int) bexp->argList;
00236 if (theIndex == -1L)
00237 { ExpressionData(theEnv)->ExpressionArray[obji].argList = NULL; }
00238 else
00239 { ExpressionData(theEnv)->ExpressionArray[obji].argList = (struct expr *) &ExpressionData(theEnv)->ExpressionArray[theIndex]; }
00240 }
00241
00242
00243
00244
00245
00246 globle void ClearBloadedExpressions(
00247 void *theEnv)
00248 {
00249 unsigned long int i;
00250 size_t space;
00251
00252
00253
00254
00255
00256 for (i = 0; i < (unsigned long) ExpressionData(theEnv)->NumberOfExpressions; i++)
00257 {
00258 switch (ExpressionData(theEnv)->ExpressionArray[i].type)
00259 {
00260 case SYMBOL :
00261 case STRING :
00262 case INSTANCE_NAME :
00263 case GBL_VARIABLE :
00264 DecrementSymbolCount(theEnv,(SYMBOL_HN *) ExpressionData(theEnv)->ExpressionArray[i].value);
00265 break;
00266 case FLOAT :
00267 DecrementFloatCount(theEnv,(FLOAT_HN *) ExpressionData(theEnv)->ExpressionArray[i].value);
00268 break;
00269 case INTEGER :
00270 DecrementIntegerCount(theEnv,(INTEGER_HN *) ExpressionData(theEnv)->ExpressionArray[i].value);
00271 break;
00272
00273 #if DEFTEMPLATE_CONSTRUCT
00274 case FACT_ADDRESS :
00275 EnvDecrementFactCount(theEnv,ExpressionData(theEnv)->ExpressionArray[i].value);
00276 break;
00277 #endif
00278
00279 #if OBJECT_SYSTEM
00280 case INSTANCE_ADDRESS :
00281 EnvDecrementInstanceCount(theEnv,ExpressionData(theEnv)->ExpressionArray[i].value);
00282 break;
00283 #endif
00284
00285 case RVOID:
00286 break;
00287
00288 default:
00289 if (EvaluationData(theEnv)->PrimitivesArray[ExpressionData(theEnv)->ExpressionArray[i].type] == NULL) break;
00290 if (EvaluationData(theEnv)->PrimitivesArray[ExpressionData(theEnv)->ExpressionArray[i].type]->bitMap)
00291 { DecrementBitMapCount(theEnv,(BITMAP_HN *) ExpressionData(theEnv)->ExpressionArray[i].value); }
00292 break;
00293 }
00294 }
00295
00296
00297
00298
00299
00300 space = ExpressionData(theEnv)->NumberOfExpressions * sizeof(struct expr);
00301 if (space != 0) genfree(theEnv,(void *) ExpressionData(theEnv)->ExpressionArray,space);
00302 ExpressionData(theEnv)->ExpressionArray = 0;
00303 }
00304
00305
00306 #if BLOAD_AND_BSAVE
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319 globle void FindHashedExpressions(
00320 void *theEnv)
00321 {
00322 register unsigned i;
00323 EXPRESSION_HN *exphash;
00324
00325 for (i = 0 ; i < EXPRESSION_HASH_SIZE ; i++)
00326 for (exphash = ExpressionData(theEnv)->ExpressionHashTable[i] ; exphash != NULL ; exphash = exphash->next)
00327 {
00328 MarkNeededItems(theEnv,exphash->exp);
00329 exphash->bsaveID = ExpressionData(theEnv)->ExpressionCount;
00330 ExpressionData(theEnv)->ExpressionCount += ExpressionSize(exphash->exp);
00331 }
00332 }
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342 globle void BsaveHashedExpressions(
00343 void *theEnv,
00344 FILE *fp)
00345 {
00346 register unsigned i;
00347 EXPRESSION_HN *exphash;
00348
00349 for (i = 0 ; i < EXPRESSION_HASH_SIZE ; i++)
00350 for (exphash = ExpressionData(theEnv)->ExpressionHashTable[i] ; exphash != NULL ; exphash = exphash->next)
00351 BsaveExpression(theEnv,exphash->exp,fp);
00352 }
00353
00354
00355
00356
00357
00358 globle void BsaveConstructExpressions(
00359 void *theEnv,
00360 FILE *fp)
00361 {
00362 struct BinaryItem *biPtr;
00363
00364 for (biPtr = BsaveData(theEnv)->ListOfBinaryItems;
00365 biPtr != NULL;
00366 biPtr = biPtr->next)
00367 {
00368 if (biPtr->expressionFunction != NULL)
00369 { (*biPtr->expressionFunction)(theEnv,fp); }
00370 }
00371 }
00372
00373
00374
00375
00376
00377 globle void BsaveExpression(
00378 void *theEnv,
00379 struct expr *testPtr,
00380 FILE *fp)
00381 {
00382 BSAVE_EXPRESSION newTest;
00383 long int newIndex;
00384
00385 while (testPtr != NULL)
00386 {
00387 ExpressionData(theEnv)->ExpressionCount++;
00388
00389
00390
00391
00392
00393 newTest.type = testPtr->type;
00394
00395
00396
00397
00398
00399 if (testPtr->argList == NULL)
00400 { newTest.argList = -1L; }
00401 else
00402 { newTest.argList = ExpressionData(theEnv)->ExpressionCount; }
00403
00404
00405
00406
00407
00408 if (testPtr->nextArg == NULL)
00409 { newTest.nextArg = -1L; }
00410 else
00411 {
00412 newIndex = ExpressionData(theEnv)->ExpressionCount + ExpressionSize(testPtr->argList);
00413 newTest.nextArg = newIndex;
00414 }
00415
00416
00417
00418
00419
00420 switch(testPtr->type)
00421 {
00422 case FLOAT:
00423 newTest.value = (long) ((FLOAT_HN *) testPtr->value)->bucket;
00424 break;
00425
00426 case INTEGER:
00427 newTest.value = (long) ((INTEGER_HN *) testPtr->value)->bucket;
00428 break;
00429
00430 case FCALL:
00431 newTest.value = (long) ((struct FunctionDefinition *)
00432 testPtr->value)->bsaveIndex;
00433 break;
00434
00435 case GCALL:
00436 #if DEFGENERIC_CONSTRUCT
00437 if (testPtr->value != NULL)
00438 newTest.value = ((struct constructHeader *) testPtr->value)->bsaveID;
00439 else
00440 #endif
00441 newTest.value = -1L;
00442 break;
00443
00444 case PCALL:
00445 #if DEFFUNCTION_CONSTRUCT
00446 if (testPtr->value != NULL)
00447 newTest.value = ((struct constructHeader *) testPtr->value)->bsaveID;
00448 else
00449 #endif
00450 newTest.value = -1L;
00451 break;
00452
00453 case DEFTEMPLATE_PTR:
00454 #if DEFTEMPLATE_CONSTRUCT
00455 if (testPtr->value != NULL)
00456 newTest.value = ((struct constructHeader *) testPtr->value)->bsaveID;
00457 else
00458 #endif
00459 newTest.value = -1L;
00460 break;
00461
00462 case DEFCLASS_PTR:
00463 #if OBJECT_SYSTEM
00464 if (testPtr->value != NULL)
00465 newTest.value = ((struct constructHeader *) testPtr->value)->bsaveID;
00466 else
00467 #endif
00468 newTest.value = -1L;
00469 break;
00470
00471 case DEFGLOBAL_PTR:
00472 #if DEFGLOBAL_CONSTRUCT
00473 if (testPtr->value != NULL)
00474 newTest.value = ((struct defglobal *) testPtr->value)->header.bsaveID;
00475 else
00476 #endif
00477 newTest.value = -1L;
00478 break;
00479
00480 #if OBJECT_SYSTEM
00481 case INSTANCE_NAME:
00482 #endif
00483 case SYMBOL:
00484 case GBL_VARIABLE:
00485 case STRING:
00486 newTest.value = (long) ((SYMBOL_HN *) testPtr->value)->bucket;
00487 break;
00488
00489 case FACT_ADDRESS:
00490 case INSTANCE_ADDRESS:
00491 case EXTERNAL_ADDRESS:
00492 newTest.value = -1L;
00493 break;
00494
00495 case RVOID:
00496 break;
00497
00498 default:
00499 if (EvaluationData(theEnv)->PrimitivesArray[testPtr->type] == NULL) break;
00500 if (EvaluationData(theEnv)->PrimitivesArray[testPtr->type]->bitMap)
00501 { newTest.value = (long) ((BITMAP_HN *) testPtr->value)->bucket; }
00502 break;
00503 }
00504
00505
00506
00507
00508
00509 GenWrite(&newTest,(unsigned long) sizeof(BSAVE_EXPRESSION),fp);
00510
00511
00512
00513
00514
00515 if (testPtr->argList != NULL)
00516 {
00517 BsaveExpression(theEnv,testPtr->argList,fp);
00518 }
00519
00520 testPtr = testPtr->nextArg;
00521 }
00522 }
00523
00524 #endif
00525
00526 #endif
00527