1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
/* stack.h
* tag: stack and stack access functions
*
* Copyright (C) 2003 Patrick Mauritz, Stefan Reinauer
*
* See the file "COPYING" for further information about
* the copyright and warranty status of this work.
*/
#ifndef __STACK_H
#define __STACK_H
#define dstacksize 512
extern int dstackcnt;
extern cell dstack[dstacksize];
#define rstacksize 512
extern int rstackcnt;
extern cell rstack[rstacksize];
extern int dbgrstackcnt;
//typedef struct opaque_xt *xt_t;
//typedef struct opaque_ihandle *ihandle_t;
//typedef struct opaque_phandle *phandle_t;
typedef ucell xt_t;
typedef ucell ihandle_t;
typedef ucell phandle_t;
static inline void PUSH(ucell value) {
dstack[++dstackcnt] = (value);
}
static inline void PUSH_xt( xt_t xt ) { PUSH( (ucell)xt ); }
static inline void PUSH_ih( ihandle_t ih ) { PUSH( (ucell)ih ); }
static inline void PUSH_ph( phandle_t ph ) { PUSH( (ucell)ph ); }
static inline ucell POP(void) {
return (ucell) dstack[dstackcnt--];
}
static inline xt_t POP_xt( void ) { return (xt_t)POP(); }
static inline ihandle_t POP_ih( void ) { return (ihandle_t)POP(); }
static inline phandle_t POP_ph( void ) { return (phandle_t)POP(); }
static inline void DROP(void) {
dstackcnt--;
}
static inline void DDROP(void) {
dstackcnt -= 2;
}
static inline void DPUSH(ducell value) {
#ifdef NEED_FAKE_INT128_T
dstack[++dstackcnt] = (cell) value.lo;
dstack[++dstackcnt] = (cell) value.hi;
#else
dstack[++dstackcnt] = (cell) value;
dstack[++dstackcnt] = (cell) (value >> bitspercell);
#endif
}
static inline ducell DPOP(void) {
#ifdef NEED_FAKE_INT128_T
ducell du;
du.hi = (ucell) dstack[dstackcnt--];
du.lo = (ucell) dstack[dstackcnt--];
return du;
#else
ducell du;
du = ((ducell)(ucell) dstack[dstackcnt--]) << bitspercell;
du |= (ucell) dstack[dstackcnt--];
return du;
#endif
}
static inline ucell GETTOS(void) {
return dstack[dstackcnt];
}
#define GETITEM(number) (dstack[dstackcnt - number])
static inline void PUSHR(ucell value) {
rstack[++rstackcnt] = (value);
}
static inline ucell POPR(void) {
return (ucell) rstack[rstackcnt--];
}
static inline ucell GETTORS(void) {
return rstack[rstackcnt];
}
#if defined(DEBUG_DSTACK) || defined(FCOMPILER)
void printdstack(void);
#endif
#if defined(DEBUG_RSTACK) || defined(FCOMPILER)
void printrstack(void);
#endif
#endif
|