lua

A copy of the Lua development repository
Log | Files | Refs | README

ldo.h (3451B)


      1 /*
      2 ** $Id: ldo.h $
      3 ** Stack and Call structure of Lua
      4 ** See Copyright Notice in lua.h
      5 */
      6 
      7 #ifndef ldo_h
      8 #define ldo_h
      9 
     10 
     11 #include "llimits.h"
     12 #include "lobject.h"
     13 #include "lstate.h"
     14 #include "lzio.h"
     15 
     16 
     17 /*
     18 ** Macro to check stack size and grow stack if needed.  Parameters
     19 ** 'pre'/'pos' allow the macro to preserve a pointer into the
     20 ** stack across reallocations, doing the work only when needed.
     21 ** It also allows the running of one GC step when the stack is
     22 ** reallocated.
     23 ** 'condmovestack' is used in heavy tests to force a stack reallocation
     24 ** at every check.
     25 */
     26 
     27 #if !defined(HARDSTACKTESTS)
     28 #define condmovestack(L,pre,pos)	((void)0)
     29 #else
     30 /* realloc stack keeping its size */
     31 #define condmovestack(L,pre,pos)  \
     32   { int sz_ = stacksize(L); pre; luaD_reallocstack((L), sz_, 0); pos; }
     33 #endif
     34 
     35 #define luaD_checkstackaux(L,n,pre,pos)  \
     36 	if (l_unlikely(L->stack_last.p - L->top.p <= (n))) \
     37 	  { pre; luaD_growstack(L, n, 1); pos; } \
     38 	else { condmovestack(L,pre,pos); }
     39 
     40 /* In general, 'pre'/'pos' are empty (nothing to save) */
     41 #define luaD_checkstack(L,n)	luaD_checkstackaux(L,n,(void)0,(void)0)
     42 
     43 
     44 
     45 #define savestack(L,pt)		(cast_charp(pt) - cast_charp(L->stack.p))
     46 #define restorestack(L,n)	cast(StkId, cast_charp(L->stack.p) + (n))
     47 
     48 
     49 /* macro to check stack size, preserving 'p' */
     50 #define checkstackp(L,n,p)  \
     51   luaD_checkstackaux(L, n, \
     52     ptrdiff_t t__ = savestack(L, p),  /* save 'p' */ \
     53     p = restorestack(L, t__))  /* 'pos' part: restore 'p' */
     54 
     55 
     56 /*
     57 ** Maximum depth for nested C calls, syntactical nested non-terminals,
     58 ** and other features implemented through recursion in C. (Value must
     59 ** fit in a 16-bit unsigned integer. It must also be compatible with
     60 ** the size of the C stack.)
     61 */
     62 #if !defined(LUAI_MAXCCALLS)
     63 #define LUAI_MAXCCALLS		200
     64 #endif
     65 
     66 
     67 /* type of protected functions, to be ran by 'runprotected' */
     68 typedef void (*Pfunc) (lua_State *L, void *ud);
     69 
     70 LUAI_FUNC void luaD_seterrorobj (lua_State *L, TStatus errcode, StkId oldtop);
     71 LUAI_FUNC TStatus luaD_protectedparser (lua_State *L, ZIO *z,
     72                                                   const char *name,
     73                                                   const char *mode);
     74 LUAI_FUNC void luaD_hook (lua_State *L, int event, int line,
     75                                         int fTransfer, int nTransfer);
     76 LUAI_FUNC void luaD_hookcall (lua_State *L, CallInfo *ci);
     77 LUAI_FUNC int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func,
     78                                               int narg1, int delta);
     79 LUAI_FUNC CallInfo *luaD_precall (lua_State *L, StkId func, int nResults);
     80 LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults);
     81 LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults);
     82 LUAI_FUNC TStatus luaD_closeprotected (lua_State *L, ptrdiff_t level,
     83                                                      TStatus status);
     84 LUAI_FUNC TStatus luaD_pcall (lua_State *L, Pfunc func, void *u,
     85                                         ptrdiff_t oldtop, ptrdiff_t ef);
     86 LUAI_FUNC void luaD_poscall (lua_State *L, CallInfo *ci, int nres);
     87 LUAI_FUNC int luaD_reallocstack (lua_State *L, int newsize, int raiseerror);
     88 LUAI_FUNC int luaD_growstack (lua_State *L, int n, int raiseerror);
     89 LUAI_FUNC void luaD_shrinkstack (lua_State *L);
     90 LUAI_FUNC void luaD_inctop (lua_State *L);
     91 
     92 LUAI_FUNC l_noret luaD_throw (lua_State *L, TStatus errcode);
     93 LUAI_FUNC TStatus luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);
     94 
     95 #endif
     96