--- gforth/Attic/engine.c 1995/12/10 19:02:07 1.32 +++ gforth/Attic/engine.c 1997/02/16 20:51:07 1.40 @@ -19,6 +19,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include "config.h" #include #include #include @@ -44,19 +45,6 @@ #define IOR(flag) ((flag)? -512-errno : 0) -typedef union { - struct { -#ifdef WORDS_BIGENDIAN - Cell high; - Cell low; -#else - Cell low; - Cell high; -#endif; - } cells; - DCell dcell; -} Double_Store; - typedef struct F83Name { struct F83Name *next; /* the link field for old hands */ char countetc; @@ -68,52 +56,46 @@ typedef struct F83Name { #define F83NAME_SMUDGE(np) (((np)->countetc & 0x40) != 0) #define F83NAME_IMMEDIATE(np) (((np)->countetc & 0x20) != 0) -#ifdef USE_TOS -#define IF_TOS(x) x -#else -#define IF_TOS(x) -#define TOS (sp[0]) -#endif - -#ifdef USE_FTOS -#define IF_FTOS(x) x -#else -#define IF_FTOS(x) -#define FTOS (fp[0]) -#endif - Cell *SP; Float *FP; +Address UP=NULL; + +#if 0 +/* not used currently */ int emitcounter; +#endif #define NULLC '\0' char *cstr(Char *from, UCell size, int clear) -/* if clear is true, scratch can be reused, otherwise we want more of - the same */ +/* return a C-string corresponding to the Forth string ( FROM SIZE ). + the C-string lives until the next call of cstr with CLEAR being true */ { - static char *scratch=NULL; - static unsigned scratchsize=0; - static char *nextscratch; - char *oldnextscratch; + static struct cstr_buffer { + char *buffer; + size_t size; + } *buffers=NULL; + static int nbuffers=0; + static int used=0; + struct cstr_buffer *b; + if (buffers==NULL) + buffers=malloc(0); if (clear) - nextscratch=scratch; - if (scratch==NULL) { - scratch=malloc(size+1); - nextscratch=scratch; - scratchsize=size; + used=0; + if (used>=nbuffers) { + buffers=realloc(buffers,sizeof(struct cstr_buffer)*(used+1)); + buffers[used]=(struct cstr_buffer){malloc(0),0}; + nbuffers=used+1; } - else if (nextscratch+size>scratch+scratchsize) { - char *oldscratch=scratch; - scratch = realloc(scratch, (nextscratch-scratch)+size+1); - nextscratch=scratch+(nextscratch-oldscratch); - scratchsize=size; + b=&buffers[used]; + if (size+1 > b->size) { + b->buffer = realloc(b->buffer,size+1); + b->size = size+1; } - memcpy(nextscratch,from,size); - nextscratch[size]='\0'; - oldnextscratch = nextscratch; - nextscratch += size+1; - return oldnextscratch; + memcpy(b->buffer,from,size); + b->buffer[size]='\0'; + used++; + return b->buffer; } char *tilde_cstr(Char *from, UCell size, int clear) @@ -127,10 +109,12 @@ char *tilde_cstr(Char *from, UCell size, return cstr(from, size, clear); if (size<2 || from[1]=='/') { s1 = (char *)getenv ("HOME"); + if(s1 == NULL) + s1 = ""; s2 = from+1; s2_len = size-1; } else { - int i; + UCell i; for (i=1; i