release.sh changes & fixes
[minix3.git] / external / mit / lua / dist / src / lstate.h
blob907af1e60b32d4cd60ae50508a207e8875d9e067
1 /* $NetBSD: lstate.h,v 1.1.1.2 2012/03/15 00:08:04 alnsn Exp $ */
3 /*
4 ** $Id: lstate.h,v 1.1.1.2 2012/03/15 00:08:04 alnsn Exp $
5 ** Global State
6 ** See Copyright Notice in lua.h
7 */
9 #ifndef lstate_h
10 #define lstate_h
12 #include "lua.h"
14 #include "lobject.h"
15 #include "ltm.h"
16 #include "lzio.h"
20 struct lua_longjmp; /* defined in ldo.c */
23 /* table of globals */
24 #define gt(L) (&L->l_gt)
26 /* registry */
27 #define registry(L) (&G(L)->l_registry)
30 /* extra stack space to handle TM calls and some other extras */
31 #define EXTRA_STACK 5
34 #define BASIC_CI_SIZE 8
36 #define BASIC_STACK_SIZE (2*LUA_MINSTACK)
40 typedef struct stringtable {
41 GCObject **hash;
42 lu_int32 nuse; /* number of elements */
43 int size;
44 } stringtable;
48 ** informations about a call
50 typedef struct CallInfo {
51 StkId base; /* base for this function */
52 StkId func; /* function index in the stack */
53 StkId top; /* top for this function */
54 const Instruction *savedpc;
55 int nresults; /* expected number of results from this function */
56 int tailcalls; /* number of tail calls lost under this entry */
57 } CallInfo;
61 #define curr_func(L) (clvalue(L->ci->func))
62 #define ci_func(ci) (clvalue((ci)->func))
63 #define f_isLua(ci) (!ci_func(ci)->c.isC)
64 #define isLua(ci) (ttisfunction((ci)->func) && f_isLua(ci))
68 ** `global state', shared by all threads of this state
70 typedef struct global_State {
71 stringtable strt; /* hash table for strings */
72 lua_Alloc frealloc; /* function to reallocate memory */
73 void *ud; /* auxiliary data to `frealloc' */
74 lu_byte currentwhite;
75 lu_byte gcstate; /* state of garbage collector */
76 int sweepstrgc; /* position of sweep in `strt' */
77 GCObject *rootgc; /* list of all collectable objects */
78 GCObject **sweepgc; /* position of sweep in `rootgc' */
79 GCObject *gray; /* list of gray objects */
80 GCObject *grayagain; /* list of objects to be traversed atomically */
81 GCObject *weak; /* list of weak tables (to be cleared) */
82 GCObject *tmudata; /* last element of list of userdata to be GC */
83 Mbuffer buff; /* temporary buffer for string concatentation */
84 lu_mem GCthreshold;
85 lu_mem totalbytes; /* number of bytes currently allocated */
86 lu_mem estimate; /* an estimate of number of bytes actually in use */
87 lu_mem gcdept; /* how much GC is `behind schedule' */
88 int gcpause; /* size of pause between successive GCs */
89 int gcstepmul; /* GC `granularity' */
90 lua_CFunction panic; /* to be called in unprotected errors */
91 TValue l_registry;
92 struct lua_State *mainthread;
93 UpVal uvhead; /* head of double-linked list of all open upvalues */
94 struct Table *mt[NUM_TAGS]; /* metatables for basic types */
95 TString *tmname[TM_N]; /* array with tag-method names */
96 } global_State;
100 ** `per thread' state
102 struct lua_State {
103 CommonHeader;
104 lu_byte status;
105 StkId top; /* first free slot in the stack */
106 StkId base; /* base of current function */
107 global_State *l_G;
108 CallInfo *ci; /* call info for current function */
109 const Instruction *savedpc; /* `savedpc' of current function */
110 StkId stack_last; /* last free slot in the stack */
111 StkId stack; /* stack base */
112 CallInfo *end_ci; /* points after end of ci array*/
113 CallInfo *base_ci; /* array of CallInfo's */
114 int stacksize;
115 int size_ci; /* size of array `base_ci' */
116 unsigned short nCcalls; /* number of nested C calls */
117 unsigned short baseCcalls; /* nested C calls when resuming coroutine */
118 lu_byte hookmask;
119 lu_byte allowhook;
120 int basehookcount;
121 int hookcount;
122 lua_Hook hook;
123 TValue l_gt; /* table of globals */
124 TValue env; /* temporary place for environments */
125 GCObject *openupval; /* list of open upvalues in this stack */
126 GCObject *gclist;
127 struct lua_longjmp *errorJmp; /* current error recover point */
128 ptrdiff_t errfunc; /* current error handling function (stack index) */
132 #define G(L) (L->l_G)
136 ** Union of all collectable objects
138 union GCObject {
139 GCheader gch;
140 union TString ts;
141 union Udata u;
142 union Closure cl;
143 struct Table h;
144 struct Proto p;
145 struct UpVal uv;
146 struct lua_State th; /* thread */
150 /* macros to convert a GCObject into a specific value */
151 #define rawgco2ts(o) check_exp((o)->gch.tt == LUA_TSTRING, &((o)->ts))
152 #define gco2ts(o) (&rawgco2ts(o)->tsv)
153 #define rawgco2u(o) check_exp((o)->gch.tt == LUA_TUSERDATA, &((o)->u))
154 #define gco2u(o) (&rawgco2u(o)->uv)
155 #define gco2cl(o) check_exp((o)->gch.tt == LUA_TFUNCTION, &((o)->cl))
156 #define gco2h(o) check_exp((o)->gch.tt == LUA_TTABLE, &((o)->h))
157 #define gco2p(o) check_exp((o)->gch.tt == LUA_TPROTO, &((o)->p))
158 #define gco2uv(o) check_exp((o)->gch.tt == LUA_TUPVAL, &((o)->uv))
159 #define ngcotouv(o) \
160 check_exp((o) == NULL || (o)->gch.tt == LUA_TUPVAL, &((o)->uv))
161 #define gco2th(o) check_exp((o)->gch.tt == LUA_TTHREAD, &((o)->th))
163 /* macro to convert any Lua object into a GCObject */
164 #define obj2gco(v) (cast(GCObject *, (v)))
167 LUAI_FUNC lua_State *luaE_newthread (lua_State *L);
168 LUAI_FUNC void luaE_freethread (lua_State *L, lua_State *L1);
170 #endif