00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #ifndef __CSTK_H
00015 #define __CSTK_H
00016
00017 #include "ccor.h"
00018
00019 #if defined(__BORLANDC__) && __BCPLUSPLUS__<=0x310 && defined(__MSDOS__)
00020
00021 #endif
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #if !defined( USE_STK )
00038
00039 #define iSTK(x) long x;
00040 #define vSTK(x) long x;
00041
00042 #else // if defined( USE_STK )
00043
00044
00045
00046
00047
00048
00049
00050 struct Stk
00051 {
00052 static long _retval;
00053 static int _stkon;
00054 static int _exit;
00055 static JMP_BUF _jbuf;
00056 int _switched;
00057
00058 Stk() {_switched=0;}
00059 ~Stk() {if(_switched && _stkon) {_stkon=0;LONGJMP(_jbuf,1);}}
00060
00061 long operator=(long l) {return _retval=l;}
00062 };
00063
00064 extern "C" void use_stack(int *sp);
00065
00066
00067 #define iSTK(x) Stk x; \
00068 {if(!Stk::_stkon && simulation.runningModule()!=NULL) \
00069 if(SETJMP(Stk::_jbuf)==0) { \
00070 x._switched=1; \
00071 Stk::_stkon=1; \
00072 use_stack(cCoroutine::getMainSP()-32); \
00073 } else \
00074 return Stk::_retval;}
00075
00076
00077 #define vSTK(x) Stk x; \
00078 {if(!Stk::_stkon && simulation.runningModule()!=NULL) \
00079 if(SETJMP(Stk::_jbuf)==0) { \
00080 x._switched=1; \
00081 Stk::_stkon=1; \
00082 use_stack(cCoroutine::getMainSP()-32); \
00083 } else \
00084 return;}
00085
00086 #endif // defined( USE_STK )
00087
00088 #endif
00089