00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #define _MODULBIN_SOURCE_
00024
00025 #include "setup.h"
00026
00027 #if (BLOAD || BLOAD_ONLY || BLOAD_AND_BSAVE) && (! RUN_TIME)
00028
00029 #include <stdio.h>
00030 #define _STDIO_INCLUDED_
00031
00032 #include "memalloc.h"
00033 #include "constrct.h"
00034 #include "moduldef.h"
00035 #include "bload.h"
00036 #include "bsave.h"
00037 #include "envrnmnt.h"
00038
00039 #include "modulbin.h"
00040
00041
00042
00043
00044
00045 #if BLOAD_AND_BSAVE
00046 static void BsaveFind(void *);
00047 static void BsaveStorage(void *,FILE *);
00048 static void BsaveBinaryItem(void *,FILE *);
00049 #endif
00050 static void BloadStorage(void *);
00051 static void BloadBinaryItem(void *);
00052 static void UpdateDefmodule(void *,void *,long);
00053 static void UpdatePortItem(void *,void *,long);
00054 static void ClearBload(void *);
00055
00056
00057
00058
00059
00060 globle void DefmoduleBinarySetup(
00061 void *theEnv)
00062 {
00063 AddBeforeBloadFunction(theEnv,"defmodule",RemoveAllDefmodules,2000);
00064
00065 #if BLOAD_AND_BSAVE
00066 AddBinaryItem(theEnv,"defmodule",0,BsaveFind,NULL,
00067 BsaveStorage,BsaveBinaryItem,
00068 BloadStorage,BloadBinaryItem,
00069 ClearBload);
00070 #endif
00071
00072 AddAbortBloadFunction(theEnv,"defmodule",CreateMainModule,0);
00073
00074 #if (BLOAD || BLOAD_ONLY)
00075 AddBinaryItem(theEnv,"defmodule",0,NULL,NULL,NULL,NULL,
00076 BloadStorage,BloadBinaryItem,
00077 ClearBload);
00078 #endif
00079 }
00080
00081
00082
00083
00084
00085 globle void UpdateDefmoduleItemHeader(
00086 void *theEnv,
00087 struct bsaveDefmoduleItemHeader *theBsaveHeader,
00088 struct defmoduleItemHeader *theHeader,
00089 int itemSize,
00090 void *itemArray)
00091 {
00092 long firstOffset,lastOffset;
00093
00094 theHeader->theModule = ModulePointer(theBsaveHeader->theModule);
00095 if (theBsaveHeader->firstItem == -1L)
00096 {
00097 theHeader->firstItem = NULL;
00098 theHeader->lastItem = NULL;
00099 }
00100 else
00101 {
00102 firstOffset = itemSize * theBsaveHeader->firstItem;
00103 lastOffset = itemSize * theBsaveHeader->lastItem;
00104 theHeader->firstItem =
00105 (struct constructHeader *) &((char *) itemArray)[firstOffset];
00106 theHeader->lastItem =
00107 (struct constructHeader *) &((char *) itemArray)[lastOffset];
00108 }
00109 }
00110
00111 #if BLOAD_AND_BSAVE
00112
00113
00114
00115
00116
00117 globle void AssignBsaveDefmdlItemHdrVals(
00118 struct bsaveDefmoduleItemHeader *theBsaveHeader,
00119 struct defmoduleItemHeader *theHeader)
00120 {
00121 theBsaveHeader->theModule = theHeader->theModule->bsaveID;
00122 if (theHeader->firstItem == NULL)
00123 {
00124 theBsaveHeader->firstItem = -1L;
00125 theBsaveHeader->lastItem = -1L;
00126 }
00127 else
00128 {
00129 theBsaveHeader->firstItem = theHeader->firstItem->bsaveID;
00130 theBsaveHeader->lastItem = theHeader->lastItem->bsaveID;
00131 }
00132 }
00133
00134
00135
00136
00137
00138
00139 static void BsaveFind(
00140 void *theEnv)
00141 {
00142 struct defmodule *defmodulePtr;
00143 struct portItem *theList;
00144
00145
00146
00147
00148
00149
00150
00151 SaveBloadCount(theEnv,DefmoduleData(theEnv)->BNumberOfDefmodules);
00152 SaveBloadCount(theEnv,DefmoduleData(theEnv)->NumberOfPortItems);
00153
00154
00155
00156
00157
00158
00159 DefmoduleData(theEnv)->BNumberOfDefmodules = 0;
00160 DefmoduleData(theEnv)->NumberOfPortItems = 0;
00161
00162
00163
00164
00165
00166 for (defmodulePtr = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL);
00167 defmodulePtr != NULL;
00168 defmodulePtr = (struct defmodule *) EnvGetNextDefmodule(theEnv,defmodulePtr))
00169 {
00170
00171
00172
00173
00174 DefmoduleData(theEnv)->BNumberOfDefmodules++;
00175
00176
00177
00178
00179
00180
00181 defmodulePtr->name->neededSymbol = TRUE;
00182
00183
00184
00185
00186
00187
00188
00189
00190 for (theList = defmodulePtr->importList;
00191 theList != NULL;
00192 theList = theList->next)
00193 {
00194 DefmoduleData(theEnv)->NumberOfPortItems++;
00195 if (theList->moduleName != NULL)
00196 { theList->moduleName->neededSymbol = TRUE; }
00197 if (theList->constructType != NULL)
00198 { theList->constructType->neededSymbol = TRUE; }
00199 if (theList->constructName != NULL)
00200 { theList->constructName->neededSymbol = TRUE; }
00201 }
00202
00203
00204
00205
00206
00207
00208
00209
00210 for (theList = defmodulePtr->exportList;
00211 theList != NULL;
00212 theList = theList->next)
00213 {
00214 DefmoduleData(theEnv)->NumberOfPortItems++;
00215 if (theList->moduleName != NULL)
00216 { theList->moduleName->neededSymbol = TRUE; }
00217 if (theList->constructType != NULL)
00218 { theList->constructType->neededSymbol = TRUE; }
00219 if (theList->constructName != NULL)
00220 { theList->constructName->neededSymbol = TRUE; }
00221 }
00222 }
00223 }
00224
00225
00226
00227
00228
00229 static void BsaveStorage(
00230 void *theEnv,
00231 FILE *fp)
00232 {
00233 size_t space;
00234
00235 space = sizeof(long) * 2;
00236 GenWrite(&space,sizeof(size_t),fp);
00237 GenWrite(&DefmoduleData(theEnv)->BNumberOfDefmodules,sizeof(long int),fp);
00238 GenWrite(&DefmoduleData(theEnv)->NumberOfPortItems,sizeof(long int),fp);
00239 }
00240
00241
00242
00243
00244
00245 static void BsaveBinaryItem(
00246 void *theEnv,
00247 FILE *fp)
00248 {
00249 size_t space;
00250 struct defmodule *defmodulePtr;
00251 struct bsaveDefmodule newDefmodule;
00252 struct bsavePortItem newPortItem;
00253 struct portItem *theList;
00254
00255
00256
00257
00258
00259
00260 space = DefmoduleData(theEnv)->BNumberOfDefmodules * sizeof(struct bsaveDefmodule);
00261 space += DefmoduleData(theEnv)->NumberOfPortItems * sizeof(struct bsavePortItem);
00262 GenWrite(&space,sizeof(size_t),fp);
00263
00264
00265
00266
00267
00268 DefmoduleData(theEnv)->BNumberOfDefmodules = 0;
00269 DefmoduleData(theEnv)->NumberOfPortItems = 0;
00270 for (defmodulePtr = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL);
00271 defmodulePtr != NULL;
00272 defmodulePtr = (struct defmodule *) EnvGetNextDefmodule(theEnv,defmodulePtr))
00273 {
00274 newDefmodule.name = defmodulePtr->name->bucket;
00275
00276 DefmoduleData(theEnv)->BNumberOfDefmodules++;
00277 if (defmodulePtr->next != NULL)
00278 { newDefmodule.next = DefmoduleData(theEnv)->BNumberOfDefmodules; }
00279 else
00280 { newDefmodule.next = -1L; }
00281
00282 if (defmodulePtr->importList == NULL)
00283 { newDefmodule.importList = -1L; }
00284 else
00285 {
00286 newDefmodule.importList = DefmoduleData(theEnv)->NumberOfPortItems;
00287 for (theList = defmodulePtr->importList;
00288 theList != NULL;
00289 theList = theList->next)
00290 { DefmoduleData(theEnv)->NumberOfPortItems++; }
00291 }
00292
00293 if (defmodulePtr->exportList == NULL)
00294 { newDefmodule.exportList = -1L; }
00295 else
00296 {
00297 newDefmodule.exportList = DefmoduleData(theEnv)->NumberOfPortItems;
00298 for (theList = defmodulePtr->exportList;
00299 theList != NULL;
00300 theList = theList->next)
00301 { DefmoduleData(theEnv)->NumberOfPortItems++; }
00302 }
00303
00304 newDefmodule.bsaveID = defmodulePtr->bsaveID;
00305 GenWrite(&newDefmodule,sizeof(struct bsaveDefmodule),fp);
00306 }
00307
00308
00309
00310
00311
00312 DefmoduleData(theEnv)->NumberOfPortItems = 0;
00313 defmodulePtr = (struct defmodule *) EnvGetNextDefmodule(theEnv,NULL);
00314 while (defmodulePtr != NULL)
00315 {
00316 for (theList = defmodulePtr->importList;
00317 theList != NULL;
00318 theList = theList->next)
00319 {
00320 DefmoduleData(theEnv)->NumberOfPortItems++;
00321 if (theList->moduleName == NULL) newPortItem.moduleName = -1L;
00322 else newPortItem.moduleName = (long) theList->moduleName->bucket;
00323
00324 if (theList->constructType == NULL) newPortItem.constructType = -1L;
00325 else newPortItem.constructType = (long) theList->constructType->bucket;
00326
00327 if (theList->constructName == NULL) newPortItem.constructName = -1L;
00328 else newPortItem.constructName = (long) theList->constructName->bucket;
00329
00330 if (theList->next == NULL) newPortItem.next = -1L;
00331 else newPortItem.next = DefmoduleData(theEnv)->NumberOfPortItems;
00332
00333 GenWrite(&newPortItem,sizeof(struct bsavePortItem),fp);
00334 }
00335
00336 for (theList = defmodulePtr->exportList;
00337 theList != NULL;
00338 theList = theList->next)
00339 {
00340 DefmoduleData(theEnv)->NumberOfPortItems++;
00341 if (theList->moduleName == NULL) newPortItem.moduleName = -1L;
00342 else newPortItem.moduleName = (long) theList->moduleName->bucket;
00343
00344 if (theList->constructType == NULL) newPortItem.constructType = -1L;
00345 else newPortItem.constructType = (long) theList->constructType->bucket;
00346
00347 if (theList->constructName == NULL) newPortItem.constructName = -1L;
00348 else newPortItem.constructName = (long) theList->constructName->bucket;
00349
00350 if (theList->next == NULL) newPortItem.next = -1L;
00351 else newPortItem.next = DefmoduleData(theEnv)->NumberOfPortItems;
00352
00353 GenWrite(&newPortItem,sizeof(struct bsavePortItem),fp);
00354 }
00355
00356 defmodulePtr = (struct defmodule *) EnvGetNextDefmodule(theEnv,defmodulePtr);
00357 }
00358
00359
00360
00361
00362
00363
00364
00365
00366 RestoreBloadCount(theEnv,&DefmoduleData(theEnv)->BNumberOfDefmodules);
00367 RestoreBloadCount(theEnv,&DefmoduleData(theEnv)->NumberOfPortItems);
00368 }
00369
00370 #endif
00371
00372
00373
00374
00375
00376 static void BloadStorage(
00377 void *theEnv)
00378 {
00379 size_t space;
00380
00381
00382
00383
00384
00385
00386 GenReadBinary(theEnv,&space,sizeof(size_t));
00387 GenReadBinary(theEnv,&DefmoduleData(theEnv)->BNumberOfDefmodules,sizeof(long int));
00388 GenReadBinary(theEnv,&DefmoduleData(theEnv)->NumberOfPortItems,sizeof(long int));
00389
00390
00391
00392
00393
00394
00395 if (DefmoduleData(theEnv)->BNumberOfDefmodules == 0)
00396 {
00397 DefmoduleData(theEnv)->DefmoduleArray = NULL;
00398 return;
00399 }
00400
00401 space = (DefmoduleData(theEnv)->BNumberOfDefmodules * sizeof(struct defmodule));
00402 DefmoduleData(theEnv)->DefmoduleArray = (struct defmodule *) genalloc(theEnv,space);
00403
00404
00405
00406
00407
00408
00409 if (DefmoduleData(theEnv)->NumberOfPortItems == 0)
00410 {
00411 DefmoduleData(theEnv)->PortItemArray = NULL;
00412 return;
00413 }
00414
00415 space = (DefmoduleData(theEnv)->NumberOfPortItems * sizeof(struct portItem));
00416 DefmoduleData(theEnv)->PortItemArray = (struct portItem *) genalloc(theEnv,space);
00417 }
00418
00419
00420
00421
00422
00423 static void BloadBinaryItem(
00424 void *theEnv)
00425 {
00426 size_t space;
00427
00428 GenReadBinary(theEnv,&space,sizeof(size_t));
00429 if (DefmoduleData(theEnv)->BNumberOfDefmodules == 0) return;
00430
00431 BloadandRefresh(theEnv,DefmoduleData(theEnv)->BNumberOfDefmodules,sizeof(struct bsaveDefmodule),UpdateDefmodule);
00432 BloadandRefresh(theEnv,DefmoduleData(theEnv)->NumberOfPortItems,sizeof(struct bsavePortItem),UpdatePortItem);
00433
00434 SetListOfDefmodules(theEnv,(void *) DefmoduleData(theEnv)->DefmoduleArray);
00435 EnvSetCurrentModule(theEnv,(void *) EnvGetNextDefmodule(theEnv,NULL));
00436 }
00437
00438
00439
00440
00441
00442 static void UpdateDefmodule(
00443 void *theEnv,
00444 void *buf,
00445 long obji)
00446 {
00447 struct bsaveDefmodule *bdp;
00448 struct moduleItem *theItem;
00449 int i;
00450
00451 bdp = (struct bsaveDefmodule *) buf;
00452 DefmoduleData(theEnv)->DefmoduleArray[obji].name = SymbolPointer(bdp->name);
00453 IncrementSymbolCount(DefmoduleData(theEnv)->DefmoduleArray[obji].name);
00454 if (bdp->next != -1L)
00455 { DefmoduleData(theEnv)->DefmoduleArray[obji].next = (struct defmodule *) &DefmoduleData(theEnv)->DefmoduleArray[bdp->next]; }
00456 else
00457 { DefmoduleData(theEnv)->DefmoduleArray[obji].next = NULL; }
00458
00459 if (GetNumberOfModuleItems(theEnv) == 0)
00460 { DefmoduleData(theEnv)->DefmoduleArray[obji].itemsArray = NULL; }
00461 else
00462 {
00463 DefmoduleData(theEnv)->DefmoduleArray[obji].itemsArray =
00464 (struct defmoduleItemHeader **) gm2(theEnv,sizeof(void *) * GetNumberOfModuleItems(theEnv));
00465 }
00466
00467 for (i = 0, theItem = GetListOfModuleItems(theEnv);
00468 (i < GetNumberOfModuleItems(theEnv)) && (theItem != NULL) ;
00469 i++, theItem = theItem->next)
00470 {
00471 if (theItem->bloadModuleReference == NULL)
00472 { DefmoduleData(theEnv)->DefmoduleArray[obji].itemsArray[i] = NULL; }
00473 else
00474 {
00475 DefmoduleData(theEnv)->DefmoduleArray[obji].itemsArray[i] =
00476 (struct defmoduleItemHeader *)
00477 (*theItem->bloadModuleReference)(theEnv,obji);
00478 }
00479 }
00480
00481 DefmoduleData(theEnv)->DefmoduleArray[obji].ppForm = NULL;
00482
00483 if (bdp->importList != -1L)
00484 { DefmoduleData(theEnv)->DefmoduleArray[obji].importList = (struct portItem *) &DefmoduleData(theEnv)->PortItemArray[bdp->importList]; }
00485 else
00486 { DefmoduleData(theEnv)->DefmoduleArray[obji].importList = NULL; }
00487
00488 if (bdp->exportList != -1L)
00489 { DefmoduleData(theEnv)->DefmoduleArray[obji].exportList = (struct portItem *) &DefmoduleData(theEnv)->PortItemArray[bdp->exportList]; }
00490 else
00491 { DefmoduleData(theEnv)->DefmoduleArray[obji].exportList = NULL; }
00492 DefmoduleData(theEnv)->DefmoduleArray[obji].bsaveID = bdp->bsaveID;
00493 }
00494
00495
00496
00497
00498
00499 static void UpdatePortItem(
00500 void *theEnv,
00501 void *buf,
00502 long obji)
00503 {
00504 struct bsavePortItem *bdp;
00505
00506 bdp = (struct bsavePortItem *) buf;
00507
00508 if (bdp->moduleName != -1L)
00509 {
00510 DefmoduleData(theEnv)->PortItemArray[obji].moduleName = SymbolPointer(bdp->moduleName);
00511 IncrementSymbolCount(DefmoduleData(theEnv)->PortItemArray[obji].moduleName);
00512 }
00513 else
00514 { DefmoduleData(theEnv)->PortItemArray[obji].moduleName = NULL; }
00515
00516 if (bdp->constructType != -1L)
00517 {
00518 DefmoduleData(theEnv)->PortItemArray[obji].constructType = SymbolPointer(bdp->constructType);
00519 IncrementSymbolCount(DefmoduleData(theEnv)->PortItemArray[obji].constructType);
00520 }
00521 else
00522 { DefmoduleData(theEnv)->PortItemArray[obji].constructType = NULL; }
00523
00524 if (bdp->constructName != -1L)
00525 {
00526 DefmoduleData(theEnv)->PortItemArray[obji].constructName = SymbolPointer(bdp->constructName);
00527 IncrementSymbolCount(DefmoduleData(theEnv)->PortItemArray[obji].constructName);
00528 }
00529 else
00530 { DefmoduleData(theEnv)->PortItemArray[obji].constructName = NULL; }
00531
00532 if (bdp->next != -1L)
00533 { DefmoduleData(theEnv)->PortItemArray[obji].next = (struct portItem *) &DefmoduleData(theEnv)->PortItemArray[bdp->next]; }
00534 else
00535 { DefmoduleData(theEnv)->PortItemArray[obji].next = NULL; }
00536 }
00537
00538
00539
00540
00541
00542 static void ClearBload(
00543 void *theEnv)
00544 {
00545 long i;
00546 size_t space;
00547 struct portItem *theList;
00548
00549
00550
00551
00552
00553
00554 for (i = 0; i < DefmoduleData(theEnv)->BNumberOfDefmodules; i++)
00555 {
00556 DecrementSymbolCount(theEnv,DefmoduleData(theEnv)->DefmoduleArray[i].name);
00557 for (theList = DefmoduleData(theEnv)->DefmoduleArray[i].importList;
00558 theList != NULL;
00559 theList = theList->next)
00560 {
00561 if (theList->moduleName != NULL) DecrementSymbolCount(theEnv,theList->moduleName);
00562 if (theList->constructType != NULL) DecrementSymbolCount(theEnv,theList->constructType);
00563 if (theList->constructName != NULL) DecrementSymbolCount(theEnv,theList->constructName);
00564 }
00565
00566 for (theList = DefmoduleData(theEnv)->DefmoduleArray[i].exportList;
00567 theList != NULL;
00568 theList = theList->next)
00569 {
00570 if (theList->moduleName != NULL) DecrementSymbolCount(theEnv,theList->moduleName);
00571 if (theList->constructType != NULL) DecrementSymbolCount(theEnv,theList->constructType);
00572 if (theList->constructName != NULL) DecrementSymbolCount(theEnv,theList->constructName);
00573 }
00574
00575 rm(theEnv,DefmoduleData(theEnv)->DefmoduleArray[i].itemsArray,sizeof(void *) * GetNumberOfModuleItems(theEnv));
00576 }
00577
00578
00579
00580
00581
00582
00583 space = DefmoduleData(theEnv)->BNumberOfDefmodules * sizeof(struct defmodule);
00584 if (space != 0) genfree(theEnv,(void *) DefmoduleData(theEnv)->DefmoduleArray,space);
00585 DefmoduleData(theEnv)->BNumberOfDefmodules = 0;
00586
00587
00588
00589
00590
00591
00592 space = DefmoduleData(theEnv)->NumberOfPortItems * sizeof(struct portItem);
00593 if (space != 0) genfree(theEnv,(void *) DefmoduleData(theEnv)->PortItemArray,space);
00594 DefmoduleData(theEnv)->NumberOfPortItems = 0;
00595
00596
00597
00598
00599
00600 SetListOfDefmodules(theEnv,NULL);
00601 CreateMainModule(theEnv);
00602 DefmoduleData(theEnv)->MainModuleRedefinable = TRUE;
00603 }
00604
00605 #endif
00606
00607