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 #include "setup.h"
00027
00028 #if DEFFUNCTION_CONSTRUCT && (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE)
00029
00030 #include "bload.h"
00031 #include "bsave.h"
00032
00033 #include "memalloc.h"
00034 #include "cstrcbin.h"
00035 #include "envrnmnt.h"
00036 #include "modulbin.h"
00037
00038 #define _DFFNXBIN_SOURCE_
00039 #include "dffnxbin.h"
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 typedef struct bsaveDeffunctionModule
00053 {
00054 struct bsaveDefmoduleItemHeader header;
00055 } BSAVE_DEFFUNCTION_MODULE;
00056
00057 typedef struct bsaveDeffunctionStruct
00058 {
00059 struct bsaveConstructHeader header;
00060 int minNumberOfParameters,
00061 maxNumberOfParameters,
00062 numberOfLocalVars;
00063 long name,
00064 code;
00065 } BSAVE_DEFFUNCTION;
00066
00067
00068
00069
00070
00071
00072
00073 #if BLOAD_AND_BSAVE
00074 static void BsaveDeffunctionFind(void *);
00075 static void MarkDeffunctionItems(void *,struct constructHeader *,void *);
00076 static void BsaveDeffunctionExpressions(void *,FILE *);
00077 static void BsaveDeffunctionExpression(void *,struct constructHeader *,void *);
00078 static void BsaveStorageDeffunctions(void *,FILE *);
00079 static void BsaveDeffunctions(void *,FILE *);
00080 static void BsaveDeffunction(void *,struct constructHeader *,void *);
00081 #endif
00082
00083 static void BloadStorageDeffunctions(void *);
00084 static void BloadDeffunctions(void *);
00085 static void UpdateDeffunctionModule(void *,void *,long);
00086 static void UpdateDeffunction(void *,void *,long);
00087 static void ClearDeffunctionBload(void *);
00088 static void DeallocateDeffunctionBloadData(void *);
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105 globle void SetupDeffunctionsBload(
00106 void *theEnv)
00107 {
00108 AllocateEnvironmentData(theEnv,DFFNXBIN_DATA,sizeof(struct deffunctionBinaryData),DeallocateDeffunctionBloadData);
00109 #if BLOAD_AND_BSAVE
00110 AddBinaryItem(theEnv,"deffunctions",0,BsaveDeffunctionFind,BsaveDeffunctionExpressions,
00111 BsaveStorageDeffunctions,BsaveDeffunctions,
00112 BloadStorageDeffunctions,BloadDeffunctions,
00113 ClearDeffunctionBload);
00114 #else
00115 AddBinaryItem(theEnv,"deffunctions",0,NULL,NULL,NULL,NULL,
00116 BloadStorageDeffunctions,BloadDeffunctions,
00117 ClearDeffunctionBload);
00118 #endif
00119 }
00120
00121
00122
00123
00124
00125 static void DeallocateDeffunctionBloadData(
00126 void *theEnv)
00127 {
00128 size_t space;
00129
00130 #if (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) && (! RUN_TIME)
00131 space = DeffunctionBinaryData(theEnv)->DeffunctionCount * sizeof(struct deffunctionStruct);
00132 if (space != 0) genfree(theEnv,(void *) DeffunctionBinaryData(theEnv)->DeffunctionArray,space);
00133
00134 space = DeffunctionBinaryData(theEnv)->ModuleCount * sizeof(struct deffunctionModule);
00135 if (space != 0) genfree(theEnv,(void *) DeffunctionBinaryData(theEnv)->ModuleArray,space);
00136 #endif
00137 }
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148 globle void *BloadDeffunctionModuleReference(
00149 void *theEnv,
00150 int theIndex)
00151 {
00152 return ((void *) &DeffunctionBinaryData(theEnv)->ModuleArray[theIndex]);
00153 }
00154
00155
00156
00157
00158
00159
00160
00161 #if BLOAD_AND_BSAVE
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178 static void BsaveDeffunctionFind(
00179 void *theEnv)
00180 {
00181 SaveBloadCount(theEnv,DeffunctionBinaryData(theEnv)->ModuleCount);
00182 SaveBloadCount(theEnv,DeffunctionBinaryData(theEnv)->DeffunctionCount);
00183 DeffunctionBinaryData(theEnv)->DeffunctionCount = 0L;
00184
00185 DeffunctionBinaryData(theEnv)->ModuleCount =
00186 DoForAllConstructs(theEnv,MarkDeffunctionItems,DeffunctionData(theEnv)->DeffunctionModuleIndex,
00187 FALSE,NULL);
00188 }
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200 #if WIN_BTC
00201 #pragma argsused
00202 #endif
00203 static void MarkDeffunctionItems(
00204 void *theEnv,
00205 struct constructHeader *theDeffunction,
00206 void *userBuffer)
00207 {
00208 #if MAC_MCW || WIN_MCW || MAC_XCD
00209 #pragma unused(userBuffer)
00210 #endif
00211
00212 MarkConstructHeaderNeededItems(theDeffunction,DeffunctionBinaryData(theEnv)->DeffunctionCount++);
00213 ExpressionData(theEnv)->ExpressionCount += ExpressionSize(((DEFFUNCTION *) theDeffunction)->code);
00214 MarkNeededItems(theEnv,((DEFFUNCTION *) theDeffunction)->code);
00215 }
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226 static void BsaveDeffunctionExpressions(
00227 void *theEnv,
00228 FILE *fp)
00229 {
00230 DoForAllConstructs(theEnv,BsaveDeffunctionExpression,DeffunctionData(theEnv)->DeffunctionModuleIndex,
00231 FALSE,(void *) fp);
00232 }
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244 static void BsaveDeffunctionExpression(
00245 void *theEnv,
00246 struct constructHeader *theDeffunction,
00247 void *userBuffer)
00248 {
00249 BsaveExpression(theEnv,((DEFFUNCTION *) theDeffunction)->code,(FILE *) userBuffer);
00250 }
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262 static void BsaveStorageDeffunctions(
00263 void *theEnv,
00264 FILE *fp)
00265 {
00266 size_t space;
00267
00268 space = sizeof(unsigned long) * 2;
00269 GenWrite((void *) &space,sizeof(size_t),fp);
00270 GenWrite((void *) &DeffunctionBinaryData(theEnv)->ModuleCount,sizeof(unsigned long),fp);
00271 GenWrite((void *) &DeffunctionBinaryData(theEnv)->DeffunctionCount,sizeof(unsigned long),fp);
00272 }
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284 static void BsaveDeffunctions(
00285 void *theEnv,
00286 FILE *fp)
00287 {
00288 size_t space;
00289 struct defmodule *theModule;
00290 DEFFUNCTION_MODULE *theModuleItem;
00291 BSAVE_DEFFUNCTION_MODULE dummy_mitem;
00292
00293 space = ((sizeof(BSAVE_DEFFUNCTION_MODULE) * DeffunctionBinaryData(theEnv)->ModuleCount) +
00294 (sizeof(BSAVE_DEFFUNCTION) * DeffunctionBinaryData(theEnv)->DeffunctionCount));
00295 GenWrite((void *) &space,sizeof(size_t),fp);
00296
00297
00298
00299
00300 DeffunctionBinaryData(theEnv)->DeffunctionCount = 0L;
00301 theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL);
00302 while (theModule != NULL)
00303 {
00304 theModuleItem = (DEFFUNCTION_MODULE *)
00305 GetModuleItem(theEnv,theModule,FindModuleItem(theEnv,"deffunction")->moduleIndex);
00306 AssignBsaveDefmdlItemHdrVals(&dummy_mitem.header,&theModuleItem->header);
00307 GenWrite((void *) &dummy_mitem,sizeof(BSAVE_DEFFUNCTION_MODULE),fp);
00308 theModule = (struct defmodule *) EnvGetNextDefmodule(theEnv,(void *) theModule);
00309 }
00310
00311
00312
00313
00314 DoForAllConstructs(theEnv,BsaveDeffunction,DeffunctionData(theEnv)->DeffunctionModuleIndex,
00315 FALSE,(void *) fp);
00316
00317 RestoreBloadCount(theEnv,&DeffunctionBinaryData(theEnv)->ModuleCount);
00318 RestoreBloadCount(theEnv,&DeffunctionBinaryData(theEnv)->DeffunctionCount);
00319 }
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330 static void BsaveDeffunction(
00331 void *theEnv,
00332 struct constructHeader *theDeffunction,
00333 void *userBuffer)
00334 {
00335 DEFFUNCTION *dptr = (DEFFUNCTION *) theDeffunction;
00336 BSAVE_DEFFUNCTION dummy_df;
00337
00338 AssignBsaveConstructHeaderVals(&dummy_df.header,&dptr->header);
00339 dummy_df.minNumberOfParameters = dptr->minNumberOfParameters;
00340 dummy_df.maxNumberOfParameters = dptr->maxNumberOfParameters;
00341 dummy_df.numberOfLocalVars = dptr->numberOfLocalVars;
00342 if (dptr->code != NULL)
00343 {
00344 dummy_df.code = ExpressionData(theEnv)->ExpressionCount;
00345 ExpressionData(theEnv)->ExpressionCount += ExpressionSize(dptr->code);
00346 }
00347 else
00348 dummy_df.code = -1L;
00349 GenWrite((void *) &dummy_df,sizeof(BSAVE_DEFFUNCTION),(FILE *) userBuffer);
00350 }
00351
00352 #endif
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364 static void BloadStorageDeffunctions(
00365 void *theEnv)
00366 {
00367 size_t space;
00368
00369 GenReadBinary(theEnv,(void *) &space,sizeof(size_t));
00370 if (space == 0L)
00371 return;
00372 GenReadBinary(theEnv,(void *) &DeffunctionBinaryData(theEnv)->ModuleCount,sizeof(unsigned long));
00373 GenReadBinary(theEnv,(void *) &DeffunctionBinaryData(theEnv)->DeffunctionCount,sizeof(unsigned long));
00374 if (DeffunctionBinaryData(theEnv)->ModuleCount == 0L)
00375 {
00376 DeffunctionBinaryData(theEnv)->ModuleArray = NULL;
00377 DeffunctionBinaryData(theEnv)->DeffunctionArray = NULL;
00378 return;
00379 }
00380
00381 space = (DeffunctionBinaryData(theEnv)->ModuleCount * sizeof(DEFFUNCTION_MODULE));
00382 DeffunctionBinaryData(theEnv)->ModuleArray = (DEFFUNCTION_MODULE *) genalloc(theEnv,space);
00383
00384 if (DeffunctionBinaryData(theEnv)->DeffunctionCount == 0L)
00385 {
00386 DeffunctionBinaryData(theEnv)->DeffunctionArray = NULL;
00387 return;
00388 }
00389
00390 space = (DeffunctionBinaryData(theEnv)->DeffunctionCount * sizeof(DEFFUNCTION));
00391 DeffunctionBinaryData(theEnv)->DeffunctionArray = (DEFFUNCTION *) genalloc(theEnv,space);
00392 }
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405 static void BloadDeffunctions(
00406 void *theEnv)
00407 {
00408 size_t space;
00409
00410 GenReadBinary(theEnv,(void *) &space,sizeof(size_t));
00411 BloadandRefresh(theEnv,DeffunctionBinaryData(theEnv)->ModuleCount,sizeof(BSAVE_DEFFUNCTION_MODULE),UpdateDeffunctionModule);
00412 BloadandRefresh(theEnv,DeffunctionBinaryData(theEnv)->DeffunctionCount,sizeof(BSAVE_DEFFUNCTION),UpdateDeffunction);
00413 }
00414
00415
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427 static void UpdateDeffunctionModule(
00428 void *theEnv,
00429 void *buf,
00430 long obji)
00431 {
00432 BSAVE_DEFFUNCTION_MODULE *bdptr;
00433
00434 bdptr = (BSAVE_DEFFUNCTION_MODULE *) buf;
00435 UpdateDefmoduleItemHeader(theEnv,&bdptr->header,&DeffunctionBinaryData(theEnv)->ModuleArray[obji].header,
00436 (int) sizeof(DEFFUNCTION),(void *) DeffunctionBinaryData(theEnv)->DeffunctionArray);
00437 }
00438
00439
00440
00441
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451 static void UpdateDeffunction(
00452 void *theEnv,
00453 void *buf,
00454 long obji)
00455 {
00456 BSAVE_DEFFUNCTION *bdptr;
00457 DEFFUNCTION *dptr;
00458
00459 bdptr = (BSAVE_DEFFUNCTION *) buf;
00460 dptr = (DEFFUNCTION *) &DeffunctionBinaryData(theEnv)->DeffunctionArray[obji];
00461
00462 UpdateConstructHeader(theEnv,&bdptr->header,&dptr->header,
00463 (int) sizeof(DEFFUNCTION_MODULE),(void *) DeffunctionBinaryData(theEnv)->ModuleArray,
00464 (int) sizeof(DEFFUNCTION),(void *) DeffunctionBinaryData(theEnv)->DeffunctionArray);
00465
00466 dptr->code = ExpressionPointer(bdptr->code);
00467 dptr->busy = 0;
00468 dptr->executing = 0;
00469 #if DEBUGGING_FUNCTIONS
00470 dptr->trace = (unsigned short) DeffunctionData(theEnv)->WatchDeffunctions;
00471 #endif
00472 dptr->minNumberOfParameters = bdptr->minNumberOfParameters;
00473 dptr->maxNumberOfParameters = bdptr->maxNumberOfParameters;
00474 dptr->numberOfLocalVars = bdptr->numberOfLocalVars;
00475 }
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487 static void ClearDeffunctionBload(
00488 void *theEnv)
00489 {
00490 register long i;
00491 size_t space;
00492
00493 space = (sizeof(DEFFUNCTION_MODULE) * DeffunctionBinaryData(theEnv)->ModuleCount);
00494 if (space == 0L)
00495 return;
00496 genfree(theEnv,(void *) DeffunctionBinaryData(theEnv)->ModuleArray,space);
00497 DeffunctionBinaryData(theEnv)->ModuleArray = NULL;
00498 DeffunctionBinaryData(theEnv)->ModuleCount = 0L;
00499
00500 for (i = 0L ; i < DeffunctionBinaryData(theEnv)->DeffunctionCount ; i++)
00501 UnmarkConstructHeader(theEnv,&DeffunctionBinaryData(theEnv)->DeffunctionArray[i].header);
00502 space = (sizeof(DEFFUNCTION) * DeffunctionBinaryData(theEnv)->DeffunctionCount);
00503 if (space == 0L)
00504 return;
00505 genfree(theEnv,(void *) DeffunctionBinaryData(theEnv)->DeffunctionArray,space);
00506 DeffunctionBinaryData(theEnv)->DeffunctionArray = NULL;
00507 DeffunctionBinaryData(theEnv)->DeffunctionCount = 0L;
00508 }
00509
00510 #endif
00511