Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-11-07 10:37:56

0001 /*
0002 ** $Id: ldo.h $
0003 ** Stack and Call structure of Lua
0004 ** See Copyright Notice in lua.h
0005 */
0006 
0007 #ifndef ldo_h
0008 #define ldo_h
0009 
0010 
0011 #include "llimits.h"
0012 #include "lobject.h"
0013 #include "lstate.h"
0014 #include "lzio.h"
0015 
0016 
0017 /*
0018 ** Macro to check stack size and grow stack if needed.  Parameters
0019 ** 'pre'/'pos' allow the macro to preserve a pointer into the
0020 ** stack across reallocations, doing the work only when needed.
0021 ** It also allows the running of one GC step when the stack is
0022 ** reallocated.
0023 ** 'condmovestack' is used in heavy tests to force a stack reallocation
0024 ** at every check.
0025 */
0026 #define luaD_checkstackaux(L,n,pre,pos)  \
0027     if (l_unlikely(L->stack_last.p - L->top.p <= (n))) \
0028       { pre; luaD_growstack(L, n, 1); pos; } \
0029         else { condmovestack(L,pre,pos); }
0030 
0031 /* In general, 'pre'/'pos' are empty (nothing to save) */
0032 #define luaD_checkstack(L,n)    luaD_checkstackaux(L,n,(void)0,(void)0)
0033 
0034 
0035 
0036 #define savestack(L,pt)     (cast_charp(pt) - cast_charp(L->stack.p))
0037 #define restorestack(L,n)   cast(StkId, cast_charp(L->stack.p) + (n))
0038 
0039 
0040 /* macro to check stack size, preserving 'p' */
0041 #define checkstackp(L,n,p)  \
0042   luaD_checkstackaux(L, n, \
0043     ptrdiff_t t__ = savestack(L, p),  /* save 'p' */ \
0044     p = restorestack(L, t__))  /* 'pos' part: restore 'p' */
0045 
0046 
0047 /* macro to check stack size and GC, preserving 'p' */
0048 #define checkstackGCp(L,n,p)  \
0049   luaD_checkstackaux(L, n, \
0050     ptrdiff_t t__ = savestack(L, p);  /* save 'p' */ \
0051     luaC_checkGC(L),  /* stack grow uses memory */ \
0052     p = restorestack(L, t__))  /* 'pos' part: restore 'p' */
0053 
0054 
0055 /* macro to check stack size and GC */
0056 #define checkstackGC(L,fsize)  \
0057     luaD_checkstackaux(L, (fsize), luaC_checkGC(L), (void)0)
0058 
0059 
0060 /* type of protected functions, to be ran by 'runprotected' */
0061 typedef void (*Pfunc) (lua_State *L, void *ud);
0062 
0063 LUAI_FUNC l_noret luaD_errerr (lua_State *L);
0064 LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop);
0065 LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name,
0066                                                   const char *mode);
0067 LUAI_FUNC void luaD_hook (lua_State *L, int event, int line,
0068                                         int fTransfer, int nTransfer);
0069 LUAI_FUNC void luaD_hookcall (lua_State *L, CallInfo *ci);
0070 LUAI_FUNC int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func,
0071                                               int narg1, int delta);
0072 LUAI_FUNC CallInfo *luaD_precall (lua_State *L, StkId func, int nResults);
0073 LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults);
0074 LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults);
0075 LUAI_FUNC int luaD_closeprotected (lua_State *L, ptrdiff_t level, int status);
0076 LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u,
0077                                         ptrdiff_t oldtop, ptrdiff_t ef);
0078 LUAI_FUNC void luaD_poscall (lua_State *L, CallInfo *ci, int nres);
0079 LUAI_FUNC int luaD_reallocstack (lua_State *L, int newsize, int raiseerror);
0080 LUAI_FUNC int luaD_growstack (lua_State *L, int n, int raiseerror);
0081 LUAI_FUNC void luaD_shrinkstack (lua_State *L);
0082 LUAI_FUNC void luaD_inctop (lua_State *L);
0083 
0084 LUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode);
0085 LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);
0086 
0087 #endif
0088