2 * tag: stack and stack access functions
4 * Copyright (C) 2003 Patrick Mauritz, Stefan Reinauer
6 * See the file "COPYING" for further information about
7 * the copyright and warranty status of this work.
13 #define dstacksize 512
15 extern cell dstack
[dstacksize
];
17 #define rstacksize 512
19 extern cell rstack
[rstacksize
];
21 extern int dbgrstackcnt
;
23 //typedef struct opaque_xt *xt_t;
24 //typedef struct opaque_ihandle *ihandle_t;
25 //typedef struct opaque_phandle *phandle_t;
28 typedef ucell ihandle_t
;
29 typedef ucell phandle_t
;
33 #ifdef NATIVE_BITWIDTH_EQUALS_HOST_BITWIDTH
35 static inline ucell
pointer2cell(const void* x
)
37 return (ucell
)(uintptr_t)x
;
40 static inline void* cell2pointer(ucell x
)
42 return (void*)(uintptr_t)x
;
47 static inline void PUSH(ucell value
) {
48 dstack
[++dstackcnt
] = (value
);
50 static inline void PUSH_xt( xt_t xt
) { PUSH( (ucell
)xt
); }
51 static inline void PUSH_ih( ihandle_t ih
) { PUSH( (ucell
)ih
); }
52 static inline void PUSH_ph( phandle_t ph
) { PUSH( (ucell
)ph
); }
54 static inline ucell
POP(void) {
55 return (ucell
) dstack
[dstackcnt
--];
57 static inline xt_t
POP_xt( void ) { return (xt_t
)POP(); }
58 static inline ihandle_t
POP_ih( void ) { return (ihandle_t
)POP(); }
59 static inline phandle_t
POP_ph( void ) { return (phandle_t
)POP(); }
61 static inline void DROP(void) {
65 static inline void DDROP(void) {
69 static inline void DPUSH(ducell value
) {
70 #ifdef NEED_FAKE_INT128_T
71 dstack
[++dstackcnt
] = (cell
) value
.lo
;
72 dstack
[++dstackcnt
] = (cell
) value
.hi
;
74 dstack
[++dstackcnt
] = (cell
) value
;
75 dstack
[++dstackcnt
] = (cell
) (value
>> bitspercell
);
79 static inline ducell
DPOP(void) {
80 #ifdef NEED_FAKE_INT128_T
82 du
.hi
= (ucell
) dstack
[dstackcnt
--];
83 du
.lo
= (ucell
) dstack
[dstackcnt
--];
87 du
= ((ducell
)(ucell
) dstack
[dstackcnt
--]) << bitspercell
;
88 du
|= (ucell
) dstack
[dstackcnt
--];
93 static inline ucell
GETTOS(void) {
94 return dstack
[dstackcnt
];
97 #define GETITEM(number) (dstack[dstackcnt - number])
98 static inline void PUSHR(ucell value
) {
99 rstack
[++rstackcnt
] = (value
);
102 static inline ucell
POPR(void) {
103 return (ucell
) rstack
[rstackcnt
--];
105 static inline ucell
GETTORS(void) {
106 return rstack
[rstackcnt
];
110 #if defined(DEBUG_DSTACK) || defined(FCOMPILER)
111 void printdstack(void);
113 #if defined(DEBUG_RSTACK) || defined(FCOMPILER)
114 void printrstack(void);