Skip to content

Commit c08e7c9

Browse files
committed
Phase 122: Complete header file LuaT refactoring
Changed types from lu_byte to LuaT throughout headers: **Node class (ltable.h):** - Changed tt_ and key_tt from lu_byte to LuaT - Updated getKeyType() to return LuaT - Updated setKeyType() to take LuaT parameter - Updated constructor to use LuaT parameters **Table class (ltable.h):** - Changed getArrayTag() to return LuaT* instead of lu_byte* - Changed get/getInt/getShortStr/getStr to return LuaT - Updated farr2val/fval2arr to use LuaT parameters - Updated luaH_* function signatures to return LuaT **Inline functions (lobject.h, lobject_core.h):** - Updated luaH_fastgeti to use LuaT& tag parameter - Updated luaH_fastseti to use LuaT* local variable - Added tagisempty(LuaT) overload **GC casts (lstate.h):** - Updated all gco2* functions to use LuaT enum values - Changed LUA_V* constants to LuaT::* enum values Status: All headers updated to use LuaT types Next: Update implementation (.cpp) files
1 parent 930febf commit c08e7c9

4 files changed

Lines changed: 37 additions & 36 deletions

File tree

src/core/lstate.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,17 +1229,17 @@ inline TString* gco2ts(GCObject* o) noexcept {
12291229
}
12301230

12311231
inline Udata* gco2u(GCObject* o) noexcept {
1232-
lua_assert(o->getType() == LUA_VUSERDATA);
1232+
lua_assert(o->getType() == ctb(LuaT::USERDATA));
12331233
return reinterpret_cast<Udata*>(o);
12341234
}
12351235

12361236
inline LClosure* gco2lcl(GCObject* o) noexcept {
1237-
lua_assert(o->getType() == LUA_VLCL);
1237+
lua_assert(o->getType() == ctb(LuaT::LCL));
12381238
return reinterpret_cast<LClosure*>(o);
12391239
}
12401240

12411241
inline CClosure* gco2ccl(GCObject* o) noexcept {
1242-
lua_assert(o->getType() == LUA_VCCL);
1242+
lua_assert(o->getType() == ctb(LuaT::CCL));
12431243
return reinterpret_cast<CClosure*>(o);
12441244
}
12451245

@@ -1249,22 +1249,22 @@ inline Closure* gco2cl(GCObject* o) noexcept {
12491249
}
12501250

12511251
inline Table* gco2t(GCObject* o) noexcept {
1252-
lua_assert(o->getType() == LUA_VTABLE);
1252+
lua_assert(o->getType() == ctb(LuaT::TABLE));
12531253
return reinterpret_cast<Table*>(o);
12541254
}
12551255

12561256
inline Proto* gco2p(GCObject* o) noexcept {
1257-
lua_assert(o->getType() == LUA_VPROTO);
1257+
lua_assert(o->getType() == ctb(LuaT::PROTO));
12581258
return reinterpret_cast<Proto*>(o);
12591259
}
12601260

12611261
inline lua_State* gco2th(GCObject* o) noexcept {
1262-
lua_assert(o->getType() == LUA_VTHREAD);
1262+
lua_assert(o->getType() == ctb(LuaT::THREAD));
12631263
return reinterpret_cast<lua_State*>(o);
12641264
}
12651265

12661266
inline UpVal* gco2upv(GCObject* o) noexcept {
1267-
lua_assert(o->getType() == LUA_VUPVAL);
1267+
lua_assert(o->getType() == ctb(LuaT::UPVAL));
12681268
return reinterpret_cast<UpVal*>(o);
12691269
}
12701270

src/objects/lobject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ inline bool operator!=(const TString& l, const TString& r) noexcept {
487487

488488
// Phase 88: Convert luaH_fastgeti and luaH_fastseti macros to inline functions
489489
// These are hot-path table access functions used throughout the VM
490-
inline void luaH_fastgeti(Table* t, lua_Integer k, TValue* res, lu_byte& tag) noexcept {
490+
inline void luaH_fastgeti(Table* t, lua_Integer k, TValue* res, LuaT& tag) noexcept {
491491
Table* h = t;
492492
lua_Unsigned u = l_castS2U(k) - 1u;
493493
if (u < h->arraySize()) {
@@ -504,7 +504,7 @@ inline void luaH_fastseti(Table* t, lua_Integer k, TValue* val, int& hres) noexc
504504
Table* h = t;
505505
lua_Unsigned u = l_castS2U(k) - 1u;
506506
if (u < h->arraySize()) {
507-
lu_byte* tag = h->getArrayTag(u);
507+
LuaT* tag = h->getArrayTag(u);
508508
if (checknoTM(h->getMetatable(), TMS::TM_NEWINDEX) || !tagisempty(*tag)) {
509509
fval2arr(h, u, tag, val);
510510
hres = HOK;

src/objects/lobject_core.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ constexpr bool TValue::isNil() const noexcept { return checktype(this, LUA_TNIL)
5252
** simpler to just test whether the value is nil.
5353
*/
5454
constexpr bool tagisempty(int tag) noexcept { return novariant(tag) == LUA_TNIL; }
55+
constexpr bool tagisempty(LuaT tag) noexcept { return novariant(tag) == LUA_TNIL; }
5556

5657

5758
/* macro to test for a standard nil */

src/objects/ltable.h

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ class Node {
4444
union {
4545
struct {
4646
Value value_; /* value */
47-
lu_byte tt_; /* value type tag */
48-
lu_byte key_tt; /* key type */
47+
LuaT tt_; /* value type tag */
48+
LuaT key_tt; /* key type */
4949
int next; /* for chaining */
5050
Value key_val; /* key value */
5151
} u;
@@ -54,10 +54,10 @@ class Node {
5454

5555
public:
5656
// Default constructor
57-
constexpr Node() noexcept : u{{0}, static_cast<lu_byte>(LuaT::NIL), LUA_TNIL, 0, {0}} {}
57+
constexpr Node() noexcept : u{{0}, LuaT::NIL, static_cast<LuaT>(LUA_TNIL), 0, {0}} {}
5858

5959
// Constructor for initializing with explicit values
60-
constexpr Node(Value val, lu_byte val_tt, lu_byte key_tt, int next_val, Value key_val) noexcept
60+
constexpr Node(Value val, LuaT val_tt, LuaT key_tt, int next_val, Value key_val) noexcept
6161
: u{val, val_tt, key_tt, next_val, key_val} {}
6262

6363
// Copy assignment operator (needed because union contains TValue with user-declared operator=)
@@ -76,8 +76,8 @@ class Node {
7676
void setNext(int n) noexcept { u.next = n; }
7777

7878
// Key type access
79-
lu_byte getKeyType() const noexcept { return u.key_tt; }
80-
void setKeyType(lu_byte tt) noexcept { u.key_tt = tt; }
79+
LuaT getKeyType() const noexcept { return u.key_tt; }
80+
void setKeyType(LuaT tt) noexcept { u.key_tt = tt; }
8181

8282
// Key value access
8383
const Value& getKeyValue() const noexcept { return u.key_val; }
@@ -86,23 +86,23 @@ class Node {
8686

8787
// Key type checks
8888
bool isKeyNil() const noexcept {
89-
return u.key_tt == LUA_TNIL;
89+
return novariant(u.key_tt) == LUA_TNIL;
9090
}
9191

9292
bool isKeyInteger() const noexcept {
93-
return u.key_tt == LUA_VNUMINT;
93+
return u.key_tt == LuaT::NUMINT;
9494
}
9595

9696
bool isKeyShrStr() const noexcept {
97-
return u.key_tt == ctb(LUA_VSHRSTR);
97+
return u.key_tt == ctb(LuaT::SHRSTR);
9898
}
9999

100100
bool isKeyDead() const noexcept {
101-
return u.key_tt == LUA_TDEADKEY;
101+
return novariant(u.key_tt) == LUA_TDEADKEY;
102102
}
103103

104104
bool isKeyCollectable() const noexcept {
105-
return (u.key_tt & BIT_ISCOLLECTABLE) != 0;
105+
return (static_cast<int>(u.key_tt) & BIT_ISCOLLECTABLE) != 0;
106106
}
107107

108108
// Key value getters (typed)
@@ -124,11 +124,11 @@ class Node {
124124

125125
// Key setters
126126
void setKeyNil() noexcept {
127-
u.key_tt = LUA_TNIL;
127+
u.key_tt = LuaT::NIL;
128128
}
129129

130130
void setKeyDead() noexcept {
131-
u.key_tt = LUA_TDEADKEY;
131+
u.key_tt = static_cast<LuaT>(LUA_TDEADKEY);
132132
}
133133

134134
// Copy TValue to key
@@ -244,12 +244,12 @@ class Table : public GCBase<Table> {
244244
return static_cast<const unsigned int*>(static_cast<const void*>(array));
245245
}
246246

247-
lu_byte* getArrayTag(lua_Unsigned k) noexcept {
248-
return static_cast<lu_byte*>(static_cast<void*>(array)) + sizeof(unsigned) + k;
247+
LuaT* getArrayTag(lua_Unsigned k) noexcept {
248+
return reinterpret_cast<LuaT*>(static_cast<lu_byte*>(static_cast<void*>(array)) + sizeof(unsigned) + k);
249249
}
250250

251-
const lu_byte* getArrayTag(lua_Unsigned k) const noexcept {
252-
return static_cast<const lu_byte*>(static_cast<const void*>(array)) + sizeof(unsigned) + k;
251+
const LuaT* getArrayTag(lua_Unsigned k) const noexcept {
252+
return reinterpret_cast<const LuaT*>(static_cast<const lu_byte*>(static_cast<const void*>(array)) + sizeof(unsigned) + k);
253253
}
254254

255255
Value* getArrayVal(lua_Unsigned k) noexcept {
@@ -269,10 +269,10 @@ class Table : public GCBase<Table> {
269269
const Node* getNode(unsigned int i) const noexcept { return &node[i]; }
270270

271271
// Method declarations (implemented in ltable.cpp)
272-
lu_byte get(const TValue* key, TValue* res);
273-
lu_byte getInt(lua_Integer key, TValue* res);
274-
lu_byte getShortStr(TString* key, TValue* res);
275-
lu_byte getStr(TString* key, TValue* res);
272+
LuaT get(const TValue* key, TValue* res);
273+
LuaT getInt(lua_Integer key, TValue* res);
274+
LuaT getShortStr(TString* key, TValue* res);
275+
LuaT getStr(TString* key, TValue* res);
276276
TValue* HgetShortStr(TString* key);
277277

278278
int pset(const TValue* key, TValue* val);
@@ -432,20 +432,20 @@ inline void obj2arr(Table* h, lua_Unsigned k, const TValue* val) noexcept {
432432
** following inline functions also move TValues to/from arrays, but receive the
433433
** precomputed tag value or address as an extra argument.
434434
*/
435-
inline void farr2val(const Table* h, lua_Unsigned k, lu_byte tag, TValue* res) noexcept {
435+
inline void farr2val(const Table* h, lua_Unsigned k, LuaT tag, TValue* res) noexcept {
436436
res->setType(tag);
437437
res->valueField() = *h->getArrayVal(k);
438438
}
439439

440-
inline void fval2arr(Table* h, lua_Unsigned k, lu_byte* tag, const TValue* val) noexcept {
440+
inline void fval2arr(Table* h, lua_Unsigned k, LuaT* tag, const TValue* val) noexcept {
441441
*tag = val->getType();
442442
*h->getArrayVal(k) = val->getValue();
443443
}
444444

445-
LUAI_FUNC lu_byte luaH_get (Table *t, const TValue *key, TValue *res);
446-
LUAI_FUNC lu_byte luaH_getshortstr (Table *t, TString *key, TValue *res);
447-
LUAI_FUNC lu_byte luaH_getstr (Table *t, TString *key, TValue *res);
448-
LUAI_FUNC lu_byte luaH_getint (Table *t, lua_Integer key, TValue *res);
445+
LUAI_FUNC LuaT luaH_get (Table *t, const TValue *key, TValue *res);
446+
LUAI_FUNC LuaT luaH_getshortstr (Table *t, TString *key, TValue *res);
447+
LUAI_FUNC LuaT luaH_getstr (Table *t, TString *key, TValue *res);
448+
LUAI_FUNC LuaT luaH_getint (Table *t, lua_Integer key, TValue *res);
449449

450450
/* Special get for metamethods */
451451
LUAI_FUNC const TValue *luaH_Hgetshortstr (Table *t, TString *key);

0 commit comments

Comments
 (0)