00001 /* 00002 ** $Id: lstate.h,v 2.24.1.2 2008/01/03 15:20:39 roberto Exp $ 00003 ** Global State 00004 ** See Copyright Notice in lua.h 00005 */ 00006 00007 #ifndef lstate_h 00008 #define lstate_h 00009 00010 #include "lua.h" 00011 00012 #include "lobject.h" 00013 #include "ltm.h" 00014 #include "lzio.h" 00015 00016 00017 00018 struct lua_longjmp; /* defined in ldo.c */ 00019 00020 00021 /* table of globals */ 00022 #define gt(L) (&L->l_gt) 00023 00024 /* registry */ 00025 #define registry(L) (&G(L)->l_registry) 00026 00027 00028 /* extra stack space to handle TM calls and some other extras */ 00029 #define EXTRA_STACK 5 00030 00031 00032 #define BASIC_CI_SIZE 8 00033 00034 #define BASIC_STACK_SIZE (2*LUA_MINSTACK) 00035 00036 00037 00038 typedef struct stringtable { 00039 GCObject **hash; 00040 lu_int32 nuse; /* number of elements */ 00041 int size; 00042 } stringtable; 00043 00044 00045 /* 00046 ** informations about a call 00047 */ 00048 typedef struct CallInfo { 00049 StkId base; /* base for this function */ 00050 StkId func; /* function index in the stack */ 00051 StkId top; /* top for this function */ 00052 const Instruction *savedpc; 00053 int nresults; /* expected number of results from this function */ 00054 int tailcalls; /* number of tail calls lost under this entry */ 00055 } CallInfo; 00056 00057 00058 00059 #define curr_func(L) (clvalue(L->ci->func)) 00060 #define ci_func(ci) (clvalue((ci)->func)) 00061 #define f_isLua(ci) (!ci_func(ci)->c.isC) 00062 #define isLua(ci) (ttisfunction((ci)->func) && f_isLua(ci)) 00063 00064 00065 /* 00066 ** `global state', shared by all threads of this state 00067 */ 00068 typedef struct global_State { 00069 stringtable strt; /* hash table for strings */ 00070 lua_Alloc frealloc; /* function to reallocate memory */ 00071 void *ud; /* auxiliary data to `frealloc' */ 00072 lu_byte currentwhite; 00073 lu_byte gcstate; /* state of garbage collector */ 00074 int sweepstrgc; /* position of sweep in `strt' */ 00075 GCObject *rootgc; /* list of all collectable objects */ 00076 GCObject **sweepgc; /* position of sweep in `rootgc' */ 00077 GCObject *gray; /* list of gray objects */ 00078 GCObject *grayagain; /* list of objects to be traversed atomically */ 00079 GCObject *weak; /* list of weak tables (to be cleared) */ 00080 GCObject *tmudata; /* last element of list of userdata to be GC */ 00081 Mbuffer buff; /* temporary buffer for string concatentation */ 00082 lu_mem GCthreshold; 00083 lu_mem totalbytes; /* number of bytes currently allocated */ 00084 lu_mem estimate; /* an estimate of number of bytes actually in use */ 00085 lu_mem gcdept; /* how much GC is `behind schedule' */ 00086 int gcpause; /* size of pause between successive GCs */ 00087 int gcstepmul; /* GC `granularity' */ 00088 lua_CFunction panic; /* to be called in unprotected errors */ 00089 TValue l_registry; 00090 struct lua_State *mainthread; 00091 UpVal uvhead; /* head of double-linked list of all open upvalues */ 00092 struct Table *mt[NUM_TAGS]; /* metatables for basic types */ 00093 TString *tmname[TM_N]; /* array with tag-method names */ 00094 } global_State; 00095 00096 00097 /* 00098 ** `per thread' state 00099 */ 00100 struct lua_State { 00101 CommonHeader; 00102 lu_byte status; 00103 StkId top; /* first free slot in the stack */ 00104 StkId base; /* base of current function */ 00105 global_State *l_G; 00106 CallInfo *ci; /* call info for current function */ 00107 const Instruction *savedpc; /* `savedpc' of current function */ 00108 StkId stack_last; /* last free slot in the stack */ 00109 StkId stack; /* stack base */ 00110 CallInfo *end_ci; /* points after end of ci array*/ 00111 CallInfo *base_ci; /* array of CallInfo's */ 00112 int stacksize; 00113 int size_ci; /* size of array `base_ci' */ 00114 unsigned short nCcalls; /* number of nested C calls */ 00115 unsigned short baseCcalls; /* nested C calls when resuming coroutine */ 00116 lu_byte hookmask; 00117 lu_byte allowhook; 00118 int basehookcount; 00119 int hookcount; 00120 lua_Hook hook; 00121 TValue l_gt; /* table of globals */ 00122 TValue env; /* temporary place for environments */ 00123 GCObject *openupval; /* list of open upvalues in this stack */ 00124 GCObject *gclist; 00125 struct lua_longjmp *errorJmp; /* current error recover point */ 00126 ptrdiff_t errfunc; /* current error handling function (stack index) */ 00127 void *active_ctx; /* stores active function invocation */ 00128 }; 00129 00130 00131 #define G(L) (L->l_G) 00132 00133 00134 /* 00135 ** Union of all collectable objects 00136 */ 00137 union GCObject { 00138 GCheader gch; 00139 union TString ts; 00140 union Udata u; 00141 union Closure cl; 00142 struct Table h; 00143 struct Proto p; 00144 struct UpVal uv; 00145 struct lua_State th; /* thread */ 00146 }; 00147 00148 00149 /* macros to convert a GCObject into a specific value */ 00150 #define rawgco2ts(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts)) 00151 #define gco2ts(o) (&rawgco2ts(o)->tsv) 00152 #define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u)) 00153 #define gco2u(o) (&rawgco2u(o)->uv) 00154 #define gco2cl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl)) 00155 #define gco2h(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h)) 00156 #define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p)) 00157 #define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv)) 00158 #define ngcotouv(o) \ 00159 check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv)) 00160 #define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th)) 00161 00162 /* macro to convert any Lua object into a GCObject */ 00163 #define obj2gco(v) (cast(GCObject *, (v))) 00164 00165 00166 LUAI_FUNC lua_State *luaE_newthread (lua_State *L); 00167 LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1); 00168 00169 #endif 00170
ContextLogger2—ContextLogger2 Logger Daemon Internals—Generated on Mon May 2 13:49:54 2011 by Doxygen 1.6.1