Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Diff of /sml/trunk/src/runtime/kernel/boot.c
ViewVC logotype

Diff of /sml/trunk/src/runtime/kernel/boot.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 139, Mon Sep 7 21:11:35 1998 UTC revision 223, Sat Apr 17 16:27:01 1999 UTC
# Line 29  Line 29 
29  pers_id_t       RunTimePerID = {RUNTIME_PERID};  pers_id_t       RunTimePerID = {RUNTIME_PERID};
30    
31    
32  /* The persistent ID list is stored in the PervStruct refcell.  It is a  /* The persistent ID list is stored in the PervStruct refcell.  It has
33   * list of (PerID, ML-object) pairs.   * the following ML type:
34     *
35     *    datatype runDynEnv
36     *      = NILrde
37     *      | CONSrde of (Word8Vector.vector * Object.object * runDynEnv)
38   */   */
39  #define PerIDList       (*PTR_MLtoC(ml_val_t, PervStruct))  #define PerIDList       (*PTR_MLtoC(ml_val_t, PervStruct))
40    
# Line 77  Line 81 
81    
82    /* boot the system */    /* boot the system */
83      while (BinFileList != LIST_nil) {      while (BinFileList != LIST_nil) {
84          strcpy(fname, PTR_MLtoC(char, LIST_hd(BinFileList)));          strcpy(fname, STR_MLtoC(LIST_hd(BinFileList)));
85          Say ("[Loading %s]\n", fname);          Say ("[Loading %s]\n", fname);
86          BinFileList = LIST_tl(BinFileList);          BinFileList = LIST_tl(BinFileList);
87          LoadBinFile (msp, binDir, fname);          LoadBinFile (msp, binDir, fname);
# Line 386  Line 390 
390              Die ("cannot seek on bin file \"%s%c%s\"", binDir, PATH_ARC_SEP, fname);              Die ("cannot seek on bin file \"%s%c%s\"", binDir, PATH_ARC_SEP, fname);
391      }      }
392    
393    /* Read code objects and run them.  We add a comment string to each code    /* Read code objects and run them.  The first code object will be the
394     * object to mark which bin file it came from.  This code should be the     * data segment.  We add a comment string to each code object to mark
395     * same as that in ../c-libs/smlnj-runtime/mkcode.c.     * which bin file it came from.  This code should be the same as that
396       * in ../c-libs/smlnj-runtime/mkcode.c.
397     */     */
398      isDataSeg = TRUE;  
     val = ML_nil;  
399      remainingCode = hdr.codeSzB;      remainingCode = hdr.codeSzB;
400    
401      /* read the size for the data object */
402        ReadBinFile (file, &thisSzB, sizeof(Int32_t), binDir, fname);
403        thisSzB = BIGENDIAN_TO_HOST(thisSzB);
404    
405        remainingCode -= thisSzB + sizeof(Int32_t);
406        if (remainingCode < 0)
407            Die ("format error (data size mismatch) in bin file \"%s%c%s\"",
408                binDir, PATH_ARC_SEP, fname);
409    
410        if (thisSzB > 0) {
411            Byte_t          *dataObj = NEW_VEC(Byte_t, thisSzB);
412    
413            ReadBinFile (file, dataObj, thisSzB, binDir, fname);
414            SaveCState (msp, &BinFileList, &importRec, NIL(ml_val_t *));
415            val = BuildLiterals (msp, dataObj, thisSzB);
416            FREE(dataObj);
417            RestoreCState (msp, &BinFileList, &importRec, NIL(ml_val_t *));
418        }
419        else {
420            val = ML_unit;
421        }
422      /* do a functional update of the last element of the importRec. */
423        for (i = 0;  i < importRecLen;  i++)
424            ML_AllocWrite(msp, i, PTR_MLtoC(ml_val_t, importRec)[i-1]);
425        ML_AllocWrite(msp, importRecLen, val);
426        val = ML_Alloc(msp, importRecLen);
427      /* do a GC, if necessary */
428        if (NeedGC (msp, PERID_LEN+REC_SZB(5)))
429            InvokeGCWithRoots (msp, 0, &BinFileList, &val, NIL(ml_val_t *));
430    
431      while (remainingCode > 0) {      while (remainingCode > 0) {
432          int             strLen = strlen(fname);          int             strLen, padLen, extraLen;
         int             padLen, extraLen;  
433    
434        /* read the size for this code object */        /* read the size for this code object */
435          ReadBinFile (file, &thisSzB, sizeof(Int32_t), binDir, fname);          ReadBinFile (file, &thisSzB, sizeof(Int32_t), binDir, fname);
# Line 406  Line 440 
440         * length byte is WORD_SZB bytes.  The padding is inserted between         * length byte is WORD_SZB bytes.  The padding is inserted between
441         * the code and the string.         * the code and the string.
442         */         */
443            strLen = strlen(fname);
444          if (strLen > 255)          if (strLen > 255)
445              strLen = 255;              strLen = 255;
446          extraLen = strLen+1;  /* include byte for length */          extraLen = strLen+1;  /* include byte for length */
# Line 420  Line 455 
455    
456        /* allocate space and read code object */        /* allocate space and read code object */
457          codeObj = ML_AllocCode (msp, thisSzB+extraLen);          codeObj = ML_AllocCode (msp, thisSzB+extraLen);
458          ReadBinFile (file, PTR_MLtoC(void, codeObj), thisSzB, binDir, fname);          ReadBinFile (file, STR_MLtoC(codeObj), thisSzB, binDir, fname);
459    
460        /* tack on the bin-file name as a comment string. */        /* tack on the bin-file name as a comment string. */
461          memcpy (PTR_MLtoC(char, codeObj)+thisSzB+padLen, fname, strLen);          memcpy (STR_MLtoC(codeObj)+thisSzB+padLen, fname, strLen);
462          *(PTR_MLtoC(Byte_t, codeObj)+thisSzB+extraLen-1) = (Byte_t)strLen;          *(GET_SEQ_DATAPTR(Byte_t, codeObj)+thisSzB+extraLen-1) = (Byte_t)strLen;
463    
464          FlushICache (PTR_MLtoC(void, codeObj), thisSzB);          FlushICache (STR_MLtoC(codeObj), thisSzB);
465    
466        /* create closure */        /* create closure */
467          REC_ALLOC1 (msp, closure, PTR_CtoML(PTR_MLtoC(ml_val_t, codeObj) + 1));          REC_ALLOC1 (msp, closure, GET_SEQ_DATA(codeObj));
468    
469        /* apply the closure to the import PerID vector */        /* apply the closure to the import PerID vector */
         if (isDataSeg) {  
             SaveCState (msp, &BinFileList, &importRec, NIL(ml_val_t *));  
             val = ApplyMLFn (msp, closure, val, TRUE);  
             RestoreCState (msp, &BinFileList, &importRec, NIL(ml_val_t *));  
           /* do a functional update of the last element of the importRec. */  
             for (i = 0;  i < importRecLen;  i++)  
                 ML_AllocWrite(msp, i, PTR_MLtoC(ml_val_t, importRec)[i-1]);  
             ML_AllocWrite(msp, importRecLen, val);  
             val = ML_Alloc(msp, importRecLen);  
             isDataSeg = FALSE;  
         }  
         else {  
470              SaveCState (msp, &BinFileList, NIL(ml_val_t *));              SaveCState (msp, &BinFileList, NIL(ml_val_t *));
471              val = ApplyMLFn (msp, closure, val, TRUE);              val = ApplyMLFn (msp, closure, val, TRUE);
472              RestoreCState (msp, &BinFileList, NIL(ml_val_t *));              RestoreCState (msp, &BinFileList, NIL(ml_val_t *));
         }  
473    
474        /* do a GC, if necessary */        /* do a GC, if necessary */
475          if (NeedGC (msp, PERID_LEN+REC_SZB(5)))          if (NeedGC (msp, PERID_LEN+REC_SZB(5)))
# Line 470  Line 492 
492  {  {
493      ml_val_t        mlPerID;      ml_val_t        mlPerID;
494    
495    /* Allocate a string for the PerID */    /* Allocate space for the PerID */
496      mlPerID = ML_AllocString (msp, PERID_LEN);      mlPerID = ML_AllocString (msp, PERID_LEN);
497      memcpy (PTR_MLtoC(char, mlPerID), (char *)perID, PERID_LEN);      memcpy (STR_MLtoC(mlPerID), (char *)perID, PERID_LEN);
498    
499    /* Allocate the list element */    /* Allocate the list element */
500      REC_ALLOC3(msp, PerIDList, mlPerID, obj, PerIDList);      REC_ALLOC3(msp, PerIDList, mlPerID, obj, PerIDList);
# Line 483  Line 505 
505   */   */
506  PVT ml_val_t LookupPerID (pers_id_t *perID)  PVT ml_val_t LookupPerID (pers_id_t *perID)
507  {  {
508      ml_val_t        p;      ml_val_t        p, id;
509    
510      for (p = PerIDList;  p != ML_unit;  p = REC_SEL(p, 2)) {      for (p = PerIDList;  p != ML_unit;  p = REC_SEL(p, 2)) {
511          if (memcmp((char *)perID, REC_SELPTR(char, p, 0), PERID_LEN) == 0)          id = REC_SEL(p, 0);
512            if (memcmp((char *)perID, STR_MLtoC(id), PERID_LEN) == 0)
513              return (REC_SEL(p, 1));              return (REC_SEL(p, 1));
514      }      }
515    

Legend:
Removed from v.139  
changed lines
  Added in v.223

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0