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
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 #include <stdlib.h>
00050
00051 #include "setup.h"
00052
00053 #if OBJECT_SYSTEM
00054
00055 #include "argacces.h"
00056 #include "classcom.h"
00057 #include "classfun.h"
00058 #include "cstrnchk.h"
00059 #include "engine.h"
00060 #include "envrnmnt.h"
00061 #include "inscom.h"
00062 #include "insmngr.h"
00063 #include "memalloc.h"
00064 #include "modulutl.h"
00065 #include "msgcom.h"
00066 #include "msgfun.h"
00067 #include "prccode.h"
00068 #include "router.h"
00069 #include "utility.h"
00070
00071 #if DEFRULE_CONSTRUCT
00072 #include "drive.h"
00073 #include "objrtmch.h"
00074 #endif
00075
00076 #define _INSFUN_SOURCE_
00077 #include "insfun.h"
00078
00079
00080
00081
00082
00083
00084 #define BIG_PRIME 11329
00085
00086
00087
00088
00089
00090
00091
00092 static INSTANCE_TYPE *FindImportedInstance(void *,struct defmodule *,struct defmodule *,INSTANCE_TYPE *);
00093
00094 #if DEFRULE_CONSTRUCT
00095 static void NetworkModifyForSharedSlot(void *,int,DEFCLASS *,SLOT_DESC *);
00096 #endif
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113 #if WIN_BTC
00114 #pragma argsused
00115 #endif
00116 globle void EnvIncrementInstanceCount(
00117 void *theEnv,
00118 void *vptr)
00119 {
00120 #if MAC_MCW || WIN_MCW || MAC_XCD
00121 #pragma unused(theEnv)
00122 #endif
00123
00124 ((INSTANCE_TYPE *) vptr)->busy++;
00125 }
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 #if WIN_BTC
00137 #pragma argsused
00138 #endif
00139 globle void EnvDecrementInstanceCount(
00140 void *theEnv,
00141 void *vptr)
00142 {
00143 #if MAC_MCW || WIN_MCW || MAC_XCD
00144 #pragma unused(theEnv)
00145 #endif
00146
00147 ((INSTANCE_TYPE *) vptr)->busy--;
00148 }
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159 globle void InitializeInstanceTable(
00160 void *theEnv)
00161 {
00162 register int i;
00163
00164 InstanceData(theEnv)->InstanceTable = (INSTANCE_TYPE **)
00165 gm2(theEnv,(int) (sizeof(INSTANCE_TYPE *) * INSTANCE_TABLE_HASH_SIZE));
00166 for (i = 0 ; i < INSTANCE_TABLE_HASH_SIZE ; i++)
00167 InstanceData(theEnv)->InstanceTable[i] = NULL;
00168 }
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181 globle void CleanupInstances(
00182 void *theEnv)
00183 {
00184 IGARBAGE *gprv,*gtmp,*dump;
00185
00186 if (InstanceData(theEnv)->MaintainGarbageInstances)
00187 return;
00188 gprv = NULL;
00189 gtmp = InstanceData(theEnv)->InstanceGarbageList;
00190 while (gtmp != NULL)
00191 {
00192 if ((gtmp->ins->busy == 0) && (gtmp->ins->depth > EvaluationData(theEnv)->CurrentEvaluationDepth)
00193 #if DEFRULE_CONSTRUCT
00194 && (gtmp->ins->header.busyCount == 0)
00195 #endif
00196 )
00197 {
00198 UtilityData(theEnv)->EphemeralItemCount -= 2;
00199 UtilityData(theEnv)->EphemeralItemSize -= InstanceSizeHeuristic(gtmp->ins) + sizeof(IGARBAGE);
00200 DecrementSymbolCount(theEnv,gtmp->ins->name);
00201 rtn_struct(theEnv,instance,gtmp->ins);
00202 if (gprv == NULL)
00203 InstanceData(theEnv)->InstanceGarbageList = gtmp->nxt;
00204 else
00205 gprv->nxt = gtmp->nxt;
00206 dump = gtmp;
00207 gtmp = gtmp->nxt;
00208 rtn_struct(theEnv,igarbage,dump);
00209 }
00210 else
00211 {
00212 gprv = gtmp;
00213 gtmp = gtmp->nxt;
00214 }
00215 }
00216 }
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230 globle unsigned HashInstance(
00231 SYMBOL_HN *cname)
00232 {
00233 unsigned long tally;
00234
00235 tally = ((unsigned long) cname->bucket) * BIG_PRIME;
00236 return((unsigned) (tally % INSTANCE_TABLE_HASH_SIZE));
00237 }
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249 globle void DestroyAllInstances(
00250 void *theEnv)
00251 {
00252 INSTANCE_TYPE *iptr;
00253 int svmaintain;
00254
00255 SaveCurrentModule(theEnv);
00256 svmaintain = InstanceData(theEnv)->MaintainGarbageInstances;
00257 InstanceData(theEnv)->MaintainGarbageInstances = TRUE;
00258 iptr = InstanceData(theEnv)->InstanceList;
00259 while (iptr != NULL)
00260 {
00261 EnvSetCurrentModule(theEnv,(void *) iptr->cls->header.whichModule->theModule);
00262 DirectMessage(theEnv,MessageHandlerData(theEnv)->DELETE_SYMBOL,iptr,NULL,NULL);
00263 iptr = iptr->nxtList;
00264 while ((iptr != NULL) ? iptr->garbage : FALSE)
00265 iptr = iptr->nxtList;
00266 }
00267 InstanceData(theEnv)->MaintainGarbageInstances = svmaintain;
00268 RestoreCurrentModule(theEnv);
00269 }
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285 globle void RemoveInstanceData(
00286 void *theEnv,
00287 INSTANCE_TYPE *ins)
00288 {
00289 long i;
00290 INSTANCE_SLOT *sp;
00291
00292 DecrementDefclassBusyCount(theEnv,(void *) ins->cls);
00293 for (i = 0 ; i < ins->cls->instanceSlotCount ; i++)
00294 {
00295 sp = ins->slotAddresses[i];
00296 if ((sp == &sp->desc->sharedValue) ?
00297 (--sp->desc->sharedCount == 0) : TRUE)
00298 {
00299 if (sp->desc->multiple)
00300 {
00301 MultifieldDeinstall(theEnv,(MULTIFIELD_PTR) sp->value);
00302 AddToMultifieldList(theEnv,(MULTIFIELD_PTR) sp->value);
00303 }
00304 else
00305 AtomDeinstall(theEnv,(int) sp->type,sp->value);
00306 sp->value = NULL;
00307 }
00308 }
00309 if (ins->cls->instanceSlotCount != 0)
00310 {
00311 rm(theEnv,(void *) ins->slotAddresses,
00312 (ins->cls->instanceSlotCount * sizeof(INSTANCE_SLOT *)));
00313 if (ins->cls->localInstanceSlotCount != 0)
00314 rm(theEnv,(void *) ins->slots,
00315 (ins->cls->localInstanceSlotCount * sizeof(INSTANCE_SLOT)));
00316 }
00317 ins->slots = NULL;
00318 ins->slotAddresses = NULL;
00319 }
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331 globle INSTANCE_TYPE *FindInstanceBySymbol(
00332 void *theEnv,
00333 SYMBOL_HN *moduleAndInstanceName)
00334 {
00335 unsigned modulePosition,searchImports;
00336 SYMBOL_HN *moduleName,*instanceName;
00337 struct defmodule *currentModule,*theModule;
00338
00339 currentModule = ((struct defmodule *) EnvGetCurrentModule(theEnv));
00340
00341
00342
00343
00344
00345 modulePosition = FindModuleSeparator(ValueToString(moduleAndInstanceName));
00346 if (modulePosition == FALSE)
00347 {
00348 theModule = currentModule;
00349 instanceName = moduleAndInstanceName;
00350 searchImports = FALSE;
00351 }
00352
00353
00354
00355
00356
00357
00358 else if (modulePosition == 1)
00359 {
00360 theModule = currentModule;
00361 instanceName = ExtractConstructName(theEnv,modulePosition,ValueToString(moduleAndInstanceName));
00362 searchImports = TRUE;
00363 }
00364
00365
00366
00367
00368
00369 else
00370 {
00371 moduleName = ExtractModuleName(theEnv,modulePosition,ValueToString(moduleAndInstanceName));
00372 theModule = (struct defmodule *) EnvFindDefmodule(theEnv,ValueToString(moduleName));
00373 instanceName = ExtractConstructName(theEnv,modulePosition,ValueToString(moduleAndInstanceName));
00374 if (theModule == NULL)
00375 return(NULL);
00376 searchImports = FALSE;
00377 }
00378 return(FindInstanceInModule(theEnv,instanceName,theModule,currentModule,searchImports));
00379 }
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398 globle INSTANCE_TYPE *FindInstanceInModule(
00399 void *theEnv,
00400 SYMBOL_HN *instanceName,
00401 struct defmodule *theModule,
00402 struct defmodule *currentModule,
00403 unsigned searchImports)
00404 {
00405 INSTANCE_TYPE *startInstance,*ins;
00406
00407
00408
00409
00410
00411 startInstance = InstanceData(theEnv)->InstanceTable[HashInstance(instanceName)];
00412 while (startInstance != NULL)
00413 {
00414 if (startInstance->name == instanceName)
00415 break;
00416 startInstance = startInstance->nxtHash;
00417 }
00418
00419 if (startInstance == NULL)
00420 return(NULL);
00421
00422
00423
00424
00425
00426
00427
00428 for (ins = startInstance ;
00429 (ins != NULL) ? (ins->name == startInstance->name) : FALSE ;
00430 ins = ins->nxtHash)
00431 if ((ins->cls->header.whichModule->theModule == theModule) &&
00432 DefclassInScope(theEnv,ins->cls,currentModule))
00433 return(ins);
00434
00435
00436
00437
00438
00439 if (searchImports == FALSE)
00440 return(NULL);
00441 MarkModulesAsUnvisited(theEnv);
00442 return(FindImportedInstance(theEnv,theModule,currentModule,startInstance));
00443 }
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454 globle INSTANCE_SLOT *FindInstanceSlot(
00455 void *theEnv,
00456 INSTANCE_TYPE *ins,
00457 SYMBOL_HN *sname)
00458 {
00459 register int i;
00460
00461 i = FindInstanceTemplateSlot(theEnv,ins->cls,sname);
00462 return((i != -1) ? ins->slotAddresses[i] : NULL);
00463 }
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476 globle int FindInstanceTemplateSlot(
00477 void *theEnv,
00478 DEFCLASS *cls,
00479 SYMBOL_HN *sname)
00480 {
00481 int sid;
00482
00483 sid = FindSlotNameID(theEnv,sname);
00484 if (sid == -1)
00485 return(-1);
00486 if (sid > (int) cls->maxSlotNameID)
00487 return(-1);
00488 return((int) cls->slotNameMap[sid] - 1);
00489 }
00490
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509 globle int PutSlotValue(
00510 void *theEnv,
00511 INSTANCE_TYPE *ins,
00512 INSTANCE_SLOT *sp,
00513 DATA_OBJECT *val,
00514 DATA_OBJECT *setVal,
00515 char *theCommand)
00516 {
00517 if (ValidSlotValue(theEnv,val,sp->desc,ins,theCommand) == FALSE)
00518 {
00519 SetpType(setVal,SYMBOL);
00520 SetpValue(setVal,EnvFalseSymbol(theEnv));
00521 return(FALSE);
00522 }
00523 return(DirectPutSlotValue(theEnv,ins,sp,val,setVal));
00524 }
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543 globle int DirectPutSlotValue(
00544 void *theEnv,
00545 INSTANCE_TYPE *ins,
00546 INSTANCE_SLOT *sp,
00547 DATA_OBJECT *val,
00548 DATA_OBJECT *setVal)
00549 {
00550 register long i,j;
00551 #if DEFRULE_CONSTRUCT
00552 int sharedTraversalID;
00553 INSTANCE_SLOT *bsp,**spaddr;
00554 #endif
00555 DATA_OBJECT tmpVal;
00556
00557 SetpType(setVal,SYMBOL);
00558 SetpValue(setVal,EnvFalseSymbol(theEnv));
00559 if (val == NULL)
00560 {
00561 SystemError(theEnv,"INSFUN",1);
00562 EnvExitRouter(theEnv,EXIT_FAILURE);
00563 }
00564 else if (GetpValue(val) == ProceduralPrimitiveData(theEnv)->NoParamValue)
00565 {
00566 if (sp->desc->dynamicDefault)
00567 {
00568 val = &tmpVal;
00569 if (!EvaluateAndStoreInDataObject(theEnv,sp->desc->multiple,
00570 (EXPRESSION *) sp->desc->defaultValue,val,TRUE))
00571 return(FALSE);
00572 }
00573 else
00574 val = (DATA_OBJECT *) sp->desc->defaultValue;
00575 }
00576 #if DEFRULE_CONSTRUCT
00577 if (EngineData(theEnv)->JoinOperationInProgress && sp->desc->reactive &&
00578 (ins->cls->reactive || sp->desc->shared))
00579 {
00580 PrintErrorID(theEnv,"INSFUN",5,FALSE);
00581 EnvPrintRouter(theEnv,WERROR,"Cannot modify reactive instance slots while\n");
00582 EnvPrintRouter(theEnv,WERROR," pattern-matching is in process.\n");
00583 SetEvaluationError(theEnv,TRUE);
00584 return(FALSE);
00585 }
00586
00587
00588
00589
00590
00591
00592 if (ins->basisSlots != NULL)
00593 {
00594 spaddr = &ins->slotAddresses[ins->cls->slotNameMap[sp->desc->slotName->id] - 1];
00595 bsp = ins->basisSlots + (spaddr - ins->slotAddresses);
00596 if (bsp->value == NULL)
00597 {
00598 bsp->type = sp->type;
00599 bsp->value = sp->value;
00600 if (sp->desc->multiple)
00601 MultifieldInstall(theEnv,(MULTIFIELD_PTR) bsp->value);
00602 else
00603 AtomInstall(theEnv,(int) bsp->type,bsp->value);
00604 }
00605 }
00606
00607 #endif
00608 if (sp->desc->multiple == 0)
00609 {
00610 AtomDeinstall(theEnv,(int) sp->type,sp->value);
00611
00612
00613
00614
00615
00616 if (GetpType(val) == MULTIFIELD)
00617 {
00618 sp->type = GetMFType(GetpValue(val),GetpDOBegin(val));
00619 sp->value = GetMFValue(GetpValue(val),GetpDOBegin(val));
00620 }
00621 else
00622 {
00623 sp->type = val->type;
00624 sp->value = val->value;
00625 }
00626 AtomInstall(theEnv,(int) sp->type,sp->value);
00627 SetpType(setVal,sp->type);
00628 SetpValue(setVal,sp->value);
00629 }
00630 else
00631 {
00632 MultifieldDeinstall(theEnv,(MULTIFIELD_PTR) sp->value);
00633 AddToMultifieldList(theEnv,(MULTIFIELD_PTR) sp->value);
00634 sp->type = MULTIFIELD;
00635 if (val->type == MULTIFIELD)
00636 {
00637 sp->value = CreateMultifield2(theEnv,(unsigned long) GetpDOLength(val));
00638 for (i = 1 , j = GetpDOBegin(val) ; i <= GetpDOLength(val) ; i++ , j++)
00639 {
00640 SetMFType(sp->value,i,GetMFType(val->value,j));
00641 SetMFValue(sp->value,i,GetMFValue(val->value,j));
00642 }
00643 }
00644 else
00645 {
00646 sp->value = CreateMultifield2(theEnv,1L);
00647 SetMFType(sp->value,1,(short) val->type);
00648 SetMFValue(sp->value,1,val->value);
00649 }
00650 MultifieldInstall(theEnv,(struct multifield *) sp->value);
00651 SetpType(setVal,MULTIFIELD);
00652 SetpValue(setVal,sp->value);
00653 SetpDOBegin(setVal,1);
00654 SetpDOEnd(setVal,GetMFLength(sp->value));
00655 }
00656
00657
00658
00659
00660
00661
00662
00663 sp->override = ins->initializeInProgress;
00664
00665 #if DEBUGGING_FUNCTIONS
00666 if (ins->cls->traceSlots)
00667 {
00668 if (sp->desc->shared)
00669 EnvPrintRouter(theEnv,WTRACE,"::= shared slot ");
00670 else
00671 EnvPrintRouter(theEnv,WTRACE,"::= local slot ");
00672 EnvPrintRouter(theEnv,WTRACE,ValueToString(sp->desc->slotName->name));
00673 EnvPrintRouter(theEnv,WTRACE," in instance ");
00674 EnvPrintRouter(theEnv,WTRACE,ValueToString(ins->name));
00675 EnvPrintRouter(theEnv,WTRACE," <- ");
00676 if (sp->type != MULTIFIELD)
00677 PrintAtom(theEnv,WTRACE,(int) sp->type,sp->value);
00678 else
00679 PrintMultifield(theEnv,WTRACE,(MULTIFIELD_PTR) sp->value,0,
00680 (long) (GetInstanceSlotLength(sp) - 1),TRUE);
00681 EnvPrintRouter(theEnv,WTRACE,"\n");
00682 }
00683 #endif
00684 InstanceData(theEnv)->ChangesToInstances = TRUE;
00685
00686 #if DEFRULE_CONSTRUCT
00687 if (ins->cls->reactive && sp->desc->reactive)
00688 {
00689
00690
00691
00692
00693
00694 if (sp->desc->shared)
00695 {
00696 sharedTraversalID = GetTraversalID(theEnv);
00697 if (sharedTraversalID != -1)
00698 {
00699 NetworkModifyForSharedSlot(theEnv,sharedTraversalID,sp->desc->cls,sp->desc);
00700 ReleaseTraversalID(theEnv);
00701 }
00702 else
00703 {
00704 PrintErrorID(theEnv,"INSFUN",6,FALSE);
00705 EnvPrintRouter(theEnv,WERROR,"Unable to pattern-match on shared slot ");
00706 EnvPrintRouter(theEnv,WERROR,ValueToString(sp->desc->slotName->name));
00707 EnvPrintRouter(theEnv,WERROR," in class ");
00708 EnvPrintRouter(theEnv,WERROR,EnvGetDefclassName(theEnv,(void *) sp->desc->cls));
00709 EnvPrintRouter(theEnv,WERROR,".\n");
00710 }
00711 }
00712 else
00713 ObjectNetworkAction(theEnv,OBJECT_MODIFY,(INSTANCE_TYPE *) ins,(int) sp->desc->slotName->id);
00714 }
00715 #endif
00716
00717 return(TRUE);
00718 }
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735 globle int ValidSlotValue(
00736 void *theEnv,
00737 DATA_OBJECT *val,
00738 SLOT_DESC *sd,
00739 INSTANCE_TYPE *ins,
00740 char *theCommand)
00741 {
00742 register int violationCode;
00743
00744
00745
00746
00747
00748 if (GetpValue(val) == ProceduralPrimitiveData(theEnv)->NoParamValue)
00749 return(TRUE);
00750 if ((sd->multiple == 0) && (val->type == MULTIFIELD) &&
00751 (GetpDOLength(val) != 1))
00752 {
00753 PrintErrorID(theEnv,"INSFUN",7,FALSE);
00754 PrintDataObject(theEnv,WERROR,val);
00755 EnvPrintRouter(theEnv,WERROR," illegal for single-field ");
00756 PrintSlot(theEnv,WERROR,sd,ins,theCommand);
00757 EnvPrintRouter(theEnv,WERROR,".\n");
00758 SetEvaluationError(theEnv,TRUE);
00759 return(FALSE);
00760 }
00761 if (val->type == RVOID)
00762 {
00763 PrintErrorID(theEnv,"INSFUN",8,FALSE);
00764 EnvPrintRouter(theEnv,WERROR,"Void function illegal value for ");
00765 PrintSlot(theEnv,WERROR,sd,ins,theCommand);
00766 EnvPrintRouter(theEnv,WERROR,".\n");
00767 SetEvaluationError(theEnv,TRUE);
00768 return(FALSE);
00769 }
00770 if (EnvGetDynamicConstraintChecking(theEnv))
00771 {
00772 violationCode = ConstraintCheckDataObject(theEnv,val,sd->constraint);
00773 if (violationCode != NO_VIOLATION)
00774 {
00775 PrintErrorID(theEnv,"CSTRNCHK",1,FALSE);
00776 if ((GetpType(val) == MULTIFIELD) && (sd->multiple == 0))
00777 PrintAtom(theEnv,WERROR,GetMFType(GetpValue(val),GetpDOBegin(val)),
00778 GetMFValue(GetpValue(val),GetpDOEnd(val)));
00779 else
00780 PrintDataObject(theEnv,WERROR,val);
00781 EnvPrintRouter(theEnv,WERROR," for ");
00782 PrintSlot(theEnv,WERROR,sd,ins,theCommand);
00783 ConstraintViolationErrorMessage(theEnv,NULL,NULL,0,0,NULL,0,
00784 violationCode,sd->constraint,FALSE);
00785 SetEvaluationError(theEnv,TRUE);
00786 return(FALSE);
00787 }
00788 }
00789 return(TRUE);
00790 }
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802 globle INSTANCE_TYPE *CheckInstance(
00803 void *theEnv,
00804 char *func)
00805 {
00806 INSTANCE_TYPE *ins;
00807 DATA_OBJECT temp;
00808
00809 EvaluateExpression(theEnv,GetFirstArgument(),&temp);
00810 if (temp.type == INSTANCE_ADDRESS)
00811 {
00812 ins = (INSTANCE_TYPE *) temp.value;
00813 if (ins->garbage == 1)
00814 {
00815 StaleInstanceAddress(theEnv,func,0);
00816 SetEvaluationError(theEnv,TRUE);
00817 return(NULL);
00818 }
00819 }
00820 else if ((temp.type == INSTANCE_NAME) ||
00821 (temp.type == SYMBOL))
00822 {
00823 ins = FindInstanceBySymbol(theEnv,(SYMBOL_HN *) temp.value);
00824 if (ins == NULL)
00825 {
00826 NoInstanceError(theEnv,ValueToString(temp.value),func);
00827 return(NULL);
00828 }
00829 }
00830 else
00831 {
00832 PrintErrorID(theEnv,"INSFUN",1,FALSE);
00833 EnvPrintRouter(theEnv,WERROR,"Expected a valid instance in function ");
00834 EnvPrintRouter(theEnv,WERROR,func);
00835 EnvPrintRouter(theEnv,WERROR,".\n");
00836 SetEvaluationError(theEnv,TRUE);
00837 return(NULL);
00838 }
00839 return(ins);
00840 }
00841
00842
00843
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853 globle void NoInstanceError(
00854 void *theEnv,
00855 char *iname,
00856 char *func)
00857 {
00858 PrintErrorID(theEnv,"INSFUN",2,FALSE);
00859 EnvPrintRouter(theEnv,WERROR,"No such instance ");
00860 EnvPrintRouter(theEnv,WERROR,iname);
00861 EnvPrintRouter(theEnv,WERROR," in function ");
00862 EnvPrintRouter(theEnv,WERROR,func);
00863 EnvPrintRouter(theEnv,WERROR,".\n");
00864 SetEvaluationError(theEnv,TRUE);
00865 }
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877 globle void StaleInstanceAddress(
00878 void *theEnv,
00879 char *func,
00880 int whichArg)
00881 {
00882 PrintErrorID(theEnv,"INSFUN",4,FALSE);
00883 EnvPrintRouter(theEnv,WERROR,"Invalid instance-address in function ");
00884 EnvPrintRouter(theEnv,WERROR,func);
00885 if (whichArg > 0)
00886 {
00887 EnvPrintRouter(theEnv,WERROR,", argument #");
00888 PrintLongInteger(theEnv,WERROR,(long long) whichArg);
00889 }
00890 EnvPrintRouter(theEnv,WERROR,".\n");
00891 }
00892
00893
00894
00895
00896
00897
00898
00899
00900
00901
00902
00903 globle int EnvGetInstancesChanged(
00904 void *theEnv)
00905 {
00906 return(InstanceData(theEnv)->ChangesToInstances);
00907 }
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917 globle void EnvSetInstancesChanged(
00918 void *theEnv,
00919 int changed)
00920 {
00921 InstanceData(theEnv)->ChangesToInstances = changed;
00922 }
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937 globle void PrintSlot(
00938 void *theEnv,
00939 char *logName,
00940 SLOT_DESC *sd,
00941 INSTANCE_TYPE *ins,
00942 char *theCommand)
00943 {
00944 EnvPrintRouter(theEnv,logName,"slot ");
00945 EnvPrintRouter(theEnv,logName,ValueToString(sd->slotName->name));
00946 if (ins != NULL)
00947 {
00948 EnvPrintRouter(theEnv,logName," of instance [");
00949 EnvPrintRouter(theEnv,logName,ValueToString(ins->name));
00950 EnvPrintRouter(theEnv,logName,"]");
00951 }
00952 else if (sd->cls != NULL)
00953 {
00954 EnvPrintRouter(theEnv,logName," of class ");
00955 EnvPrintRouter(theEnv,logName,EnvGetDefclassName(theEnv,(void *) sd->cls));
00956 }
00957 EnvPrintRouter(theEnv,logName," found in ");
00958 if (theCommand != NULL)
00959 EnvPrintRouter(theEnv,logName,theCommand);
00960 else
00961 PrintHandler(theEnv,logName,MessageHandlerData(theEnv)->CurrentCore->hnd,FALSE);
00962 }
00963
00964
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974
00975 globle void PrintInstanceNameAndClass(
00976 void *theEnv,
00977 char *logicalName,
00978 INSTANCE_TYPE *theInstance,
00979 intBool linefeedFlag)
00980 {
00981 EnvPrintRouter(theEnv,logicalName,"[");
00982 EnvPrintRouter(theEnv,logicalName,EnvGetInstanceName(theEnv,(void *) theInstance));
00983 EnvPrintRouter(theEnv,logicalName,"] of ");
00984 PrintClassName(theEnv,logicalName,theInstance->cls,linefeedFlag);
00985 }
00986
00987
00988
00989
00990
00991
00992
00993
00994
00995
00996
00997
00998 globle void PrintInstanceName(
00999 void *theEnv,
01000 char *logName,
01001 void *vins)
01002 {
01003 INSTANCE_TYPE *ins;
01004
01005 ins = (INSTANCE_TYPE *) vins;
01006 if (ins->garbage)
01007 {
01008 EnvPrintRouter(theEnv,logName,"<stale instance [");
01009 EnvPrintRouter(theEnv,logName,ValueToString(ins->name));
01010 EnvPrintRouter(theEnv,logName,"]>");
01011 }
01012 else
01013 {
01014 EnvPrintRouter(theEnv,logName,"[");
01015 EnvPrintRouter(theEnv,logName,ValueToString(GetFullInstanceName(theEnv,ins)));
01016 EnvPrintRouter(theEnv,logName,"]");
01017 }
01018 }
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030 globle void PrintInstanceLongForm(
01031 void *theEnv,
01032 char *logName,
01033 void *vins)
01034 {
01035 INSTANCE_TYPE *ins = (INSTANCE_TYPE *) vins;
01036
01037 if (PrintUtilityData(theEnv)->InstanceAddressesToNames)
01038 {
01039 if (ins == &InstanceData(theEnv)->DummyInstance)
01040 EnvPrintRouter(theEnv,logName,"\"<Dummy Instance>\"");
01041 else
01042 {
01043 EnvPrintRouter(theEnv,logName,"[");
01044 EnvPrintRouter(theEnv,logName,ValueToString(GetFullInstanceName(theEnv,ins)));
01045 EnvPrintRouter(theEnv,logName,"]");
01046 }
01047 }
01048 else
01049 {
01050 if (PrintUtilityData(theEnv)->AddressesToStrings)
01051 EnvPrintRouter(theEnv,logName,"\"");
01052 if (ins == &InstanceData(theEnv)->DummyInstance)
01053 EnvPrintRouter(theEnv,logName,"<Dummy Instance>");
01054 else if (ins->garbage)
01055 {
01056 EnvPrintRouter(theEnv,logName,"<Stale Instance-");
01057 EnvPrintRouter(theEnv,logName,ValueToString(ins->name));
01058 EnvPrintRouter(theEnv,logName,">");
01059 }
01060 else
01061 {
01062 EnvPrintRouter(theEnv,logName,"<Instance-");
01063 EnvPrintRouter(theEnv,logName,ValueToString(GetFullInstanceName(theEnv,ins)));
01064 EnvPrintRouter(theEnv,logName,">");
01065 }
01066 if (PrintUtilityData(theEnv)->AddressesToStrings)
01067 EnvPrintRouter(theEnv,logName,"\"");
01068 }
01069 }
01070
01071 #if DEFRULE_CONSTRUCT
01072
01073
01074
01075
01076
01077
01078
01079
01080
01081
01082
01083
01084
01085
01086
01087 globle void DecrementObjectBasisCount(
01088 void *theEnv,
01089 void *vins)
01090 {
01091 INSTANCE_TYPE *ins;
01092 long i;
01093
01094 ins = (INSTANCE_TYPE *) vins;
01095 ins->header.busyCount--;
01096 if (ins->header.busyCount == 0)
01097 {
01098 if (ins->garbage)
01099 RemoveInstanceData(theEnv,ins);
01100 if (ins->cls->instanceSlotCount != 0)
01101 {
01102 for (i = 0 ; i < ins->cls->instanceSlotCount ; i++)
01103 if (ins->basisSlots[i].value != NULL)
01104 {
01105 if (ins->basisSlots[i].desc->multiple)
01106 MultifieldDeinstall(theEnv,(struct multifield *) ins->basisSlots[i].value);
01107 else
01108 AtomDeinstall(theEnv,(int) ins->basisSlots[i].type,
01109 ins->basisSlots[i].value);
01110 }
01111 rm(theEnv,(void *) ins->basisSlots,
01112 (ins->cls->instanceSlotCount * sizeof(INSTANCE_SLOT)));
01113 ins->basisSlots = NULL;
01114 }
01115 }
01116 }
01117
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134 globle void IncrementObjectBasisCount(
01135 void *theEnv,
01136 void *vins)
01137 {
01138 INSTANCE_TYPE *ins;
01139 long i;
01140
01141 ins = (INSTANCE_TYPE *) vins;
01142 if (ins->header.busyCount == 0)
01143 {
01144 if (ins->cls->instanceSlotCount != 0)
01145 {
01146 ins->basisSlots = (INSTANCE_SLOT *)
01147 gm2(theEnv,(sizeof(INSTANCE_SLOT) * ins->cls->instanceSlotCount));
01148 for (i = 0 ; i < ins->cls->instanceSlotCount ; i++)
01149 {
01150 ins->basisSlots[i].desc = ins->slotAddresses[i]->desc;
01151 ins->basisSlots[i].value = NULL;
01152 }
01153 }
01154 }
01155 ins->header.busyCount++;
01156 }
01157
01158
01159
01160
01161
01162
01163
01164
01165
01166
01167
01168
01169 globle void MatchObjectFunction(
01170 void *theEnv,
01171 void *vins)
01172 {
01173 ObjectNetworkAction(theEnv,OBJECT_ASSERT,(INSTANCE_TYPE *) vins,-1);
01174 }
01175
01176
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188 #if WIN_BTC
01189 #pragma argsused
01190 #endif
01191 globle intBool NetworkSynchronized(
01192 void *theEnv,
01193 void *vins)
01194 {
01195 #if MAC_MCW || WIN_MCW || MAC_XCD
01196 #pragma unused(theEnv)
01197 #endif
01198
01199 return(((INSTANCE_TYPE *) vins)->reteSynchronized);
01200 }
01201 #endif
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215
01216
01217
01218
01219
01220
01221
01222
01223
01224
01225
01226 static INSTANCE_TYPE *FindImportedInstance(
01227 void *theEnv,
01228 struct defmodule *theModule,
01229 struct defmodule *currentModule,
01230 INSTANCE_TYPE *startInstance)
01231 {
01232 struct portItem *importList;
01233 INSTANCE_TYPE *ins;
01234
01235 if (theModule->visitedFlag)
01236 return(NULL);
01237 theModule->visitedFlag = TRUE;
01238 importList = theModule->importList;
01239 while (importList != NULL)
01240 {
01241 theModule = (struct defmodule *)
01242 EnvFindDefmodule(theEnv,ValueToString(importList->moduleName));
01243 for (ins = startInstance ;
01244 (ins != NULL) ? (ins->name == startInstance->name) : FALSE ;
01245 ins = ins->nxtHash)
01246 if ((ins->cls->header.whichModule->theModule == theModule) &&
01247 DefclassInScope(theEnv,ins->cls,currentModule))
01248 return(ins);
01249 ins = FindImportedInstance(theEnv,theModule,currentModule,startInstance);
01250 if (ins != NULL)
01251 return(ins);
01252 importList = importList->next;
01253 }
01254
01255
01256
01257
01258 for (ins = startInstance ;
01259 (ins != NULL) ? (ins->name == startInstance->name) : FALSE ;
01260 ins = ins->nxtHash)
01261 if (ins->cls->system)
01262 return(ins);
01263
01264 return(NULL);
01265 }
01266
01267 #if DEFRULE_CONSTRUCT
01268
01269
01270
01271
01272
01273
01274
01275
01276
01277
01278
01279
01280
01281
01282
01283
01284
01285
01286
01287 static void NetworkModifyForSharedSlot(
01288 void *theEnv,
01289 int sharedTraversalID,
01290 DEFCLASS *cls,
01291 SLOT_DESC *sd)
01292 {
01293 INSTANCE_TYPE *ins;
01294 long i;
01295
01296
01297
01298
01299 if (TestTraversalID(cls->traversalRecord,sharedTraversalID))
01300 return;
01301 SetTraversalID(cls->traversalRecord,sharedTraversalID);
01302
01303
01304
01305
01306
01307
01308 if ((sd->slotName->id > cls->maxSlotNameID) ? FALSE :
01309 ((cls->slotNameMap[sd->slotName->id] == 0) ? FALSE :
01310 (cls->instanceTemplate[cls->slotNameMap[sd->slotName->id] - 1] == sd)))
01311 {
01312 for (ins = cls->instanceList ; ins != NULL ; ins = ins->nxtClass)
01313 ObjectNetworkAction(theEnv,OBJECT_MODIFY,(INSTANCE_TYPE *) ins,(int) sd->slotName->id);
01314 }
01315
01316
01317
01318
01319 for (i = 0 ; i < cls->directSubclasses.classCount ; i++)
01320 NetworkModifyForSharedSlot(theEnv,sharedTraversalID,cls->directSubclasses.classArray[i],sd);
01321 }
01322
01323 #endif
01324
01325 #endif
01326
01327