--- gforth/vmgen-ex2/engine.c 2002/06/02 15:46:17 1.1 +++ gforth/vmgen-ex2/engine.c 2002/06/02 17:02:56 1.2 @@ -53,6 +53,7 @@ #endif #endif /* defined(THREADING_SCHEME) */ +#ifdef __GNUC__ #if THREADING_SCHEME==1 /* direct threading scheme 1: autoinc, long latency (HPPA, Sharc) */ # define NEXT_P0 ({cfa=*ip++;}) @@ -135,14 +136,35 @@ #define IPTOS ((Cell)(NEXT_INST)) #define CASE +#define INST_ADDR(name) (Label)&&I_##name +#define LABEL(name) I_##name +#else /* !defined(__GNUC__) */ +/* use switch dispatch */ +#define DEF_CA +#define NEXT_P0 +#define NEXT_P1 +#define NEXT_P2 goto next_inst; +#define SET_IP(p) (ip=(p)) +#define IP ip +#define NEXT_INST (*ip) +#define INC_IP(const_inc) (ip+=(const_inc)) +#define IPTOS NEXT_INST +#define INST_ADDR(name) I_##name +#define LABEL(name) case I_##name + +#endif /* !defined(__GNUC__) */ + #ifdef VM_PROFILING #define SUPER_END vm_count_block(IP) #else #define SUPER_END #endif -#define INST_ADDR(name) (Label)&&I_##name -#define LABEL(name) I_##name +#ifndef __GNUC__ +enum { +#include "mini-labels.i" +}; +#endif /* the return type can be anything you want it to */ long engine(Cell *ip0, Cell *sp, char *fp) @@ -175,7 +197,17 @@ long engine(Cell *ip0, Cell *sp, char *f SET_IP(ip0); SUPER_END; /* count the BB starting at ip0 */ - NEXT; +#ifdef __GNUC__ + NEXT; #include "mini-vm.i" +#else + next_inst: + switch((*ip++).inst) { +#include "mini-vm.i" + default: + fprintf(stderr,"unknown instruction %d at %p\n", ip[-1], ip-1); + exit(1); + } +#endif }