ldo.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. #define luaD_checkstackaux(L,n,pre,pos) \
  22. if (l_unlikely(L->stack_last.p - L->top.p <= (n))) \
  23. { pre; luaD_growstack(L, n, 1); pos; } \
  24. else { condmovestack(L,pre,pos); }
  25. /* In general, 'pre'/'pos' are empty (nothing to save) */
  26. #define luaD_checkstack(L,n) luaD_checkstackaux(L,n,(void)0,(void)0)
  27. #define savestack(L,pt) (cast_charp(pt) - cast_charp(L->stack.p))
  28. #define restorestack(L,n) cast(StkId, cast_charp(L->stack.p) + (n))
  29. /* macro to check stack size, preserving 'p' */
  30. #define checkstackp(L,n,p) \
  31. luaD_checkstackaux(L, n, \
  32. ptrdiff_t t__ = savestack(L, p), /* save 'p' */ \
  33. p = restorestack(L, t__)) /* 'pos' part: restore 'p' */
  34. /* macro to check stack size and GC, preserving 'p' */
  35. #define checkstackGCp(L,n,p) \
  36. luaD_checkstackaux(L, n, \
  37. ptrdiff_t t__ = savestack(L, p); /* save 'p' */ \
  38. luaC_checkGC(L), /* stack grow uses memory */ \
  39. p = restorestack(L, t__)) /* 'pos' part: restore 'p' */
  40. /* macro to check stack size and GC */
  41. #define checkstackGC(L,fsize) \
  42. luaD_checkstackaux(L, (fsize), luaC_checkGC(L), (void)0)
  43. /* type of protected functions, to be ran by 'runprotected' */
  44. typedef void (*Pfunc) (lua_State *L, void *ud);
  45. LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop);
  46. LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name,
  47. const char *mode);
  48. LUAI_FUNC void luaD_hook (lua_State *L, int event, int line,
  49. int fTransfer, int nTransfer);
  50. LUAI_FUNC void luaD_hookcall (lua_State *L, CallInfo *ci);
  51. LUAI_FUNC int luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func,
  52. int narg1, int delta);
  53. LUAI_FUNC CallInfo *luaD_precall (lua_State *L, StkId func, int nResults);
  54. LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults);
  55. LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults);
  56. LUAI_FUNC StkId luaD_tryfuncTM (lua_State *L, StkId func);
  57. LUAI_FUNC int luaD_closeprotected (lua_State *L, ptrdiff_t level, int status);
  58. LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u,
  59. ptrdiff_t oldtop, ptrdiff_t ef);
  60. LUAI_FUNC void luaD_poscall (lua_State *L, CallInfo *ci, int nres);
  61. LUAI_FUNC int luaD_reallocstack (lua_State *L, int newsize, int raiseerror);
  62. LUAI_FUNC int luaD_growstack (lua_State *L, int n, int raiseerror);
  63. LUAI_FUNC void luaD_shrinkstack (lua_State *L);
  64. LUAI_FUNC void luaD_inctop (lua_State *L);
  65. LUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode);
  66. LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);
  67. #endif