--- gforth/engine/engine.c 2001/12/01 20:33:14 1.32 +++ gforth/engine/engine.c 2002/01/20 19:04:11 1.39 @@ -19,6 +19,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. */ +undefine(`symbols') + #include "config.h" #include "forth.h" #include @@ -280,14 +282,6 @@ static int ufileattr[6]= { # define CPU_DEP1 0 #endif -/* declare and compute cfa for certain threading variants */ -/* warning: this is nonsyntactical; it will not work in place of a statement */ -#ifndef GETCFA -#define DOCFA -#else -#define DOCFA Xt cfa; GETCFA(cfa) -#endif - /* instructions containing these must be the last instruction of a super-instruction (e.g., branches, EXECUTE, and other instructions ending the basic block). Instructions containing SET_IP get this @@ -300,6 +294,7 @@ static int ufileattr[6]= { #else #define SUPER_END #endif +#define SUPER_CONTINUE #ifdef GFORTH_DEBUGGING /* define some VM registers as global variables, so they survive exceptions; @@ -309,7 +304,22 @@ Xt *ip; Cell *rp; #endif +#ifdef DEBUG +#define CFA_TO_NAME(__cfa) \ + Cell len, i; \ + char * name = __cfa; \ + for(i=0; i<32; i+=sizeof(Cell)) { \ + len = ((Cell*)name)[-1]; \ + if(len < 0) { \ + len &= 0x1F; \ + if((len+sizeof(Cell)) > i) break; \ + } len = 0; \ + name -= sizeof(Cell); \ + } +#endif + Xt *primtable(Label symbols[], Cell size) + /* used in primitive primtable for peephole optimization */ { #ifdef DIRECT_THREADED return symbols; @@ -323,7 +333,9 @@ Xt *primtable(Label symbols[], Cell size #endif /* !defined(DIRECT_THREADED) */ } -Label *engine(Xt *ip0, Cell *sp0, Cell *rp0, Float *fp0, Address lp0) + +define(enginerest, +`(Xt *ip0, Cell *sp0, Cell *rp0, Float *fp0, Address lp0) /* executes code at ip, if ip!=NULL returns array of machine code labels (for use in a loader), if ip==NULL */ @@ -335,9 +347,7 @@ Label *engine(Xt *ip0, Cell *sp0, Cell * register Cell *sp SPREG = sp0; register Float *fp FPREG = fp0; register Address lp LPREG = lp0; -#ifdef CFA_NEXT register Xt cfa CFAREG; -#endif #ifdef MORE_VARS MORE_VARS #endif @@ -360,10 +370,18 @@ Label *engine(Xt *ip0, Cell *sp0, Cell * (Label)&&dofield, (Label)&&dodoes, /* the following entry is normally unused; - it's there because its index indicates a does-handler */ + it is there because its index indicates a does-handler */ CPU_DEP1, +#define INST_ADDR(name) (Label)&&I_##name +#include "prim_lab.i" +#undef INST_ADDR + (Label)&&after_last, + (Label)0, +#ifdef IN_ENGINE2 +#define INST_ADDR(name) (Label)&&J_##name #include "prim_lab.i" - (Label)0 +#undef INST_ADDR +#endif }; #ifdef CPU_DEP2 CPU_DEP2 @@ -379,19 +397,22 @@ Label *engine(Xt *ip0, Cell *sp0, Cell * if (ip == NULL) { #if defined(DOUBLY_INDIRECT) -#define CODE_OFFSET (22*sizeof(Cell)) +#define CODE_OFFSET (26*sizeof(Cell)) +#define XT_OFFSET (22*sizeof(Cell)) int i; Cell code_offset = offset_image? CODE_OFFSET : 0; + Cell xt_offset = offset_image? XT_OFFSET : 0; symbols = (Label *)(malloc(MAX_SYMBOLS*sizeof(Cell)+CODE_OFFSET)+code_offset); + xts = (Label *)(malloc(MAX_SYMBOLS*sizeof(Cell)+XT_OFFSET)+xt_offset); for (i=0; i=MAX_SYMBOLS) { fprintf(stderr,"gforth-ditc: more than %d primitives\n",MAX_SYMBOLS); exit(1); } - symbols[i] = &routines[i]; + xts[i] = symbols[i] = &routines[i]; } #endif /* defined(DOUBLY_INDIRECT) */ return symbols; @@ -411,9 +432,12 @@ Label *engine(Xt *ip0, Cell *sp0, Cell * docol: { - DOCFA; #ifdef DEBUG - fprintf(stderr,"%08lx: col: %08lx\n",(Cell)ip,(Cell)PFA1(cfa)); + { + CFA_TO_NAME(cfa); + fprintf(stderr,"%08lx: col: %08lx %.*s\n",(Cell)ip,(Cell)PFA1(cfa), + len,name); + } #endif #ifdef CISC_NEXT /* this is the simple version */ @@ -437,7 +461,6 @@ Label *engine(Xt *ip0, Cell *sp0, Cell * docon: { - DOCFA; #ifdef DEBUG fprintf(stderr,"%08lx: con: %08lx\n",(Cell)ip,*(Cell*)PFA1(cfa)); #endif @@ -453,7 +476,6 @@ Label *engine(Xt *ip0, Cell *sp0, Cell * dovar: { - DOCFA; #ifdef DEBUG fprintf(stderr,"%08lx: var: %08lx\n",(Cell)ip,(Cell)PFA1(cfa)); #endif @@ -469,7 +491,6 @@ Label *engine(Xt *ip0, Cell *sp0, Cell * douser: { - DOCFA; #ifdef DEBUG fprintf(stderr,"%08lx: user: %08lx\n",(Cell)ip,(Cell)PFA1(cfa)); #endif @@ -485,7 +506,6 @@ Label *engine(Xt *ip0, Cell *sp0, Cell * dodefer: { - DOCFA; #ifdef DEBUG fprintf(stderr,"%08lx: defer: %08lx\n",(Cell)ip,*(Cell*)PFA1(cfa)); #endif @@ -495,7 +515,6 @@ Label *engine(Xt *ip0, Cell *sp0, Cell * dofield: { - DOCFA; #ifdef DEBUG fprintf(stderr,"%08lx: field: %08lx\n",(Cell)ip,(Cell)PFA1(cfa)); #endif @@ -523,8 +542,6 @@ Label *engine(Xt *ip0, Cell *sp0, Cell * */ { - DOCFA; - /* fprintf(stderr, "Got CFA %08lx at doescode %08lx/%08lx: does: %08lx\n",cfa,(Cell)ip,(Cell)PFA(cfa),(Cell)DOES_CODE1(cfa));*/ #ifdef DEBUG fprintf(stderr,"%08lx/%08lx: does: %08lx\n",(Cell)ip,(Cell)PFA(cfa),(Cell)DOES_CODE1(cfa)); @@ -544,5 +561,20 @@ Label *engine(Xt *ip0, Cell *sp0, Cell * } NEXT; +#ifndef IN_ENGINE2 +#define LABEL(name) I_##name +#else +#define LABEL(name) J_##name: asm(".skip 16"); I_##name +#endif #include "prim.i" -} +#undef LABEL + after_last: return (Label *)0; + /*needed only to get the length of the last primitive */ +}' +) + +Label *engine enginerest + +#define IN_ENGINE2 +Label *engine2 enginerest +