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 #define _EVALUATN_SOURCE_
00031
00032 #include <stdio.h>
00033 #define _STDIO_INCLUDED_
00034 #include <stdlib.h>
00035 #include <string.h>
00036 #include <ctype.h>
00037
00038 #include "setup.h"
00039
00040 #include "argacces.h"
00041 #include "commline.h"
00042 #include "constant.h"
00043 #include "envrnmnt.h"
00044 #include "memalloc.h"
00045 #include "router.h"
00046 #include "extnfunc.h"
00047 #include "prcdrfun.h"
00048 #include "multifld.h"
00049 #include "factmngr.h"
00050 #include "prntutil.h"
00051 #include "exprnpsr.h"
00052 #include "utility.h"
00053 #include "proflfun.h"
00054 #include "sysdep.h"
00055
00056 #if DEFFUNCTION_CONSTRUCT
00057 #include "dffnxfun.h"
00058 #endif
00059
00060 #if DEFGENERIC_CONSTRUCT
00061 #include "genrccom.h"
00062 #endif
00063
00064 #if OBJECT_SYSTEM
00065 #include "object.h"
00066 #endif
00067
00068 #include "evaluatn.h"
00069
00070
00071
00072
00073
00074 static void PropagateReturnAtom(void *,int,void *);
00075 static void DeallocateEvaluationData(void *);
00076 static void PrintCAddress(void *,char *,void *);
00077 static void NewCAddress(void *,DATA_OBJECT *);
00078
00079
00080
00081
00082
00083
00084
00085
00086 globle void InitializeEvaluationData(
00087 void *theEnv)
00088 {
00089 struct externalAddressType cPointer = { "C", PrintCAddress, PrintCAddress, NULL, NewCAddress, NULL };
00090
00091 AllocateEnvironmentData(theEnv,EVALUATION_DATA,sizeof(struct evaluationData),DeallocateEvaluationData);
00092
00093 InstallExternalAddressType(theEnv,&cPointer);
00094 }
00095
00096
00097
00098
00099
00100 static void DeallocateEvaluationData(
00101 void *theEnv)
00102 {
00103 int i;
00104
00105 for (i = 0; i < EvaluationData(theEnv)->numberOfAddressTypes; i++)
00106 { rtn_struct(theEnv,externalAddressType,EvaluationData(theEnv)->ExternalAddressTypes[i]); }
00107 }
00108
00109
00110
00111
00112
00113 globle int EvaluateExpression(
00114 void *theEnv,
00115 struct expr *problem,
00116 DATA_OBJECT_PTR returnValue)
00117 {
00118 struct expr *oldArgument;
00119 void *oldContext;
00120 struct FunctionDefinition *fptr;
00121 #if PROFILING_FUNCTIONS
00122 struct profileFrameInfo profileFrame;
00123 #endif
00124
00125 if (problem == NULL)
00126 {
00127 returnValue->type = SYMBOL;
00128 returnValue->value = EnvFalseSymbol(theEnv);
00129 return(EvaluationData(theEnv)->EvaluationError);
00130 }
00131
00132 switch (problem->type)
00133 {
00134 case STRING:
00135 case SYMBOL:
00136 case FLOAT:
00137 case INTEGER:
00138 #if OBJECT_SYSTEM
00139 case INSTANCE_NAME:
00140 case INSTANCE_ADDRESS:
00141 #endif
00142 case EXTERNAL_ADDRESS:
00143 returnValue->type = problem->type;
00144 returnValue->value = problem->value;
00145 break;
00146
00147 case DATA_OBJECT_ARRAY:
00148 returnValue->type = problem->type;
00149 returnValue->value = problem->value;
00150 break;
00151
00152 case FCALL:
00153 {
00154 fptr = (struct FunctionDefinition *) problem->value;
00155 oldContext = SetEnvironmentFunctionContext(theEnv,fptr->context);
00156
00157 #if PROFILING_FUNCTIONS
00158 StartProfile(theEnv,&profileFrame,
00159 &fptr->usrData,
00160 ProfileFunctionData(theEnv)->ProfileUserFunctions);
00161 #endif
00162
00163 oldArgument = EvaluationData(theEnv)->CurrentExpression;
00164 EvaluationData(theEnv)->CurrentExpression = problem;
00165
00166 switch(fptr->returnValueType)
00167 {
00168 case 'v' :
00169 if (fptr->environmentAware)
00170 { (* (void (*)(void *)) fptr->functionPointer)(theEnv); }
00171 else
00172 { (* (void (*)(void)) fptr->functionPointer)(); }
00173 returnValue->type = RVOID;
00174 returnValue->value = EnvFalseSymbol(theEnv);
00175 break;
00176 case 'b' :
00177 returnValue->type = SYMBOL;
00178 if (fptr->environmentAware)
00179 {
00180 if ((* (int (*)(void *)) fptr->functionPointer)(theEnv))
00181 returnValue->value = EnvTrueSymbol(theEnv);
00182 else
00183 returnValue->value = EnvFalseSymbol(theEnv);
00184 }
00185 else
00186 {
00187 if ((* (int (*)(void)) fptr->functionPointer)())
00188 returnValue->value = EnvTrueSymbol(theEnv);
00189 else
00190 returnValue->value = EnvFalseSymbol(theEnv);
00191 }
00192 break;
00193 case 'a' :
00194 returnValue->type = EXTERNAL_ADDRESS;
00195 if (fptr->environmentAware)
00196 {
00197 returnValue->value =
00198 (* (void *(*)(void *)) fptr->functionPointer)(theEnv);
00199 }
00200 else
00201 {
00202 returnValue->value =
00203 (* (void *(*)(void)) fptr->functionPointer)();
00204 }
00205 break;
00206 case 'g' :
00207 returnValue->type = INTEGER;
00208 if (fptr->environmentAware)
00209 {
00210 returnValue->value = (void *)
00211 EnvAddLong(theEnv,(* (long long (*)(void *)) fptr->functionPointer)(theEnv));
00212 }
00213 else
00214 {
00215 returnValue->value = (void *)
00216 EnvAddLong(theEnv,(* (long long (*)(void)) fptr->functionPointer)());
00217 }
00218 break;
00219 case 'i' :
00220 returnValue->type = INTEGER;
00221 if (fptr->environmentAware)
00222 {
00223 returnValue->value = (void *)
00224 EnvAddLong(theEnv,(long long) (* (int (*)(void *)) fptr->functionPointer)(theEnv));
00225 }
00226 else
00227 {
00228 returnValue->value = (void *)
00229 EnvAddLong(theEnv,(long long) (* (int (*)(void)) fptr->functionPointer)());
00230 }
00231 break;
00232 case 'l' :
00233 returnValue->type = INTEGER;
00234 if (fptr->environmentAware)
00235 {
00236 returnValue->value = (void *)
00237 EnvAddLong(theEnv,(long long) (* (long int (*)(void *)) fptr->functionPointer)(theEnv));
00238 }
00239 else
00240 {
00241 returnValue->value = (void *)
00242 EnvAddLong(theEnv,(long long) (* (long int (*)(void)) fptr->functionPointer)());
00243 }
00244 break;
00245 case 'f' :
00246 returnValue->type = FLOAT;
00247 if (fptr->environmentAware)
00248 {
00249 returnValue->value = (void *)
00250 EnvAddDouble(theEnv,(double) (* (float (*)(void *)) fptr->functionPointer)(theEnv));
00251 }
00252 else
00253 {
00254 returnValue->value = (void *)
00255 EnvAddDouble(theEnv,(double) (* (float (*)(void)) fptr->functionPointer)());
00256 }
00257 break;
00258 case 'd' :
00259 returnValue->type = FLOAT;
00260 if (fptr->environmentAware)
00261 {
00262 returnValue->value = (void *)
00263 EnvAddDouble(theEnv,(* (double (*)(void *)) fptr->functionPointer)(theEnv));
00264 }
00265 else
00266 {
00267 returnValue->value = (void *)
00268 EnvAddDouble(theEnv,(* (double (*)(void)) fptr->functionPointer)());
00269 }
00270 break;
00271 case 's' :
00272 returnValue->type = STRING;
00273 if (fptr->environmentAware)
00274 {
00275 returnValue->value = (void *)
00276 (* (SYMBOL_HN *(*)(void *)) fptr->functionPointer)(theEnv);
00277 }
00278 else
00279 {
00280 returnValue->value = (void *)
00281 (* (SYMBOL_HN *(*)(void)) fptr->functionPointer)();
00282 }
00283 break;
00284 case 'w' :
00285 returnValue->type = SYMBOL;
00286 if (fptr->environmentAware)
00287 {
00288 returnValue->value = (void *)
00289 (* (SYMBOL_HN *(*)(void *)) fptr->functionPointer)(theEnv);
00290 }
00291 else
00292 {
00293 returnValue->value = (void *)
00294 (* (SYMBOL_HN *(*)(void)) fptr->functionPointer)();
00295 }
00296 break;
00297 #if OBJECT_SYSTEM
00298 case 'x' :
00299 returnValue->type = INSTANCE_ADDRESS;
00300 if (fptr->environmentAware)
00301 {
00302 returnValue->value =
00303 (* (void *(*)(void *)) fptr->functionPointer)(theEnv);
00304 }
00305 else
00306 {
00307 returnValue->value =
00308 (* (void *(*)(void)) fptr->functionPointer)();
00309 }
00310 break;
00311 case 'o' :
00312 returnValue->type = INSTANCE_NAME;
00313 if (fptr->environmentAware)
00314 {
00315 returnValue->value = (void *)
00316 (* (SYMBOL_HN *(*)(void *)) fptr->functionPointer)(theEnv);
00317 }
00318 else
00319 {
00320 returnValue->value = (void *)
00321 (* (SYMBOL_HN *(*)(void)) fptr->functionPointer)();
00322 }
00323 break;
00324 #endif
00325 case 'c' :
00326 {
00327 char cbuff[2];
00328 if (fptr->environmentAware)
00329 {
00330 cbuff[0] = (* (char (*)(void *)) fptr->functionPointer)(theEnv);
00331 }
00332 else
00333 {
00334 cbuff[0] = (* (char (*)(void)) fptr->functionPointer)();
00335 }
00336 cbuff[1] = EOS;
00337 returnValue->type = SYMBOL;
00338 returnValue->value = (void *) EnvAddSymbol(theEnv,cbuff);
00339 break;
00340 }
00341
00342 case 'j' :
00343 case 'k' :
00344 case 'm' :
00345 case 'n' :
00346 case 'u' :
00347 if (fptr->environmentAware)
00348 {
00349 (* (void (*)(void *,DATA_OBJECT_PTR)) fptr->functionPointer)(theEnv,returnValue);
00350 }
00351 else
00352 {
00353 (* (void (*)(DATA_OBJECT_PTR)) fptr->functionPointer)(returnValue);
00354 }
00355 break;
00356
00357 default :
00358 SystemError(theEnv,"EVALUATN",2);
00359 EnvExitRouter(theEnv,EXIT_FAILURE);
00360 break;
00361 }
00362
00363 #if PROFILING_FUNCTIONS
00364 EndProfile(theEnv,&profileFrame);
00365 #endif
00366
00367 SetEnvironmentFunctionContext(theEnv,oldContext);
00368 EvaluationData(theEnv)->CurrentExpression = oldArgument;
00369 break;
00370 }
00371
00372 case MULTIFIELD:
00373 returnValue->type = MULTIFIELD;
00374 returnValue->value = ((DATA_OBJECT_PTR) (problem->value))->value;
00375 returnValue->begin = ((DATA_OBJECT_PTR) (problem->value))->begin;
00376 returnValue->end = ((DATA_OBJECT_PTR) (problem->value))->end;
00377 break;
00378
00379 case MF_VARIABLE:
00380 case SF_VARIABLE:
00381 if (GetBoundVariable(theEnv,returnValue,(SYMBOL_HN *) problem->value) == FALSE)
00382 {
00383 PrintErrorID(theEnv,"EVALUATN",1,FALSE);
00384 EnvPrintRouter(theEnv,WERROR,"Variable ");
00385 EnvPrintRouter(theEnv,WERROR,ValueToString(problem->value));
00386 EnvPrintRouter(theEnv,WERROR," is unbound\n");
00387 returnValue->type = SYMBOL;
00388 returnValue->value = EnvFalseSymbol(theEnv);
00389 SetEvaluationError(theEnv,TRUE);
00390 }
00391 break;
00392
00393 default:
00394 if (EvaluationData(theEnv)->PrimitivesArray[problem->type] == NULL)
00395 {
00396 SystemError(theEnv,"EVALUATN",3);
00397 EnvExitRouter(theEnv,EXIT_FAILURE);
00398 }
00399
00400 if (EvaluationData(theEnv)->PrimitivesArray[problem->type]->copyToEvaluate)
00401 {
00402 returnValue->type = problem->type;
00403 returnValue->value = problem->value;
00404 break;
00405 }
00406
00407 if (EvaluationData(theEnv)->PrimitivesArray[problem->type]->evaluateFunction == NULL)
00408 {
00409 SystemError(theEnv,"EVALUATN",4);
00410 EnvExitRouter(theEnv,EXIT_FAILURE);
00411 }
00412
00413 oldArgument = EvaluationData(theEnv)->CurrentExpression;
00414 EvaluationData(theEnv)->CurrentExpression = problem;
00415
00416 #if PROFILING_FUNCTIONS
00417 StartProfile(theEnv,&profileFrame,
00418 &EvaluationData(theEnv)->PrimitivesArray[problem->type]->usrData,
00419 ProfileFunctionData(theEnv)->ProfileUserFunctions);
00420 #endif
00421
00422 (*EvaluationData(theEnv)->PrimitivesArray[problem->type]->evaluateFunction)(theEnv,problem->value,returnValue);
00423
00424 #if PROFILING_FUNCTIONS
00425 EndProfile(theEnv,&profileFrame);
00426 #endif
00427
00428 EvaluationData(theEnv)->CurrentExpression = oldArgument;
00429 break;
00430 }
00431
00432 PropagateReturnValue(theEnv,returnValue);
00433 return(EvaluationData(theEnv)->EvaluationError);
00434 }
00435
00436
00437
00438
00439
00440 globle void InstallPrimitive(
00441 void *theEnv,
00442 struct entityRecord *thePrimitive,
00443 int whichPosition)
00444 {
00445 if (EvaluationData(theEnv)->PrimitivesArray[whichPosition] != NULL)
00446 {
00447 SystemError(theEnv,"EVALUATN",5);
00448 EnvExitRouter(theEnv,EXIT_FAILURE);
00449 }
00450
00451 EvaluationData(theEnv)->PrimitivesArray[whichPosition] = thePrimitive;
00452 }
00453
00454
00455
00456
00457
00458 globle int InstallExternalAddressType(
00459 void *theEnv,
00460 struct externalAddressType *theAddressType)
00461 {
00462 struct externalAddressType *copyEAT;
00463
00464 int rv = EvaluationData(theEnv)->numberOfAddressTypes;
00465
00466 if (EvaluationData(theEnv)->numberOfAddressTypes == MAXIMUM_EXTERNAL_ADDRESS_TYPES)
00467 {
00468 SystemError(theEnv,"EVALUATN",6);
00469 EnvExitRouter(theEnv,EXIT_FAILURE);
00470 }
00471
00472 copyEAT = (struct externalAddressType *) genalloc(theEnv,sizeof(struct externalAddressType));
00473 memcpy(copyEAT,theAddressType,sizeof(struct externalAddressType));
00474 EvaluationData(theEnv)->ExternalAddressTypes[EvaluationData(theEnv)->numberOfAddressTypes++] = copyEAT;
00475
00476 return rv;
00477 }
00478
00479
00480
00481
00482 globle void SetEvaluationError(
00483 void *theEnv,
00484 int value)
00485 {
00486 EvaluationData(theEnv)->EvaluationError = value;
00487 if (value == TRUE)
00488 { EvaluationData(theEnv)->HaltExecution = TRUE; }
00489 }
00490
00491
00492
00493
00494 globle int GetEvaluationError(
00495 void *theEnv)
00496 {
00497 return(EvaluationData(theEnv)->EvaluationError);
00498 }
00499
00500
00501
00502
00503 globle void SetHaltExecution(
00504 void *theEnv,
00505 int value)
00506 {
00507 EvaluationData(theEnv)->HaltExecution = value;
00508 }
00509
00510
00511
00512
00513 globle int GetHaltExecution(
00514 void *theEnv)
00515 {
00516 return(EvaluationData(theEnv)->HaltExecution);
00517 }
00518
00519
00520
00521
00522
00523 globle void ReturnValues(
00524 void *theEnv,
00525 DATA_OBJECT_PTR garbagePtr,
00526 intBool decrementSupplementalInfo)
00527 {
00528 DATA_OBJECT_PTR nextPtr;
00529
00530 while (garbagePtr != NULL)
00531 {
00532 nextPtr = garbagePtr->next;
00533 ValueDeinstall(theEnv,garbagePtr);
00534 if ((garbagePtr->supplementalInfo != NULL) && decrementSupplementalInfo)
00535 { DecrementSymbolCount(theEnv,(struct symbolHashNode *) garbagePtr->supplementalInfo); }
00536 rtn_struct(theEnv,dataObject,garbagePtr);
00537 garbagePtr = nextPtr;
00538 }
00539 }
00540
00541
00542
00543
00544
00545 globle void PrintDataObject(
00546 void *theEnv,
00547 char *fileid,
00548 DATA_OBJECT_PTR argPtr)
00549 {
00550 switch(argPtr->type)
00551 {
00552 case RVOID:
00553 case SYMBOL:
00554 case STRING:
00555 case INTEGER:
00556 case FLOAT:
00557 case EXTERNAL_ADDRESS:
00558 case FACT_ADDRESS:
00559 #if OBJECT_SYSTEM
00560 case INSTANCE_NAME:
00561 case INSTANCE_ADDRESS:
00562 #endif
00563 PrintAtom(theEnv,fileid,argPtr->type,argPtr->value);
00564 break;
00565
00566 case MULTIFIELD:
00567 PrintMultifield(theEnv,fileid,(struct multifield *) argPtr->value,
00568 argPtr->begin,argPtr->end,TRUE);
00569 break;
00570
00571 default:
00572 if (EvaluationData(theEnv)->PrimitivesArray[argPtr->type] != NULL)
00573 {
00574 if (EvaluationData(theEnv)->PrimitivesArray[argPtr->type]->longPrintFunction)
00575 {
00576 (*EvaluationData(theEnv)->PrimitivesArray[argPtr->type]->longPrintFunction)(theEnv,fileid,argPtr->value);
00577 break;
00578 }
00579 else if (EvaluationData(theEnv)->PrimitivesArray[argPtr->type]->shortPrintFunction)
00580 {
00581 (*EvaluationData(theEnv)->PrimitivesArray[argPtr->type]->shortPrintFunction)(theEnv,fileid,argPtr->value);
00582 break;
00583 }
00584 }
00585
00586 EnvPrintRouter(theEnv,fileid,"<UnknownPrintType");
00587 PrintLongInteger(theEnv,fileid,(long int) argPtr->type);
00588 EnvPrintRouter(theEnv,fileid,">");
00589 SetHaltExecution(theEnv,TRUE);
00590 SetEvaluationError(theEnv,TRUE);
00591 break;
00592 }
00593 }
00594
00595
00596
00597
00598
00599 globle void EnvSetMultifieldErrorValue(
00600 void *theEnv,
00601 DATA_OBJECT_PTR returnValue)
00602 {
00603 returnValue->type = MULTIFIELD;
00604 returnValue->value = EnvCreateMultifield(theEnv,0L);
00605 returnValue->begin = 1;
00606 returnValue->end = 0;
00607 }
00608
00609
00610
00611
00612
00613 globle void ValueInstall(
00614 void *theEnv,
00615 DATA_OBJECT *vPtr)
00616 {
00617 if (vPtr->type == MULTIFIELD) MultifieldInstall(theEnv,(struct multifield *) vPtr->value);
00618 else AtomInstall(theEnv,vPtr->type,vPtr->value);
00619 }
00620
00621
00622
00623
00624
00625 globle void ValueDeinstall(
00626 void *theEnv,
00627 DATA_OBJECT *vPtr)
00628 {
00629 if (vPtr->type == MULTIFIELD) MultifieldDeinstall(theEnv,(struct multifield *) vPtr->value);
00630 else AtomDeinstall(theEnv,vPtr->type,vPtr->value);
00631 }
00632
00633
00634
00635
00636
00637 globle void AtomInstall(
00638 void *theEnv,
00639 int type,
00640 void *vPtr)
00641 {
00642 switch (type)
00643 {
00644 case SYMBOL:
00645 case STRING:
00646 #if DEFGLOBAL_CONSTRUCT
00647 case GBL_VARIABLE:
00648 #endif
00649 #if OBJECT_SYSTEM
00650 case INSTANCE_NAME:
00651 #endif
00652 IncrementSymbolCount(vPtr);
00653 break;
00654
00655 case FLOAT:
00656 IncrementFloatCount(vPtr);
00657 break;
00658
00659 case INTEGER:
00660 IncrementIntegerCount(vPtr);
00661 break;
00662
00663 case EXTERNAL_ADDRESS:
00664 IncrementExternalAddressCount(vPtr);
00665 break;
00666
00667 case MULTIFIELD:
00668 MultifieldInstall(theEnv,(struct multifield *) vPtr);
00669 break;
00670
00671 case RVOID:
00672 break;
00673
00674 default:
00675 if (EvaluationData(theEnv)->PrimitivesArray[type] == NULL) break;
00676 if (EvaluationData(theEnv)->PrimitivesArray[type]->bitMap) IncrementBitMapCount(vPtr);
00677 else if (EvaluationData(theEnv)->PrimitivesArray[type]->incrementBusyCount)
00678 { (*EvaluationData(theEnv)->PrimitivesArray[type]->incrementBusyCount)(theEnv,vPtr); }
00679 break;
00680 }
00681 }
00682
00683
00684
00685
00686
00687 globle void AtomDeinstall(
00688 void *theEnv,
00689 int type,
00690 void *vPtr)
00691 {
00692 switch (type)
00693 {
00694 case SYMBOL:
00695 case STRING:
00696 #if DEFGLOBAL_CONSTRUCT
00697 case GBL_VARIABLE:
00698 #endif
00699 #if OBJECT_SYSTEM
00700 case INSTANCE_NAME:
00701 #endif
00702 DecrementSymbolCount(theEnv,(SYMBOL_HN *) vPtr);
00703 break;
00704
00705 case FLOAT:
00706 DecrementFloatCount(theEnv,(FLOAT_HN *) vPtr);
00707 break;
00708
00709 case INTEGER:
00710 DecrementIntegerCount(theEnv,(INTEGER_HN *) vPtr);
00711 break;
00712
00713 case EXTERNAL_ADDRESS:
00714 DecrementExternalAddressCount(theEnv,(EXTERNAL_ADDRESS_HN *) vPtr);
00715 break;
00716
00717 case MULTIFIELD:
00718 MultifieldDeinstall(theEnv,(struct multifield *) vPtr);
00719 break;
00720
00721 case RVOID:
00722 break;
00723
00724 default:
00725 if (EvaluationData(theEnv)->PrimitivesArray[type] == NULL) break;
00726 if (EvaluationData(theEnv)->PrimitivesArray[type]->bitMap) DecrementBitMapCount(theEnv,(BITMAP_HN *) vPtr);
00727 else if (EvaluationData(theEnv)->PrimitivesArray[type]->decrementBusyCount)
00728 { (*EvaluationData(theEnv)->PrimitivesArray[type]->decrementBusyCount)(theEnv,vPtr); }
00729 }
00730 }
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741 globle void PropagateReturnValue(
00742 void *theEnv,
00743 DATA_OBJECT *vPtr)
00744 {
00745 long i;
00746 struct multifield *theSegment;
00747 struct field *theMultifield;
00748
00749 if (vPtr->type != MULTIFIELD)
00750 { PropagateReturnAtom(theEnv,vPtr->type,vPtr->value); }
00751 else
00752 {
00753 theSegment = (struct multifield *) vPtr->value;
00754
00755 if (theSegment->depth > EvaluationData(theEnv)->CurrentEvaluationDepth)
00756 theSegment->depth = (short) EvaluationData(theEnv)->CurrentEvaluationDepth;
00757
00758 theMultifield = theSegment->theFields;
00759
00760 for (i = 0; i < theSegment->multifieldLength; i++)
00761 { PropagateReturnAtom(theEnv,theMultifield[i].type,theMultifield[i].value); }
00762 }
00763 }
00764
00765
00766
00767
00768
00769 static void PropagateReturnAtom(
00770 void *theEnv,
00771 int type,
00772 void *value)
00773 {
00774 switch (type)
00775 {
00776 case INTEGER :
00777 case FLOAT :
00778 case SYMBOL :
00779 case STRING :
00780 case EXTERNAL_ADDRESS:
00781 #if OBJECT_SYSTEM
00782 case INSTANCE_NAME :
00783 #endif
00784 if (((SYMBOL_HN *) value)->depth > EvaluationData(theEnv)->CurrentEvaluationDepth)
00785 { ((SYMBOL_HN *) value)->depth = EvaluationData(theEnv)->CurrentEvaluationDepth; }
00786 break;
00787
00788 #if OBJECT_SYSTEM
00789 case INSTANCE_ADDRESS :
00790 if (((INSTANCE_TYPE *) value)->depth > EvaluationData(theEnv)->CurrentEvaluationDepth)
00791 { ((INSTANCE_TYPE *) value)->depth = EvaluationData(theEnv)->CurrentEvaluationDepth; }
00792 break;
00793 #endif
00794 case FACT_ADDRESS :
00795 if (((int) ((struct fact *) value)->depth) > EvaluationData(theEnv)->CurrentEvaluationDepth)
00796 { ((struct fact *) value)->depth = (unsigned) EvaluationData(theEnv)->CurrentEvaluationDepth; }
00797 break;
00798 }
00799 }
00800
00801 #if DEFFUNCTION_CONSTRUCT || DEFGENERIC_CONSTRUCT
00802
00803
00804
00805
00806
00807
00808 globle int EnvFunctionCall(
00809 void *theEnv,
00810 char *name,
00811 char *args,
00812 DATA_OBJECT *result)
00813 {
00814 FUNCTION_REFERENCE theReference;
00815
00816
00817
00818
00819
00820 if (GetFunctionReference(theEnv,name,&theReference))
00821 { return(FunctionCall2(theEnv,&theReference,args,result)); }
00822
00823
00824
00825
00826
00827
00828
00829 PrintErrorID(theEnv,"EVALUATN",2,FALSE);
00830 EnvPrintRouter(theEnv,WERROR,"No function, generic function or deffunction of name ");
00831 EnvPrintRouter(theEnv,WERROR,name);
00832 EnvPrintRouter(theEnv,WERROR," exists for external call.\n");
00833 return(TRUE);
00834 }
00835
00836
00837
00838
00839
00840
00841 globle int FunctionCall2(
00842 void *theEnv,
00843 FUNCTION_REFERENCE *theReference,
00844 char *args,
00845 DATA_OBJECT *result)
00846 {
00847 EXPRESSION *argexps;
00848 int error = FALSE;
00849
00850
00851
00852
00853
00854
00855 if ((EvaluationData(theEnv)->CurrentEvaluationDepth == 0) && (! CommandLineData(theEnv)->EvaluatingTopLevelCommand) &&
00856 (EvaluationData(theEnv)->CurrentExpression == NULL))
00857 { PeriodicCleanup(theEnv,TRUE,FALSE); }
00858
00859
00860
00861
00862
00863 if (EvaluationData(theEnv)->CurrentEvaluationDepth == 0) SetHaltExecution(theEnv,FALSE);
00864 EvaluationData(theEnv)->EvaluationError = FALSE;
00865
00866
00867
00868
00869
00870 result->type = SYMBOL;
00871 result->value = EnvFalseSymbol(theEnv);
00872
00873
00874
00875
00876
00877 argexps = ParseConstantArguments(theEnv,args,&error);
00878 if (error == TRUE) return(TRUE);
00879
00880
00881
00882
00883
00884 theReference->argList = argexps;
00885 error = EvaluateExpression(theEnv,theReference,result);
00886
00887
00888
00889
00890
00891 ReturnExpression(theEnv,argexps);
00892 theReference->argList = NULL;
00893
00894
00895
00896
00897
00898 return(error);
00899 }
00900
00901 #endif
00902
00903
00904
00905
00906
00907 globle void CopyDataObject(
00908 void *theEnv,
00909 DATA_OBJECT *dst,
00910 DATA_OBJECT *src,
00911 int garbageMultifield)
00912 {
00913 if (src->type != MULTIFIELD)
00914 {
00915 dst->type = src->type;
00916 dst->value = src->value;
00917 }
00918 else
00919 {
00920 DuplicateMultifield(theEnv,dst,src);
00921 if (garbageMultifield)
00922 { AddToMultifieldList(theEnv,(struct multifield *) dst->value); }
00923 }
00924 }
00925
00926
00927
00928
00929
00930
00931 globle void TransferDataObjectValues(
00932 DATA_OBJECT *dst,
00933 DATA_OBJECT *src)
00934 {
00935 dst->type = src->type;
00936 dst->value = src->value;
00937 dst->begin = src->begin;
00938 dst->end = src->end;
00939 dst->supplementalInfo = src->supplementalInfo;
00940 dst->next = src->next;
00941 }
00942
00943
00944
00945
00946
00947
00948
00949 globle struct expr *ConvertValueToExpression(
00950 void *theEnv,
00951 DATA_OBJECT *theValue)
00952 {
00953 long i;
00954 struct expr *head = NULL, *last = NULL, *newItem;
00955
00956 if (GetpType(theValue) != MULTIFIELD)
00957 { return(GenConstant(theEnv,GetpType(theValue),GetpValue(theValue))); }
00958
00959 for (i = GetpDOBegin(theValue); i <= GetpDOEnd(theValue); i++)
00960 {
00961 newItem = GenConstant(theEnv,GetMFType(GetpValue(theValue),i),
00962 GetMFValue(GetpValue(theValue),i));
00963 if (last == NULL) head = newItem;
00964 else last->nextArg = newItem;
00965 last = newItem;
00966 }
00967
00968 if (head == NULL)
00969 return(GenConstant(theEnv,FCALL,(void *) FindFunction(theEnv,"create$")));
00970
00971 return(head);
00972 }
00973
00974
00975
00976
00977
00978 unsigned long GetAtomicHashValue(
00979 unsigned short type,
00980 void *value,
00981 int position)
00982 {
00983 unsigned long tvalue;
00984 union
00985 {
00986 double fv;
00987 void *vv;
00988 unsigned long liv;
00989 } fis;
00990
00991 switch (type)
00992 {
00993 case FLOAT:
00994 fis.liv = 0;
00995 fis.fv = ValueToDouble(value);
00996 tvalue = fis.liv;
00997 break;
00998
00999 case INTEGER:
01000 tvalue = (unsigned long) ValueToLong(value);
01001 break;
01002
01003 case EXTERNAL_ADDRESS:
01004 fis.liv = 0;
01005 fis.vv = ValueToExternalAddress(value);
01006 tvalue = (unsigned long) fis.liv;
01007 break;
01008
01009 case FACT_ADDRESS:
01010 #if OBJECT_SYSTEM
01011 case INSTANCE_ADDRESS:
01012 #endif
01013 fis.liv = 0;
01014 fis.vv = value;
01015 tvalue = (unsigned long) fis.liv;
01016 break;
01017
01018 case STRING:
01019 #if OBJECT_SYSTEM
01020 case INSTANCE_NAME:
01021 #endif
01022 case SYMBOL:
01023 tvalue = ((SYMBOL_HN *) value)->bucket;
01024 break;
01025
01026 default:
01027 tvalue = type;
01028 }
01029
01030 if (position < 0) return(tvalue);
01031
01032 return((unsigned long) (tvalue * (((unsigned long) position) + 29)));
01033 }
01034
01035
01036
01037
01038
01039
01040
01041 globle struct expr *FunctionReferenceExpression(
01042 void *theEnv,
01043 char *name)
01044 {
01045 #if DEFGENERIC_CONSTRUCT
01046 void *gfunc;
01047 #endif
01048 #if DEFFUNCTION_CONSTRUCT
01049 void *dptr;
01050 #endif
01051 struct FunctionDefinition *fptr;
01052
01053
01054
01055
01056
01057 #if DEFFUNCTION_CONSTRUCT
01058 if ((dptr = (void *) LookupDeffunctionInScope(theEnv,name)) != NULL)
01059 { return(GenConstant(theEnv,PCALL,dptr)); }
01060 #endif
01061
01062
01063
01064
01065
01066 #if DEFGENERIC_CONSTRUCT
01067 if ((gfunc = (void *) LookupDefgenericInScope(theEnv,name)) != NULL)
01068 { return(GenConstant(theEnv,GCALL,gfunc)); }
01069 #endif
01070
01071
01072
01073
01074
01075
01076 if ((fptr = FindFunction(theEnv,name)) != NULL)
01077 { return(GenConstant(theEnv,FCALL,fptr)); }
01078
01079
01080
01081
01082
01083
01084 return(NULL);
01085 }
01086
01087
01088
01089
01090
01091
01092
01093 globle intBool GetFunctionReference(
01094 void *theEnv,
01095 char *name,
01096 FUNCTION_REFERENCE *theReference)
01097 {
01098 #if DEFGENERIC_CONSTRUCT
01099 void *gfunc;
01100 #endif
01101 #if DEFFUNCTION_CONSTRUCT
01102 void *dptr;
01103 #endif
01104 struct FunctionDefinition *fptr;
01105
01106 theReference->nextArg = NULL;
01107 theReference->argList = NULL;
01108 theReference->type = RVOID;
01109 theReference->value = NULL;
01110
01111
01112
01113
01114
01115 #if DEFFUNCTION_CONSTRUCT
01116 if ((dptr = (void *) LookupDeffunctionInScope(theEnv,name)) != NULL)
01117 {
01118 theReference->type = PCALL;
01119 theReference->value = dptr;
01120 return(TRUE);
01121 }
01122 #endif
01123
01124
01125
01126
01127
01128 #if DEFGENERIC_CONSTRUCT
01129 if ((gfunc = (void *) LookupDefgenericInScope(theEnv,name)) != NULL)
01130 {
01131 theReference->type = GCALL;
01132 theReference->value = gfunc;
01133 return(TRUE);
01134 }
01135 #endif
01136
01137
01138
01139
01140
01141
01142 if ((fptr = FindFunction(theEnv,name)) != NULL)
01143 {
01144 theReference->type = FCALL;
01145 theReference->value = fptr;
01146 return(TRUE);
01147 }
01148
01149
01150
01151
01152
01153
01154 return(FALSE);
01155 }
01156
01157
01158
01159
01160 globle intBool DOsEqual(
01161 DATA_OBJECT_PTR dobj1,
01162 DATA_OBJECT_PTR dobj2)
01163 {
01164 if (GetpType(dobj1) != GetpType(dobj2))
01165 { return(FALSE); }
01166
01167 if (GetpType(dobj1) == MULTIFIELD)
01168 {
01169 if (MultifieldDOsEqual(dobj1,dobj2) == FALSE)
01170 { return(FALSE); }
01171 }
01172 else if (GetpValue(dobj1) != GetpValue(dobj2))
01173 { return(FALSE); }
01174
01175 return(TRUE);
01176 }
01177
01178
01179
01180
01181
01182
01183
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193 globle int EvaluateAndStoreInDataObject(
01194 void *theEnv,
01195 int mfp,
01196 EXPRESSION *theExp,
01197 DATA_OBJECT *val,
01198 int garbageSegment)
01199 {
01200 val->type = MULTIFIELD;
01201 val->begin = 0;
01202 val->end = -1;
01203
01204 if (theExp == NULL)
01205 {
01206 if (garbageSegment) val->value = EnvCreateMultifield(theEnv,0L);
01207 else val->value = CreateMultifield2(theEnv,0L);
01208
01209 return(TRUE);
01210 }
01211
01212 if ((mfp == 0) && (theExp->nextArg == NULL))
01213 EvaluateExpression(theEnv,theExp,val);
01214 else
01215 StoreInMultifield(theEnv,val,theExp,garbageSegment);
01216
01217 return(EvaluationData(theEnv)->EvaluationError ? FALSE : TRUE);
01218 }
01219
01220
01221
01222
01223 static void PrintCAddress(
01224 void *theEnv,
01225 char *logicalName,
01226 void *theValue)
01227 {
01228 char buffer[20];
01229
01230 EnvPrintRouter(theEnv,logicalName,"<Pointer-C-");
01231
01232 gensprintf(buffer,"%p",ValueToExternalAddress(theValue));
01233 EnvPrintRouter(theEnv,logicalName,buffer);
01234 EnvPrintRouter(theEnv,logicalName,">");
01235 }
01236
01237
01238
01239
01240 static void NewCAddress(
01241 void *theEnv,
01242 DATA_OBJECT *rv)
01243 {
01244 int numberOfArguments;
01245
01246 numberOfArguments = EnvRtnArgCount(theEnv);
01247
01248 if (numberOfArguments != 1)
01249 {
01250 PrintErrorID(theEnv,"NEW",1,FALSE);
01251 EnvPrintRouter(theEnv,WERROR,"Function new expected no additional arguments for the C external language type.\n");
01252 SetEvaluationError(theEnv,TRUE);
01253 return;
01254 }
01255
01256 SetpType(rv,EXTERNAL_ADDRESS);
01257 SetpValue(rv,EnvAddExternalAddress(theEnv,NULL,0));
01258 }
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268
01269
01270
01271
01272
01273