rlm@1: /* rlm@1: ** $Id: lstate.h,v 2.24.1.2 2008/01/03 15:20:39 roberto Exp $ rlm@1: ** Global State rlm@1: ** See Copyright Notice in lua.h rlm@1: */ rlm@1: rlm@1: #ifndef lstate_h rlm@1: #define lstate_h rlm@1: rlm@1: #include "lua.h" rlm@1: rlm@1: #include "lobject.h" rlm@1: #include "ltm.h" rlm@1: #include "lzio.h" rlm@1: rlm@1: rlm@1: rlm@1: struct lua_longjmp; /* defined in ldo.c */ rlm@1: rlm@1: rlm@1: /* table of globals */ rlm@1: #define gt(L) (&L->l_gt) rlm@1: rlm@1: /* registry */ rlm@1: #define registry(L) (&G(L)->l_registry) rlm@1: rlm@1: rlm@1: /* extra stack space to handle TM calls and some other extras */ rlm@1: #define EXTRA_STACK 5 rlm@1: rlm@1: rlm@1: #define BASIC_CI_SIZE 8 rlm@1: rlm@1: #define BASIC_STACK_SIZE (2*LUA_MINSTACK) rlm@1: rlm@1: rlm@1: rlm@1: typedef struct stringtable { rlm@1: GCObject **hash; rlm@1: lu_int32 nuse; /* number of elements */ rlm@1: int size; rlm@1: } stringtable; rlm@1: rlm@1: rlm@1: /* rlm@1: ** informations about a call rlm@1: */ rlm@1: typedef struct CallInfo { rlm@1: StkId base; /* base for this function */ rlm@1: StkId func; /* function index in the stack */ rlm@1: StkId top; /* top for this function */ rlm@1: const Instruction *savedpc; rlm@1: int nresults; /* expected number of results from this function */ rlm@1: int tailcalls; /* number of tail calls lost under this entry */ rlm@1: } CallInfo; rlm@1: rlm@1: rlm@1: rlm@1: #define curr_func(L) (clvalue(L->ci->func)) rlm@1: #define ci_func(ci) (clvalue((ci)->func)) rlm@1: #define f_isLua(ci) (!ci_func(ci)->c.isC) rlm@1: #define isLua(ci) (ttisfunction((ci)->func) && f_isLua(ci)) rlm@1: rlm@1: rlm@1: /* rlm@1: ** `global state', shared by all threads of this state rlm@1: */ rlm@1: typedef struct global_State { rlm@1: stringtable strt; /* hash table for strings */ rlm@1: lua_Alloc frealloc; /* function to reallocate memory */ rlm@1: void *ud; /* auxiliary data to `frealloc' */ rlm@1: lu_byte currentwhite; rlm@1: lu_byte gcstate; /* state of garbage collector */ rlm@1: int sweepstrgc; /* position of sweep in `strt' */ rlm@1: GCObject *rootgc; /* list of all collectable objects */ rlm@1: GCObject **sweepgc; /* position of sweep in `rootgc' */ rlm@1: GCObject *gray; /* list of gray objects */ rlm@1: GCObject *grayagain; /* list of objects to be traversed atomically */ rlm@1: GCObject *weak; /* list of weak tables (to be cleared) */ rlm@1: GCObject *tmudata; /* last element of list of userdata to be GC */ rlm@1: Mbuffer buff; /* temporary buffer for string concatentation */ rlm@1: lu_mem GCthreshold; rlm@1: lu_mem totalbytes; /* number of bytes currently allocated */ rlm@1: lu_mem estimate; /* an estimate of number of bytes actually in use */ rlm@1: lu_mem gcdept; /* how much GC is `behind schedule' */ rlm@1: int gcpause; /* size of pause between successive GCs */ rlm@1: int gcstepmul; /* GC `granularity' */ rlm@1: lua_CFunction panic; /* to be called in unprotected errors */ rlm@1: TValue l_registry; rlm@1: struct lua_State *mainthread; rlm@1: UpVal uvhead; /* head of double-linked list of all open upvalues */ rlm@1: struct Table *mt[NUM_TAGS]; /* metatables for basic types */ rlm@1: TString *tmname[TM_N]; /* array with tag-method names */ rlm@1: } global_State; rlm@1: rlm@1: rlm@1: /* rlm@1: ** `per thread' state rlm@1: */ rlm@1: struct lua_State { rlm@1: CommonHeader; rlm@1: lu_byte status; rlm@1: StkId top; /* first free slot in the stack */ rlm@1: StkId base; /* base of current function */ rlm@1: global_State *l_G; rlm@1: CallInfo *ci; /* call info for current function */ rlm@1: const Instruction *savedpc; /* `savedpc' of current function */ rlm@1: StkId stack_last; /* last free slot in the stack */ rlm@1: StkId stack; /* stack base */ rlm@1: CallInfo *end_ci; /* points after end of ci array*/ rlm@1: CallInfo *base_ci; /* array of CallInfo's */ rlm@1: int stacksize; rlm@1: int size_ci; /* size of array `base_ci' */ rlm@1: unsigned short nCcalls; /* number of nested C calls */ rlm@1: unsigned short baseCcalls; /* nested C calls when resuming coroutine */ rlm@1: lu_byte hookmask; rlm@1: lu_byte allowhook; rlm@1: int basehookcount; rlm@1: int hookcount; rlm@1: lua_Hook hook; rlm@1: TValue l_gt; /* table of globals */ rlm@1: TValue env; /* temporary place for environments */ rlm@1: GCObject *openupval; /* list of open upvalues in this stack */ rlm@1: GCObject *gclist; rlm@1: struct lua_longjmp *errorJmp; /* current error recover point */ rlm@1: ptrdiff_t errfunc; /* current error handling function (stack index) */ rlm@1: }; rlm@1: rlm@1: rlm@1: #define G(L) (L->l_G) rlm@1: rlm@1: rlm@1: /* rlm@1: ** Union of all collectable objects rlm@1: */ rlm@1: union GCObject { rlm@1: GCheader gch; rlm@1: union TString ts; rlm@1: union Udata u; rlm@1: union Closure cl; rlm@1: struct Table h; rlm@1: struct Proto p; rlm@1: struct UpVal uv; rlm@1: struct lua_State th; /* thread */ rlm@1: }; rlm@1: rlm@1: rlm@1: /* macros to convert a GCObject into a specific value */ rlm@1: #define rawgco2ts(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts)) rlm@1: #define gco2ts(o) (&rawgco2ts(o)->tsv) rlm@1: #define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u)) rlm@1: #define gco2u(o) (&rawgco2u(o)->uv) rlm@1: #define gco2cl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl)) rlm@1: #define gco2h(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h)) rlm@1: #define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p)) rlm@1: #define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv)) rlm@1: #define ngcotouv(o) \ rlm@1: check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv)) rlm@1: #define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th)) rlm@1: rlm@1: /* macro to convert any Lua object into a GCObject */ rlm@1: #define obj2gco(v) (cast(GCObject *, (v))) rlm@1: rlm@1: rlm@1: LUAI_FUNC lua_State *luaE_newthread (lua_State *L); rlm@1: LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1); rlm@1: rlm@1: #endif rlm@1: