Skip to content

Commit eaceeaa

Browse files
authored
Merge pull request #69 from NiceAndPeter/claude/reorganize-makevariant-constants-017vKEnM12PRtUT7kdDyrS8R
Reorganize MakeVariant constants in ltvalue.h
2 parents c2bda03 + 25c1978 commit eaceeaa

File tree

6 files changed

+65
-50
lines changed

6 files changed

+65
-50
lines changed

src/objects/lfunc.h

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,9 @@ typedef union StackValue *StkId;
2121
** {==================================================================
2222
** Functions
2323
** ===================================================================
24+
** Note: LUA_VUPVAL, LUA_VLCL, LUA_VLCF, LUA_VCCL now defined in ltvalue.h
2425
*/
2526

26-
inline constexpr int LUA_VUPVAL = makevariant(LUA_TUPVAL, 0);
27-
28-
29-
/* Variant tags for functions */
30-
inline constexpr int LUA_VLCL = makevariant(LUA_TFUNCTION, 0); /* Lua closure */
31-
inline constexpr int LUA_VLCF = makevariant(LUA_TFUNCTION, 1); /* light C function */
32-
inline constexpr int LUA_VCCL = makevariant(LUA_TFUNCTION, 2); /* C closure */
33-
3427
constexpr bool ttisfunction(const TValue* o) noexcept { return checktype(o, LUA_TFUNCTION); }
3528
constexpr bool ttisLclosure(const TValue* o) noexcept { return checktag(o, ctb(LUA_VLCL)); }
3629
constexpr bool ttislcf(const TValue* o) noexcept { return checktag(o, LUA_VLCF); }

src/objects/lobject_core.h

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ class lua_State;
2222

2323
/*
2424
** Extra types for collectable non-values
25+
** Note: LUA_TUPVAL and LUA_TPROTO now defined in ltvalue.h
2526
*/
26-
inline constexpr int LUA_TUPVAL = LUA_NUMTYPES; /* upvalues */
27-
inline constexpr int LUA_TPROTO = (LUA_NUMTYPES+1); /* function prototypes */
2827
inline constexpr int LUA_TDEADKEY = (LUA_NUMTYPES+2); /* removed keys in tables */
2928

3029

@@ -38,21 +37,9 @@ inline constexpr int LUA_TOTALTYPES = (LUA_TPROTO + 2);
3837
** {==================================================================
3938
** Nil
4039
** ===================================================================
40+
** Note: LUA_VNIL, LUA_VEMPTY, LUA_VABSTKEY, LUA_VNOTABLE now defined in ltvalue.h
4141
*/
4242

43-
/* Standard nil */
44-
inline constexpr int LUA_VNIL = makevariant(LUA_TNIL, 0);
45-
46-
/* Empty slot (which might be different from a slot containing nil) */
47-
inline constexpr int LUA_VEMPTY = makevariant(LUA_TNIL, 1);
48-
49-
/* Value returned for a key not found in a table (absent key) */
50-
inline constexpr int LUA_VABSTKEY = makevariant(LUA_TNIL, 2);
51-
52-
/* Special variant to signal that a fast get is accessing a non-table */
53-
inline constexpr int LUA_VNOTABLE = makevariant(LUA_TNIL, 3);
54-
55-
5643
/* macro to test for (any kind of) nil */
5744
constexpr bool ttisnil(const TValue* v) noexcept { return checktype(v, LUA_TNIL); }
5845

@@ -115,12 +102,9 @@ inline void setempty(TValue* v) noexcept { settt_(v, LUA_VEMPTY); }
115102
** {==================================================================
116103
** Booleans
117104
** ===================================================================
105+
** Note: LUA_VFALSE, LUA_VTRUE now defined in ltvalue.h
118106
*/
119107

120-
121-
inline constexpr int LUA_VFALSE = makevariant(LUA_TBOOLEAN, 0);
122-
inline constexpr int LUA_VTRUE = makevariant(LUA_TBOOLEAN, 1);
123-
124108
constexpr bool ttisboolean(const TValue* o) noexcept { return checktype(o, LUA_TBOOLEAN); }
125109
constexpr bool ttisfalse(const TValue* o) noexcept { return checktag(o, LUA_VFALSE); }
126110
constexpr bool ttistrue(const TValue* o) noexcept { return checktag(o, LUA_VTRUE); }
@@ -146,10 +130,9 @@ inline void setbtvalue(TValue* obj) noexcept { obj->setTrue(); }
146130
** {==================================================================
147131
** Threads
148132
** ===================================================================
133+
** Note: LUA_VTHREAD now defined in ltvalue.h
149134
*/
150135

151-
inline constexpr int LUA_VTHREAD = makevariant(LUA_TTHREAD, 0);
152-
153136
constexpr bool ttisthread(const TValue* o) noexcept { return checktag(o, ctb(LUA_VTHREAD)); }
154137

155138
constexpr bool TValue::isThread() const noexcept { return checktag(this, ctb(LUA_VTHREAD)); }
@@ -165,12 +148,9 @@ inline lua_State* thvalue(const TValue* o) noexcept { return o->threadValue(); }
165148
** {==================================================================
166149
** Numbers
167150
** ===================================================================
151+
** Note: LUA_VNUMINT, LUA_VNUMFLT now defined in ltvalue.h
168152
*/
169153

170-
/* Variant tags for numbers */
171-
inline constexpr int LUA_VNUMINT = makevariant(LUA_TNUMBER, 0); /* integer numbers */
172-
inline constexpr int LUA_VNUMFLT = makevariant(LUA_TNUMBER, 1); /* float numbers */
173-
174154
constexpr bool ttisnumber(const TValue* o) noexcept { return checktype(o, LUA_TNUMBER); }
175155
constexpr bool ttisfloat(const TValue* o) noexcept { return checktag(o, LUA_VNUMFLT); }
176156
constexpr bool ttisinteger(const TValue* o) noexcept { return checktag(o, LUA_VNUMINT); }
@@ -339,17 +319,9 @@ inline bool TValue::hasRightType() const noexcept { return typeTag() == gcValue(
339319
** {==================================================================
340320
** Userdata
341321
** ===================================================================
322+
** Note: LUA_VLIGHTUSERDATA, LUA_VUSERDATA now defined in ltvalue.h
342323
*/
343324

344-
345-
/*
346-
** Light userdata should be a variant of userdata, but for compatibility
347-
** reasons they are also different types.
348-
*/
349-
inline constexpr int LUA_VLIGHTUSERDATA = makevariant(LUA_TLIGHTUSERDATA, 0);
350-
351-
inline constexpr int LUA_VUSERDATA = makevariant(LUA_TUSERDATA, 0);
352-
353325
constexpr bool ttislightuserdata(const TValue* o) noexcept { return checktag(o, LUA_VLIGHTUSERDATA); }
354326
constexpr bool ttisfulluserdata(const TValue* o) noexcept { return checktag(o, ctb(LUA_VUSERDATA)); }
355327

src/objects/lproto.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ typedef l_uint32 Instruction;
2525
** {==================================================================
2626
** Prototypes
2727
** ===================================================================
28+
** Note: LUA_VPROTO now defined in ltvalue.h
2829
*/
2930

30-
inline constexpr int LUA_VPROTO = makevariant(LUA_TPROTO, 0);
31-
3231

3332
/*
3433
** Description of an upvalue for function prototypes

src/objects/lstring.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,9 @@ class global_State;
3737
** {==================================================================
3838
** Strings
3939
** ===================================================================
40+
** Note: LUA_VSHRSTR, LUA_VLNGSTR now defined in ltvalue.h
4041
*/
4142

42-
/* Variant tags for strings */
43-
inline constexpr int LUA_VSHRSTR = makevariant(LUA_TSTRING, 0); /* short strings */
44-
inline constexpr int LUA_VLNGSTR = makevariant(LUA_TSTRING, 1); /* long strings */
45-
4643
constexpr bool ttisstring(const TValue* o) noexcept { return checktype(o, LUA_TSTRING); }
4744
constexpr bool ttisshrstring(const TValue* o) noexcept { return checktag(o, ctb(LUA_VSHRSTR)); }
4845
constexpr bool ttislngstring(const TValue* o) noexcept { return checktag(o, ctb(LUA_VLNGSTR)); }

src/objects/ltable.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,9 @@ typedef union StackValue *StkId;
2121
** {==================================================================
2222
** Tables
2323
** ===================================================================
24+
** Note: LUA_VTABLE now defined in ltvalue.h
2425
*/
2526

26-
inline constexpr int LUA_VTABLE = makevariant(LUA_TTABLE, 0);
27-
2827
constexpr bool ttistable(const TValue* o) noexcept { return checktag(o, ctb(LUA_VTABLE)); }
2928

3029
constexpr bool TValue::isTable() const noexcept { return checktag(this, ctb(LUA_VTABLE)); }

src/objects/ltvalue.h

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,61 @@
2222
constexpr int makevariant(int t, int v) noexcept { return (t | (v << 4)); }
2323

2424

25+
/*
26+
** Extra types for collectable non-values
27+
*/
28+
inline constexpr int LUA_TUPVAL = LUA_NUMTYPES; /* upvalues */
29+
inline constexpr int LUA_TPROTO = (LUA_NUMTYPES+1); /* function prototypes */
30+
31+
32+
/*
33+
** {==================================================================
34+
** Variant tags for all Lua types
35+
** ===================================================================
36+
*/
37+
38+
/* Nil variants */
39+
inline constexpr int LUA_VNIL = makevariant(LUA_TNIL, 0);
40+
inline constexpr int LUA_VEMPTY = makevariant(LUA_TNIL, 1);
41+
inline constexpr int LUA_VABSTKEY = makevariant(LUA_TNIL, 2);
42+
inline constexpr int LUA_VNOTABLE = makevariant(LUA_TNIL, 3);
43+
44+
/* Boolean variants */
45+
inline constexpr int LUA_VFALSE = makevariant(LUA_TBOOLEAN, 0);
46+
inline constexpr int LUA_VTRUE = makevariant(LUA_TBOOLEAN, 1);
47+
48+
/* Number variants */
49+
inline constexpr int LUA_VNUMINT = makevariant(LUA_TNUMBER, 0); /* integer numbers */
50+
inline constexpr int LUA_VNUMFLT = makevariant(LUA_TNUMBER, 1); /* float numbers */
51+
52+
/* String variants */
53+
inline constexpr int LUA_VSHRSTR = makevariant(LUA_TSTRING, 0); /* short strings */
54+
inline constexpr int LUA_VLNGSTR = makevariant(LUA_TSTRING, 1); /* long strings */
55+
56+
/* Table variant */
57+
inline constexpr int LUA_VTABLE = makevariant(LUA_TTABLE, 0);
58+
59+
/* Function variants */
60+
inline constexpr int LUA_VLCL = makevariant(LUA_TFUNCTION, 0); /* Lua closure */
61+
inline constexpr int LUA_VLCF = makevariant(LUA_TFUNCTION, 1); /* light C function */
62+
inline constexpr int LUA_VCCL = makevariant(LUA_TFUNCTION, 2); /* C closure */
63+
64+
/* Userdata variants */
65+
inline constexpr int LUA_VLIGHTUSERDATA = makevariant(LUA_TLIGHTUSERDATA, 0);
66+
inline constexpr int LUA_VUSERDATA = makevariant(LUA_TUSERDATA, 0);
67+
68+
/* Thread variant */
69+
inline constexpr int LUA_VTHREAD = makevariant(LUA_TTHREAD, 0);
70+
71+
/* Upvalue variant (collectable non-value) */
72+
inline constexpr int LUA_VUPVAL = makevariant(LUA_TUPVAL, 0);
73+
74+
/* Proto variant (collectable non-value) */
75+
inline constexpr int LUA_VPROTO = makevariant(LUA_TPROTO, 0);
76+
77+
/* }================================================================== */
78+
79+
2580
/*
2681
** Rounding modes for float->integer coercion (needed by TValue conversion methods)
2782
*/

0 commit comments

Comments
 (0)