Diff for /gforth/engine/main.c between versions 1.113 and 1.114

version 1.113, 2003/08/01 08:11:26 version 1.114, 2003/08/03 06:27:36
Line 637  static char superend[]={ Line 637  static char superend[]={
   
 Cell npriminfos=0;  Cell npriminfos=0;
   
 int compare_li(const void *pa, const void *pb)  int compare_labels(const void *pa, const void *pb)
 {  {
     Label a = *(Label *)pa;
     Label b = *(Label *)pb;
     return a-b;
   }
   
   int a = *(int *)pa;  Label bsearch_next(Label key, Label *a, UCell n)
   int b = *(int *)pb;       /* a is sorted; return the label >=key that is the closest in a;
   Cell r = vm_prims[a]-vm_prims[b];          return NULL if there is no label in a >=key */
   if (r == 0)  {
     return b - a; /* K labels should be sorted before I labels    int mid = (n-1)/2;
                      for the same address */    if (n<1)
   return r;      return NULL;
     if (n == 1) {
       if (a[0] < key)
         return NULL;
       else
         return a[0];
     }
     if (a[mid] < key)
       return bsearch_next(key, a+mid+1, n-mid-1);
     else
       return bsearch_next(key, a, mid+1);
 }  }
   
 void check_prims(Label symbols1[])  void check_prims(Label symbols1[])
 {  {
   int i;    int i;
 #ifndef NO_DYNAMIC  #ifndef NO_DYNAMIC
   Label *symbols2, *symbols3, *ends1, *ends1k;    Label *symbols2, *symbols3, *ends1, *ends1k, *ends1ksorted;
   int *labelindexes, *sortindexes, nlabelindexes;    int nends1k;
 #endif  #endif
   
   if (debug)    if (debug)
Line 680  void check_prims(Label symbols1[]) Line 694  void check_prims(Label symbols1[])
 #endif  #endif
   ends1 = symbols1+i+1-DOESJUMP;    ends1 = symbols1+i+1-DOESJUMP;
   ends1k =   ends1+i+1-DOESJUMP;    ends1k =   ends1+i+1-DOESJUMP;
     nends1k = i+1-DOESJUMP;
   /* produce a sortindexes: sortindexes[i] gives the rank of symbols1[i] */    ends1ksorted = (Label *)alloca(nends1k*sizeof(Label));
   nlabelindexes = 3*(i+1-DOESJUMP)+DOESJUMP;    memcpy(ends1ksorted,ends1k,nends1k*sizeof(Label));
   labelindexes = (int *)alloca(nlabelindexes*sizeof(int));    qsort(ends1ksorted, nends1k, sizeof(Label), compare_labels);
   for (i=0; i<nlabelindexes; i++)  
     labelindexes[i] = i;  
   qsort(labelindexes, nlabelindexes, sizeof(int), compare_li);  
   sortindexes = (int *)alloca(nlabelindexes*sizeof(int));  
   for (i=0; i<nlabelindexes; i++)  
     sortindexes[labelindexes[i]] = i;  
       
   priminfos = calloc(i,sizeof(PrimInfo));    priminfos = calloc(i,sizeof(PrimInfo));
   for (i=DOESJUMP+1; symbols1[i+1]!=0; i++) {    for (i=DOESJUMP+1; symbols1[i+1]!=0; i++) {
Line 699  void check_prims(Label symbols1[]) Line 707  void check_prims(Label symbols1[])
     char *s1 = (char *)symbols1[i];      char *s1 = (char *)symbols1[i];
     char *s2 = (char *)symbols2[i];      char *s2 = (char *)symbols2[i];
     char *s3 = (char *)symbols3[i];      char *s3 = (char *)symbols3[i];
     int endindex = labelindexes[sortindexes[i]+2];      Label endlabel = bsearch_next(symbols1[i]+1,ends1ksorted,nends1k);
     Label endlabel = symbols1[endindex];  
   
     pi->start = s1;      pi->start = s1;
     pi->superend = superend[i-DOESJUMP-1]|no_super;      pi->superend = superend[i-DOESJUMP-1]|no_super;
Line 713  void check_prims(Label symbols1[]) Line 720  void check_prims(Label symbols1[])
     if (debug)      if (debug)
       fprintf(stderr, "Prim %3d @ %p %p %p, length=%3ld restlength=%2ld superend=%1d",        fprintf(stderr, "Prim %3d @ %p %p %p, length=%3ld restlength=%2ld superend=%1d",
               i, s1, s2, s3, (long)(pi->length), (long)(pi->restlength), pi->superend);                i, s1, s2, s3, (long)(pi->length), (long)(pi->restlength), pi->superend);
     if (sortindexes[i]+1 != sortindexes[i+npriminfos+1-DOESJUMP]) {      if (endlabel == NULL) {
         pi->start = NULL; /* not relocatable */
         if (debug)
           fprintf(stderr,"\n   non_reloc: no K label > start found\n");
         continue;
       }
       if (ends1[i] > endlabel && !pi->superend) {
       pi->start = NULL; /* not relocatable */        pi->start = NULL; /* not relocatable */
       if (debug)        if (debug)
         fprintf(stderr,"\n   non_reloc: rank[start] = %d, rank[J] = %d\n",          fprintf(stderr,"\n   non_reloc: there is a K label before the J label (restlength<0)\n");
                 sortindexes[i], sortindexes[i+npriminfos+1-DOESJUMP]);  
       continue;        continue;
     }      }
     if (endindex < (ends1k - symbols1)) { /* is endindex not a K-label? */      if (ends1[i] < pi->start && !pi->superend) {
       pi->start = NULL; /* not relocatable */        pi->start = NULL; /* not relocatable */
       if (debug)        if (debug)
         fprintf(stderr,"\n   non_reloc: endindex = %d\n", endindex);          fprintf(stderr,"\n   non_reloc: J label before I label (length<0)\n");
       continue;        continue;
     }      }
     assert(prim_len>=0);      assert(prim_len>=0);

Removed from v.1.113  
changed lines
  Added in v.1.114


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>