00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #define _DEVELOPR_SOURCE_
00029
00030 #include <stdio.h>
00031 #define _STDIO_INCLUDED_
00032
00033 #include "setup.h"
00034
00035 #include "argacces.h"
00036 #include "envrnmnt.h"
00037 #include "extnfunc.h"
00038 #include "inscom.h"
00039 #include "modulutl.h"
00040 #include "router.h"
00041 #include "utility.h"
00042
00043 #if DEFRULE_CONSTRUCT && DEFTEMPLATE_CONSTRUCT
00044 #include "tmpltdef.h"
00045 #include "factbld.h"
00046 #include "facthsh.h"
00047 #endif
00048
00049 #if DEFRULE_CONSTRUCT && OBJECT_SYSTEM
00050 #include "classcom.h"
00051 #include "classfun.h"
00052 #include "objrtmch.h"
00053 #endif
00054 #if OBJECT_SYSTEM
00055 #include "insfun.h"
00056 #endif
00057
00058 #include "developr.h"
00059
00060 #if DEVELOPER
00061
00062 #if DEFRULE_CONSTRUCT && OBJECT_SYSTEM
00063 static void PrintOPNLevel(void *theEnv,OBJECT_PATTERN_NODE *,char *,int);
00064 #endif
00065
00066
00067
00068
00069 globle void DeveloperCommands(
00070 void *theEnv)
00071 {
00072 #if ! RUN_TIME
00073 EnvDefineFunction2(theEnv,"primitives-info",'v', PTIEF PrimitiveTablesInfo,"PrimitiveTablesInfo","00");
00074 EnvDefineFunction2(theEnv,"primitives-usage",'v', PTIEF PrimitiveTablesUsage,"PrimitiveTablesUsage","00");
00075 EnvDefineFunction2(theEnv,"enable-gc-heuristics",'v', PTIEF EnableGCHeuristics,"EnableGCHeuristics","00");
00076 EnvDefineFunction2(theEnv,"disable-gc-heuristics",'v', PTIEF DisableGCHeuristics,"DisableGCHeuristics","00");
00077
00078 #if DEFRULE_CONSTRUCT && DEFTEMPLATE_CONSTRUCT
00079 EnvDefineFunction2(theEnv,"show-fpn",'v', PTIEF ShowFactPatternNetwork,"ShowFactPatternNetwork","11w");
00080 EnvDefineFunction2(theEnv,"show-fht",'v', PTIEF ShowFactHashTable,"ShowFactHashTable","00");
00081 #endif
00082
00083 #if DEFRULE_CONSTRUCT && OBJECT_SYSTEM
00084 EnvDefineFunction2(theEnv,"show-opn",'v',PTIEF PrintObjectPatternNetwork,
00085 "PrintObjectPatternNetwork","00");
00086 #endif
00087
00088 #if OBJECT_SYSTEM
00089 EnvDefineFunction2(theEnv,"instance-table-usage",'v', PTIEF InstanceTableUsage,"InstanceTableUsage","00");
00090 #endif
00091
00092 #endif
00093 }
00094
00095
00096
00097
00098 globle void EnableGCHeuristics(
00099 void *theEnv)
00100 {
00101 EnvArgCountCheck(theEnv,"enable-gc-heuristics",EXACTLY,0);
00102 SetGarbageCollectionHeuristics(theEnv,TRUE);
00103 }
00104
00105
00106
00107
00108 globle void DisableGCHeuristics(
00109 void *theEnv)
00110 {
00111 EnvArgCountCheck(theEnv,"disable-gc-heuristics",EXACTLY,0);
00112 SetGarbageCollectionHeuristics(theEnv,FALSE);
00113 }
00114
00115
00116
00117
00118
00119 globle void PrimitiveTablesInfo(
00120 void *theEnv)
00121 {
00122 unsigned long i;
00123 SYMBOL_HN **symbolArray, *symbolPtr;
00124 FLOAT_HN **floatArray, *floatPtr;
00125 INTEGER_HN **integerArray, *integerPtr;
00126 BITMAP_HN **bitMapArray, *bitMapPtr;
00127 unsigned long int symbolCount = 0, integerCount = 0;
00128 unsigned long int floatCount = 0, bitMapCount = 0;
00129
00130 EnvArgCountCheck(theEnv,"primitives-info",EXACTLY,0);
00131
00132
00133
00134
00135
00136 symbolArray = GetSymbolTable(theEnv);
00137 for (i = 0; i < SYMBOL_HASH_SIZE; i++)
00138 {
00139 for (symbolPtr = symbolArray[i]; symbolPtr != NULL; symbolPtr = symbolPtr->next)
00140 { symbolCount++; }
00141 }
00142
00143
00144
00145
00146
00147 integerArray = GetIntegerTable(theEnv);
00148 for (i = 0; i < INTEGER_HASH_SIZE; i++)
00149 {
00150 for (integerPtr = integerArray[i]; integerPtr != NULL; integerPtr = integerPtr->next)
00151 { integerCount++; }
00152 }
00153
00154
00155
00156
00157
00158 floatArray = GetFloatTable(theEnv);
00159 for (i = 0; i < FLOAT_HASH_SIZE; i++)
00160 {
00161 for (floatPtr = floatArray[i]; floatPtr != NULL; floatPtr = floatPtr->next)
00162 { floatCount++; }
00163 }
00164
00165
00166
00167
00168
00169 bitMapArray = GetBitMapTable(theEnv);
00170 for (i = 0; i < BITMAP_HASH_SIZE; i++)
00171 {
00172 for (bitMapPtr = bitMapArray[i]; bitMapPtr != NULL; bitMapPtr = bitMapPtr->next)
00173 { bitMapCount++; }
00174 }
00175
00176
00177
00178
00179
00180 EnvPrintRouter(theEnv,WDISPLAY,"Symbols: ");
00181 PrintLongInteger(theEnv,WDISPLAY,(long long) symbolCount);
00182 EnvPrintRouter(theEnv,WDISPLAY,"\n");
00183 EnvPrintRouter(theEnv,WDISPLAY,"Integers: ");
00184 PrintLongInteger(theEnv,WDISPLAY,(long long) integerCount);
00185 EnvPrintRouter(theEnv,WDISPLAY,"\n");
00186 EnvPrintRouter(theEnv,WDISPLAY,"Floats: ");
00187 PrintLongInteger(theEnv,WDISPLAY,(long long) floatCount);
00188 EnvPrintRouter(theEnv,WDISPLAY,"\n");
00189 EnvPrintRouter(theEnv,WDISPLAY,"BitMaps: ");
00190 PrintLongInteger(theEnv,WDISPLAY,(long long) bitMapCount);
00191 EnvPrintRouter(theEnv,WDISPLAY,"\n");
00192
00193
00194
00195
00196
00197 }
00198
00199 #define COUNT_SIZE 21
00200
00201
00202
00203
00204
00205 globle void PrimitiveTablesUsage(
00206 void *theEnv)
00207 {
00208 unsigned long i;
00209 int symbolCounts[COUNT_SIZE], floatCounts[COUNT_SIZE];
00210 SYMBOL_HN **symbolArray, *symbolPtr;
00211 FLOAT_HN **floatArray, *floatPtr;
00212 unsigned long int symbolCount, totalSymbolCount = 0;
00213 unsigned long int floatCount, totalFloatCount = 0;
00214
00215 EnvArgCountCheck(theEnv,"primitives-usage",EXACTLY,0);
00216
00217 for (i = 0; i < 21; i++)
00218 {
00219 symbolCounts[i] = 0;
00220 floatCounts[i] = 0;
00221 }
00222
00223
00224
00225
00226
00227 symbolArray = GetSymbolTable(theEnv);
00228 for (i = 0; i < SYMBOL_HASH_SIZE; i++)
00229 {
00230 symbolCount = 0;
00231 for (symbolPtr = symbolArray[i]; symbolPtr != NULL; symbolPtr = symbolPtr->next)
00232 {
00233 symbolCount++;
00234 totalSymbolCount++;
00235 }
00236
00237 if (symbolCount < (COUNT_SIZE - 1))
00238 { symbolCounts[symbolCount]++; }
00239 else
00240 { symbolCounts[COUNT_SIZE - 1]++; }
00241 }
00242
00243
00244
00245
00246
00247 floatArray = GetFloatTable(theEnv);
00248 for (i = 0; i < FLOAT_HASH_SIZE; i++)
00249 {
00250 floatCount = 0;
00251 for (floatPtr = floatArray[i]; floatPtr != NULL; floatPtr = floatPtr->next)
00252 {
00253 floatCount++;
00254 totalFloatCount++;
00255 }
00256
00257 if (floatCount < (COUNT_SIZE - 1))
00258 { floatCounts[floatCount]++; }
00259 else
00260 { floatCounts[COUNT_SIZE - 1]++; }
00261 }
00262
00263
00264
00265
00266
00267
00268 EnvPrintRouter(theEnv,WDISPLAY,"Total Symbols: ");
00269 PrintLongInteger(theEnv,WDISPLAY,(long long) totalSymbolCount);
00270 EnvPrintRouter(theEnv,WDISPLAY,"\n");
00271 for (i = 0; i < COUNT_SIZE; i++)
00272 {
00273 PrintLongInteger(theEnv,WDISPLAY,(long long) i);
00274 EnvPrintRouter(theEnv,WDISPLAY," ");
00275 PrintLongInteger(theEnv,WDISPLAY,(long long) symbolCounts[i]);
00276 EnvPrintRouter(theEnv,WDISPLAY,"\n");
00277 }
00278
00279 EnvPrintRouter(theEnv,WDISPLAY,"\nTotal Floats: ");
00280 PrintLongInteger(theEnv,WDISPLAY,(long long) totalFloatCount);
00281 EnvPrintRouter(theEnv,WDISPLAY,"\n");
00282 for (i = 0; i < COUNT_SIZE; i++)
00283 {
00284 PrintLongInteger(theEnv,WDISPLAY,(long long) i);
00285 EnvPrintRouter(theEnv,WDISPLAY," ");
00286 PrintLongInteger(theEnv,WDISPLAY,(long long) floatCounts[i]);
00287 EnvPrintRouter(theEnv,WDISPLAY,"\n");
00288 }
00289
00290 }
00291
00292 #if DEFRULE_CONSTRUCT && DEFTEMPLATE_CONSTRUCT
00293
00294
00295
00296
00297
00298 globle void ShowFactPatternNetwork(
00299 void *theEnv)
00300 {
00301 struct factPatternNode *patternPtr;
00302 struct deftemplate *theDeftemplate;
00303 char *theName;
00304 int depth = 0, i;
00305
00306 theName = GetConstructName(theEnv,"show-fpn","template name");
00307 if (theName == NULL) return;
00308
00309 theDeftemplate = (struct deftemplate *) EnvFindDeftemplate(theEnv,theName);
00310 if (theDeftemplate == NULL) return;
00311
00312 patternPtr = theDeftemplate->patternNetwork;
00313 while (patternPtr != NULL)
00314 {
00315 for (i = 0; i < depth; i++) EnvPrintRouter(theEnv,WDISPLAY," ");
00316 if (patternPtr->header.singlefieldNode) EnvPrintRouter(theEnv,WDISPLAY,"SF ");
00317 else if (patternPtr->header.multifieldNode)
00318 {
00319 EnvPrintRouter(theEnv,WDISPLAY,"MF");
00320 if (patternPtr->header.endSlot) EnvPrintRouter(theEnv,WDISPLAY,")");
00321 else EnvPrintRouter(theEnv,WDISPLAY,"*");
00322 PrintLongInteger(theEnv,WDISPLAY,(long long) patternPtr->leaveFields);
00323 EnvPrintRouter(theEnv,WDISPLAY," ");
00324 }
00325
00326 EnvPrintRouter(theEnv,WDISPLAY,"Slot: ");
00327
00328 PrintLongInteger(theEnv,WDISPLAY,(long long) patternPtr->whichSlot);
00329 EnvPrintRouter(theEnv,WDISPLAY," Field: ");
00330 PrintLongInteger(theEnv,WDISPLAY,(long long) patternPtr->whichField);
00331 EnvPrintRouter(theEnv,WDISPLAY," Expression: ");
00332 if (patternPtr->networkTest == NULL) EnvPrintRouter(theEnv,WDISPLAY,"None");
00333 else PrintExpression(theEnv,WDISPLAY,patternPtr->networkTest);
00334 EnvPrintRouter(theEnv,WDISPLAY," RightHash: ");
00335 if (patternPtr->header.rightHash == NULL) EnvPrintRouter(theEnv,WDISPLAY,"None");
00336 else PrintExpression(theEnv,WDISPLAY,patternPtr->header.rightHash);
00337 EnvPrintRouter(theEnv,WDISPLAY,"\n");
00338
00339 if (patternPtr->nextLevel == NULL)
00340 {
00341 while (patternPtr->rightNode == NULL)
00342 {
00343 patternPtr = patternPtr->lastLevel;
00344 depth--;
00345 if (patternPtr == NULL) return;
00346 }
00347 patternPtr = patternPtr->rightNode;
00348 }
00349 else
00350 {
00351 patternPtr = patternPtr->nextLevel;
00352 depth++;
00353 }
00354 }
00355 }
00356
00357 #endif
00358
00359 #if DEFRULE_CONSTRUCT && OBJECT_SYSTEM
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370 globle void PrintObjectPatternNetwork(
00371 void *theEnv)
00372 {
00373 char indentbuf[80];
00374
00375 indentbuf[0] = '\0';
00376 PrintOPNLevel(theEnv,ObjectNetworkPointer(theEnv),indentbuf,0);
00377 }
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390 static void PrintOPNLevel(
00391 void *theEnv,
00392 OBJECT_PATTERN_NODE *pptr,
00393 char *indentbuf,
00394 int ilen)
00395 {
00396 CLASS_BITMAP *cbmp;
00397 SLOT_BITMAP *sbmp;
00398 register unsigned i;
00399 OBJECT_PATTERN_NODE *uptr;
00400 OBJECT_ALPHA_NODE *alphaPtr;
00401
00402 while (pptr != NULL)
00403 {
00404 EnvPrintRouter(theEnv,WDISPLAY,indentbuf);
00405 if (pptr->alphaNode != NULL)
00406 EnvPrintRouter(theEnv,WDISPLAY,"+");
00407 EnvPrintRouter(theEnv,WDISPLAY,ValueToString(FindIDSlotName(theEnv,pptr->slotNameID)));
00408 EnvPrintRouter(theEnv,WDISPLAY," (");
00409 PrintLongInteger(theEnv,WDISPLAY,(long long) pptr->slotNameID);
00410 EnvPrintRouter(theEnv,WDISPLAY,") ");
00411 EnvPrintRouter(theEnv,WDISPLAY,pptr->endSlot ? "EPF#" : "PF#");
00412 PrintLongInteger(theEnv,WDISPLAY,(long long) pptr->whichField);
00413 EnvPrintRouter(theEnv,WDISPLAY," ");
00414 EnvPrintRouter(theEnv,WDISPLAY,pptr->multifieldNode ? "$? " : "? ");
00415 if (pptr->networkTest != NULL)
00416 PrintExpression(theEnv,WDISPLAY,pptr->networkTest);
00417 EnvPrintRouter(theEnv,WDISPLAY,"\n");
00418 alphaPtr = pptr->alphaNode;
00419 while (alphaPtr != NULL)
00420 {
00421 EnvPrintRouter(theEnv,WDISPLAY,indentbuf);
00422 EnvPrintRouter(theEnv,WDISPLAY," Classes:");
00423 cbmp = (CLASS_BITMAP *) ValueToBitMap(alphaPtr->classbmp);
00424 for (i = 0 ; i <= cbmp->maxid ; i++)
00425 if (TestBitMap(cbmp->map,i))
00426 {
00427 EnvPrintRouter(theEnv,WDISPLAY," ");
00428 EnvPrintRouter(theEnv,WDISPLAY,EnvGetDefclassName(theEnv,(void *) DefclassData(theEnv)->ClassIDMap[i]));
00429 }
00430 if (alphaPtr->slotbmp != NULL)
00431 {
00432 sbmp = (SLOT_BITMAP *) ValueToBitMap(pptr->alphaNode->slotbmp);
00433 EnvPrintRouter(theEnv,WDISPLAY," *** Slots:");
00434 for (i = NAME_ID ; i <= sbmp->maxid ; i++)
00435 if (TestBitMap(sbmp->map,i))
00436 {
00437 for (uptr = pptr ; uptr != NULL ; uptr = uptr->lastLevel)
00438 if (uptr->slotNameID == i)
00439 break;
00440 if (uptr == NULL)
00441 {
00442 EnvPrintRouter(theEnv,WDISPLAY," ");
00443 EnvPrintRouter(theEnv,WDISPLAY,ValueToString(FindIDSlotName(theEnv,i)));
00444 }
00445 }
00446 }
00447 if (alphaPtr->header.rightHash != NULL)
00448 {
00449 EnvPrintRouter(theEnv,WDISPLAY," RH: ");
00450 PrintExpression(theEnv,WDISPLAY,alphaPtr->header.rightHash);
00451 }
00452
00453 EnvPrintRouter(theEnv,WDISPLAY,"\n");
00454 alphaPtr = alphaPtr->nxtInGroup;
00455 }
00456 indentbuf[ilen++] = (char) ((pptr->rightNode != NULL) ? '|' : ' ');
00457 indentbuf[ilen++] = ' ';
00458 indentbuf[ilen++] = ' ';
00459 indentbuf[ilen] = '\0';
00460 PrintOPNLevel(theEnv,pptr->nextLevel,indentbuf,ilen);
00461 ilen -= 3;
00462 indentbuf[ilen] = '\0';
00463 pptr = pptr->rightNode;
00464 }
00465 }
00466
00467 #endif
00468
00469 #if OBJECT_SYSTEM
00470
00471
00472
00473
00474
00475 globle void InstanceTableUsage(
00476 void *theEnv)
00477 {
00478 unsigned long i;
00479 int instanceCounts[COUNT_SIZE];
00480 INSTANCE_TYPE *ins;
00481 unsigned long int instanceCount, totalInstanceCount = 0;
00482
00483 EnvArgCountCheck(theEnv,"instance-table-usage",EXACTLY,0);
00484
00485 for (i = 0; i < COUNT_SIZE; i++)
00486 { instanceCounts[i] = 0; }
00487
00488
00489
00490
00491
00492 for (i = 0; i < INSTANCE_TABLE_HASH_SIZE; i++)
00493 {
00494 instanceCount = 0;
00495 for (ins = InstanceData(theEnv)->InstanceTable[i]; ins != NULL; ins = ins->nxtHash)
00496 {
00497 instanceCount++;
00498 totalInstanceCount++;
00499 }
00500
00501 if (instanceCount < (COUNT_SIZE - 1))
00502 { instanceCounts[instanceCount]++; }
00503 else
00504 { instanceCounts[COUNT_SIZE - 1]++; }
00505 }
00506
00507
00508
00509
00510
00511 EnvPrintRouter(theEnv,WDISPLAY,"Total Instances: ");
00512 PrintLongInteger(theEnv,WDISPLAY,(long long) totalInstanceCount);
00513 EnvPrintRouter(theEnv,WDISPLAY,"\n");
00514 for (i = 0; i < COUNT_SIZE; i++)
00515 {
00516 PrintLongInteger(theEnv,WDISPLAY,(long long) i);
00517 EnvPrintRouter(theEnv,WDISPLAY," ");
00518 PrintLongInteger(theEnv,WDISPLAY,(long long) instanceCounts[i]);
00519 EnvPrintRouter(theEnv,WDISPLAY,"\n");
00520 }
00521 }
00522
00523 #endif
00524
00525 #endif
00526
00527