Diff for /gforth/Attic/engine.c between versions 1.13 and 1.16

version 1.13, 1994/08/31 19:42:44 version 1.16, 1994/09/26 20:31:10
Line 41  typedef struct F83Name { Line 41  typedef struct F83Name {
 #define F83NAME_SMUDGE(np)      (((np)->countetc & 0x40) != 0)  #define F83NAME_SMUDGE(np)      (((np)->countetc & 0x40) != 0)
 #define F83NAME_IMMEDIATE(np)   (((np)->countetc & 0x20) != 0)  #define F83NAME_IMMEDIATE(np)   (((np)->countetc & 0x20) != 0)
   
 /* NEXT and NEXT1 are split into several parts to help scheduling */  /* NEXT and NEXT1 are split into several parts to help scheduling,
      unless CISC_NEXT is defined */
   #ifdef CISC_NEXT
   #define NEXT1_P1
   #define NEXT_P1
   #define DEF_CA
 #ifdef DIRECT_THREADED  #ifdef DIRECT_THREADED
 #       define NEXT1_P1  #define NEXT1_P2 ({goto *cfa;})
 #       ifdef i386  
 #               define NEXT1_P2 ({cfa=*ip++; goto *cfa;})  
 #       else  
 #               define NEXT1_P2 ({goto *cfa;})  
 #       endif  
 #       define DEF_CA  
 #else  
 #       define NEXT1_P1 ({ca = *cfa;})  
 #       define NEXT1_P2 ({goto *ca;})  
 #       define DEF_CA   Label ca;  
 #endif  
 #if defined(i386) && defined(DIRECT_THREADED)  
 #       define NEXT_P1  
 #       define NEXT1 ({goto *cfa;})  
 #else  #else
 #       define NEXT_P1 ({cfa = *ip++; NEXT1_P1;})  #define NEXT1_P2 ({goto **cfa;})
 #       define NEXT1 ({DEF_CA NEXT1_P1; NEXT1_P2;})  #endif /* DIRECT_THREADED */
 #endif  #define NEXT_P2 ({cfa = *ip++; NEXT1_P2;})
   #else /* CISC_NEXT */
   #ifdef DIRECT_THREADED
   #define NEXT1_P1
   #define NEXT1_P2 ({goto *cfa;})
   #define DEF_CA
   #else /* DIRECT_THREADED */
   #define NEXT1_P1 ({ca = *cfa;})
   #define NEXT1_P2 ({goto *ca;})
   #define DEF_CA  Label ca;
   #endif /* DIRECT_THREADED */
   #define NEXT_P1 ({cfa=*ip++; NEXT1_P1;})
   #define NEXT_P2 NEXT1_P2
   #endif /* CISC_NEXT */
   
 #define NEXT ({DEF_CA NEXT_P1; NEXT1_P2;})  #define NEXT1 ({DEF_CA NEXT1_P1; NEXT1_P2;})
   #define NEXT ({DEF_CA NEXT_P1; NEXT_P2;})
   
 #ifdef USE_TOS  #ifdef USE_TOS
 #define IF_TOS(x) x  #define IF_TOS(x) x
Line 82  typedef struct F83Name { Line 87  typedef struct F83Name {
 int emitcounter;  int emitcounter;
 #define NULLC '\0'  #define NULLC '\0'
   
 #ifdef copycstr  char *cstr(Char *from, UCell size, int clear)
 #   define cstr(to,from,size)\  /* if clear is true, scratch can be reused, otherwise we want more of
         {       memcpy(to,from,size);\     the same */
                 to[size]=NULLC;}  {
 #else    static char *scratch=NULL;
 char scratch[1024];    static unsigned scratchsize=0;
 int soffset;    static char *nextscratch;
 #   define cstr(from,size) \    char *oldnextscratch;
            ({ char * to = scratch; \  
               memcpy(to,from,size); \    if (clear)
               to[size] = NULLC; \      nextscratch=scratch;
               soffset = size+1; \    if (scratch==NULL) {
               to; \      scratch=malloc(size+1);
            })      nextscratch=scratch;
 #   define cstr1(from,size) \      scratchsize=size;
            ({ char * to = scratch+soffset; \    }
               memcpy(to,from,size); \    else if (nextscratch+size>scratch+scratchsize) {
               to[size] = NULLC; \      char *oldscratch=scratch;
               soffset += size+1; \      scratch = realloc(scratch, (nextscratch-scratch)+size+1);
               to; \      nextscratch=scratch+(nextscratch-oldscratch);
            })      scratchsize=size;
 #endif    }
     memcpy(nextscratch,from,size);
     nextscratch[size]='\0';
     oldnextscratch = nextscratch;
     nextscratch += size+1;
     return oldnextscratch;
   }
   
 #define NEWLINE '\n'  #define NEWLINE '\n'
   
Line 112  static char* fileattr[6]={"r","rb","r+", Line 123  static char* fileattr[6]={"r","rb","r+",
   
 static Address up0=NULL;  static Address up0=NULL;
   
 #if defined(i386) && defined(FORCE_REG)  /* if machine.h has not defined explicit registers, define them as implicit */
 #  define REG(reg) __asm__(reg)  #ifndef IPREG
   #define IPREG
 Label *engine(Xt *ip0, Cell *sp0, Cell *rp, Float *fp, Address lp)  #endif
 {  #ifndef SPREG
    register Xt *ip REG("%esi")=ip0;  #define SPREG
    register Cell *sp REG("%edi")=sp0;  #endif
   #ifndef RPREG
 #else  #define RPREG
 #  define REG(reg)  #endif
   #ifndef FPREG
 Label *engine(Xt *ip, Cell *sp, Cell *rp, Float *fp, Address lp)  #define FPREG
 {  
 #endif  #endif
   #ifndef LPREG
   #define LPREG
   #endif
   #ifndef CFAREG
   #define CFAREG
   #endif
   #ifndef UPREG
   #define UPREG
   #endif
   #ifndef TOSREG
   #define TOSREG
   #endif
   #ifndef FTOSREG
   #define FTOSREG
   #endif
   
   Label *engine(Xt *ip0, Cell *sp0, Cell *rp0, Float *fp0, Address lp0)
 /* executes code at ip, if ip!=NULL  /* executes code at ip, if ip!=NULL
    returns array of machine code labels (for use in a loader), if ip==NULL     returns array of machine code labels (for use in a loader), if ip==NULL
 */  */
   register Xt cfa  {
 #ifdef i386    register Xt *ip IPREG = ip0;
 #  ifdef USE_TOS    register Cell *sp SPREG = sp0;
    REG("%ecx")    register Cell *rp RPREG = rp0;
 #  else    register Float *fp FPREG = fp0;
    REG("%edx")    register Address lp LPREG = lp0;
 #  endif    register Xt cfa CFAREG;
 #endif    register Address up UPREG = up0;
    ;    IF_TOS(register Cell TOS TOSREG;)
   Address up=up0;    IF_FTOS(register Float FTOS FTOSREG;)
   static Label symbols[]= {    static Label symbols[]= {
     &&docol,      &&docol,
     &&docon,      &&docon,
Line 149  Label *engine(Xt *ip, Cell *sp, Cell *rp Line 176  Label *engine(Xt *ip, Cell *sp, Cell *rp
     &&dodoes,  /* dummy for does handler address */      &&dodoes,  /* dummy for does handler address */
 #include "prim_labels.i"  #include "prim_labels.i"
   };    };
   IF_TOS(register Cell TOS;)  
   IF_FTOS(Float FTOS;)  
 #ifdef CPU_DEP  #ifdef CPU_DEP
   CPU_DEP;    CPU_DEP;
 #endif  #endif
   
   #ifdef DEBUG
     fprintf(stderr,"ip=%x, sp=%x, rp=%x, fp=%x, lp=%x, up=%x\n",
             ip,sp,rp,fp,lp,up);
   #endif
   
   if (ip == NULL)    if (ip == NULL)
     return symbols;      return symbols;
   
Line 165  Label *engine(Xt *ip, Cell *sp, Cell *rp Line 195  Label *engine(Xt *ip, Cell *sp, Cell *rp
       
  docol:   docol:
 #ifdef DEBUG  #ifdef DEBUG
   printf("%08x: col: %08x\n",(Cell)ip,(Cell)PFA1(cfa));    fprintf(stderr,"%08x: col: %08x\n",(Cell)ip,(Cell)PFA1(cfa));
 #endif  #endif
 #ifdef i386  #ifdef CISC_NEXT
   /* this is the simple version */    /* this is the simple version */
   *--rp = (Cell)ip;    *--rp = (Cell)ip;
   ip = (Xt *)PFA1(cfa);    ip = (Xt *)PFA1(cfa);
   NEXT;    NEXT;
 #endif  #else
   /* this one is important, so we help the compiler optimizing    /* this one is important, so we help the compiler optimizing
      The following version may be better (for scheduling), but probably has       The following version may be better (for scheduling), but probably has
      problems with code fields employing calls and delay slots       problems with code fields employing calls and delay slots
Line 186  Label *engine(Xt *ip, Cell *sp, Cell *rp Line 216  Label *engine(Xt *ip, Cell *sp, Cell *rp
     ip = current_ip+1;      ip = current_ip+1;
     NEXT1_P2;      NEXT1_P2;
   }    }
   #endif
       
  docon:   docon:
 #ifdef DEBUG  #ifdef DEBUG
   printf("%08x: con: %08x\n",(Cell)ip,*(Cell*)PFA1(cfa));    fprintf(stderr,"%08x: con: %08x\n",(Cell)ip,*(Cell*)PFA1(cfa));
 #endif  #endif
 #ifdef USE_TOS  #ifdef USE_TOS
   *sp-- = TOS;    *sp-- = TOS;
Line 201  Label *engine(Xt *ip, Cell *sp, Cell *rp Line 232  Label *engine(Xt *ip, Cell *sp, Cell *rp
       
  dovar:   dovar:
 #ifdef DEBUG  #ifdef DEBUG
   printf("%08x: var: %08x\n",(Cell)ip,(Cell)PFA1(cfa));    fprintf(stderr,"%08x: var: %08x\n",(Cell)ip,(Cell)PFA1(cfa));
 #endif  #endif
 #ifdef USE_TOS  #ifdef USE_TOS
   *sp-- = TOS;    *sp-- = TOS;
Line 215  Label *engine(Xt *ip, Cell *sp, Cell *rp Line 246  Label *engine(Xt *ip, Cell *sp, Cell *rp
       
  douser:   douser:
 #ifdef DEBUG  #ifdef DEBUG
   printf("%08x: user: %08x\n",(Cell)ip,(Cell)PFA1(cfa));    fprintf(stderr,"%08x: user: %08x\n",(Cell)ip,(Cell)PFA1(cfa));
 #endif  #endif
 #ifdef USE_TOS  #ifdef USE_TOS
   *sp-- = TOS;    *sp-- = TOS;
Line 227  Label *engine(Xt *ip, Cell *sp, Cell *rp Line 258  Label *engine(Xt *ip, Cell *sp, Cell *rp
       
  dodefer:   dodefer:
 #ifdef DEBUG  #ifdef DEBUG
   printf("%08x: defer: %08x\n",(Cell)ip,(Cell)PFA1(cfa));    fprintf(stderr,"%08x: defer: %08x\n",(Cell)ip,(Cell)PFA1(cfa));
 #endif  #endif
   cfa = *(Xt *)PFA1(cfa);    cfa = *(Xt *)PFA1(cfa);
   NEXT1;    NEXT1;
Line 251  Label *engine(Xt *ip, Cell *sp, Cell *rp Line 282  Label *engine(Xt *ip, Cell *sp, Cell *rp
             
      */       */
 #ifdef DEBUG  #ifdef DEBUG
   printf("%08x/%08x: does: %08x\n",(Cell)ip,(Cell)cfa,*(Cell)PFA(cfa));    fprintf(stderr,"%08x/%08x: does: %08x\n",(Cell)ip,(Cell)cfa,DOES_CODE1(cfa));
   fflush(stdout);    fflush(stderr);
 #endif  #endif
   *--rp = (Cell)ip;    *--rp = (Cell)ip;
   /* PFA1 might collide with DOES_CODE1 here, so we use PFA */    /* PFA1 might collide with DOES_CODE1 here, so we use PFA */
Line 264  Label *engine(Xt *ip, Cell *sp, Cell *rp Line 295  Label *engine(Xt *ip, Cell *sp, Cell *rp
   *--sp = (Cell)PFA(cfa);    *--sp = (Cell)PFA(cfa);
 #endif  #endif
   NEXT;    NEXT;
     
 #include "primitives.i"  #include "primitives.i"
 }  }

Removed from v.1.13  
changed lines
  Added in v.1.16


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