--- gforth/Attic/engine.c 1994/02/11 16:30:46 1.1 +++ gforth/Attic/engine.c 1994/05/18 17:29:52 1.6 @@ -1,5 +1,5 @@ /* - $Id: engine.c,v 1.1 1994/02/11 16:30:46 anton Exp $ + $Id: engine.c,v 1.6 1994/05/18 17:29:52 pazsan Exp $ Copyright 1992 by the ANSI figForth Development Group */ @@ -12,11 +12,17 @@ #include #include #include +#include +#include #include "forth.h" #include "io.h" -extern unlink(char *); -extern ftruncate(int, int); +#ifndef unlink + extern unlink(char *); +#endif +#ifndef ftruncate + extern ftruncate(int, int); +#endif typedef union { struct { @@ -44,16 +50,18 @@ typedef struct F83Name { /* NEXT and NEXT1 are split into several parts to help scheduling */ #ifdef DIRECT_THREADED -#define NEXT1_P1 -#define NEXT1_P2 ({goto *cfa;}) -#else -#define NEXT1_P1 ({ca = *cfa;}) -#define NEXT1_P2 ({goto *ca;}) +# define NEXT1_P1 +# define NEXT1_P2 ({goto *cfa;}) +# define DEF_CA +#else +# define NEXT1_P1 ({ca = *cfa;}) +# define NEXT1_P2 ({goto *ca;}) +# define DEF_CA Label ca; #endif #define NEXT_P1 ({cfa = *ip++; NEXT1_P1;}) -#define NEXT1 ({NEXT1_P1; NEXT1_P2;}) -#define NEXT ({NEXT_P1; NEXT1_P2;}) +#define NEXT1 ({DEF_CA NEXT1_P1; NEXT1_P2;}) +#define NEXT ({DEF_CA NEXT_P1; NEXT1_P2;}) #ifdef USE_TOS #define IF_TOS(x) x @@ -69,36 +77,56 @@ typedef struct F83Name { #define FTOS (fp[0]) #endif -#define DODOES (symbols[3]) - int emitcounter; #define NULLC '\0' -#define cstr(to, from, size)\ - { memcpy(to, from, size);\ +#define cstr(to,from,size)\ + { memcpy(to,from,size);\ to[size]=NULLC;} #define NEWLINE '\n' static char* fileattr[6]={"r","rb","r+","r+b","w+","w+b"}; -Label *engine(Xt *ip, Cell *sp, Cell *rp, Float *fp) +#if ~defined(select) && defined(DOS) +/* select replacement for DOS computers for ms only */ +void select(int n, int a, int b, int c, struct timeval * timeout) +{ + struct timeval time1; + struct timeval time2; + struct timezone zone1; + + gettimeofday(&time1,&zone1); + time1.tv_sec += timeout->tv_sec; + time1.tv_usec += timeout->tv_usec; + while(time1.tv_usec >= 1000000) + { + time1.tv_usec -= 1000000; + time1.tv_sec++; + } + do + { + gettimeofday(&time2,&zone1); + } + while(time2.tv_usec < time1.tv_usec || time2.tv_sec < time1.tv_sec); +} +#endif + +Label *engine(Xt *ip, Cell *sp, Cell *rp, Float *fp, Address lp) /* executes code at ip, if ip!=NULL returns array of machine code labels (for use in a loader), if ip==NULL - This is very preliminary, as the bootstrap architecture is not yet decided */ { Xt cfa; - Address lp=NULL; + Address up=NULL; static Label symbols[]= { &&docol, &&docon, &&dovar, + &&douser, &&dodoes, + &&dodoes, /* dummy for does handler address */ #include "prim_labels.i" }; -#ifndef DIRECT_THREADED - Label ca; -#endif IF_TOS(register Cell TOS;) IF_FTOS(Float FTOS;) #ifdef CPU_DEP @@ -115,7 +143,7 @@ Label *engine(Xt *ip, Cell *sp, Cell *rp docol: #ifdef DEBUG - printf("col: %x\n",(Cell)PFA1(cfa)); + printf("%08x: col: %08x\n",(Cell)ip,(Cell)PFA1(cfa)); #endif #ifdef undefined /* this is the simple version */ @@ -128,17 +156,18 @@ Label *engine(Xt *ip, Cell *sp, Cell *rp problems with code fields employing calls and delay slots */ { + DEF_CA Xt *current_ip = (Xt *)PFA1(cfa); cfa = *current_ip; NEXT1_P1; *--rp = (Cell)ip; ip = current_ip+1; + NEXT1_P2; } - NEXT1_P2; docon: #ifdef DEBUG - printf("con: %x\n",*(Cell*)PFA1(cfa)); + printf("%08x: con: %08x\n",(Cell)ip,*(Cell*)PFA1(cfa)); #endif #ifdef USE_TOS *sp-- = TOS; @@ -150,7 +179,7 @@ Label *engine(Xt *ip, Cell *sp, Cell *rp dovar: #ifdef DEBUG - printf("var: %x\n",(Cell)PFA1(cfa)); + printf("%08x: var: %08x\n",(Cell)ip,(Cell)PFA1(cfa)); #endif #ifdef USE_TOS *sp-- = TOS; @@ -162,6 +191,18 @@ Label *engine(Xt *ip, Cell *sp, Cell *rp /* !! user? */ + douser: +#ifdef DEBUG + printf("%08x: user: %08x\n",(Cell)ip,(Cell)PFA1(cfa)); +#endif +#ifdef USE_TOS + *sp-- = TOS; + TOS = (Cell)(up+*(Cell*)PFA1(cfa)); +#else + *--sp = (Cell)(up+*(Cell*)PFA1(cfa)); +#endif + NEXT; + dodoes: /* this assumes the following structure: defining-word: @@ -181,7 +222,8 @@ Label *engine(Xt *ip, Cell *sp, Cell *rp */ #ifdef DEBUG - printf("does: %x\n",(Cell)PFA(cfa)); + printf("%08x/%08x: does: %08x\n",(Cell)ip,(Cell)cfa,*(Cell)PFA(cfa)); + fflush(stdout); #endif *--rp = (Cell)ip; /* PFA1 might collide with DOES_CODE1 here, so we use PFA */