--- gforth/Attic/engine.c 1994/02/11 16:30:46 1.1 +++ gforth/Attic/engine.c 1994/06/01 16:40:01 1.8 @@ -1,5 +1,5 @@ /* - $Id: engine.c,v 1.1 1994/02/11 16:30:46 anton Exp $ + $Id: engine.c,v 1.8 1994/06/01 16:40:01 pazsan Exp $ Copyright 1992 by the ANSI figForth Development Group */ @@ -12,12 +12,12 @@ #include #include #include +#include +#include +#include #include "forth.h" #include "io.h" -extern unlink(char *); -extern ftruncate(int, int); - typedef union { struct { #ifdef BIG_ENDIAN @@ -44,16 +44,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 +71,32 @@ 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) +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 +113,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 +126,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 +149,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 +161,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 +192,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 */