diff options
Diffstat (limited to 'lobject.h')
-rw-r--r-- | lobject.h | 136 |
1 files changed, 76 insertions, 60 deletions
@@ -17,16 +17,16 @@ | |||
17 | 17 | ||
18 | 18 | ||
19 | /* | 19 | /* |
20 | ** Extra tags for collectable non-values | 20 | ** Extra types for collectable non-values |
21 | */ | 21 | */ |
22 | #define LUA_TUPVAL LUA_NUMTAGS /* upvalues */ | 22 | #define LUA_TUPVAL LUA_NUMTYPES /* upvalues */ |
23 | #define LUA_TPROTO (LUA_NUMTAGS+1) /* function prototypes */ | 23 | #define LUA_TPROTO (LUA_NUMTYPES+1) /* function prototypes */ |
24 | 24 | ||
25 | 25 | ||
26 | /* | 26 | /* |
27 | ** number of all possible tags (including LUA_TNONE) | 27 | ** number of all possible types (including LUA_TNONE) |
28 | */ | 28 | */ |
29 | #define LUA_TOTALTAGS (LUA_TPROTO + 2) | 29 | #define LUA_TOTALTYPES (LUA_TPROTO + 2) |
30 | 30 | ||
31 | 31 | ||
32 | /* | 32 | /* |
@@ -154,30 +154,28 @@ typedef StackValue *StkId; | |||
154 | ** =================================================================== | 154 | ** =================================================================== |
155 | */ | 155 | */ |
156 | 156 | ||
157 | /* macro to test for (any kind of) nil */ | 157 | /* Standard nil */ |
158 | #define ttisnil(v) checktype((v), LUA_TNIL) | 158 | #define LUA_VNIL makevariant(LUA_TNIL, 1) |
159 | 159 | ||
160 | /* macro to test for a "pure" nil */ | 160 | /* Empty slot (which might be different from a slot containing nil) */ |
161 | #define ttisstrictnil(o) checktag((o), LUA_TNIL) | 161 | #define LUA_VEMPTY makevariant(LUA_TNIL, 2) |
162 | 162 | ||
163 | /* Value returned for a key not found in a table (absent key) */ | ||
164 | #define LUA_VABSTKEY makevariant(LUA_TNIL, 3) | ||
163 | 165 | ||
164 | #define setnilvalue(obj) settt_(obj, LUA_TNIL) | ||
165 | 166 | ||
167 | /* macro to test for (any kind of) nil */ | ||
168 | #define ttisnil(v) checktype((v), LUA_TNIL) | ||
166 | 169 | ||
167 | /* | ||
168 | ** Variant tag, used only in tables to signal an empty slot | ||
169 | ** (which might be different from a slot containing nil) | ||
170 | */ | ||
171 | #define LUA_TEMPTY makevariant(LUA_TNIL, 1) | ||
172 | 170 | ||
173 | /* | 171 | /* macro to test for a standard nil */ |
174 | ** Variant used only in the value returned for a key not found in a | 172 | #define ttisstrictnil(o) checktag((o), LUA_VNIL) |
175 | ** table (absent key). | 173 | |
176 | */ | 174 | |
177 | #define LUA_TABSTKEY makevariant(LUA_TNIL, 2) | 175 | #define setnilvalue(obj) settt_(obj, LUA_VNIL) |
178 | 176 | ||
179 | 177 | ||
180 | #define isabstkey(v) checktag((v), LUA_TABSTKEY) | 178 | #define isabstkey(v) checktag((v), LUA_VABSTKEY) |
181 | 179 | ||
182 | 180 | ||
183 | /* | 181 | /* |
@@ -195,11 +193,11 @@ typedef StackValue *StkId; | |||
195 | 193 | ||
196 | 194 | ||
197 | /* macro defining a value corresponding to an absent key */ | 195 | /* macro defining a value corresponding to an absent key */ |
198 | #define ABSTKEYCONSTANT {NULL}, LUA_TABSTKEY | 196 | #define ABSTKEYCONSTANT {NULL}, LUA_VABSTKEY |
199 | 197 | ||
200 | 198 | ||
201 | /* mark an entry as empty */ | 199 | /* mark an entry as empty */ |
202 | #define setempty(v) settt_(v, LUA_TEMPTY) | 200 | #define setempty(v) settt_(v, LUA_VEMPTY) |
203 | 201 | ||
204 | 202 | ||
205 | 203 | ||
@@ -213,19 +211,19 @@ typedef StackValue *StkId; | |||
213 | */ | 211 | */ |
214 | 212 | ||
215 | 213 | ||
216 | #define LUA_TFALSE makevariant(LUA_TBOOLEAN, 1) | 214 | #define LUA_VFALSE makevariant(LUA_TBOOLEAN, 1) |
217 | #define LUA_TTRUE makevariant(LUA_TBOOLEAN, 2) | 215 | #define LUA_VTRUE makevariant(LUA_TBOOLEAN, 2) |
218 | 216 | ||
219 | #define ttisboolean(o) checktype((o), LUA_TBOOLEAN) | 217 | #define ttisboolean(o) checktype((o), LUA_TBOOLEAN) |
220 | #define ttisfalse(o) checktag((o), LUA_TFALSE) | 218 | #define ttisfalse(o) checktag((o), LUA_VFALSE) |
221 | #define ttistrue(o) checktag((o), LUA_TTRUE) | 219 | #define ttistrue(o) checktag((o), LUA_VTRUE) |
222 | 220 | ||
223 | 221 | ||
224 | #define l_isfalse(o) (ttisfalse(o) || ttisnil(o)) | 222 | #define l_isfalse(o) (ttisfalse(o) || ttisnil(o)) |
225 | 223 | ||
226 | 224 | ||
227 | #define setbfvalue(obj) settt_(obj, LUA_TFALSE) | 225 | #define setbfvalue(obj) settt_(obj, LUA_VFALSE) |
228 | #define setbtvalue(obj) settt_(obj, LUA_TTRUE) | 226 | #define setbtvalue(obj) settt_(obj, LUA_VTRUE) |
229 | 227 | ||
230 | /* }================================================================== */ | 228 | /* }================================================================== */ |
231 | 229 | ||
@@ -236,13 +234,15 @@ typedef StackValue *StkId; | |||
236 | ** =================================================================== | 234 | ** =================================================================== |
237 | */ | 235 | */ |
238 | 236 | ||
239 | #define ttisthread(o) checktag((o), ctb(LUA_TTHREAD)) | 237 | #define LUA_VTHREAD makevariant(LUA_TTHREAD, 1) |
238 | |||
239 | #define ttisthread(o) checktag((o), ctb(LUA_VTHREAD)) | ||
240 | 240 | ||
241 | #define thvalue(o) check_exp(ttisthread(o), gco2th(val_(o).gc)) | 241 | #define thvalue(o) check_exp(ttisthread(o), gco2th(val_(o).gc)) |
242 | 242 | ||
243 | #define setthvalue(L,obj,x) \ | 243 | #define setthvalue(L,obj,x) \ |
244 | { TValue *io = (obj); lua_State *x_ = (x); \ | 244 | { TValue *io = (obj); lua_State *x_ = (x); \ |
245 | val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TTHREAD)); \ | 245 | val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_VTHREAD)); \ |
246 | checkliveness(L,io); } | 246 | checkliveness(L,io); } |
247 | 247 | ||
248 | #define setthvalue2s(L,o,t) setthvalue(L,s2v(o),t) | 248 | #define setthvalue2s(L,o,t) setthvalue(L,s2v(o),t) |
@@ -295,12 +295,12 @@ typedef struct GCObject { | |||
295 | */ | 295 | */ |
296 | 296 | ||
297 | /* Variant tags for numbers */ | 297 | /* Variant tags for numbers */ |
298 | #define LUA_TNUMINT makevariant(LUA_TNUMBER, 1) /* integer numbers */ | 298 | #define LUA_VNUMINT makevariant(LUA_TNUMBER, 1) /* integer numbers */ |
299 | #define LUA_TNUMFLT makevariant(LUA_TNUMBER, 2) /* float numbers */ | 299 | #define LUA_VNUMFLT makevariant(LUA_TNUMBER, 2) /* float numbers */ |
300 | 300 | ||
301 | #define ttisnumber(o) checktype((o), LUA_TNUMBER) | 301 | #define ttisnumber(o) checktype((o), LUA_TNUMBER) |
302 | #define ttisfloat(o) checktag((o), LUA_TNUMFLT) | 302 | #define ttisfloat(o) checktag((o), LUA_VNUMFLT) |
303 | #define ttisinteger(o) checktag((o), LUA_TNUMINT) | 303 | #define ttisinteger(o) checktag((o), LUA_VNUMINT) |
304 | 304 | ||
305 | #define nvalue(o) check_exp(ttisnumber(o), \ | 305 | #define nvalue(o) check_exp(ttisnumber(o), \ |
306 | (ttisinteger(o) ? cast_num(ivalue(o)) : fltvalue(o))) | 306 | (ttisinteger(o) ? cast_num(ivalue(o)) : fltvalue(o))) |
@@ -311,13 +311,13 @@ typedef struct GCObject { | |||
311 | #define ivalueraw(v) ((v).i) | 311 | #define ivalueraw(v) ((v).i) |
312 | 312 | ||
313 | #define setfltvalue(obj,x) \ | 313 | #define setfltvalue(obj,x) \ |
314 | { TValue *io=(obj); val_(io).n=(x); settt_(io, LUA_TNUMFLT); } | 314 | { TValue *io=(obj); val_(io).n=(x); settt_(io, LUA_VNUMFLT); } |
315 | 315 | ||
316 | #define chgfltvalue(obj,x) \ | 316 | #define chgfltvalue(obj,x) \ |
317 | { TValue *io=(obj); lua_assert(ttisfloat(io)); val_(io).n=(x); } | 317 | { TValue *io=(obj); lua_assert(ttisfloat(io)); val_(io).n=(x); } |
318 | 318 | ||
319 | #define setivalue(obj,x) \ | 319 | #define setivalue(obj,x) \ |
320 | { TValue *io=(obj); val_(io).i=(x); settt_(io, LUA_TNUMINT); } | 320 | { TValue *io=(obj); val_(io).i=(x); settt_(io, LUA_VNUMINT); } |
321 | 321 | ||
322 | #define chgivalue(obj,x) \ | 322 | #define chgivalue(obj,x) \ |
323 | { TValue *io=(obj); lua_assert(ttisinteger(io)); val_(io).i=(x); } | 323 | { TValue *io=(obj); lua_assert(ttisinteger(io)); val_(io).i=(x); } |
@@ -332,12 +332,12 @@ typedef struct GCObject { | |||
332 | */ | 332 | */ |
333 | 333 | ||
334 | /* Variant tags for strings */ | 334 | /* Variant tags for strings */ |
335 | #define LUA_TSHRSTR makevariant(LUA_TSTRING, 1) /* short strings */ | 335 | #define LUA_VSHRSTR makevariant(LUA_TSTRING, 1) /* short strings */ |
336 | #define LUA_TLNGSTR makevariant(LUA_TSTRING, 2) /* long strings */ | 336 | #define LUA_VLNGSTR makevariant(LUA_TSTRING, 2) /* long strings */ |
337 | 337 | ||
338 | #define ttisstring(o) checktype((o), LUA_TSTRING) | 338 | #define ttisstring(o) checktype((o), LUA_TSTRING) |
339 | #define ttisshrstring(o) checktag((o), ctb(LUA_TSHRSTR)) | 339 | #define ttisshrstring(o) checktag((o), ctb(LUA_VSHRSTR)) |
340 | #define ttislngstring(o) checktag((o), ctb(LUA_TLNGSTR)) | 340 | #define ttislngstring(o) checktag((o), ctb(LUA_VLNGSTR)) |
341 | 341 | ||
342 | #define tsvalueraw(v) (gco2ts((v).gc)) | 342 | #define tsvalueraw(v) (gco2ts((v).gc)) |
343 | 343 | ||
@@ -384,7 +384,7 @@ typedef struct TString { | |||
384 | #define svalue(o) getstr(tsvalue(o)) | 384 | #define svalue(o) getstr(tsvalue(o)) |
385 | 385 | ||
386 | /* get string length from 'TString *s' */ | 386 | /* get string length from 'TString *s' */ |
387 | #define tsslen(s) ((s)->tt == LUA_TSHRSTR ? (s)->shrlen : (s)->u.lnglen) | 387 | #define tsslen(s) ((s)->tt == LUA_VSHRSTR ? (s)->shrlen : (s)->u.lnglen) |
388 | 388 | ||
389 | /* get string length from 'TValue *o' */ | 389 | /* get string length from 'TValue *o' */ |
390 | #define vslen(o) tsslen(tsvalue(o)) | 390 | #define vslen(o) tsslen(tsvalue(o)) |
@@ -398,8 +398,16 @@ typedef struct TString { | |||
398 | ** =================================================================== | 398 | ** =================================================================== |
399 | */ | 399 | */ |
400 | 400 | ||
401 | #define ttislightuserdata(o) checktag((o), LUA_TLIGHTUSERDATA) | 401 | |
402 | #define ttisfulluserdata(o) checktype((o), LUA_TUSERDATA) | 402 | /* |
403 | ** Light userdata should be a variant of userdata, but for compatibility | ||
404 | ** reasons they are also different types. | ||
405 | */ | ||
406 | #define LUA_VLIGHTUSERDATA makevariant(LUA_TLIGHTUSERDATA, 1) | ||
407 | #define LUA_VUSERDATA makevariant(LUA_TUSERDATA, 1) | ||
408 | |||
409 | #define ttislightuserdata(o) checktag((o), LUA_VLIGHTUSERDATA) | ||
410 | #define ttisfulluserdata(o) checktag((o), ctb(LUA_VUSERDATA)) | ||
403 | 411 | ||
404 | #define pvalue(o) check_exp(ttislightuserdata(o), val_(o).p) | 412 | #define pvalue(o) check_exp(ttislightuserdata(o), val_(o).p) |
405 | #define uvalue(o) check_exp(ttisfulluserdata(o), gco2u(val_(o).gc)) | 413 | #define uvalue(o) check_exp(ttisfulluserdata(o), gco2u(val_(o).gc)) |
@@ -407,11 +415,11 @@ typedef struct TString { | |||
407 | #define pvalueraw(v) ((v).p) | 415 | #define pvalueraw(v) ((v).p) |
408 | 416 | ||
409 | #define setpvalue(obj,x) \ | 417 | #define setpvalue(obj,x) \ |
410 | { TValue *io=(obj); val_(io).p=(x); settt_(io, LUA_TLIGHTUSERDATA); } | 418 | { TValue *io=(obj); val_(io).p=(x); settt_(io, LUA_VLIGHTUSERDATA); } |
411 | 419 | ||
412 | #define setuvalue(L,obj,x) \ | 420 | #define setuvalue(L,obj,x) \ |
413 | { TValue *io = (obj); Udata *x_ = (x); \ | 421 | { TValue *io = (obj); Udata *x_ = (x); \ |
414 | val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TUSERDATA)); \ | 422 | val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_VUSERDATA)); \ |
415 | checkliveness(L,io); } | 423 | checkliveness(L,io); } |
416 | 424 | ||
417 | 425 | ||
@@ -474,6 +482,9 @@ typedef struct Udata0 { | |||
474 | ** =================================================================== | 482 | ** =================================================================== |
475 | */ | 483 | */ |
476 | 484 | ||
485 | #define LUA_VPROTO makevariant(LUA_TPROTO, 1) | ||
486 | |||
487 | |||
477 | /* | 488 | /* |
478 | ** Description of an upvalue for function prototypes | 489 | ** Description of an upvalue for function prototypes |
479 | */ | 490 | */ |
@@ -548,16 +559,19 @@ typedef struct Proto { | |||
548 | ** =================================================================== | 559 | ** =================================================================== |
549 | */ | 560 | */ |
550 | 561 | ||
562 | #define LUA_VUPVAL makevariant(LUA_TUPVAL, 1) | ||
563 | |||
564 | |||
551 | /* Variant tags for functions */ | 565 | /* Variant tags for functions */ |
552 | #define LUA_TLCL makevariant(LUA_TFUNCTION, 1) /* Lua closure */ | 566 | #define LUA_VLCL makevariant(LUA_TFUNCTION, 1) /* Lua closure */ |
553 | #define LUA_TLCF makevariant(LUA_TFUNCTION, 2) /* light C function */ | 567 | #define LUA_VLCF makevariant(LUA_TFUNCTION, 2) /* light C function */ |
554 | #define LUA_TCCL makevariant(LUA_TFUNCTION, 3) /* C closure */ | 568 | #define LUA_VCCL makevariant(LUA_TFUNCTION, 3) /* C closure */ |
555 | 569 | ||
556 | #define ttisfunction(o) checktype(o, LUA_TFUNCTION) | 570 | #define ttisfunction(o) checktype(o, LUA_TFUNCTION) |
557 | #define ttisclosure(o) ((rawtt(o) & 0x1F) == LUA_TLCL) | 571 | #define ttisclosure(o) ((rawtt(o) & 0x1F) == LUA_VLCL) |
558 | #define ttisLclosure(o) checktag((o), ctb(LUA_TLCL)) | 572 | #define ttisLclosure(o) checktag((o), ctb(LUA_VLCL)) |
559 | #define ttislcf(o) checktag((o), LUA_TLCF) | 573 | #define ttislcf(o) checktag((o), LUA_VLCF) |
560 | #define ttisCclosure(o) checktag((o), ctb(LUA_TCCL)) | 574 | #define ttisCclosure(o) checktag((o), ctb(LUA_VCCL)) |
561 | 575 | ||
562 | #define isLfunction(o) ttisLclosure(o) | 576 | #define isLfunction(o) ttisLclosure(o) |
563 | 577 | ||
@@ -570,17 +584,17 @@ typedef struct Proto { | |||
570 | 584 | ||
571 | #define setclLvalue(L,obj,x) \ | 585 | #define setclLvalue(L,obj,x) \ |
572 | { TValue *io = (obj); LClosure *x_ = (x); \ | 586 | { TValue *io = (obj); LClosure *x_ = (x); \ |
573 | val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TLCL)); \ | 587 | val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_VLCL)); \ |
574 | checkliveness(L,io); } | 588 | checkliveness(L,io); } |
575 | 589 | ||
576 | #define setclLvalue2s(L,o,cl) setclLvalue(L,s2v(o),cl) | 590 | #define setclLvalue2s(L,o,cl) setclLvalue(L,s2v(o),cl) |
577 | 591 | ||
578 | #define setfvalue(obj,x) \ | 592 | #define setfvalue(obj,x) \ |
579 | { TValue *io=(obj); val_(io).f=(x); settt_(io, LUA_TLCF); } | 593 | { TValue *io=(obj); val_(io).f=(x); settt_(io, LUA_VLCF); } |
580 | 594 | ||
581 | #define setclCvalue(L,obj,x) \ | 595 | #define setclCvalue(L,obj,x) \ |
582 | { TValue *io = (obj); CClosure *x_ = (x); \ | 596 | { TValue *io = (obj); CClosure *x_ = (x); \ |
583 | val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TCCL)); \ | 597 | val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_VCCL)); \ |
584 | checkliveness(L,io); } | 598 | checkliveness(L,io); } |
585 | 599 | ||
586 | 600 | ||
@@ -636,13 +650,15 @@ typedef union Closure { | |||
636 | ** =================================================================== | 650 | ** =================================================================== |
637 | */ | 651 | */ |
638 | 652 | ||
639 | #define ttistable(o) checktag((o), ctb(LUA_TTABLE)) | 653 | #define LUA_VTABLE makevariant(LUA_TTABLE, 1) |
654 | |||
655 | #define ttistable(o) checktag((o), ctb(LUA_VTABLE)) | ||
640 | 656 | ||
641 | #define hvalue(o) check_exp(ttistable(o), gco2t(val_(o).gc)) | 657 | #define hvalue(o) check_exp(ttistable(o), gco2t(val_(o).gc)) |
642 | 658 | ||
643 | #define sethvalue(L,obj,x) \ | 659 | #define sethvalue(L,obj,x) \ |
644 | { TValue *io = (obj); Table *x_ = (x); \ | 660 | { TValue *io = (obj); Table *x_ = (x); \ |
645 | val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_TTABLE)); \ | 661 | val_(io).gc = obj2gco(x_); settt_(io, ctb(LUA_VTABLE)); \ |
646 | checkliveness(L,io); } | 662 | checkliveness(L,io); } |
647 | 663 | ||
648 | #define sethvalue2s(L,o,h) sethvalue(L,s2v(o),h) | 664 | #define sethvalue2s(L,o,h) sethvalue(L,s2v(o),h) |
@@ -713,9 +729,9 @@ typedef struct Table { | |||
713 | #define keyval(node) ((node)->u.key_val) | 729 | #define keyval(node) ((node)->u.key_val) |
714 | 730 | ||
715 | #define keyisnil(node) (keytt(node) == LUA_TNIL) | 731 | #define keyisnil(node) (keytt(node) == LUA_TNIL) |
716 | #define keyisinteger(node) (keytt(node) == LUA_TNUMINT) | 732 | #define keyisinteger(node) (keytt(node) == LUA_VNUMINT) |
717 | #define keyival(node) (keyval(node).i) | 733 | #define keyival(node) (keyval(node).i) |
718 | #define keyisshrstr(node) (keytt(node) == ctb(LUA_TSHRSTR)) | 734 | #define keyisshrstr(node) (keytt(node) == ctb(LUA_VSHRSTR)) |
719 | #define keystrval(node) (gco2ts(keyval(node).gc)) | 735 | #define keystrval(node) (gco2ts(keyval(node).gc)) |
720 | 736 | ||
721 | #define setnilkey(node) (keytt(node) = LUA_TNIL) | 737 | #define setnilkey(node) (keytt(node) = LUA_TNIL) |