diff options
author | Marcin Bukat <marcin.bukat@gmail.com> | 2014-04-02 20:46:06 +0200 |
---|---|---|
committer | Marcin Bukat <marcin.bukat@gmail.com> | 2014-04-02 20:46:06 +0200 |
commit | bfd0179042b0b02fb88748d54e56e7e208bb117f (patch) | |
tree | 42d5fd51574054caaf673420fca1ec962d62d2f2 /apps/plugins/lua/lobject.h | |
parent | 36378988ad4059982742f05f5eb50580b456840a (diff) | |
download | rockbox-bfd0179042b0b02fb88748d54e56e7e208bb117f.tar.gz rockbox-bfd0179042b0b02fb88748d54e56e7e208bb117f.zip |
Revert "Update lua plugin to 5.2.3"
FILE typedef to *void needs more work to not break sim and
application builds. I checked only a few random native builds
unfortunately. Sorry for inconvenience.
Diffstat (limited to 'apps/plugins/lua/lobject.h')
-rw-r--r-- | apps/plugins/lua/lobject.h | 460 |
1 files changed, 117 insertions, 343 deletions
diff --git a/apps/plugins/lua/lobject.h b/apps/plugins/lua/lobject.h index 3a630b944c..93288fe0fb 100644 --- a/apps/plugins/lua/lobject.h +++ b/apps/plugins/lua/lobject.h | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lobject.h,v 2.71.1.1 2013/04/12 18:48:47 roberto Exp $ | 2 | ** $Id$ |
3 | ** Type definitions for Lua objects | 3 | ** Type definitions for Lua objects |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -16,52 +16,18 @@ | |||
16 | #include "lua.h" | 16 | #include "lua.h" |
17 | 17 | ||
18 | 18 | ||
19 | /* | 19 | /* tags for values visible from Lua */ |
20 | ** Extra tags for non-values | 20 | #define LAST_TAG LUA_TTHREAD |
21 | */ | ||
22 | #define LUA_TPROTO LUA_NUMTAGS | ||
23 | #define LUA_TUPVAL (LUA_NUMTAGS+1) | ||
24 | #define LUA_TDEADKEY (LUA_NUMTAGS+2) | ||
25 | 21 | ||
26 | /* | 22 | #define NUM_TAGS (LAST_TAG+1) |
27 | ** number of all possible tags (including LUA_TNONE but excluding DEADKEY) | ||
28 | */ | ||
29 | #define LUA_TOTALTAGS (LUA_TUPVAL+2) | ||
30 | 23 | ||
31 | 24 | ||
32 | /* | 25 | /* |
33 | ** tags for Tagged Values have the following use of bits: | 26 | ** Extra tags for non-values |
34 | ** bits 0-3: actual tag (a LUA_T* value) | ||
35 | ** bits 4-5: variant bits | ||
36 | ** bit 6: whether value is collectable | ||
37 | */ | 27 | */ |
38 | 28 | #define LUA_TPROTO (LAST_TAG+1) | |
39 | #define VARBITS (3 << 4) | 29 | #define LUA_TUPVAL (LAST_TAG+2) |
40 | 30 | #define LUA_TDEADKEY (LAST_TAG+3) | |
41 | |||
42 | /* | ||
43 | ** LUA_TFUNCTION variants: | ||
44 | ** 0 - Lua function | ||
45 | ** 1 - light C function | ||
46 | ** 2 - regular C function (closure) | ||
47 | */ | ||
48 | |||
49 | /* Variant tags for functions */ | ||
50 | #define LUA_TLCL (LUA_TFUNCTION | (0 << 4)) /* Lua closure */ | ||
51 | #define LUA_TLCF (LUA_TFUNCTION | (1 << 4)) /* light C function */ | ||
52 | #define LUA_TCCL (LUA_TFUNCTION | (2 << 4)) /* C closure */ | ||
53 | |||
54 | |||
55 | /* Variant tags for strings */ | ||
56 | #define LUA_TSHRSTR (LUA_TSTRING | (0 << 4)) /* short strings */ | ||
57 | #define LUA_TLNGSTR (LUA_TSTRING | (1 << 4)) /* long strings */ | ||
58 | |||
59 | |||
60 | /* Bit mark for collectable types */ | ||
61 | #define BIT_ISCOLLECTABLE (1 << 6) | ||
62 | |||
63 | /* mark a tag as collectable */ | ||
64 | #define ctb(t) ((t) | BIT_ISCOLLECTABLE) | ||
65 | 31 | ||
66 | 32 | ||
67 | /* | 33 | /* |
@@ -86,165 +52,120 @@ typedef struct GCheader { | |||
86 | 52 | ||
87 | 53 | ||
88 | 54 | ||
55 | |||
89 | /* | 56 | /* |
90 | ** Union of all Lua values | 57 | ** Union of all Lua values |
91 | */ | 58 | */ |
92 | typedef union Value Value; | 59 | typedef union { |
93 | 60 | GCObject *gc; | |
94 | 61 | void *p; | |
95 | #define numfield lua_Number n; /* numbers */ | 62 | lua_Number n; |
96 | 63 | int b; | |
64 | } Value; | ||
97 | 65 | ||
98 | 66 | ||
99 | /* | 67 | /* |
100 | ** Tagged Values. This is the basic representation of values in Lua, | 68 | ** Tagged Values |
101 | ** an actual value plus a tag with its type. | ||
102 | */ | 69 | */ |
103 | 70 | ||
104 | #define TValuefields Value value_; int tt_ | 71 | #define TValuefields Value value; int tt |
105 | |||
106 | typedef struct lua_TValue TValue; | ||
107 | |||
108 | |||
109 | /* macro defining a nil value */ | ||
110 | #define NILCONSTANT {NULL}, LUA_TNIL | ||
111 | 72 | ||
112 | 73 | typedef struct lua_TValue { | |
113 | #define val_(o) ((o)->value_) | 74 | TValuefields; |
114 | #define num_(o) (val_(o).n) | 75 | } TValue; |
115 | |||
116 | |||
117 | /* raw type tag of a TValue */ | ||
118 | #define rttype(o) ((o)->tt_) | ||
119 | |||
120 | /* tag with no variants (bits 0-3) */ | ||
121 | #define novariant(x) ((x) & 0x0F) | ||
122 | |||
123 | /* type tag of a TValue (bits 0-3 for tags + variant bits 4-5) */ | ||
124 | #define ttype(o) (rttype(o) & 0x3F) | ||
125 | |||
126 | /* type tag of a TValue with no variants (bits 0-3) */ | ||
127 | #define ttypenv(o) (novariant(rttype(o))) | ||
128 | 76 | ||
129 | 77 | ||
130 | /* Macros to test type */ | 78 | /* Macros to test type */ |
131 | #define checktag(o,t) (rttype(o) == (t)) | 79 | #define ttisnil(o) (ttype(o) == LUA_TNIL) |
132 | #define checktype(o,t) (ttypenv(o) == (t)) | 80 | #define ttisnumber(o) (ttype(o) == LUA_TNUMBER) |
133 | #define ttisnumber(o) checktag((o), LUA_TNUMBER) | 81 | #define ttisstring(o) (ttype(o) == LUA_TSTRING) |
134 | #define ttisnil(o) checktag((o), LUA_TNIL) | 82 | #define ttistable(o) (ttype(o) == LUA_TTABLE) |
135 | #define ttisboolean(o) checktag((o), LUA_TBOOLEAN) | 83 | #define ttisfunction(o) (ttype(o) == LUA_TFUNCTION) |
136 | #define ttislightuserdata(o) checktag((o), LUA_TLIGHTUSERDATA) | 84 | #define ttisboolean(o) (ttype(o) == LUA_TBOOLEAN) |
137 | #define ttisstring(o) checktype((o), LUA_TSTRING) | 85 | #define ttisuserdata(o) (ttype(o) == LUA_TUSERDATA) |
138 | #define ttisshrstring(o) checktag((o), ctb(LUA_TSHRSTR)) | 86 | #define ttisthread(o) (ttype(o) == LUA_TTHREAD) |
139 | #define ttislngstring(o) checktag((o), ctb(LUA_TLNGSTR)) | 87 | #define ttislightuserdata(o) (ttype(o) == LUA_TLIGHTUSERDATA) |
140 | #define ttistable(o) checktag((o), ctb(LUA_TTABLE)) | ||
141 | #define ttisfunction(o) checktype(o, LUA_TFUNCTION) | ||
142 | #define ttisclosure(o) ((rttype(o) & 0x1F) == LUA_TFUNCTION) | ||
143 | #define ttisCclosure(o) checktag((o), ctb(LUA_TCCL)) | ||
144 | #define ttisLclosure(o) checktag((o), ctb(LUA_TLCL)) | ||
145 | #define ttislcf(o) checktag((o), LUA_TLCF) | ||
146 | #define ttisuserdata(o) checktag((o), ctb(LUA_TUSERDATA)) | ||
147 | #define ttisthread(o) checktag((o), ctb(LUA_TTHREAD)) | ||
148 | #define ttisdeadkey(o) checktag((o), LUA_TDEADKEY) | ||
149 | |||
150 | #define ttisequal(o1,o2) (rttype(o1) == rttype(o2)) | ||
151 | 88 | ||
152 | /* Macros to access values */ | 89 | /* Macros to access values */ |
153 | #define nvalue(o) check_exp(ttisnumber(o), num_(o)) | 90 | #define ttype(o) ((o)->tt) |
154 | #define gcvalue(o) check_exp(iscollectable(o), val_(o).gc) | 91 | #define gcvalue(o) check_exp(iscollectable(o), (o)->value.gc) |
155 | #define pvalue(o) check_exp(ttislightuserdata(o), val_(o).p) | 92 | #define pvalue(o) check_exp(ttislightuserdata(o), (o)->value.p) |
156 | #define rawtsvalue(o) check_exp(ttisstring(o), &val_(o).gc->ts) | 93 | #define nvalue(o) check_exp(ttisnumber(o), (o)->value.n) |
94 | #define rawtsvalue(o) check_exp(ttisstring(o), &(o)->value.gc->ts) | ||
157 | #define tsvalue(o) (&rawtsvalue(o)->tsv) | 95 | #define tsvalue(o) (&rawtsvalue(o)->tsv) |
158 | #define rawuvalue(o) check_exp(ttisuserdata(o), &val_(o).gc->u) | 96 | #define rawuvalue(o) check_exp(ttisuserdata(o), &(o)->value.gc->u) |
159 | #define uvalue(o) (&rawuvalue(o)->uv) | 97 | #define uvalue(o) (&rawuvalue(o)->uv) |
160 | #define clvalue(o) check_exp(ttisclosure(o), &val_(o).gc->cl) | 98 | #define clvalue(o) check_exp(ttisfunction(o), &(o)->value.gc->cl) |
161 | #define clLvalue(o) check_exp(ttisLclosure(o), &val_(o).gc->cl.l) | 99 | #define hvalue(o) check_exp(ttistable(o), &(o)->value.gc->h) |
162 | #define clCvalue(o) check_exp(ttisCclosure(o), &val_(o).gc->cl.c) | 100 | #define bvalue(o) check_exp(ttisboolean(o), (o)->value.b) |
163 | #define fvalue(o) check_exp(ttislcf(o), val_(o).f) | 101 | #define thvalue(o) check_exp(ttisthread(o), &(o)->value.gc->th) |
164 | #define hvalue(o) check_exp(ttistable(o), &val_(o).gc->h) | ||
165 | #define bvalue(o) check_exp(ttisboolean(o), val_(o).b) | ||
166 | #define thvalue(o) check_exp(ttisthread(o), &val_(o).gc->th) | ||
167 | /* a dead value may get the 'gc' field, but cannot access its contents */ | ||
168 | #define deadvalue(o) check_exp(ttisdeadkey(o), cast(void *, val_(o).gc)) | ||
169 | 102 | ||
170 | #define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0)) | 103 | #define l_isfalse(o) (ttisnil(o) || (ttisboolean(o) && bvalue(o) == 0)) |
171 | 104 | ||
172 | 105 | /* | |
173 | #define iscollectable(o) (rttype(o) & BIT_ISCOLLECTABLE) | 106 | ** for internal debug only |
174 | 107 | */ | |
175 | 108 | #define checkconsistency(obj) \ | |
176 | /* Macros for internal tests */ | 109 | lua_assert(!iscollectable(obj) || (ttype(obj) == (obj)->value.gc->gch.tt)) |
177 | #define righttt(obj) (ttype(obj) == gcvalue(obj)->gch.tt) | ||
178 | 110 | ||
179 | #define checkliveness(g,obj) \ | 111 | #define checkliveness(g,obj) \ |
180 | lua_longassert(!iscollectable(obj) || \ | 112 | lua_assert(!iscollectable(obj) || \ |
181 | (righttt(obj) && !isdead(g,gcvalue(obj)))) | 113 | ((ttype(obj) == (obj)->value.gc->gch.tt) && !isdead(g, (obj)->value.gc))) |
182 | 114 | ||
183 | 115 | ||
184 | /* Macros to set values */ | 116 | /* Macros to set values */ |
185 | #define settt_(o,t) ((o)->tt_=(t)) | 117 | #define setnilvalue(obj) ((obj)->tt=LUA_TNIL) |
186 | 118 | ||
187 | #define setnvalue(obj,x) \ | 119 | #define setnvalue(obj,x) \ |
188 | { TValue *io=(obj); num_(io)=(x); settt_(io, LUA_TNUMBER); } | 120 | { TValue *i_o=(obj); i_o->value.n=(x); i_o->tt=LUA_TNUMBER; } |
189 | |||
190 | #define setnilvalue(obj) settt_(obj, LUA_TNIL) | ||
191 | |||
192 | #define setfvalue(obj,x) \ | ||
193 | { TValue *io=(obj); val_(io).f=(x); settt_(io, LUA_TLCF); } | ||
194 | 121 | ||
195 | #define setpvalue(obj,x) \ | 122 | #define setpvalue(obj,x) \ |
196 | { TValue *io=(obj); val_(io).p=(x); settt_(io, LUA_TLIGHTUSERDATA); } | 123 | { TValue *i_o=(obj); i_o->value.p=(x); i_o->tt=LUA_TLIGHTUSERDATA; } |
197 | 124 | ||
198 | #define setbvalue(obj,x) \ | 125 | #define setbvalue(obj,x) \ |
199 | { TValue *io=(obj); val_(io).b=(x); settt_(io, LUA_TBOOLEAN); } | 126 | { TValue *i_o=(obj); i_o->value.b=(x); i_o->tt=LUA_TBOOLEAN; } |
200 | |||
201 | #define setgcovalue(L,obj,x) \ | ||
202 | { TValue *io=(obj); GCObject *i_g=(x); \ | ||
203 | val_(io).gc=i_g; settt_(io, ctb(gch(i_g)->tt)); } | ||
204 | 127 | ||
205 | #define setsvalue(L,obj,x) \ | 128 | #define setsvalue(L,obj,x) \ |
206 | { TValue *io=(obj); \ | 129 | { TValue *i_o=(obj); \ |
207 | TString *x_ = (x); \ | 130 | i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TSTRING; \ |
208 | val_(io).gc=cast(GCObject *, x_); settt_(io, ctb(x_->tsv.tt)); \ | 131 | checkliveness(G(L),i_o); } |
209 | checkliveness(G(L),io); } | ||
210 | 132 | ||
211 | #define setuvalue(L,obj,x) \ | 133 | #define setuvalue(L,obj,x) \ |
212 | { TValue *io=(obj); \ | 134 | { TValue *i_o=(obj); \ |
213 | val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TUSERDATA)); \ | 135 | i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TUSERDATA; \ |
214 | checkliveness(G(L),io); } | 136 | checkliveness(G(L),i_o); } |
215 | 137 | ||
216 | #define setthvalue(L,obj,x) \ | 138 | #define setthvalue(L,obj,x) \ |
217 | { TValue *io=(obj); \ | 139 | { TValue *i_o=(obj); \ |
218 | val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TTHREAD)); \ | 140 | i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTHREAD; \ |
219 | checkliveness(G(L),io); } | 141 | checkliveness(G(L),i_o); } |
220 | 142 | ||
221 | #define setclLvalue(L,obj,x) \ | 143 | #define setclvalue(L,obj,x) \ |
222 | { TValue *io=(obj); \ | 144 | { TValue *i_o=(obj); \ |
223 | val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TLCL)); \ | 145 | i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TFUNCTION; \ |
224 | checkliveness(G(L),io); } | 146 | checkliveness(G(L),i_o); } |
225 | |||
226 | #define setclCvalue(L,obj,x) \ | ||
227 | { TValue *io=(obj); \ | ||
228 | val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TCCL)); \ | ||
229 | checkliveness(G(L),io); } | ||
230 | 147 | ||
231 | #define sethvalue(L,obj,x) \ | 148 | #define sethvalue(L,obj,x) \ |
232 | { TValue *io=(obj); \ | 149 | { TValue *i_o=(obj); \ |
233 | val_(io).gc=cast(GCObject *, (x)); settt_(io, ctb(LUA_TTABLE)); \ | 150 | i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TTABLE; \ |
234 | checkliveness(G(L),io); } | 151 | checkliveness(G(L),i_o); } |
152 | |||
153 | #define setptvalue(L,obj,x) \ | ||
154 | { TValue *i_o=(obj); \ | ||
155 | i_o->value.gc=cast(GCObject *, (x)); i_o->tt=LUA_TPROTO; \ | ||
156 | checkliveness(G(L),i_o); } | ||
235 | 157 | ||
236 | #define setdeadvalue(obj) settt_(obj, LUA_TDEADKEY) | ||
237 | 158 | ||
238 | 159 | ||
239 | 160 | ||
240 | #define setobj(L,obj1,obj2) \ | 161 | #define setobj(L,obj1,obj2) \ |
241 | { const TValue *io2=(obj2); TValue *io1=(obj1); \ | 162 | { const TValue *o2=(obj2); TValue *o1=(obj1); \ |
242 | io1->value_ = io2->value_; io1->tt_ = io2->tt_; \ | 163 | o1->value = o2->value; o1->tt=o2->tt; \ |
243 | checkliveness(G(L),io1); } | 164 | checkliveness(G(L),o1); } |
244 | 165 | ||
245 | 166 | ||
246 | /* | 167 | /* |
247 | ** different types of assignments, according to destination | 168 | ** different types of sets, according to destination |
248 | */ | 169 | */ |
249 | 170 | ||
250 | /* from stack to (same) stack */ | 171 | /* from stack to (same) stack */ |
@@ -262,204 +183,47 @@ typedef struct lua_TValue TValue; | |||
262 | #define setobj2n setobj | 183 | #define setobj2n setobj |
263 | #define setsvalue2n setsvalue | 184 | #define setsvalue2n setsvalue |
264 | 185 | ||
265 | 186 | #define setttype(obj, tt) (ttype(obj) = (tt)) | |
266 | /* check whether a number is valid (useful only for NaN trick) */ | ||
267 | #define luai_checknum(L,o,c) { /* empty */ } | ||
268 | |||
269 | |||
270 | /* | ||
271 | ** {====================================================== | ||
272 | ** NaN Trick | ||
273 | ** ======================================================= | ||
274 | */ | ||
275 | #if defined(LUA_NANTRICK) | ||
276 | |||
277 | /* | ||
278 | ** numbers are represented in the 'd_' field. All other values have the | ||
279 | ** value (NNMARK | tag) in 'tt__'. A number with such pattern would be | ||
280 | ** a "signaled NaN", which is never generated by regular operations by | ||
281 | ** the CPU (nor by 'strtod') | ||
282 | */ | ||
283 | |||
284 | /* allows for external implementation for part of the trick */ | ||
285 | #if !defined(NNMARK) /* { */ | ||
286 | |||
287 | |||
288 | #if !defined(LUA_IEEEENDIAN) | ||
289 | #error option 'LUA_NANTRICK' needs 'LUA_IEEEENDIAN' | ||
290 | #endif | ||
291 | |||
292 | |||
293 | #define NNMARK 0x7FF7A500 | ||
294 | #define NNMASK 0x7FFFFF00 | ||
295 | |||
296 | #undef TValuefields | ||
297 | #undef NILCONSTANT | ||
298 | |||
299 | #if (LUA_IEEEENDIAN == 0) /* { */ | ||
300 | |||
301 | /* little endian */ | ||
302 | #define TValuefields \ | ||
303 | union { struct { Value v__; int tt__; } i; double d__; } u | ||
304 | #define NILCONSTANT {{{NULL}, tag2tt(LUA_TNIL)}} | ||
305 | /* field-access macros */ | ||
306 | #define v_(o) ((o)->u.i.v__) | ||
307 | #define d_(o) ((o)->u.d__) | ||
308 | #define tt_(o) ((o)->u.i.tt__) | ||
309 | |||
310 | #else /* }{ */ | ||
311 | |||
312 | /* big endian */ | ||
313 | #define TValuefields \ | ||
314 | union { struct { int tt__; Value v__; } i; double d__; } u | ||
315 | #define NILCONSTANT {{tag2tt(LUA_TNIL), {NULL}}} | ||
316 | /* field-access macros */ | ||
317 | #define v_(o) ((o)->u.i.v__) | ||
318 | #define d_(o) ((o)->u.d__) | ||
319 | #define tt_(o) ((o)->u.i.tt__) | ||
320 | |||
321 | #endif /* } */ | ||
322 | |||
323 | #endif /* } */ | ||
324 | 187 | ||
325 | 188 | ||
326 | /* correspondence with standard representation */ | 189 | #define iscollectable(o) (ttype(o) >= LUA_TSTRING) |
327 | #undef val_ | ||
328 | #define val_(o) v_(o) | ||
329 | #undef num_ | ||
330 | #define num_(o) d_(o) | ||
331 | 190 | ||
332 | 191 | ||
333 | #undef numfield | ||
334 | #define numfield /* no such field; numbers are the entire struct */ | ||
335 | |||
336 | /* basic check to distinguish numbers from non-numbers */ | ||
337 | #undef ttisnumber | ||
338 | #define ttisnumber(o) ((tt_(o) & NNMASK) != NNMARK) | ||
339 | |||
340 | #define tag2tt(t) (NNMARK | (t)) | ||
341 | |||
342 | #undef rttype | ||
343 | #define rttype(o) (ttisnumber(o) ? LUA_TNUMBER : tt_(o) & 0xff) | ||
344 | |||
345 | #undef settt_ | ||
346 | #define settt_(o,t) (tt_(o) = tag2tt(t)) | ||
347 | |||
348 | #undef setnvalue | ||
349 | #define setnvalue(obj,x) \ | ||
350 | { TValue *io_=(obj); num_(io_)=(x); lua_assert(ttisnumber(io_)); } | ||
351 | |||
352 | #undef setobj | ||
353 | #define setobj(L,obj1,obj2) \ | ||
354 | { const TValue *o2_=(obj2); TValue *o1_=(obj1); \ | ||
355 | o1_->u = o2_->u; \ | ||
356 | checkliveness(G(L),o1_); } | ||
357 | |||
358 | |||
359 | /* | ||
360 | ** these redefinitions are not mandatory, but these forms are more efficient | ||
361 | */ | ||
362 | |||
363 | #undef checktag | ||
364 | #undef checktype | ||
365 | #define checktag(o,t) (tt_(o) == tag2tt(t)) | ||
366 | #define checktype(o,t) (ctb(tt_(o) | VARBITS) == ctb(tag2tt(t) | VARBITS)) | ||
367 | |||
368 | #undef ttisequal | ||
369 | #define ttisequal(o1,o2) \ | ||
370 | (ttisnumber(o1) ? ttisnumber(o2) : (tt_(o1) == tt_(o2))) | ||
371 | |||
372 | |||
373 | #undef luai_checknum | ||
374 | #define luai_checknum(L,o,c) { if (!ttisnumber(o)) c; } | ||
375 | |||
376 | #endif | ||
377 | /* }====================================================== */ | ||
378 | |||
379 | |||
380 | |||
381 | /* | ||
382 | ** {====================================================== | ||
383 | ** types and prototypes | ||
384 | ** ======================================================= | ||
385 | */ | ||
386 | |||
387 | |||
388 | union Value { | ||
389 | GCObject *gc; /* collectable objects */ | ||
390 | void *p; /* light userdata */ | ||
391 | int b; /* booleans */ | ||
392 | lua_CFunction f; /* light C functions */ | ||
393 | numfield /* numbers */ | ||
394 | }; | ||
395 | |||
396 | |||
397 | struct lua_TValue { | ||
398 | TValuefields; | ||
399 | }; | ||
400 | |||
401 | 192 | ||
402 | typedef TValue *StkId; /* index to stack elements */ | 193 | typedef TValue *StkId; /* index to stack elements */ |
403 | 194 | ||
404 | 195 | ||
405 | |||
406 | |||
407 | /* | 196 | /* |
408 | ** Header for string value; string bytes follow the end of this structure | 197 | ** String headers for string table |
409 | */ | 198 | */ |
410 | typedef union TString { | 199 | typedef union TString { |
411 | L_Umaxalign dummy; /* ensures maximum alignment for strings */ | 200 | L_Umaxalign dummy; /* ensures maximum alignment for strings */ |
412 | struct { | 201 | struct { |
413 | CommonHeader; | 202 | CommonHeader; |
414 | lu_byte extra; /* reserved words for short strings; "has hash" for longs */ | 203 | lu_byte reserved; |
415 | unsigned int hash; | 204 | unsigned int hash; |
416 | size_t len; /* number of characters in string */ | 205 | size_t len; |
417 | } tsv; | 206 | } tsv; |
418 | } TString; | 207 | } TString; |
419 | 208 | ||
420 | 209 | ||
421 | /* get the actual string (array of bytes) from a TString */ | ||
422 | #define getstr(ts) cast(const char *, (ts) + 1) | 210 | #define getstr(ts) cast(const char *, (ts) + 1) |
423 | |||
424 | /* get the actual string (array of bytes) from a Lua value */ | ||
425 | #define svalue(o) getstr(rawtsvalue(o)) | 211 | #define svalue(o) getstr(rawtsvalue(o)) |
426 | 212 | ||
427 | 213 | ||
428 | /* | 214 | |
429 | ** Header for userdata; memory area follows the end of this structure | ||
430 | */ | ||
431 | typedef union Udata { | 215 | typedef union Udata { |
432 | L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */ | 216 | L_Umaxalign dummy; /* ensures maximum alignment for `local' udata */ |
433 | struct { | 217 | struct { |
434 | CommonHeader; | 218 | CommonHeader; |
435 | struct Table *metatable; | 219 | struct Table *metatable; |
436 | struct Table *env; | 220 | struct Table *env; |
437 | size_t len; /* number of bytes */ | 221 | size_t len; |
438 | } uv; | 222 | } uv; |
439 | } Udata; | 223 | } Udata; |
440 | 224 | ||
441 | 225 | ||
442 | 226 | ||
443 | /* | ||
444 | ** Description of an upvalue for function prototypes | ||
445 | */ | ||
446 | typedef struct Upvaldesc { | ||
447 | TString *name; /* upvalue name (for debug information) */ | ||
448 | lu_byte instack; /* whether it is in stack */ | ||
449 | lu_byte idx; /* index of upvalue (in stack or in outer function's list) */ | ||
450 | } Upvaldesc; | ||
451 | |||
452 | |||
453 | /* | ||
454 | ** Description of a local variable for function prototypes | ||
455 | ** (used for debug information) | ||
456 | */ | ||
457 | typedef struct LocVar { | ||
458 | TString *varname; | ||
459 | int startpc; /* first point where variable is active */ | ||
460 | int endpc; /* first point where variable is dead */ | ||
461 | } LocVar; | ||
462 | |||
463 | 227 | ||
464 | /* | 228 | /* |
465 | ** Function Prototypes | 229 | ** Function Prototypes |
@@ -469,12 +233,11 @@ typedef struct Proto { | |||
469 | TValue *k; /* constants used by the function */ | 233 | TValue *k; /* constants used by the function */ |
470 | Instruction *code; | 234 | Instruction *code; |
471 | struct Proto **p; /* functions defined inside the function */ | 235 | struct Proto **p; /* functions defined inside the function */ |
472 | int *lineinfo; /* map from opcodes to source lines (debug information) */ | 236 | int *lineinfo; /* map from opcodes to source lines */ |
473 | LocVar *locvars; /* information about local variables (debug information) */ | 237 | struct LocVar *locvars; /* information about local variables */ |
474 | Upvaldesc *upvalues; /* upvalue information */ | 238 | TString **upvalues; /* upvalue names */ |
475 | union Closure *cache; /* last created closure with this prototype */ | 239 | TString *source; |
476 | TString *source; /* used for debug information */ | 240 | int sizeupvalues; |
477 | int sizeupvalues; /* size of 'upvalues' */ | ||
478 | int sizek; /* size of `k' */ | 241 | int sizek; /* size of `k' */ |
479 | int sizecode; | 242 | int sizecode; |
480 | int sizelineinfo; | 243 | int sizelineinfo; |
@@ -483,16 +246,31 @@ typedef struct Proto { | |||
483 | int linedefined; | 246 | int linedefined; |
484 | int lastlinedefined; | 247 | int lastlinedefined; |
485 | GCObject *gclist; | 248 | GCObject *gclist; |
486 | lu_byte numparams; /* number of fixed parameters */ | 249 | lu_byte nups; /* number of upvalues */ |
250 | lu_byte numparams; | ||
487 | lu_byte is_vararg; | 251 | lu_byte is_vararg; |
488 | lu_byte maxstacksize; /* maximum stack used by this function */ | 252 | lu_byte maxstacksize; |
489 | } Proto; | 253 | } Proto; |
490 | 254 | ||
491 | 255 | ||
256 | /* masks for new-style vararg */ | ||
257 | #define VARARG_HASARG 1 | ||
258 | #define VARARG_ISVARARG 2 | ||
259 | #define VARARG_NEEDSARG 4 | ||
260 | |||
261 | |||
262 | typedef struct LocVar { | ||
263 | TString *varname; | ||
264 | int startpc; /* first point where variable is active */ | ||
265 | int endpc; /* first point where variable is dead */ | ||
266 | } LocVar; | ||
267 | |||
268 | |||
492 | 269 | ||
493 | /* | 270 | /* |
494 | ** Lua Upvalues | 271 | ** Upvalues |
495 | */ | 272 | */ |
273 | |||
496 | typedef struct UpVal { | 274 | typedef struct UpVal { |
497 | CommonHeader; | 275 | CommonHeader; |
498 | TValue *v; /* points to stack or to its own value */ | 276 | TValue *v; /* points to stack or to its own value */ |
@@ -511,19 +289,20 @@ typedef struct UpVal { | |||
511 | */ | 289 | */ |
512 | 290 | ||
513 | #define ClosureHeader \ | 291 | #define ClosureHeader \ |
514 | CommonHeader; lu_byte nupvalues; GCObject *gclist | 292 | CommonHeader; lu_byte isC; lu_byte nupvalues; GCObject *gclist; \ |
293 | struct Table *env | ||
515 | 294 | ||
516 | typedef struct CClosure { | 295 | typedef struct CClosure { |
517 | ClosureHeader; | 296 | ClosureHeader; |
518 | lua_CFunction f; | 297 | lua_CFunction f; |
519 | TValue upvalue[1]; /* list of upvalues */ | 298 | TValue upvalue[1]; |
520 | } CClosure; | 299 | } CClosure; |
521 | 300 | ||
522 | 301 | ||
523 | typedef struct LClosure { | 302 | typedef struct LClosure { |
524 | ClosureHeader; | 303 | ClosureHeader; |
525 | struct Proto *p; | 304 | struct Proto *p; |
526 | UpVal *upvals[1]; /* list of upvalues */ | 305 | UpVal *upvals[1]; |
527 | } LClosure; | 306 | } LClosure; |
528 | 307 | ||
529 | 308 | ||
@@ -533,9 +312,8 @@ typedef union Closure { | |||
533 | } Closure; | 312 | } Closure; |
534 | 313 | ||
535 | 314 | ||
536 | #define isLfunction(o) ttisLclosure(o) | 315 | #define iscfunction(o) (ttype(o) == LUA_TFUNCTION && clvalue(o)->c.isC) |
537 | 316 | #define isLfunction(o) (ttype(o) == LUA_TFUNCTION && !clvalue(o)->c.isC) | |
538 | #define getproto(o) (clLvalue(o)->p) | ||
539 | 317 | ||
540 | 318 | ||
541 | /* | 319 | /* |
@@ -559,7 +337,7 @@ typedef struct Node { | |||
559 | 337 | ||
560 | typedef struct Table { | 338 | typedef struct Table { |
561 | CommonHeader; | 339 | CommonHeader; |
562 | lu_byte flags; /* 1<<p means tagmethod(p) is not present */ | 340 | lu_byte flags; /* 1<<p means tagmethod(p) is not present */ |
563 | lu_byte lsizenode; /* log2 of size of `node' array */ | 341 | lu_byte lsizenode; /* log2 of size of `node' array */ |
564 | struct Table *metatable; | 342 | struct Table *metatable; |
565 | TValue *array; /* array part */ | 343 | TValue *array; /* array part */ |
@@ -582,21 +360,17 @@ typedef struct Table { | |||
582 | #define sizenode(t) (twoto((t)->lsizenode)) | 360 | #define sizenode(t) (twoto((t)->lsizenode)) |
583 | 361 | ||
584 | 362 | ||
585 | /* | ||
586 | ** (address of) a fixed nil value | ||
587 | */ | ||
588 | #define luaO_nilobject (&luaO_nilobject_) | 363 | #define luaO_nilobject (&luaO_nilobject_) |
589 | 364 | ||
365 | LUAI_DATA const TValue luaO_nilobject_; | ||
590 | 366 | ||
591 | LUAI_DDEC const TValue luaO_nilobject_; | 367 | #define ceillog2(x) (luaO_log2((x)-1) + 1) |
592 | |||
593 | 368 | ||
369 | LUAI_FUNC int luaO_log2 (unsigned int x); | ||
594 | LUAI_FUNC int luaO_int2fb (unsigned int x); | 370 | LUAI_FUNC int luaO_int2fb (unsigned int x); |
595 | LUAI_FUNC int luaO_fb2int (int x); | 371 | LUAI_FUNC int luaO_fb2int (int x); |
596 | LUAI_FUNC int luaO_ceillog2 (unsigned int x); | 372 | LUAI_FUNC int luaO_rawequalObj (const TValue *t1, const TValue *t2); |
597 | LUAI_FUNC lua_Number luaO_arith (int op, lua_Number v1, lua_Number v2); | 373 | LUAI_FUNC int luaO_str2d (const char *s, lua_Number *result); |
598 | LUAI_FUNC int luaO_str2d (const char *s, size_t len, lua_Number *result); | ||
599 | LUAI_FUNC int luaO_hexavalue (int c); | ||
600 | LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt, | 374 | LUAI_FUNC const char *luaO_pushvfstring (lua_State *L, const char *fmt, |
601 | va_list argp); | 375 | va_list argp); |
602 | LUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...); | 376 | LUAI_FUNC const char *luaO_pushfstring (lua_State *L, const char *fmt, ...); |