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 #include "setup.h"
00038
00039 #ifndef _STDIO_INCLUDED_
00040 #include <stdio.h>
00041 #define _STDIO_INCLUDED_
00042 #endif
00043
00044 #include <stdlib.h>
00045 #include <ctype.h>
00046
00047 #include "memalloc.h"
00048 #include "constant.h"
00049 #include "envrnmnt.h"
00050 #if DEFGLOBAL_CONSTRUCT
00051 #include "globlpsr.h"
00052 #endif
00053 #include "exprnpsr.h"
00054 #include "multifld.h"
00055 #if OBJECT_SYSTEM
00056 #include "object.h"
00057 #endif
00058 #include "prcdrpsr.h"
00059 #include "router.h"
00060 #include "utility.h"
00061
00062 #define _PRCCODE_SOURCE_
00063 #include "prccode.h"
00064
00065
00066
00067
00068
00069
00070 typedef struct
00071 {
00072 unsigned firstFlag : 1;
00073 unsigned first : 15;
00074 unsigned secondFlag : 1;
00075 unsigned second : 15;
00076 } PACKED_PROC_VAR;
00077
00078
00079
00080
00081
00082
00083
00084 static void EvaluateProcParameters(void *,EXPRESSION *,int,char *,char *);
00085 static intBool RtnProcParam(void *,void *,DATA_OBJECT *);
00086 static intBool GetProcBind(void *,void *,DATA_OBJECT *);
00087 static intBool PutProcBind(void *,void *,DATA_OBJECT *);
00088 static intBool RtnProcWild(void *,void *,DATA_OBJECT *);
00089 static void DeallocateProceduralPrimitiveData(void *);
00090 static void ReleaseProcParameters(void *);
00091
00092 #if (! BLOAD_ONLY) && (! RUN_TIME)
00093 static int FindProcParameter(SYMBOL_HN *,EXPRESSION *,SYMBOL_HN *);
00094 static int ReplaceProcBinds(void *,EXPRESSION *,
00095 int (*)(void *,EXPRESSION *,void *),void *);
00096 static EXPRESSION *CompactActions(void *,EXPRESSION *);
00097 #endif
00098
00099 #if (! DEFFUNCTION_CONSTRUCT) || (! DEFGENERIC_CONSTRUCT)
00100 static intBool EvaluateBadCall(void *,void *,DATA_OBJECT *);
00101 #endif
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121 globle void InstallProcedurePrimitives(
00122 void *theEnv)
00123 {
00124 ENTITY_RECORD procParameterInfo = { "PROC_PARAM", PROC_PARAM,0,1,0,NULL,NULL,NULL,
00125 RtnProcParam,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL },
00126 procWildInfo = { "PROC_WILD_PARAM", PROC_WILD_PARAM,0,1,0,NULL,NULL,NULL,
00127 RtnProcWild,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL },
00128 procGetInfo = { "PROC_GET_BIND", PROC_GET_BIND,0,1,0,NULL,NULL,NULL,
00129 GetProcBind,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL },
00130 procBindInfo = { "PROC_BIND", PROC_BIND,0,1,0,NULL,NULL,NULL,
00131 PutProcBind,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
00132 #if ! DEFFUNCTION_CONSTRUCT
00133 ENTITY_RECORD deffunctionEntityRecord =
00134 { "PCALL", PCALL,0,0,1,
00135 NULL,NULL,NULL,
00136 EvaluateBadCall,
00137 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
00138 #endif
00139 #if ! DEFGENERIC_CONSTRUCT
00140 ENTITY_RECORD genericEntityRecord =
00141 { "GCALL", GCALL,0,0,1,
00142 NULL,NULL,NULL,
00143 EvaluateBadCall,
00144 NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL };
00145 #endif
00146
00147 AllocateEnvironmentData(theEnv,PROCEDURAL_PRIMITIVE_DATA,sizeof(struct proceduralPrimitiveData),DeallocateProceduralPrimitiveData);
00148
00149 memcpy(&ProceduralPrimitiveData(theEnv)->ProcParameterInfo,&procParameterInfo,sizeof(struct entityRecord));
00150 memcpy(&ProceduralPrimitiveData(theEnv)->ProcWildInfo,&procWildInfo,sizeof(struct entityRecord));
00151 memcpy(&ProceduralPrimitiveData(theEnv)->ProcGetInfo,&procGetInfo,sizeof(struct entityRecord));
00152 memcpy(&ProceduralPrimitiveData(theEnv)->ProcBindInfo,&procBindInfo,sizeof(struct entityRecord));
00153
00154 InstallPrimitive(theEnv,&ProceduralPrimitiveData(theEnv)->ProcParameterInfo,PROC_PARAM);
00155 InstallPrimitive(theEnv,&ProceduralPrimitiveData(theEnv)->ProcWildInfo,PROC_WILD_PARAM);
00156 InstallPrimitive(theEnv,&ProceduralPrimitiveData(theEnv)->ProcGetInfo,PROC_GET_BIND);
00157 InstallPrimitive(theEnv,&ProceduralPrimitiveData(theEnv)->ProcBindInfo,PROC_BIND);
00158
00159 ProceduralPrimitiveData(theEnv)->Oldindex = -1;
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169 #if ! DEFFUNCTION_CONSTRUCT
00170 memcpy(&ProceduralPrimitiveData(theEnv)->DeffunctionEntityRecord,&deffunctionEntityRecord,sizeof(struct entityRecord));
00171 InstallPrimitive(theEnv,&ProceduralPrimitiveData(theEnv)->DeffunctionEntityRecord,PCALL);
00172 #endif
00173
00174 #if ! DEFGENERIC_CONSTRUCT
00175 memcpy(&ProceduralPrimitiveData(theEnv)->GenericEntityRecord,&genericEntityRecord,sizeof(struct entityRecord));
00176 InstallPrimitive(theEnv,&ProceduralPrimitiveData(theEnv)->GenericEntityRecord,GCALL);
00177 #endif
00178
00179
00180
00181
00182
00183
00184 ProceduralPrimitiveData(theEnv)->NoParamValue = CreateMultifield2(theEnv,0L);
00185 MultifieldInstall(theEnv,(MULTIFIELD_PTR) ProceduralPrimitiveData(theEnv)->NoParamValue);
00186 }
00187
00188
00189
00190
00191
00192 static void DeallocateProceduralPrimitiveData(
00193 void *theEnv)
00194 {
00195 ReturnMultifield(theEnv,(struct multifield *) ProceduralPrimitiveData(theEnv)->NoParamValue);
00196 ReleaseProcParameters(theEnv);
00197 }
00198
00199 #if (! BLOAD_ONLY) && (! RUN_TIME)
00200
00201 #if DEFFUNCTION_CONSTRUCT || OBJECT_SYSTEM
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227 globle EXPRESSION *ParseProcParameters(
00228 void *theEnv,
00229 char *readSource,
00230 struct token *tkn,
00231 EXPRESSION *parameterList,
00232 SYMBOL_HN **wildcard,
00233 int *min,
00234 int *max,
00235 int *error,
00236 int (*checkfunc)(void *,char *))
00237 {
00238 EXPRESSION *nextOne,*lastOne,*check;
00239 int paramprintp = 0;
00240
00241 *wildcard = NULL;
00242 *min = 0;
00243 *error = TRUE;
00244 lastOne = nextOne = parameterList;
00245 while (nextOne != NULL)
00246 {
00247 (*min)++;
00248 lastOne = nextOne;
00249 nextOne = nextOne->nextArg;
00250 }
00251 if (tkn->type != LPAREN)
00252 {
00253 SyntaxErrorMessage(theEnv,"parameter list");
00254 ReturnExpression(theEnv,parameterList);
00255 return(NULL);
00256 }
00257 GetToken(theEnv,readSource,tkn);
00258 while ((tkn->type == SF_VARIABLE) || (tkn->type == MF_VARIABLE))
00259 {
00260 for (check = parameterList ; check != NULL ; check = check->nextArg)
00261 if (check->value == tkn->value)
00262 {
00263 PrintErrorID(theEnv,"PRCCODE",7,FALSE);
00264 EnvPrintRouter(theEnv,WERROR,"Duplicate parameter names not allowed.\n");
00265 ReturnExpression(theEnv,parameterList);
00266 return(NULL);
00267 }
00268 if (*wildcard != NULL)
00269 {
00270 PrintErrorID(theEnv,"PRCCODE",8,FALSE);
00271 EnvPrintRouter(theEnv,WERROR,"No parameters allowed after wildcard parameter.\n");
00272 ReturnExpression(theEnv,parameterList);
00273 return(NULL);
00274 }
00275 if ((checkfunc != NULL) ? (*checkfunc)(theEnv,ValueToString(tkn->value)) : FALSE)
00276 {
00277 ReturnExpression(theEnv,parameterList);
00278 return(NULL);
00279 }
00280 nextOne = GenConstant(theEnv,tkn->type,tkn->value);
00281 if (tkn->type == MF_VARIABLE)
00282 *wildcard = (SYMBOL_HN *) tkn->value;
00283 else
00284 (*min)++;
00285 if (lastOne == NULL)
00286 { parameterList = nextOne; }
00287 else
00288 { lastOne->nextArg = nextOne; }
00289 lastOne = nextOne;
00290 SavePPBuffer(theEnv," ");
00291 paramprintp = 1;
00292 GetToken(theEnv,readSource,tkn);
00293 }
00294 if (tkn->type != RPAREN)
00295 {
00296 SyntaxErrorMessage(theEnv,"parameter list");
00297 ReturnExpression(theEnv,parameterList);
00298 return(NULL);
00299 }
00300 if (paramprintp)
00301 {
00302 PPBackup(theEnv);
00303 PPBackup(theEnv);
00304 SavePPBuffer(theEnv,")");
00305 }
00306 *error = FALSE;
00307 *max = (*wildcard != NULL) ? -1 : *min;
00308 return(parameterList);
00309 }
00310
00311 #endif
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353 globle EXPRESSION *ParseProcActions(
00354 void *theEnv,
00355 char *bodytype,
00356 char *readSource,
00357 struct token *tkn,
00358 EXPRESSION *params,
00359 SYMBOL_HN *wildcard,
00360 int (*altvarfunc)(void *,EXPRESSION *,void *),
00361 int (*altbindfunc)(void *,EXPRESSION *,void *),
00362 int *lvarcnt,
00363 void *userBuffer)
00364 {
00365 EXPRESSION *actions,*pactions;
00366
00367
00368
00369
00370
00371
00372
00373 ClearParsedBindNames(theEnv);
00374 actions = GroupActions(theEnv,readSource,tkn,TRUE,NULL,FALSE);
00375 if (actions == NULL)
00376 return(NULL);
00377
00378
00379
00380
00381
00382
00383
00384 if (altbindfunc != NULL)
00385 {
00386 if (ReplaceProcBinds(theEnv,actions,altbindfunc,userBuffer))
00387 {
00388 ClearParsedBindNames(theEnv);
00389 ReturnExpression(theEnv,actions);
00390 return(NULL);
00391 }
00392 }
00393
00394
00395
00396
00397
00398
00399
00400
00401 *lvarcnt = CountParsedBindNames(theEnv);
00402 if (ReplaceProcVars(theEnv,bodytype,actions,params,wildcard,altvarfunc,userBuffer))
00403 {
00404 ClearParsedBindNames(theEnv);
00405 ReturnExpression(theEnv,actions);
00406 return(NULL);
00407 }
00408
00409
00410
00411
00412
00413
00414
00415 actions = CompactActions(theEnv,actions);
00416 pactions = PackExpression(theEnv,actions);
00417 ReturnExpression(theEnv,actions);
00418 ClearParsedBindNames(theEnv);
00419 return(pactions);
00420 }
00421
00422
00423
00424
00425
00426
00427
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457 globle int ReplaceProcVars(
00458 void *theEnv,
00459 char *bodytype,
00460 EXPRESSION *actions,
00461 EXPRESSION *parameterList,
00462 SYMBOL_HN *wildcard,
00463 int (*altvarfunc)(void *,EXPRESSION *,void *),
00464 void *specdata)
00465 {
00466 int position,altcode;
00467 intBool boundPosn;
00468 EXPRESSION *arg_lvl,*altvarexp;
00469 SYMBOL_HN *bindName;
00470 PACKED_PROC_VAR pvar;
00471
00472 while (actions != NULL)
00473 {
00474 if (actions->type == SF_VARIABLE)
00475 {
00476
00477
00478
00479 bindName = (SYMBOL_HN *) actions->value;
00480 position = FindProcParameter(bindName,parameterList,wildcard);
00481
00482
00483
00484
00485 boundPosn = SearchParsedBindNames(theEnv,bindName);
00486
00487
00488
00489
00490
00491
00492 if ((position == 0) && (boundPosn == 0))
00493 {
00494
00495
00496
00497
00498 if ((altvarfunc != NULL) ? ((*altvarfunc)(theEnv,actions,specdata) != 1) : TRUE)
00499 {
00500 PrintErrorID(theEnv,"PRCCODE",3,TRUE);
00501 EnvPrintRouter(theEnv,WERROR,"Undefined variable ");
00502 EnvPrintRouter(theEnv,WERROR,ValueToString(bindName));
00503 EnvPrintRouter(theEnv,WERROR," referenced in ");
00504 EnvPrintRouter(theEnv,WERROR,bodytype);
00505 EnvPrintRouter(theEnv,WERROR,".\n");
00506 return(TRUE);
00507 }
00508 }
00509
00510
00511
00512
00513
00514
00515 else if ((position > 0) && (boundPosn == 0))
00516 {
00517 actions->type = (unsigned short) ((bindName != wildcard) ? PROC_PARAM : PROC_WILD_PARAM);
00518 actions->value = EnvAddBitMap(theEnv,(void *) &position,(int) sizeof(int));
00519 }
00520
00521
00522
00523
00524
00525 else
00526 {
00527 if (altvarfunc != NULL)
00528 {
00529 altvarexp = GenConstant(theEnv,actions->type,actions->value);
00530 altcode = (*altvarfunc)(theEnv,altvarexp,specdata);
00531 if (altcode == 0)
00532 {
00533 rtn_struct(theEnv,expr,altvarexp);
00534 altvarexp = NULL;
00535 }
00536 else if (altcode == -1)
00537 {
00538 rtn_struct(theEnv,expr,altvarexp);
00539 return(TRUE);
00540 }
00541 }
00542 else
00543 altvarexp = NULL;
00544 actions->type = PROC_GET_BIND;
00545 ClearBitString((void *) &pvar,(int) sizeof(PACKED_PROC_VAR));
00546 pvar.first = boundPosn;
00547 pvar.second = position;
00548 pvar.secondFlag = (bindName != wildcard) ? 0 : 1;
00549 actions->value = EnvAddBitMap(theEnv,(void *) &pvar,(int) sizeof(PACKED_PROC_VAR));
00550 actions->argList = GenConstant(theEnv,SYMBOL,(void *) bindName);
00551 actions->argList->nextArg = altvarexp;
00552 }
00553 }
00554 #if DEFGLOBAL_CONSTRUCT
00555 else if (actions->type == GBL_VARIABLE)
00556 {
00557 if (ReplaceGlobalVariable(theEnv,actions) == FALSE)
00558 return(-1);
00559 }
00560 #endif
00561 if ((altvarfunc != NULL) ? ((*altvarfunc)(theEnv,actions,specdata) == -1) : FALSE)
00562 return(TRUE);
00563 if (actions->argList != NULL)
00564 {
00565 if (ReplaceProcVars(theEnv,bodytype,actions->argList,parameterList,
00566 wildcard,altvarfunc,specdata))
00567 return(TRUE);
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577 if ((actions->value == (void *) FindFunction(theEnv,"bind")) &&
00578 (actions->argList->type == SYMBOL))
00579 {
00580 actions->type = PROC_BIND;
00581 boundPosn = SearchParsedBindNames(theEnv,(SYMBOL_HN *) actions->argList->value);
00582 actions->value = EnvAddBitMap(theEnv,(void *) &boundPosn,(int) sizeof(intBool));
00583 arg_lvl = actions->argList->nextArg;
00584 rtn_struct(theEnv,expr,actions->argList);
00585 actions->argList = arg_lvl;
00586 }
00587 }
00588 actions = actions->nextArg;
00589 }
00590 return(FALSE);
00591 }
00592
00593 #if DEFGENERIC_CONSTRUCT
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605 globle EXPRESSION *GenProcWildcardReference(
00606 void *theEnv,
00607 int theIndex)
00608 {
00609 return(GenConstant(theEnv,PROC_WILD_PARAM,EnvAddBitMap(theEnv,(void *) &theIndex,(int) sizeof(int))));
00610 }
00611
00612 #endif
00613
00614 #endif
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632
00633
00634
00635
00636
00637
00638
00639
00640
00641
00642
00643
00644 globle void PushProcParameters(
00645 void *theEnv,
00646 EXPRESSION *parameterList,
00647 int numberOfParameters,
00648 char *pname,
00649 char *bodytype,
00650 void (*UnboundErrFunc)(void *))
00651 {
00652 register PROC_PARAM_STACK *ptmp;
00653
00654 ptmp = get_struct(theEnv,ProcParamStack);
00655 ptmp->ParamArray = ProceduralPrimitiveData(theEnv)->ProcParamArray;
00656 ptmp->ParamArraySize = ProceduralPrimitiveData(theEnv)->ProcParamArraySize;
00657 ptmp->UnboundErrFunc = ProceduralPrimitiveData(theEnv)->ProcUnboundErrFunc;
00658 ptmp->nxt = ProceduralPrimitiveData(theEnv)->pstack;
00659 ProceduralPrimitiveData(theEnv)->pstack = ptmp;
00660 EvaluateProcParameters(theEnv,parameterList,numberOfParameters,pname,bodytype);
00661 if (EvaluationData(theEnv)->EvaluationError)
00662 {
00663 ptmp = ProceduralPrimitiveData(theEnv)->pstack;
00664 ProceduralPrimitiveData(theEnv)->pstack = ProceduralPrimitiveData(theEnv)->pstack->nxt;
00665 rtn_struct(theEnv,ProcParamStack,ptmp);
00666 return;
00667 }
00668
00669
00670
00671
00672
00673
00674
00675 #if DEFGENERIC_CONSTRUCT
00676 ptmp->ParamExpressions = ProceduralPrimitiveData(theEnv)->ProcParamExpressions;
00677 ProceduralPrimitiveData(theEnv)->ProcParamExpressions = NULL;
00678 #endif
00679 ptmp->WildcardValue = ProceduralPrimitiveData(theEnv)->WildcardValue;
00680 ProceduralPrimitiveData(theEnv)->WildcardValue = NULL;
00681 ProceduralPrimitiveData(theEnv)->ProcUnboundErrFunc = UnboundErrFunc;
00682 }
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692 globle void PopProcParameters(
00693 void *theEnv)
00694 {
00695 register PROC_PARAM_STACK *ptmp;
00696
00697 if (ProceduralPrimitiveData(theEnv)->ProcParamArray != NULL)
00698 rm(theEnv,(void *) ProceduralPrimitiveData(theEnv)->ProcParamArray,(sizeof(DATA_OBJECT) * ProceduralPrimitiveData(theEnv)->ProcParamArraySize));
00699
00700 #if DEFGENERIC_CONSTRUCT
00701 if (ProceduralPrimitiveData(theEnv)->ProcParamExpressions != NULL)
00702 rm(theEnv,(void *) ProceduralPrimitiveData(theEnv)->ProcParamExpressions,(sizeof(EXPRESSION) * ProceduralPrimitiveData(theEnv)->ProcParamArraySize));
00703 #endif
00704
00705 ptmp = ProceduralPrimitiveData(theEnv)->pstack;
00706 ProceduralPrimitiveData(theEnv)->pstack = ProceduralPrimitiveData(theEnv)->pstack->nxt;
00707 ProceduralPrimitiveData(theEnv)->ProcParamArray = ptmp->ParamArray;
00708 ProceduralPrimitiveData(theEnv)->ProcParamArraySize = ptmp->ParamArraySize;
00709
00710 #if DEFGENERIC_CONSTRUCT
00711 ProceduralPrimitiveData(theEnv)->ProcParamExpressions = ptmp->ParamExpressions;
00712 #endif
00713
00714 if (ProceduralPrimitiveData(theEnv)->WildcardValue != NULL)
00715 {
00716 MultifieldDeinstall(theEnv,(MULTIFIELD_PTR) ProceduralPrimitiveData(theEnv)->WildcardValue->value);
00717 if (ProceduralPrimitiveData(theEnv)->WildcardValue->value != ProceduralPrimitiveData(theEnv)->NoParamValue)
00718 AddToMultifieldList(theEnv,(MULTIFIELD_PTR) ProceduralPrimitiveData(theEnv)->WildcardValue->value);
00719 rtn_struct(theEnv,dataObject,ProceduralPrimitiveData(theEnv)->WildcardValue);
00720 }
00721 ProceduralPrimitiveData(theEnv)->WildcardValue = ptmp->WildcardValue;
00722 ProceduralPrimitiveData(theEnv)->ProcUnboundErrFunc = ptmp->UnboundErrFunc;
00723 rtn_struct(theEnv,ProcParamStack,ptmp);
00724 }
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734 static void ReleaseProcParameters(
00735 void *theEnv)
00736 {
00737 register PROC_PARAM_STACK *ptmp, *next;
00738
00739 if (ProceduralPrimitiveData(theEnv)->ProcParamArray != NULL)
00740 rm(theEnv,(void *) ProceduralPrimitiveData(theEnv)->ProcParamArray,(sizeof(DATA_OBJECT) * ProceduralPrimitiveData(theEnv)->ProcParamArraySize));
00741
00742
00743 if (ProceduralPrimitiveData(theEnv)->WildcardValue != NULL)
00744 {
00745 if (ProceduralPrimitiveData(theEnv)->WildcardValue->value != ProceduralPrimitiveData(theEnv)->NoParamValue)
00746 { ReturnMultifield(theEnv,(struct multifield *) ProceduralPrimitiveData(theEnv)->WildcardValue->value); }
00747
00748 rtn_struct(theEnv,dataObject,ProceduralPrimitiveData(theEnv)->WildcardValue);
00749 }
00750
00751 #if DEFGENERIC_CONSTRUCT
00752 if (ProceduralPrimitiveData(theEnv)->ProcParamExpressions != NULL)
00753 rm(theEnv,(void *) ProceduralPrimitiveData(theEnv)->ProcParamExpressions,(sizeof(EXPRESSION) * ProceduralPrimitiveData(theEnv)->ProcParamArraySize));
00754 #endif
00755
00756 ptmp = ProceduralPrimitiveData(theEnv)->pstack;
00757
00758 while (ptmp != NULL)
00759 {
00760 next = ptmp->nxt;
00761
00762 if (ptmp->ParamArray != NULL)
00763 { rm(theEnv,(void *) ptmp->ParamArray,(sizeof(DATA_OBJECT) * ptmp->ParamArraySize)); }
00764
00765 #if DEFGENERIC_CONSTRUCT
00766 if (ptmp->ParamExpressions != NULL)
00767 { rm(theEnv,(void *) ptmp->ParamExpressions,(sizeof(EXPRESSION) * ptmp->ParamArraySize)); }
00768 #endif
00769
00770 if (ptmp->WildcardValue != NULL)
00771 {
00772 if (ptmp->WildcardValue->value != ProceduralPrimitiveData(theEnv)->NoParamValue)
00773 { ReturnMultifield(theEnv,(struct multifield *) ptmp->WildcardValue->value); }
00774
00775 rtn_struct(theEnv,dataObject,ptmp->WildcardValue);
00776 }
00777
00778 rtn_struct(theEnv,ProcParamStack,ptmp);
00779 ptmp = next;
00780 }
00781 }
00782
00783 #if DEFGENERIC_CONSTRUCT
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797 globle EXPRESSION *GetProcParamExpressions(
00798 void *theEnv)
00799 {
00800 register int i;
00801
00802 if ((ProceduralPrimitiveData(theEnv)->ProcParamArray == NULL) || (ProceduralPrimitiveData(theEnv)->ProcParamExpressions != NULL))
00803 return(ProceduralPrimitiveData(theEnv)->ProcParamExpressions);
00804 ProceduralPrimitiveData(theEnv)->ProcParamExpressions = (EXPRESSION *)
00805 gm2(theEnv,(sizeof(EXPRESSION) * ProceduralPrimitiveData(theEnv)->ProcParamArraySize));
00806 for (i = 0 ; i < ProceduralPrimitiveData(theEnv)->ProcParamArraySize ; i++)
00807 {
00808 ProceduralPrimitiveData(theEnv)->ProcParamExpressions[i].type = ProceduralPrimitiveData(theEnv)->ProcParamArray[i].type;
00809 if (ProceduralPrimitiveData(theEnv)->ProcParamArray[i].type != MULTIFIELD)
00810 ProceduralPrimitiveData(theEnv)->ProcParamExpressions[i].value = ProceduralPrimitiveData(theEnv)->ProcParamArray[i].value;
00811 else
00812 ProceduralPrimitiveData(theEnv)->ProcParamExpressions[i].value = (void *) &ProceduralPrimitiveData(theEnv)->ProcParamArray[i];
00813 ProceduralPrimitiveData(theEnv)->ProcParamExpressions[i].argList = NULL;
00814 ProceduralPrimitiveData(theEnv)->ProcParamExpressions[i].nextArg =
00815 ((i + 1) != ProceduralPrimitiveData(theEnv)->ProcParamArraySize) ? &ProceduralPrimitiveData(theEnv)->ProcParamExpressions[i+1] : NULL;
00816 }
00817 return(ProceduralPrimitiveData(theEnv)->ProcParamExpressions);
00818 }
00819
00820 #endif
00821
00822
00823
00824
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834
00835
00836
00837
00838
00839
00840
00841 globle void EvaluateProcActions(
00842 void *theEnv,
00843 struct defmodule *theModule,
00844 EXPRESSION *actions,
00845 int lvarcnt,
00846 DATA_OBJECT *result,
00847 void (*crtproc)(void *))
00848 {
00849 DATA_OBJECT *oldLocalVarArray;
00850 register int i;
00851 struct defmodule *oldModule;
00852 EXPRESSION *oldActions;
00853 struct trackedMemory *theTM;
00854
00855 oldLocalVarArray = ProceduralPrimitiveData(theEnv)->LocalVarArray;
00856 ProceduralPrimitiveData(theEnv)->LocalVarArray = (lvarcnt == 0) ? NULL :
00857 (DATA_OBJECT *) gm2(theEnv,(sizeof(DATA_OBJECT) * lvarcnt));
00858
00859 if (lvarcnt != 0)
00860 { theTM = AddTrackedMemory(theEnv,ProceduralPrimitiveData(theEnv)->LocalVarArray,sizeof(DATA_OBJECT) * lvarcnt); }
00861 else
00862 { theTM = NULL; }
00863
00864 for (i = 0 ; i < lvarcnt ; i++)
00865 ProceduralPrimitiveData(theEnv)->LocalVarArray[i].supplementalInfo = EnvFalseSymbol(theEnv);
00866
00867 oldModule = ((struct defmodule *) EnvGetCurrentModule(theEnv));
00868 if (oldModule != theModule)
00869 EnvSetCurrentModule(theEnv,(void *) theModule);
00870 oldActions = ProceduralPrimitiveData(theEnv)->CurrentProcActions;
00871 ProceduralPrimitiveData(theEnv)->CurrentProcActions = actions;
00872
00873 if (EvaluateExpression(theEnv,actions,result))
00874 {
00875 result->type = SYMBOL;
00876 result->value = EnvFalseSymbol(theEnv);
00877 }
00878
00879 ProceduralPrimitiveData(theEnv)->CurrentProcActions = oldActions;
00880 if (oldModule != ((struct defmodule *) EnvGetCurrentModule(theEnv)))
00881 EnvSetCurrentModule(theEnv,(void *) oldModule);
00882 if ((crtproc != NULL) ? EvaluationData(theEnv)->HaltExecution : FALSE)
00883 {
00884 PrintErrorID(theEnv,"PRCCODE",4,FALSE);
00885 EnvPrintRouter(theEnv,WERROR,"Execution halted during the actions of ");
00886 (*crtproc)(theEnv);
00887 }
00888 if ((ProceduralPrimitiveData(theEnv)->WildcardValue != NULL) ? (result->value == ProceduralPrimitiveData(theEnv)->WildcardValue->value) : FALSE)
00889 {
00890 MultifieldDeinstall(theEnv,(MULTIFIELD_PTR) ProceduralPrimitiveData(theEnv)->WildcardValue->value);
00891 if (ProceduralPrimitiveData(theEnv)->WildcardValue->value != ProceduralPrimitiveData(theEnv)->NoParamValue)
00892 AddToMultifieldList(theEnv,(MULTIFIELD_PTR) ProceduralPrimitiveData(theEnv)->WildcardValue->value);
00893 rtn_struct(theEnv,dataObject,ProceduralPrimitiveData(theEnv)->WildcardValue);
00894 ProceduralPrimitiveData(theEnv)->WildcardValue = NULL;
00895 }
00896
00897 if (lvarcnt != 0)
00898 {
00899 RemoveTrackedMemory(theEnv,theTM);
00900 for (i = 0 ; i < lvarcnt ; i++)
00901 if (ProceduralPrimitiveData(theEnv)->LocalVarArray[i].supplementalInfo == EnvTrueSymbol(theEnv))
00902 ValueDeinstall(theEnv,&ProceduralPrimitiveData(theEnv)->LocalVarArray[i]);
00903 rm(theEnv,(void *) ProceduralPrimitiveData(theEnv)->LocalVarArray,(sizeof(DATA_OBJECT) * lvarcnt));
00904 }
00905
00906 ProceduralPrimitiveData(theEnv)->LocalVarArray = oldLocalVarArray;
00907 }
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918 globle void PrintProcParamArray(
00919 void *theEnv,
00920 char *logName)
00921 {
00922 register int i;
00923
00924 EnvPrintRouter(theEnv,logName," (");
00925 for (i = 0 ; i < ProceduralPrimitiveData(theEnv)->ProcParamArraySize ; i++)
00926 {
00927 PrintDataObject(theEnv,logName,&ProceduralPrimitiveData(theEnv)->ProcParamArray[i]);
00928 if (i != ProceduralPrimitiveData(theEnv)->ProcParamArraySize-1)
00929 EnvPrintRouter(theEnv,logName," ");
00930 }
00931 EnvPrintRouter(theEnv,logName,")\n");
00932 }
00933
00934
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947 globle void GrabProcWildargs(
00948 void *theEnv,
00949 DATA_OBJECT *result,
00950 int theIndex)
00951 {
00952 register int i,j;
00953 long k;
00954 long size;
00955 DATA_OBJECT *val;
00956
00957 result->type = MULTIFIELD;
00958 result->begin = 0;
00959 if (ProceduralPrimitiveData(theEnv)->WildcardValue == NULL)
00960 {
00961 ProceduralPrimitiveData(theEnv)->WildcardValue = get_struct(theEnv,dataObject);
00962 ProceduralPrimitiveData(theEnv)->WildcardValue->begin = 0;
00963 }
00964 else if (theIndex == ProceduralPrimitiveData(theEnv)->Oldindex)
00965 {
00966 result->end = ProceduralPrimitiveData(theEnv)->WildcardValue->end;
00967 result->value = ProceduralPrimitiveData(theEnv)->WildcardValue->value;
00968 return;
00969 }
00970 else
00971 {
00972 MultifieldDeinstall(theEnv,(MULTIFIELD_PTR) ProceduralPrimitiveData(theEnv)->WildcardValue->value);
00973 if (ProceduralPrimitiveData(theEnv)->WildcardValue->value != ProceduralPrimitiveData(theEnv)->NoParamValue)
00974 AddToMultifieldList(theEnv,(MULTIFIELD_PTR) ProceduralPrimitiveData(theEnv)->WildcardValue->value);
00975 }
00976 ProceduralPrimitiveData(theEnv)->Oldindex = theIndex;
00977 size = ProceduralPrimitiveData(theEnv)->ProcParamArraySize - theIndex + 1;
00978 if (size <= 0)
00979 {
00980 result->end = ProceduralPrimitiveData(theEnv)->WildcardValue->end = -1;
00981 result->value = ProceduralPrimitiveData(theEnv)->WildcardValue->value = ProceduralPrimitiveData(theEnv)->NoParamValue;
00982 MultifieldInstall(theEnv,(MULTIFIELD_PTR) ProceduralPrimitiveData(theEnv)->WildcardValue->value);
00983 return;
00984 }
00985 for (i = theIndex-1 ; i < ProceduralPrimitiveData(theEnv)->ProcParamArraySize ; i++)
00986 {
00987 if (ProceduralPrimitiveData(theEnv)->ProcParamArray[i].type == MULTIFIELD)
00988 size += ProceduralPrimitiveData(theEnv)->ProcParamArray[i].end - ProceduralPrimitiveData(theEnv)->ProcParamArray[i].begin;
00989 }
00990 result->end = ProceduralPrimitiveData(theEnv)->WildcardValue->end = size-1;
00991 result->value = ProceduralPrimitiveData(theEnv)->WildcardValue->value = (void *) CreateMultifield2(theEnv,(unsigned long) size);
00992 for (i = theIndex-1 , j = 1 ; i < ProceduralPrimitiveData(theEnv)->ProcParamArraySize ; i++)
00993 {
00994 if (ProceduralPrimitiveData(theEnv)->ProcParamArray[i].type != MULTIFIELD)
00995 {
00996 SetMFType(result->value,j,(short) ProceduralPrimitiveData(theEnv)->ProcParamArray[i].type);
00997 SetMFValue(result->value,j,ProceduralPrimitiveData(theEnv)->ProcParamArray[i].value);
00998 j++;
00999 }
01000 else
01001 {
01002 val = &ProceduralPrimitiveData(theEnv)->ProcParamArray[i];
01003 for (k = val->begin + 1 ; k <= val->end + 1 ; k++ , j++)
01004 {
01005 SetMFType(result->value,j,GetMFType(val->value,k));
01006 SetMFValue(result->value,j,GetMFValue(val->value,k));
01007 }
01008 }
01009 }
01010 MultifieldInstall(theEnv,(MULTIFIELD_PTR) ProceduralPrimitiveData(theEnv)->WildcardValue->value);
01011 }
01012
01013
01014
01015
01016
01017
01018
01019
01020
01021
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039 static void EvaluateProcParameters(
01040 void *theEnv,
01041 EXPRESSION *parameterList,
01042 int numberOfParameters,
01043 char *pname,
01044 char *bodytype)
01045 {
01046 DATA_OBJECT *rva,temp;
01047 int i = 0;
01048
01049 if (numberOfParameters == 0)
01050 {
01051 ProceduralPrimitiveData(theEnv)->ProcParamArray = NULL;
01052 ProceduralPrimitiveData(theEnv)->ProcParamArraySize = 0;
01053 return;
01054 }
01055
01056 rva = (DATA_OBJECT *) gm2(theEnv,(sizeof(DATA_OBJECT) * numberOfParameters));
01057 while (parameterList != NULL)
01058 {
01059 if ((EvaluateExpression(theEnv,parameterList,&temp) == TRUE) ? TRUE :
01060 (temp.type == RVOID))
01061 {
01062 if (temp.type == RVOID)
01063 {
01064 PrintErrorID(theEnv,"PRCCODE",2,FALSE);
01065 EnvPrintRouter(theEnv,WERROR,"Functions without a return value are illegal as ");
01066 EnvPrintRouter(theEnv,WERROR,bodytype);
01067 EnvPrintRouter(theEnv,WERROR," arguments.\n");
01068 SetEvaluationError(theEnv,TRUE);
01069 }
01070 PrintErrorID(theEnv,"PRCCODE",6,FALSE);
01071 EnvPrintRouter(theEnv,WERROR,"This error occurred while evaluating arguments ");
01072 EnvPrintRouter(theEnv,WERROR,"for the ");
01073 EnvPrintRouter(theEnv,WERROR,bodytype);
01074 EnvPrintRouter(theEnv,WERROR," ");
01075 EnvPrintRouter(theEnv,WERROR,pname);
01076 EnvPrintRouter(theEnv,WERROR,".\n");
01077 rm(theEnv,(void *) rva,(sizeof(DATA_OBJECT) * numberOfParameters));
01078 return;
01079 }
01080 rva[i].type = temp.type;
01081 rva[i].value = temp.value;
01082 rva[i].begin = temp.begin;
01083 rva[i].end = temp.end;
01084 parameterList = parameterList->nextArg;
01085 i++;
01086 }
01087 ProceduralPrimitiveData(theEnv)->ProcParamArraySize = numberOfParameters;
01088 ProceduralPrimitiveData(theEnv)->ProcParamArray = rva;
01089 }
01090
01091
01092
01093
01094
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104 static intBool RtnProcParam(
01105 void *theEnv,
01106 void *value,
01107 DATA_OBJECT *result)
01108 {
01109 register DATA_OBJECT *src;
01110
01111 src = &ProceduralPrimitiveData(theEnv)->ProcParamArray[*((int *) ValueToBitMap(value)) - 1];
01112 result->type = src->type;
01113 result->value = src->value;
01114 result->begin = src->begin;
01115 result->end = src->end;
01116 return(TRUE);
01117 }
01118
01119
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132 static intBool GetProcBind(
01133 void *theEnv,
01134 void *value,
01135 DATA_OBJECT *result)
01136 {
01137 register DATA_OBJECT *src;
01138 PACKED_PROC_VAR *pvar;
01139
01140 pvar = (PACKED_PROC_VAR *) ValueToBitMap(value);
01141 src = &ProceduralPrimitiveData(theEnv)->LocalVarArray[pvar->first - 1];
01142 if (src->supplementalInfo == EnvTrueSymbol(theEnv))
01143 {
01144 result->type = src->type;
01145 result->value = src->value;
01146 result->begin = src->begin;
01147 result->end = src->end;
01148 return(TRUE);
01149 }
01150 if (GetFirstArgument()->nextArg != NULL)
01151 {
01152 EvaluateExpression(theEnv,GetFirstArgument()->nextArg,result);
01153 return(TRUE);
01154 }
01155 if (pvar->second == 0)
01156 {
01157 PrintErrorID(theEnv,"PRCCODE",5,FALSE);
01158 SetEvaluationError(theEnv,TRUE);
01159 EnvPrintRouter(theEnv,WERROR,"Variable ");
01160 EnvPrintRouter(theEnv,WERROR,ValueToString(GetFirstArgument()->value));
01161 if (ProceduralPrimitiveData(theEnv)->ProcUnboundErrFunc != NULL)
01162 {
01163 EnvPrintRouter(theEnv,WERROR," unbound in ");
01164 (*ProceduralPrimitiveData(theEnv)->ProcUnboundErrFunc)(theEnv);
01165 }
01166 else
01167 EnvPrintRouter(theEnv,WERROR," unbound.\n");
01168 result->type = SYMBOL;
01169 result->value = EnvFalseSymbol(theEnv);
01170 return(TRUE);
01171 }
01172 if (pvar->secondFlag == 0)
01173 {
01174 src = &ProceduralPrimitiveData(theEnv)->ProcParamArray[pvar->second - 1];
01175 result->type = src->type;
01176 result->value = src->value;
01177 result->begin = src->begin;
01178 result->end = src->end;
01179 }
01180 else
01181 GrabProcWildargs(theEnv,result,(int) pvar->second);
01182 return(TRUE);
01183 }
01184
01185
01186
01187
01188
01189
01190
01191
01192
01193
01194
01195
01196
01197 static intBool PutProcBind(
01198 void *theEnv,
01199 void *value,
01200 DATA_OBJECT *result)
01201 {
01202 register DATA_OBJECT *dst;
01203
01204 dst = &ProceduralPrimitiveData(theEnv)->LocalVarArray[*((int *) ValueToBitMap(value)) - 1];
01205 if (GetFirstArgument() == NULL)
01206 {
01207 if (dst->supplementalInfo == EnvTrueSymbol(theEnv))
01208 ValueDeinstall(theEnv,dst);
01209 dst->supplementalInfo = EnvFalseSymbol(theEnv);
01210 result->type = SYMBOL;
01211 result->value = EnvFalseSymbol(theEnv);
01212 }
01213 else
01214 {
01215 if (GetFirstArgument()->nextArg != NULL)
01216 StoreInMultifield(theEnv,result,GetFirstArgument(),TRUE);
01217 else
01218 EvaluateExpression(theEnv,GetFirstArgument(),result);
01219 if (dst->supplementalInfo == EnvTrueSymbol(theEnv))
01220 ValueDeinstall(theEnv,dst);
01221 dst->supplementalInfo = EnvTrueSymbol(theEnv);
01222 dst->type = result->type;
01223 dst->value = result->value;
01224 dst->begin = result->begin;
01225 dst->end = result->end;
01226 ValueInstall(theEnv,dst);
01227 }
01228 return(TRUE);
01229 }
01230
01231
01232
01233
01234
01235
01236
01237
01238
01239
01240
01241
01242
01243
01244 static intBool RtnProcWild(
01245 void *theEnv,
01246 void *value,
01247 DATA_OBJECT *result)
01248 {
01249 GrabProcWildargs(theEnv,result,*(int *) ValueToBitMap(value));
01250 return(TRUE);
01251 }
01252
01253 #if (! BLOAD_ONLY) && (! RUN_TIME)
01254
01255
01256
01257
01258
01259
01260
01261
01262
01263
01264
01265
01266
01267
01268 static int FindProcParameter(
01269 SYMBOL_HN *name,
01270 EXPRESSION *parameterList,
01271 SYMBOL_HN *wildcard)
01272 {
01273 int i = 1;
01274
01275 while (parameterList != NULL)
01276 {
01277 if (parameterList->value == (void *) name)
01278 return(i);
01279 i++;
01280 parameterList = parameterList->nextArg;
01281 }
01282
01283
01284
01285
01286 if (name == wildcard)
01287 return(i);
01288 return(0);
01289 }
01290
01291
01292
01293
01294
01295
01296
01297
01298
01299
01300
01301
01302
01303
01304
01305
01306
01307
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317
01318
01319
01320
01321
01322
01323
01324
01325 static int ReplaceProcBinds(
01326 void *theEnv,
01327 EXPRESSION *actions,
01328 int (*altbindfunc)(void *,EXPRESSION *,void *),
01329 void *userBuffer)
01330 {
01331 int bcode;
01332 SYMBOL_HN *bname;
01333
01334 while (actions != NULL)
01335 {
01336 if (actions->argList != NULL)
01337 {
01338 if (ReplaceProcBinds(theEnv,actions->argList,altbindfunc,userBuffer))
01339 return(TRUE);
01340 if ((actions->value == (void *) FindFunction(theEnv,"bind")) &&
01341 (actions->argList->type == SYMBOL))
01342 {
01343 bname = (SYMBOL_HN *) actions->argList->value;
01344 bcode = (*altbindfunc)(theEnv,actions,userBuffer);
01345 if (bcode == -1)
01346 return(TRUE);
01347 if (bcode == 1)
01348 RemoveParsedBindName(theEnv,bname);
01349 }
01350 }
01351 actions = actions->nextArg;
01352 }
01353 return(FALSE);
01354 }
01355
01356
01357
01358
01359
01360
01361
01362
01363
01364
01365
01366
01367
01368
01369
01370
01371
01372 static EXPRESSION *CompactActions(
01373 void *theEnv,
01374 EXPRESSION *actions)
01375 {
01376 register struct expr *tmp;
01377
01378 if (actions->argList == NULL)
01379 {
01380 actions->type = SYMBOL;
01381 actions->value = EnvFalseSymbol(theEnv);
01382 }
01383 else if (actions->argList->nextArg == NULL)
01384 {
01385 tmp = actions;
01386 actions = actions->argList;
01387 rtn_struct(theEnv,expr,tmp);
01388 }
01389 return(actions);
01390 }
01391
01392 #endif
01393
01394 #if (! DEFFUNCTION_CONSTRUCT) || (! DEFGENERIC_CONSTRUCT)
01395
01396
01397
01398
01399
01400
01401
01402
01403
01404
01405
01406
01407
01408
01409
01410
01411 #if WIN_BTC
01412 #pragma argsused
01413 #endif
01414 static intBool EvaluateBadCall(
01415 void *theEnv,
01416 void *value,
01417 DATA_OBJECT *result)
01418 {
01419 #if MAC_MCW || WIN_MCW || MAC_XCD
01420 #pragma unused(value)
01421 #endif
01422 PrintErrorID(theEnv,"PRCCODE",1,FALSE);
01423 EnvPrintRouter(theEnv,WERROR,"Attempted to call a deffunction/generic function ");
01424 EnvPrintRouter(theEnv,WERROR,"which does not exist.\n");
01425 SetEvaluationError(theEnv,TRUE);
01426 SetpType(result,SYMBOL);
01427 SetpValue(result,EnvFalseSymbol(theEnv));
01428 return(FALSE);
01429 }
01430
01431 #endif
01432