xref: /freebsd/contrib/lua/src/lstate.h (revision 0495ed398c4f64013bab2327eb13a303e1f90c13)
18e3e3a7aSWarner Losh /*
2*0495ed39SKyle Evans ** $Id: lstate.h $
38e3e3a7aSWarner Losh ** Global State
48e3e3a7aSWarner Losh ** See Copyright Notice in lua.h
58e3e3a7aSWarner Losh */
68e3e3a7aSWarner Losh 
78e3e3a7aSWarner Losh #ifndef lstate_h
88e3e3a7aSWarner Losh #define lstate_h
98e3e3a7aSWarner Losh 
108e3e3a7aSWarner Losh #include "lua.h"
118e3e3a7aSWarner Losh 
128e3e3a7aSWarner Losh #include "lobject.h"
138e3e3a7aSWarner Losh #include "ltm.h"
148e3e3a7aSWarner Losh #include "lzio.h"
158e3e3a7aSWarner Losh 
168e3e3a7aSWarner Losh 
178e3e3a7aSWarner Losh /*
188e3e3a7aSWarner Losh ** Some notes about garbage-collected objects: All objects in Lua must
198e3e3a7aSWarner Losh ** be kept somehow accessible until being freed, so all objects always
208e3e3a7aSWarner Losh ** belong to one (and only one) of these lists, using field 'next' of
218e3e3a7aSWarner Losh ** the 'CommonHeader' for the link:
228e3e3a7aSWarner Losh **
238e3e3a7aSWarner Losh ** 'allgc': all objects not marked for finalization;
248e3e3a7aSWarner Losh ** 'finobj': all objects marked for finalization;
258e3e3a7aSWarner Losh ** 'tobefnz': all objects ready to be finalized;
268e3e3a7aSWarner Losh ** 'fixedgc': all objects that are not to be collected (currently
278e3e3a7aSWarner Losh ** only small strings, such as reserved words).
28e112e9d2SKyle Evans **
29*0495ed39SKyle Evans ** For the generational collector, some of these lists have marks for
30*0495ed39SKyle Evans ** generations. Each mark points to the first element in the list for
31*0495ed39SKyle Evans ** that particular generation; that generation goes until the next mark.
32*0495ed39SKyle Evans **
33*0495ed39SKyle Evans ** 'allgc' -> 'survival': new objects;
34*0495ed39SKyle Evans ** 'survival' -> 'old': objects that survived one collection;
35*0495ed39SKyle Evans ** 'old1' -> 'reallyold': objects that became old in last collection;
36*0495ed39SKyle Evans ** 'reallyold' -> NULL: objects old for more than one cycle.
37*0495ed39SKyle Evans **
38*0495ed39SKyle Evans ** 'finobj' -> 'finobjsur': new objects marked for finalization;
39*0495ed39SKyle Evans ** 'finobjsur' -> 'finobjold1': survived   """";
40*0495ed39SKyle Evans ** 'finobjold1' -> 'finobjrold': just old  """";
41*0495ed39SKyle Evans ** 'finobjrold' -> NULL: really old       """".
42*0495ed39SKyle Evans **
43*0495ed39SKyle Evans ** All lists can contain elements older than their main ages, due
44*0495ed39SKyle Evans ** to 'luaC_checkfinalizer' and 'udata2finalize', which move
45*0495ed39SKyle Evans ** objects between the normal lists and the "marked for finalization"
46*0495ed39SKyle Evans ** lists. Moreover, barriers can age young objects in young lists as
47*0495ed39SKyle Evans ** OLD0, which then become OLD1. However, a list never contains
48*0495ed39SKyle Evans ** elements younger than their main ages.
49*0495ed39SKyle Evans **
50*0495ed39SKyle Evans ** The generational collector also uses a pointer 'firstold1', which
51*0495ed39SKyle Evans ** points to the first OLD1 object in the list. It is used to optimize
52*0495ed39SKyle Evans ** 'markold'. (Potentially OLD1 objects can be anywhere between 'allgc'
53*0495ed39SKyle Evans ** and 'reallyold', but often the list has no OLD1 objects or they are
54*0495ed39SKyle Evans ** after 'old1'.) Note the difference between it and 'old1':
55*0495ed39SKyle Evans ** 'firstold1': no OLD1 objects before this point; there can be all
56*0495ed39SKyle Evans **   ages after it.
57*0495ed39SKyle Evans ** 'old1': no objects younger than OLD1 after this point.
58*0495ed39SKyle Evans */
59*0495ed39SKyle Evans 
60*0495ed39SKyle Evans /*
61e112e9d2SKyle Evans ** Moreover, there is another set of lists that control gray objects.
62e112e9d2SKyle Evans ** These lists are linked by fields 'gclist'. (All objects that
63e112e9d2SKyle Evans ** can become gray have such a field. The field is not the same
64e112e9d2SKyle Evans ** in all objects, but it always has this name.)  Any gray object
65e112e9d2SKyle Evans ** must belong to one of these lists, and all objects in these lists
66*0495ed39SKyle Evans ** must be gray (with two exceptions explained below):
67e112e9d2SKyle Evans **
68e112e9d2SKyle Evans ** 'gray': regular gray objects, still waiting to be visited.
69e112e9d2SKyle Evans ** 'grayagain': objects that must be revisited at the atomic phase.
70e112e9d2SKyle Evans **   That includes
71e112e9d2SKyle Evans **   - black objects got in a write barrier;
72e112e9d2SKyle Evans **   - all kinds of weak tables during propagation phase;
73e112e9d2SKyle Evans **   - all threads.
74e112e9d2SKyle Evans ** 'weak': tables with weak values to be cleared;
75e112e9d2SKyle Evans ** 'ephemeron': ephemeron tables with white->white entries;
76e112e9d2SKyle Evans ** 'allweak': tables with weak keys and/or weak values to be cleared.
77*0495ed39SKyle Evans **
78*0495ed39SKyle Evans ** The exceptions to that "gray rule" are:
79*0495ed39SKyle Evans ** - TOUCHED2 objects in generational mode stay in a gray list (because
80*0495ed39SKyle Evans ** they must be visited again at the end of the cycle), but they are
81*0495ed39SKyle Evans ** marked black because assignments to them must activate barriers (to
82*0495ed39SKyle Evans ** move them back to TOUCHED1).
83*0495ed39SKyle Evans ** - Open upvales are kept gray to avoid barriers, but they stay out
84*0495ed39SKyle Evans ** of gray lists. (They don't even have a 'gclist' field.)
858e3e3a7aSWarner Losh */
868e3e3a7aSWarner Losh 
878e3e3a7aSWarner Losh 
88*0495ed39SKyle Evans 
89*0495ed39SKyle Evans /*
90*0495ed39SKyle Evans ** About 'nCcalls':  This count has two parts: the lower 16 bits counts
91*0495ed39SKyle Evans ** the number of recursive invocations in the C stack; the higher
92*0495ed39SKyle Evans ** 16 bits counts the number of non-yieldable calls in the stack.
93*0495ed39SKyle Evans ** (They are together so that we can change and save both with one
94*0495ed39SKyle Evans ** instruction.)
95*0495ed39SKyle Evans */
96*0495ed39SKyle Evans 
97*0495ed39SKyle Evans 
98*0495ed39SKyle Evans /* true if this thread does not have non-yieldable calls in the stack */
99*0495ed39SKyle Evans #define yieldable(L)		(((L)->nCcalls & 0xffff0000) == 0)
100*0495ed39SKyle Evans 
101*0495ed39SKyle Evans /* real number of C calls */
102*0495ed39SKyle Evans #define getCcalls(L)	((L)->nCcalls & 0xffff)
103*0495ed39SKyle Evans 
104*0495ed39SKyle Evans 
105*0495ed39SKyle Evans /* Increment the number of non-yieldable calls */
106*0495ed39SKyle Evans #define incnny(L)	((L)->nCcalls += 0x10000)
107*0495ed39SKyle Evans 
108*0495ed39SKyle Evans /* Decrement the number of non-yieldable calls */
109*0495ed39SKyle Evans #define decnny(L)	((L)->nCcalls -= 0x10000)
110*0495ed39SKyle Evans 
111*0495ed39SKyle Evans /* Non-yieldable call increment */
112*0495ed39SKyle Evans #define nyci	(0x10000 | 1)
113*0495ed39SKyle Evans 
114*0495ed39SKyle Evans 
115*0495ed39SKyle Evans 
116*0495ed39SKyle Evans 
1178e3e3a7aSWarner Losh struct lua_longjmp;  /* defined in ldo.c */
1188e3e3a7aSWarner Losh 
1198e3e3a7aSWarner Losh 
1208e3e3a7aSWarner Losh /*
1218e3e3a7aSWarner Losh ** Atomic type (relative to signals) to better ensure that 'lua_sethook'
1228e3e3a7aSWarner Losh ** is thread safe
1238e3e3a7aSWarner Losh */
1248e3e3a7aSWarner Losh #if !defined(l_signalT)
1258e3e3a7aSWarner Losh #include <signal.h>
1268e3e3a7aSWarner Losh #define l_signalT	sig_atomic_t
1278e3e3a7aSWarner Losh #endif
1288e3e3a7aSWarner Losh 
1298e3e3a7aSWarner Losh 
130*0495ed39SKyle Evans /*
131*0495ed39SKyle Evans ** Extra stack space to handle TM calls and some other extras. This
132*0495ed39SKyle Evans ** space is not included in 'stack_last'. It is used only to avoid stack
133*0495ed39SKyle Evans ** checks, either because the element will be promptly popped or because
134*0495ed39SKyle Evans ** there will be a stack check soon after the push. Function frames
135*0495ed39SKyle Evans ** never use this extra space, so it does not need to be kept clean.
136*0495ed39SKyle Evans */
1378e3e3a7aSWarner Losh #define EXTRA_STACK   5
1388e3e3a7aSWarner Losh 
1398e3e3a7aSWarner Losh 
1408e3e3a7aSWarner Losh #define BASIC_STACK_SIZE        (2*LUA_MINSTACK)
1418e3e3a7aSWarner Losh 
142*0495ed39SKyle Evans #define stacksize(th)	cast_int((th)->stack_last - (th)->stack)
143*0495ed39SKyle Evans 
1448e3e3a7aSWarner Losh 
1458e3e3a7aSWarner Losh /* kinds of Garbage Collection */
146*0495ed39SKyle Evans #define KGC_INC		0	/* incremental gc */
147*0495ed39SKyle Evans #define KGC_GEN		1	/* generational gc */
1488e3e3a7aSWarner Losh 
1498e3e3a7aSWarner Losh 
1508e3e3a7aSWarner Losh typedef struct stringtable {
1518e3e3a7aSWarner Losh   TString **hash;
1528e3e3a7aSWarner Losh   int nuse;  /* number of elements */
1538e3e3a7aSWarner Losh   int size;
1548e3e3a7aSWarner Losh } stringtable;
1558e3e3a7aSWarner Losh 
1568e3e3a7aSWarner Losh 
1578e3e3a7aSWarner Losh /*
1588e3e3a7aSWarner Losh ** Information about a call.
1598e3e3a7aSWarner Losh */
1608e3e3a7aSWarner Losh typedef struct CallInfo {
1618e3e3a7aSWarner Losh   StkId func;  /* function index in the stack */
1628e3e3a7aSWarner Losh   StkId	top;  /* top for this function */
1638e3e3a7aSWarner Losh   struct CallInfo *previous, *next;  /* dynamic call link */
1648e3e3a7aSWarner Losh   union {
1658e3e3a7aSWarner Losh     struct {  /* only for Lua functions */
1668e3e3a7aSWarner Losh       const Instruction *savedpc;
167*0495ed39SKyle Evans       volatile l_signalT trap;
168*0495ed39SKyle Evans       int nextraargs;  /* # of extra arguments in vararg functions */
1698e3e3a7aSWarner Losh     } l;
1708e3e3a7aSWarner Losh     struct {  /* only for C functions */
1718e3e3a7aSWarner Losh       lua_KFunction k;  /* continuation in case of yields */
1728e3e3a7aSWarner Losh       ptrdiff_t old_errfunc;
1738e3e3a7aSWarner Losh       lua_KContext ctx;  /* context info. in case of yields */
1748e3e3a7aSWarner Losh     } c;
1758e3e3a7aSWarner Losh   } u;
176*0495ed39SKyle Evans   union {
177*0495ed39SKyle Evans     int funcidx;  /* called-function index */
178*0495ed39SKyle Evans     int nyield;  /* number of values yielded */
179*0495ed39SKyle Evans     struct {  /* info about transferred values (for call/return hooks) */
180*0495ed39SKyle Evans       unsigned short ftransfer;  /* offset of first value transferred */
181*0495ed39SKyle Evans       unsigned short ntransfer;  /* number of values transferred */
182*0495ed39SKyle Evans     } transferinfo;
183*0495ed39SKyle Evans   } u2;
1848e3e3a7aSWarner Losh   short nresults;  /* expected number of results from this function */
1858e3e3a7aSWarner Losh   unsigned short callstatus;
1868e3e3a7aSWarner Losh } CallInfo;
1878e3e3a7aSWarner Losh 
1888e3e3a7aSWarner Losh 
1898e3e3a7aSWarner Losh /*
1908e3e3a7aSWarner Losh ** Bits in CallInfo status
1918e3e3a7aSWarner Losh */
1928e3e3a7aSWarner Losh #define CIST_OAH	(1<<0)	/* original value of 'allowhook' */
193*0495ed39SKyle Evans #define CIST_C		(1<<1)	/* call is running a C function */
194*0495ed39SKyle Evans #define CIST_FRESH	(1<<2)  /* call is on a fresh "luaV_execute" frame */
195*0495ed39SKyle Evans #define CIST_HOOKED	(1<<3)	/* call is running a debug hook */
1968e3e3a7aSWarner Losh #define CIST_YPCALL	(1<<4)	/* call is a yieldable protected call */
1978e3e3a7aSWarner Losh #define CIST_TAIL	(1<<5)	/* call was tail called */
1988e3e3a7aSWarner Losh #define CIST_HOOKYIELD	(1<<6)	/* last hook called yielded */
199*0495ed39SKyle Evans #define CIST_FIN	(1<<7)  /* call is running a finalizer */
200*0495ed39SKyle Evans #define CIST_TRAN	(1<<8)	/* 'ci' has transfer information */
201*0495ed39SKyle Evans #if defined(LUA_COMPAT_LT_LE)
202*0495ed39SKyle Evans #define CIST_LEQ	(1<<9)  /* using __lt for __le */
203*0495ed39SKyle Evans #endif
2048e3e3a7aSWarner Losh 
205*0495ed39SKyle Evans /* active function is a Lua function */
206*0495ed39SKyle Evans #define isLua(ci)	(!((ci)->callstatus & CIST_C))
207*0495ed39SKyle Evans 
208*0495ed39SKyle Evans /* call is running Lua code (not a hook) */
209*0495ed39SKyle Evans #define isLuacode(ci)	(!((ci)->callstatus & (CIST_C | CIST_HOOKED)))
2108e3e3a7aSWarner Losh 
2118e3e3a7aSWarner Losh /* assume that CIST_OAH has offset 0 and that 'v' is strictly 0/1 */
2128e3e3a7aSWarner Losh #define setoah(st,v)	((st) = ((st) & ~CIST_OAH) | (v))
2138e3e3a7aSWarner Losh #define getoah(st)	((st) & CIST_OAH)
2148e3e3a7aSWarner Losh 
2158e3e3a7aSWarner Losh 
2168e3e3a7aSWarner Losh /*
2178e3e3a7aSWarner Losh ** 'global state', shared by all threads of this state
2188e3e3a7aSWarner Losh */
2198e3e3a7aSWarner Losh typedef struct global_State {
2208e3e3a7aSWarner Losh   lua_Alloc frealloc;  /* function to reallocate memory */
2218e3e3a7aSWarner Losh   void *ud;         /* auxiliary data to 'frealloc' */
2228e3e3a7aSWarner Losh   l_mem totalbytes;  /* number of bytes currently allocated - GCdebt */
2238e3e3a7aSWarner Losh   l_mem GCdebt;  /* bytes allocated not yet compensated by the collector */
2248e3e3a7aSWarner Losh   lu_mem GCestimate;  /* an estimate of the non-garbage memory in use */
225*0495ed39SKyle Evans   lu_mem lastatomic;  /* see function 'genstep' in file 'lgc.c' */
2268e3e3a7aSWarner Losh   stringtable strt;  /* hash table for strings */
2278e3e3a7aSWarner Losh   TValue l_registry;
228*0495ed39SKyle Evans   TValue nilvalue;  /* a nil value */
2298e3e3a7aSWarner Losh   unsigned int seed;  /* randomized seed for hashes */
2308e3e3a7aSWarner Losh   lu_byte currentwhite;
2318e3e3a7aSWarner Losh   lu_byte gcstate;  /* state of garbage collector */
2328e3e3a7aSWarner Losh   lu_byte gckind;  /* kind of GC running */
233*0495ed39SKyle Evans   lu_byte genminormul;  /* control for minor generational collections */
234*0495ed39SKyle Evans   lu_byte genmajormul;  /* control for major generational collections */
2358e3e3a7aSWarner Losh   lu_byte gcrunning;  /* true if GC is running */
236*0495ed39SKyle Evans   lu_byte gcemergency;  /* true if this is an emergency collection */
237*0495ed39SKyle Evans   lu_byte gcpause;  /* size of pause between successive GCs */
238*0495ed39SKyle Evans   lu_byte gcstepmul;  /* GC "speed" */
239*0495ed39SKyle Evans   lu_byte gcstepsize;  /* (log2 of) GC granularity */
2408e3e3a7aSWarner Losh   GCObject *allgc;  /* list of all collectable objects */
2418e3e3a7aSWarner Losh   GCObject **sweepgc;  /* current position of sweep in list */
2428e3e3a7aSWarner Losh   GCObject *finobj;  /* list of collectable objects with finalizers */
2438e3e3a7aSWarner Losh   GCObject *gray;  /* list of gray objects */
2448e3e3a7aSWarner Losh   GCObject *grayagain;  /* list of objects to be traversed atomically */
2458e3e3a7aSWarner Losh   GCObject *weak;  /* list of tables with weak values */
2468e3e3a7aSWarner Losh   GCObject *ephemeron;  /* list of ephemeron tables (weak keys) */
2478e3e3a7aSWarner Losh   GCObject *allweak;  /* list of all-weak tables */
2488e3e3a7aSWarner Losh   GCObject *tobefnz;  /* list of userdata to be GC */
2498e3e3a7aSWarner Losh   GCObject *fixedgc;  /* list of objects not to be collected */
250*0495ed39SKyle Evans   /* fields for generational collector */
251*0495ed39SKyle Evans   GCObject *survival;  /* start of objects that survived one GC cycle */
252*0495ed39SKyle Evans   GCObject *old1;  /* start of old1 objects */
253*0495ed39SKyle Evans   GCObject *reallyold;  /* objects more than one cycle old ("really old") */
254*0495ed39SKyle Evans   GCObject *firstold1;  /* first OLD1 object in the list (if any) */
255*0495ed39SKyle Evans   GCObject *finobjsur;  /* list of survival objects with finalizers */
256*0495ed39SKyle Evans   GCObject *finobjold1;  /* list of old1 objects with finalizers */
257*0495ed39SKyle Evans   GCObject *finobjrold;  /* list of really old objects with finalizers */
2588e3e3a7aSWarner Losh   struct lua_State *twups;  /* list of threads with open upvalues */
2598e3e3a7aSWarner Losh   lua_CFunction panic;  /* to be called in unprotected errors */
2608e3e3a7aSWarner Losh   struct lua_State *mainthread;
261*0495ed39SKyle Evans   TString *memerrmsg;  /* message for memory-allocation errors */
2628e3e3a7aSWarner Losh   TString *tmname[TM_N];  /* array with tag-method names */
2638e3e3a7aSWarner Losh   struct Table *mt[LUA_NUMTAGS];  /* metatables for basic types */
2648e3e3a7aSWarner Losh   TString *strcache[STRCACHE_N][STRCACHE_M];  /* cache for strings in API */
265*0495ed39SKyle Evans   lua_WarnFunction warnf;  /* warning function */
266*0495ed39SKyle Evans   void *ud_warn;         /* auxiliary data to 'warnf' */
2678e3e3a7aSWarner Losh } global_State;
2688e3e3a7aSWarner Losh 
2698e3e3a7aSWarner Losh 
2708e3e3a7aSWarner Losh /*
2718e3e3a7aSWarner Losh ** 'per thread' state
2728e3e3a7aSWarner Losh */
2738e3e3a7aSWarner Losh struct lua_State {
2748e3e3a7aSWarner Losh   CommonHeader;
2758e3e3a7aSWarner Losh   lu_byte status;
276*0495ed39SKyle Evans   lu_byte allowhook;
277*0495ed39SKyle Evans   unsigned short nci;  /* number of items in 'ci' list */
2788e3e3a7aSWarner Losh   StkId top;  /* first free slot in the stack */
2798e3e3a7aSWarner Losh   global_State *l_G;
2808e3e3a7aSWarner Losh   CallInfo *ci;  /* call info for current function */
281*0495ed39SKyle Evans   StkId stack_last;  /* end of stack (last element + 1) */
2828e3e3a7aSWarner Losh   StkId stack;  /* stack base */
2838e3e3a7aSWarner Losh   UpVal *openupval;  /* list of open upvalues in this stack */
2848e3e3a7aSWarner Losh   GCObject *gclist;
2858e3e3a7aSWarner Losh   struct lua_State *twups;  /* list of threads with open upvalues */
2868e3e3a7aSWarner Losh   struct lua_longjmp *errorJmp;  /* current error recover point */
2878e3e3a7aSWarner Losh   CallInfo base_ci;  /* CallInfo for first level (C calling Lua) */
2888e3e3a7aSWarner Losh   volatile lua_Hook hook;
2898e3e3a7aSWarner Losh   ptrdiff_t errfunc;  /* current error handling function (stack index) */
290*0495ed39SKyle Evans   l_uint32 nCcalls;  /* number of nested (non-yieldable | C)  calls */
291*0495ed39SKyle Evans   int oldpc;  /* last pc traced */
2928e3e3a7aSWarner Losh   int basehookcount;
2938e3e3a7aSWarner Losh   int hookcount;
294*0495ed39SKyle Evans   volatile l_signalT hookmask;
2958e3e3a7aSWarner Losh };
2968e3e3a7aSWarner Losh 
2978e3e3a7aSWarner Losh 
2988e3e3a7aSWarner Losh #define G(L)	(L->l_G)
2998e3e3a7aSWarner Losh 
3008e3e3a7aSWarner Losh 
3018e3e3a7aSWarner Losh /*
3028e3e3a7aSWarner Losh ** Union of all collectable objects (only for conversions)
303*0495ed39SKyle Evans ** ISO C99, 6.5.2.3 p.5:
304*0495ed39SKyle Evans ** "if a union contains several structures that share a common initial
305*0495ed39SKyle Evans ** sequence [...], and if the union object currently contains one
306*0495ed39SKyle Evans ** of these structures, it is permitted to inspect the common initial
307*0495ed39SKyle Evans ** part of any of them anywhere that a declaration of the complete type
308*0495ed39SKyle Evans ** of the union is visible."
3098e3e3a7aSWarner Losh */
3108e3e3a7aSWarner Losh union GCUnion {
3118e3e3a7aSWarner Losh   GCObject gc;  /* common header */
3128e3e3a7aSWarner Losh   struct TString ts;
3138e3e3a7aSWarner Losh   struct Udata u;
3148e3e3a7aSWarner Losh   union Closure cl;
3158e3e3a7aSWarner Losh   struct Table h;
3168e3e3a7aSWarner Losh   struct Proto p;
3178e3e3a7aSWarner Losh   struct lua_State th;  /* thread */
318*0495ed39SKyle Evans   struct UpVal upv;
3198e3e3a7aSWarner Losh };
3208e3e3a7aSWarner Losh 
3218e3e3a7aSWarner Losh 
322*0495ed39SKyle Evans /*
323*0495ed39SKyle Evans ** ISO C99, 6.7.2.1 p.14:
324*0495ed39SKyle Evans ** "A pointer to a union object, suitably converted, points to each of
325*0495ed39SKyle Evans ** its members [...], and vice versa."
326*0495ed39SKyle Evans */
3278e3e3a7aSWarner Losh #define cast_u(o)	cast(union GCUnion *, (o))
3288e3e3a7aSWarner Losh 
3298e3e3a7aSWarner Losh /* macros to convert a GCObject into a specific value */
3308e3e3a7aSWarner Losh #define gco2ts(o)  \
3318e3e3a7aSWarner Losh 	check_exp(novariant((o)->tt) == LUA_TSTRING, &((cast_u(o))->ts))
332*0495ed39SKyle Evans #define gco2u(o)  check_exp((o)->tt == LUA_VUSERDATA, &((cast_u(o))->u))
333*0495ed39SKyle Evans #define gco2lcl(o)  check_exp((o)->tt == LUA_VLCL, &((cast_u(o))->cl.l))
334*0495ed39SKyle Evans #define gco2ccl(o)  check_exp((o)->tt == LUA_VCCL, &((cast_u(o))->cl.c))
3358e3e3a7aSWarner Losh #define gco2cl(o)  \
3368e3e3a7aSWarner Losh 	check_exp(novariant((o)->tt) == LUA_TFUNCTION, &((cast_u(o))->cl))
337*0495ed39SKyle Evans #define gco2t(o)  check_exp((o)->tt == LUA_VTABLE, &((cast_u(o))->h))
338*0495ed39SKyle Evans #define gco2p(o)  check_exp((o)->tt == LUA_VPROTO, &((cast_u(o))->p))
339*0495ed39SKyle Evans #define gco2th(o)  check_exp((o)->tt == LUA_VTHREAD, &((cast_u(o))->th))
340*0495ed39SKyle Evans #define gco2upv(o)	check_exp((o)->tt == LUA_VUPVAL, &((cast_u(o))->upv))
3418e3e3a7aSWarner Losh 
3428e3e3a7aSWarner Losh 
343*0495ed39SKyle Evans /*
344*0495ed39SKyle Evans ** macro to convert a Lua object into a GCObject
345*0495ed39SKyle Evans ** (The access to 'tt' tries to ensure that 'v' is actually a Lua object.)
346*0495ed39SKyle Evans */
347*0495ed39SKyle Evans #define obj2gco(v)	check_exp((v)->tt >= LUA_TSTRING, &(cast_u(v)->gc))
3488e3e3a7aSWarner Losh 
3498e3e3a7aSWarner Losh 
3508e3e3a7aSWarner Losh /* actual number of total bytes allocated */
3518e3e3a7aSWarner Losh #define gettotalbytes(g)	cast(lu_mem, (g)->totalbytes + (g)->GCdebt)
3528e3e3a7aSWarner Losh 
3538e3e3a7aSWarner Losh LUAI_FUNC void luaE_setdebt (global_State *g, l_mem debt);
3548e3e3a7aSWarner Losh LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);
3558e3e3a7aSWarner Losh LUAI_FUNC CallInfo *luaE_extendCI (lua_State *L);
3568e3e3a7aSWarner Losh LUAI_FUNC void luaE_freeCI (lua_State *L);
3578e3e3a7aSWarner Losh LUAI_FUNC void luaE_shrinkCI (lua_State *L);
358*0495ed39SKyle Evans LUAI_FUNC void luaE_checkcstack (lua_State *L);
359*0495ed39SKyle Evans LUAI_FUNC void luaE_incCstack (lua_State *L);
360*0495ed39SKyle Evans LUAI_FUNC void luaE_warning (lua_State *L, const char *msg, int tocont);
361*0495ed39SKyle Evans LUAI_FUNC void luaE_warnerror (lua_State *L, const char *where);
3628e3e3a7aSWarner Losh 
3638e3e3a7aSWarner Losh 
3648e3e3a7aSWarner Losh #endif
3658e3e3a7aSWarner Losh 
366