lstate.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /*
  2. ** $Id: lstate.h,v 1.68 2001/12/18 20:52:30 roberto Exp $
  3. ** Global State
  4. ** See Copyright Notice in lua.h
  5. */
  6. #ifndef lstate_h
  7. #define lstate_h
  8. #include "lua.h"
  9. #include "lobject.h"
  10. #include "ltm.h"
  11. #include "luadebug.h"
  12. /*
  13. ** macros for thread syncronization inside Lua core machine:
  14. ** all accesses to the global state and to global objects are syncronized.
  15. ** Because threads can read the stack of other threads
  16. ** (when running garbage collection),
  17. ** a thread must also syncronize any write-access to its own stack.
  18. ** Unsyncronized accesses are allowed only when reading its own stack,
  19. ** or when reading immutable fields from global objects
  20. ** (such as string values and udata values).
  21. */
  22. #ifndef lua_lock
  23. #define lua_lock(L) ((void) 0)
  24. #endif
  25. #ifndef lua_unlock
  26. #define lua_unlock(L) ((void) 0)
  27. #endif
  28. /*
  29. ** macro to allow the inclusion of user information in Lua state
  30. */
  31. #ifndef LUA_USERSTATE
  32. #define LUA_USERSTATE
  33. #endif
  34. #ifndef lua_userstateopen
  35. #define lua_userstateopen(l)
  36. #endif
  37. struct lua_longjmp; /* defined in ldo.c */
  38. /*
  39. ** reserve init of stack to store some global values
  40. */
  41. /* default meta table (both for tables and udata) */
  42. #define defaultmeta(L) (L->stack)
  43. /* table of globals */
  44. #define gt(L) (L->stack + 1)
  45. /* registry */
  46. #define registry(L) (L->stack + 2)
  47. #define RESERVED_STACK_PREFIX 3
  48. /* space to handle TM calls */
  49. #define EXTRA_STACK 4
  50. #define BASIC_CI_SIZE 6
  51. #define BASIC_STACK_SIZE (2*LUA_MINSTACK)
  52. #define DEFAULT_MAXSTACK 12000
  53. typedef struct stringtable {
  54. int size;
  55. ls_nstr nuse; /* number of elements */
  56. TString **hash;
  57. } stringtable;
  58. /*
  59. ** informations about a call
  60. */
  61. typedef struct CallInfo {
  62. StkId base; /* base for called function */
  63. const Instruction *savedpc;
  64. StkId top; /* top for this function (when it's a Lua function) */
  65. const Instruction **pc; /* points to `pc' variable in `luaV_execute' */
  66. StkId *pb; /* points to `base' variable in `luaV_execute' */
  67. /* extra information for line tracing */
  68. int lastpc; /* last pc traced */
  69. int line; /* current line */
  70. int refi; /* current index in `lineinfo' */
  71. } CallInfo;
  72. #define ci_func(ci) (clvalue((ci)->base - 1))
  73. #define yield_results refi /* reuse this field */
  74. /*
  75. ** `global state', shared by all threads of this state
  76. */
  77. typedef struct global_State {
  78. void *Mbuffer; /* global buffer */
  79. size_t Mbuffsize; /* size of Mbuffer */
  80. stringtable strt; /* hash table for strings */
  81. lu_mem GCthreshold;
  82. lu_mem nblocks; /* number of `bytes' currently allocated */
  83. Proto *rootproto; /* list of all prototypes */
  84. Closure *rootcl; /* list of all closures */
  85. Table *roottable; /* list of all tables */
  86. UpVal *rootupval; /* list of closed up values */
  87. Udata *rootudata; /* list of all userdata */
  88. Udata *tmudata; /* list of userdata to be GC */
  89. TString *tmname[TM_N]; /* array with tag-method names */
  90. } global_State;
  91. /*
  92. ** `per thread' state
  93. */
  94. struct lua_State {
  95. LUA_USERSTATE
  96. StkId top; /* first free slot in the stack */
  97. CallInfo *ci; /* call info for current function */
  98. StkId stack_last; /* last free slot in the stack */
  99. StkId stack; /* stack base */
  100. int stacksize;
  101. int maxstacksize;
  102. CallInfo *end_ci; /* points after end of ci array*/
  103. CallInfo *base_ci; /* array of CallInfo's */
  104. int size_ci; /* size of array `base_ci' */
  105. global_State *_G;
  106. lua_Hook callhook;
  107. lua_Hook linehook;
  108. int allowhooks;
  109. struct lua_longjmp *errorJmp; /* current error recover point */
  110. UpVal *openupval; /* list of open upvalues in this stack */
  111. lua_State *next; /* circular double linked list of states */
  112. lua_State *previous;
  113. };
  114. #define G(L) (L->_G)
  115. void luaE_closethread (lua_State *OL, lua_State *L);
  116. #endif