aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/LuaJIT-1.1.7/src/lobject.h
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/LuaJIT-1.1.7/src/lobject.h')
-rw-r--r--libraries/LuaJIT-1.1.7/src/lobject.h386
1 files changed, 386 insertions, 0 deletions
diff --git a/libraries/LuaJIT-1.1.7/src/lobject.h b/libraries/LuaJIT-1.1.7/src/lobject.h
new file mode 100644
index 0000000..df9c528
--- /dev/null
+++ b/libraries/LuaJIT-1.1.7/src/lobject.h
@@ -0,0 +1,386 @@
1/*
2** $Id: lobject.h,v 2.20.1.2 2008/08/06 13:29:48 roberto Exp $
3** Type definitions for Lua objects
4** See Copyright Notice in lua.h
5*/
6
7
8#ifndef lobject_h
9#define lobject_h
10
11
12#include <stdarg.h>
13
14
15#include "llimits.h"
16#include "lua.h"
17
18
19/* tags for values visible from Lua */
20#define LAST_TAG LUA_TTHREAD
21
22#define NUM_TAGS (LAST_TAG+1)
23
24
25/*
26** Extra tags for non-values
27*/
28#define LUA_TPROTO (LAST_TAG+1)
29#define LUA_TUPVAL (LAST_TAG+2)
30#define LUA_TDEADKEY (LAST_TAG+3)
31
32
33/*
34** Union of all collectable objects
35*/
36typedef union GCObject GCObject;
37
38
39/*
40** Common Header for all collectable objects (in macro form, to be
41** included in other objects)
42*/
43#define CommonHeader GCObject *next; lu_byte tt; lu_byte marked
44
45
46/*
47** Common header in struct form
48*/
49typedef struct GCheader {
50 CommonHeader;
51} GCheader;
52
53
54
55
56/*
57** Union of all Lua values
58*/
59typedef union {
60 GCObject *gc;
61 void *p;
62 lua_Number n;
63 ptrdiff_t na[sizeof(lua_Number)/sizeof(ptrdiff_t)]; /* LuaJIT kludge */
64 int b;
65} Value;
66
67
68/*
69** Tagged Values
70*/
71
72#define TValuefields Value value; int tt
73
74typedef struct lua_TValue {
75 TValuefields;
76} LUA_TVALUE_ALIGN TValue;
77
78
79/* Macros to test type */
80#define ttisnil(o) (ttype(o) == LUA_TNIL)
81#define ttisnumber(o) (ttype(o) == LUA_TNUMBER)
82#define ttisstring(o) (ttype(o) == LUA_TSTRING)
83#define ttistable(o) (ttype(o) == LUA_TTABLE)
84#define ttisfunction(o) (ttype(o) == LUA_TFUNCTION)
85#define ttisboolean(o) (ttype(o) == LUA_TBOOLEAN)
86#define ttisuserdata(o) (ttype(o) == LUA_TUSERDATA)
87#define ttisthread(o) (ttype(o) == LUA_TTHREAD)
88#define ttislightuserdata(o) (ttype(o) == LUA_TLIGHTUSERDATA)
89
90/* Macros to access values */
91#define ttype(o) ((o)->tt)
92#define gcvalue(o) check_exp(iscollectable(o), (o)->value.gc)
93#define pvalue(o) check_exp(ttislightuserdata(o), (o)->value.p)
94#define nvalue(o) check_exp(ttisnumber(o), (o)->value.n)
95#define rawtsvalue(o) check_exp(ttisstring(o), &(o)->value.gc->ts)
96#define tsvalue(o) (&rawtsvalue(o)->tsv)
97#define rawuvalue(o) check_exp(ttisuserdata(o), &(o)->value.gc->u)
98#define uvalue(o) (&rawuvalue(o)->uv)
99#define clvalue(o) check_exp(ttisfunction(o), &(o)->value.gc->cl)
100#define hvalue(o) check_exp(ttistable(o), &(o)->value.gc->h)
101#define bvalue(o) check_exp(ttisboolean(o), (o)->value.b)
102#define thvalue(o) check_exp(ttisthread(o), &(o)->value.gc->th)
103
104#define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0))
105
106/*
107** for internal debug only
108*/
109#define checkconsistency(obj) \
110 lua_assert(!iscollectable(obj) || (ttype(obj) == (obj)->value.gc->gch.tt))
111
112#define checkliveness(g,obj) \
113 lua_assert(!iscollectable(obj) || \
114 ((ttype(obj) == (obj)->value.gc->gch.tt) && !isdead(g, (obj)->value.gc)))
115
116
117/* Macros to set values */
118#define setnilvalue(obj) ((obj)->tt=LUA_TNIL)
119
120#define setnvalue(obj,x) \
121 { TValue *i_o=(obj); i_o->value.n=(x); i_o->tt=LUA_TNUMBER; }
122
123#define setpvalue(obj,x) \
124 { TValue *i_o=(obj); i_o->value.p=(x); i_o->tt=LUA_TLIGHTUSERDATA; }
125
126#define setbvalue(obj,x) \
127 { TValue *i_o=(obj); i_o->value.b=(x); i_o->tt=LUA_TBOOLEAN; }
128
129#define setsvalue(L,obj,x) \
130 { TValue *i_o=(obj); \
131 i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TSTRING; \
132 checkliveness(G(L),i_o); }
133
134#define setuvalue(L,obj,x) \
135 { TValue *i_o=(obj); \
136 i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TUSERDATA; \
137 checkliveness(G(L),i_o); }
138
139#define setthvalue(L,obj,x) \
140 { TValue *i_o=(obj); \
141 i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTHREAD; \
142 checkliveness(G(L),i_o); }
143
144#define setclvalue(L,obj,x) \
145 { TValue *i_o=(obj); \
146 i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TFUNCTION; \
147 checkliveness(G(L),i_o); }
148
149#define sethvalue(L,obj,x) \
150 { TValue *i_o=(obj); \
151 i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTABLE; \
152 checkliveness(G(L),i_o); }
153
154#define setptvalue(L,obj,x) \
155 { TValue *i_o=(obj); \
156 i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TPROTO; \
157 checkliveness(G(L),i_o); }
158
159
160
161
162#define setobj(L,obj1,obj2) \
163 { const TValue *o2=(obj2); TValue *o1=(obj1); \
164 o1->value = o2->value; o1->tt=o2->tt; \
165 checkliveness(G(L),o1); }
166
167
168/*
169** different types of sets, according to destination
170*/
171
172/* from stack to (same) stack */
173#define setobjs2s setobj
174/* to stack (not from same stack) */
175#define setobj2s setobj
176#define setsvalue2s setsvalue
177#define sethvalue2s sethvalue
178#define setptvalue2s setptvalue
179/* from table to same table */
180#define setobjt2t setobj
181/* to table */
182#define setobj2t setobj
183/* to new object */
184#define setobj2n setobj
185#define setsvalue2n setsvalue
186
187#define setttype(obj, tt) (ttype(obj) = (tt))
188
189
190#define iscollectable(o) (ttype(o) >= LUA_TSTRING)
191
192
193
194typedef TValue *StkId; /* index to stack elements */
195
196
197/*
198** String headers for string table
199*/
200typedef union TString {
201 L_Umaxalign dummy; /* ensures maximum alignment for strings */
202 struct {
203 CommonHeader;
204 lu_byte reserved;
205 unsigned int hash;
206 size_t len;
207 } tsv;
208} TString;
209
210
211#define getstr(ts) cast(const char *, (ts) + 1)
212#define svalue(o) getstr(rawtsvalue(o))
213
214
215
216typedef union Udata {
217 L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */
218 struct {
219 CommonHeader;
220 struct Table *metatable;
221 struct Table *env;
222 size_t len;
223 } uv;
224} Udata;
225
226
227
228
229/*
230** Function Prototypes
231*/
232typedef struct Proto {
233 CommonHeader;
234 TValue *k; /* constants used by the function */
235 Instruction *code;
236 struct Proto **p; /* functions defined inside the function */
237 int *lineinfo; /* map from opcodes to source lines */
238 struct LocVar *locvars; /* information about local variables */
239 TString **upvalues; /* upvalue names */
240 TString *source;
241 int sizeupvalues;
242 int sizek; /* size of `k' */
243 int sizecode;
244 int sizelineinfo;
245 int sizep; /* size of `p' */
246 int sizelocvars;
247 int linedefined;
248 int lastlinedefined;
249 GCObject *gclist;
250 lu_byte nups; /* number of upvalues */
251 lu_byte numparams;
252 lu_byte is_vararg;
253 lu_byte maxstacksize;
254 /* LuaJIT extensions */
255 void *jit_mcode; /* compiled machine code base address */
256 size_t jit_szmcode; /* size of compiled mcode */
257 int jit_status; /* JIT engine status code */
258} Proto;
259
260
261/* masks for new-style vararg */
262#define VARARG_HASARG 1
263#define VARARG_ISVARARG 2
264#define VARARG_NEEDSARG 4
265
266
267typedef struct LocVar {
268 TString *varname;
269 int startpc; /* first point where variable is active */
270 int endpc; /* first point where variable is dead */
271} LocVar;
272
273
274
275/*
276** Upvalues
277*/
278
279typedef struct UpVal {
280 CommonHeader;
281 TValue *v; /* points to stack or to its own value */
282 union {
283 TValue value; /* the value (when closed) */
284 struct { /* double linked list (when open) */
285 struct UpVal *prev;
286 struct UpVal *next;
287 } l;
288 } u;
289} UpVal;
290
291
292/*
293** Closures
294*/
295
296#define ClosureHeader \
297 CommonHeader; lu_byte isC; lu_byte nupvalues; GCObject *gclist; \
298 struct Table *env; lua_CFunction jit_gate
299
300typedef struct CClosure {
301 ClosureHeader;
302 lua_CFunction f;
303 TValue upvalue[1];
304} CClosure;
305
306
307typedef struct LClosure {
308 ClosureHeader;
309 struct Proto *p;
310 UpVal *upvals[1];
311} LClosure;
312
313
314typedef union Closure {
315 CClosure c;
316 LClosure l;
317} Closure;
318
319
320#define iscfunction(o) (ttype(o) == LUA_TFUNCTION && clvalue(o)->c.isC)
321#define isLfunction(o) (ttype(o) == LUA_TFUNCTION && !clvalue(o)->c.isC)
322
323
324/*
325** Tables
326*/
327
328typedef union TKey {
329 struct {
330 TValuefields;
331 struct Node *next; /* for chaining */
332 } nk;
333 TValue tvk;
334} TKey;
335
336
337typedef struct Node {
338 TValue i_val;
339 TKey i_key;
340} Node;
341
342
343typedef struct Table {
344 CommonHeader;
345 lu_byte flags; /* 1<<p means tagmethod(p) is not present */
346 lu_byte lsizenode; /* log2 of size of `node' array */
347 struct Table *metatable;
348 TValue *array; /* array part */
349 Node *node;
350 Node *lastfree; /* any free position is before this position */
351 GCObject *gclist;
352 int sizearray; /* size of `array' array */
353} Table;
354
355
356
357/*
358** `module' operation for hashing (size is always a power of 2)
359*/
360#define lmod(s,size) \
361 (check_exp((size&(size-1))==0, (cast(int, (s) & ((size)-1)))))
362
363
364#define twoto(x) (1<<(x))
365#define sizenode(t) (twoto((t)->lsizenode))
366
367
368#define luaO_nilobject (&luaO_nilobject_)
369
370LUAI_DATA const TValue luaO_nilobject_;
371
372#define ceillog2(x) (luaO_log2((x)-1) + 1)
373
374LUAI_FUNC int luaO_log2 (unsigned int x);
375LUAI_FUNC int luaO_int2fb (unsigned int x);
376LUAI_FUNC int luaO_fb2int (int x);
377LUAI_FUNC int luaO_rawequalObj (const TValue *t1, const TValue *t2);
378LUAI_FUNC int luaO_str2d (const char *s, lua_Number *result);
379LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt,
380 va_list argp);
381LUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...);
382LUAI_FUNC void luaO_chunkid (char *out, const char *source, size_t len);
383
384
385#endif
386