|
36 | 36 | ** bit 6: whether value is collectable |
37 | 37 | */ |
38 | 38 |
|
| 39 | +/* add variant bits to a type */ |
| 40 | +#define makevariant(t,v) ((t) | ((v) << 4)) |
| 41 | + |
39 | 42 |
|
40 | 43 |
|
41 | 44 | /* |
@@ -165,13 +168,13 @@ typedef StackValue *StkId; |
165 | 168 | ** Variant tag, used only in tables to signal an empty slot |
166 | 169 | ** (which might be different from a slot containing nil) |
167 | 170 | */ |
168 | | -#define LUA_TEMPTY (LUA_TNIL | (1 << 4)) |
| 171 | +#define LUA_TEMPTY makevariant(LUA_TNIL, 1) |
169 | 172 |
|
170 | 173 | /* |
171 | 174 | ** Variant used only in the value returned for a key not found in a |
172 | 175 | ** table (absent key). |
173 | 176 | */ |
174 | | -#define LUA_TABSTKEY (LUA_TNIL | (2 << 4)) |
| 177 | +#define LUA_TABSTKEY makevariant(LUA_TNIL, 2) |
175 | 178 |
|
176 | 179 |
|
177 | 180 | #define isabstkey(v) checktag((v), LUA_TABSTKEY) |
@@ -210,8 +213,8 @@ typedef StackValue *StkId; |
210 | 213 | */ |
211 | 214 |
|
212 | 215 |
|
213 | | -#define LUA_TFALSE (LUA_TBOOLEAN | (1 << 4)) |
214 | | -#define LUA_TTRUE (LUA_TBOOLEAN | (2 << 4)) |
| 216 | +#define LUA_TFALSE makevariant(LUA_TBOOLEAN, 1) |
| 217 | +#define LUA_TTRUE makevariant(LUA_TBOOLEAN, 2) |
215 | 218 |
|
216 | 219 | #define ttisboolean(o) checktype((o), LUA_TBOOLEAN) |
217 | 220 | #define ttisfalse(o) checktag((o), LUA_TFALSE) |
@@ -292,8 +295,8 @@ typedef struct GCObject { |
292 | 295 | */ |
293 | 296 |
|
294 | 297 | /* Variant tags for numbers */ |
295 | | -#define LUA_TNUMFLT (LUA_TNUMBER | (1 << 4)) /* float numbers */ |
296 | | -#define LUA_TNUMINT (LUA_TNUMBER | (2 << 4)) /* integer numbers */ |
| 298 | +#define LUA_TNUMINT makevariant(LUA_TNUMBER, 1) /* integer numbers */ |
| 299 | +#define LUA_TNUMFLT makevariant(LUA_TNUMBER, 2) /* float numbers */ |
297 | 300 |
|
298 | 301 | #define ttisnumber(o) checktype((o), LUA_TNUMBER) |
299 | 302 | #define ttisfloat(o) checktag((o), LUA_TNUMFLT) |
@@ -329,8 +332,8 @@ typedef struct GCObject { |
329 | 332 | */ |
330 | 333 |
|
331 | 334 | /* Variant tags for strings */ |
332 | | -#define LUA_TSHRSTR (LUA_TSTRING | (1 << 4)) /* short strings */ |
333 | | -#define LUA_TLNGSTR (LUA_TSTRING | (2 << 4)) /* long strings */ |
| 335 | +#define LUA_TSHRSTR makevariant(LUA_TSTRING, 1) /* short strings */ |
| 336 | +#define LUA_TLNGSTR makevariant(LUA_TSTRING, 2) /* long strings */ |
334 | 337 |
|
335 | 338 | #define ttisstring(o) checktype((o), LUA_TSTRING) |
336 | 339 | #define ttisshrstring(o) checktag((o), ctb(LUA_TSHRSTR)) |
@@ -546,9 +549,9 @@ typedef struct Proto { |
546 | 549 | */ |
547 | 550 |
|
548 | 551 | /* Variant tags for functions */ |
549 | | -#define LUA_TLCL (LUA_TFUNCTION | (1 << 4)) /* Lua closure */ |
550 | | -#define LUA_TLCF (LUA_TFUNCTION | (2 << 4)) /* light C function */ |
551 | | -#define LUA_TCCL (LUA_TFUNCTION | (3 << 4)) /* C closure */ |
| 552 | +#define LUA_TLCL makevariant(LUA_TFUNCTION, 1) /* Lua closure */ |
| 553 | +#define LUA_TLCF makevariant(LUA_TFUNCTION, 2) /* light C function */ |
| 554 | +#define LUA_TCCL makevariant(LUA_TFUNCTION, 3) /* C closure */ |
552 | 555 |
|
553 | 556 | #define ttisfunction(o) checktype(o, LUA_TFUNCTION) |
554 | 557 | #define ttisclosure(o) ((rawtt(o) & 0x1F) == LUA_TLCL) |
|
0 commit comments