2
0

ldo.h 3.5 KB

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