ldo.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 "lobject.h"
  9. #include "lstate.h"
  10. #include "lzio.h"
  11. /*
  12. ** Macro to check stack size and grow stack if needed. Parameters
  13. ** 'pre'/'pos' allow the macro to preserve a pointer into the
  14. ** stack across reallocations, doing the work only when needed.
  15. ** It also allows the running of one GC step when the stack is
  16. ** reallocated.
  17. ** 'condmovestack' is used in heavy tests to force a stack reallocation
  18. ** at every check.
  19. */
  20. #define luaD_checkstackaux(L,n,pre,pos) \
  21. if (L->stack_last - L->top <= (n)) \
  22. { pre; luaD_growstack(L, n, 1); pos; } \
  23. else { condmovestack(L,pre,pos); }
  24. /* In general, 'pre'/'pos' are empty (nothing to save) */
  25. #define luaD_checkstack(L,n) luaD_checkstackaux(L,n,(void)0,(void)0)
  26. #define savestack(L,p) ((char *)(p) - (char *)L->stack)
  27. #define restorestack(L,n) ((StkId)((char *)L->stack + (n)))
  28. /* macro to check stack size, preserving 'p' */
  29. #define checkstackGCp(L,n,p) \
  30. luaD_checkstackaux(L, n, \
  31. ptrdiff_t t__ = savestack(L, p); /* save 'p' */ \
  32. luaC_checkGC(L), /* stack grow uses memory */ \
  33. p = restorestack(L, t__)) /* 'pos' part: restore 'p' */
  34. /* macro to check stack size and GC */
  35. #define checkstackGC(L,fsize) \
  36. luaD_checkstackaux(L, (fsize), luaC_checkGC(L), (void)0)
  37. /* type of protected functions, to be ran by 'runprotected' */
  38. typedef void (*Pfunc) (lua_State *L, void *ud);
  39. LUAI_FUNC void luaD_seterrorobj (lua_State *L, int errcode, StkId oldtop);
  40. LUAI_FUNC int luaD_protectedparser (lua_State *L, ZIO *z, const char *name,
  41. const char *mode);
  42. LUAI_FUNC void luaD_hook (lua_State *L, int event, int line,
  43. int fTransfer, int nTransfer);
  44. LUAI_FUNC void luaD_hookcall (lua_State *L, CallInfo *ci);
  45. LUAI_FUNC void luaD_pretailcall (lua_State *L, CallInfo *ci, StkId func, int n);
  46. LUAI_FUNC CallInfo *luaD_precall (lua_State *L, StkId func, int nResults);
  47. LUAI_FUNC void luaD_call (lua_State *L, StkId func, int nResults);
  48. LUAI_FUNC void luaD_callnoyield (lua_State *L, StkId func, int nResults);
  49. LUAI_FUNC void luaD_tryfuncTM (lua_State *L, StkId func);
  50. LUAI_FUNC int luaD_pcall (lua_State *L, Pfunc func, void *u,
  51. ptrdiff_t oldtop, ptrdiff_t ef);
  52. LUAI_FUNC void luaD_poscall (lua_State *L, CallInfo *ci, int nres);
  53. LUAI_FUNC int luaD_reallocstack (lua_State *L, int newsize, int raiseerror);
  54. LUAI_FUNC int luaD_growstack (lua_State *L, int n, int raiseerror);
  55. LUAI_FUNC void luaD_shrinkstack (lua_State *L);
  56. LUAI_FUNC void luaD_inctop (lua_State *L);
  57. LUAI_FUNC l_noret luaD_throw (lua_State *L, int errcode);
  58. LUAI_FUNC int luaD_rawrunprotected (lua_State *L, Pfunc f, void *ud);
  59. #endif