--- gforth/vmgen-ex2/engine.c 2002/06/02 15:46:17 1.1 +++ gforth/vmgen-ex2/engine.c 2002/08/20 07:59:02 1.4 @@ -21,8 +21,6 @@ #include "mini.h" -#define vm_Cell2Cell(_x,_y) ((_y)=(_x)) - #define USE_spTOS 1 #ifdef USE_spTOS @@ -53,6 +51,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++;}) @@ -133,7 +132,26 @@ #define NEXT ({DEF_CA NEXT_P1; NEXT_P2;}) #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__) */ + +#define LABEL2(x) #ifdef VM_PROFILING #define SUPER_END vm_count_block(IP) @@ -141,8 +159,11 @@ #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 +196,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 }