monotone

monotone Mtn Source Tree

Root/lua/lstate.h

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

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status