From e03b75fbe95ade9ef1f02f5ab797b52fd43f2e58 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 22 Nov 2025 11:47:58 +0000 Subject: [PATCH 1/7] Phase 122: Add enum class LuaT for variant tags (part 1) - Created enum class LuaT with makevariant initializers - Removed LUA_V prefix from enum names (e.g., LUA_VNIL -> LuaT::NIL) - Added backward compatibility constants for gradual migration - All variant tags now use type-safe enum class Next steps: - Update call sites to use LuaT enum - Update function signatures to use LuaT type - Remove backward compatibility constants --- src/objects/ltvalue.h | 81 +++++++++++++++++++++++++++---------------- 1 file changed, 52 insertions(+), 29 deletions(-) diff --git a/src/objects/ltvalue.h b/src/objects/ltvalue.h index 6e0a24c7..921ce436 100644 --- a/src/objects/ltvalue.h +++ b/src/objects/ltvalue.h @@ -35,44 +35,67 @@ inline constexpr int LUA_TPROTO = (LUA_NUMTYPES+1); /* function prototypes */ ** =================================================================== */ -/* Nil variants */ -inline constexpr int LUA_VNIL = makevariant(LUA_TNIL, 0); -inline constexpr int LUA_VEMPTY = makevariant(LUA_TNIL, 1); -inline constexpr int LUA_VABSTKEY = makevariant(LUA_TNIL, 2); -inline constexpr int LUA_VNOTABLE = makevariant(LUA_TNIL, 3); +enum class LuaT : int { + /* Nil variants */ + NIL = makevariant(LUA_TNIL, 0), + EMPTY = makevariant(LUA_TNIL, 1), + ABSTKEY = makevariant(LUA_TNIL, 2), + NOTABLE = makevariant(LUA_TNIL, 3), -/* Boolean variants */ -inline constexpr int LUA_VFALSE = makevariant(LUA_TBOOLEAN, 0); -inline constexpr int LUA_VTRUE = makevariant(LUA_TBOOLEAN, 1); + /* Boolean variants */ + VFALSE = makevariant(LUA_TBOOLEAN, 0), + VTRUE = makevariant(LUA_TBOOLEAN, 1), -/* Number variants */ -inline constexpr int LUA_VNUMINT = makevariant(LUA_TNUMBER, 0); /* integer numbers */ -inline constexpr int LUA_VNUMFLT = makevariant(LUA_TNUMBER, 1); /* float numbers */ + /* Number variants */ + NUMINT = makevariant(LUA_TNUMBER, 0), /* integer numbers */ + NUMFLT = makevariant(LUA_TNUMBER, 1), /* float numbers */ -/* String variants */ -inline constexpr int LUA_VSHRSTR = makevariant(LUA_TSTRING, 0); /* short strings */ -inline constexpr int LUA_VLNGSTR = makevariant(LUA_TSTRING, 1); /* long strings */ + /* String variants */ + SHRSTR = makevariant(LUA_TSTRING, 0), /* short strings */ + LNGSTR = makevariant(LUA_TSTRING, 1), /* long strings */ -/* Table variant */ -inline constexpr int LUA_VTABLE = makevariant(LUA_TTABLE, 0); + /* Table variant */ + TABLE = makevariant(LUA_TTABLE, 0), -/* Function variants */ -inline constexpr int LUA_VLCL = makevariant(LUA_TFUNCTION, 0); /* Lua closure */ -inline constexpr int LUA_VLCF = makevariant(LUA_TFUNCTION, 1); /* light C function */ -inline constexpr int LUA_VCCL = makevariant(LUA_TFUNCTION, 2); /* C closure */ + /* Function variants */ + LCL = makevariant(LUA_TFUNCTION, 0), /* Lua closure */ + LCF = makevariant(LUA_TFUNCTION, 1), /* light C function */ + CCL = makevariant(LUA_TFUNCTION, 2), /* C closure */ -/* Userdata variants */ -inline constexpr int LUA_VLIGHTUSERDATA = makevariant(LUA_TLIGHTUSERDATA, 0); -inline constexpr int LUA_VUSERDATA = makevariant(LUA_TUSERDATA, 0); + /* Userdata variants */ + LIGHTUSERDATA = makevariant(LUA_TLIGHTUSERDATA, 0), + USERDATA = makevariant(LUA_TUSERDATA, 0), -/* Thread variant */ -inline constexpr int LUA_VTHREAD = makevariant(LUA_TTHREAD, 0); + /* Thread variant */ + THREAD = makevariant(LUA_TTHREAD, 0), -/* Upvalue variant (collectable non-value) */ -inline constexpr int LUA_VUPVAL = makevariant(LUA_TUPVAL, 0); + /* Upvalue variant (collectable non-value) */ + UPVAL = makevariant(LUA_TUPVAL, 0), -/* Proto variant (collectable non-value) */ -inline constexpr int LUA_VPROTO = makevariant(LUA_TPROTO, 0); + /* Proto variant (collectable non-value) */ + PROTO = makevariant(LUA_TPROTO, 0) +}; + +/* Backward compatibility constants (to be removed after migration) */ +inline constexpr int LUA_VNIL = static_cast(LuaT::NIL); +inline constexpr int LUA_VEMPTY = static_cast(LuaT::EMPTY); +inline constexpr int LUA_VABSTKEY = static_cast(LuaT::ABSTKEY); +inline constexpr int LUA_VNOTABLE = static_cast(LuaT::NOTABLE); +inline constexpr int LUA_VFALSE = static_cast(LuaT::VFALSE); +inline constexpr int LUA_VTRUE = static_cast(LuaT::VTRUE); +inline constexpr int LUA_VNUMINT = static_cast(LuaT::NUMINT); +inline constexpr int LUA_VNUMFLT = static_cast(LuaT::NUMFLT); +inline constexpr int LUA_VSHRSTR = static_cast(LuaT::SHRSTR); +inline constexpr int LUA_VLNGSTR = static_cast(LuaT::LNGSTR); +inline constexpr int LUA_VTABLE = static_cast(LuaT::TABLE); +inline constexpr int LUA_VLCL = static_cast(LuaT::LCL); +inline constexpr int LUA_VLCF = static_cast(LuaT::LCF); +inline constexpr int LUA_VCCL = static_cast(LuaT::CCL); +inline constexpr int LUA_VLIGHTUSERDATA = static_cast(LuaT::LIGHTUSERDATA); +inline constexpr int LUA_VUSERDATA = static_cast(LuaT::USERDATA); +inline constexpr int LUA_VTHREAD = static_cast(LuaT::THREAD); +inline constexpr int LUA_VUPVAL = static_cast(LuaT::UPVAL); +inline constexpr int LUA_VPROTO = static_cast(LuaT::PROTO); /* }================================================================== */ From 930febf4fbeeb046f1f1bf25ba1806a10aa147d6 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 22 Nov 2025 11:58:49 +0000 Subject: [PATCH 2/7] Phase 122: Refactor LUA_V* to enum class LuaT (WIP - headers) Major changes: - Changed enum class LuaT from : int to : lu_byte for memory efficiency - Changed TValue::tt_ from lu_byte to LuaT type - Changed GCObject::tt and GCBase::tt from lu_byte to LuaT - Updated all type-checking functions (checktag, ctb, etc.) to use LuaT - Updated TValue getters to return LuaT instead of lu_byte - Added overloads for backward compatibility Header files updated: - ltvalue.h: Core LuaT enum and TValue type changes - lobject_core.h: Updated GCObject, GCBase, type helpers - lobject.h: Updated TValue setters and equality operator - lstring.h: Updated string type checks - lfunc.h: Updated function/closure type checks - ltable.h: Updated table type checks and Node constructor Status: Headers updated, implementation files still need work Build status: In progress, compiler-driven migration --- src/objects/lfunc.h | 12 ++++---- src/objects/lobject.h | 46 ++++++++++++++-------------- src/objects/lobject_core.h | 63 ++++++++++++++++++++------------------ src/objects/lstring.h | 10 +++--- src/objects/ltable.h | 6 ++-- src/objects/ltvalue.h | 57 ++++++++++++++-------------------- 6 files changed, 93 insertions(+), 101 deletions(-) diff --git a/src/objects/lfunc.h b/src/objects/lfunc.h index 4b0bcafe..9b53c07e 100644 --- a/src/objects/lfunc.h +++ b/src/objects/lfunc.h @@ -25,15 +25,15 @@ typedef union StackValue *StkId; */ constexpr bool ttisfunction(const TValue* o) noexcept { return checktype(o, LUA_TFUNCTION); } -constexpr bool ttisLclosure(const TValue* o) noexcept { return checktag(o, ctb(LUA_VLCL)); } -constexpr bool ttislcf(const TValue* o) noexcept { return checktag(o, LUA_VLCF); } -constexpr bool ttisCclosure(const TValue* o) noexcept { return checktag(o, ctb(LUA_VCCL)); } +constexpr bool ttisLclosure(const TValue* o) noexcept { return checktag(o, ctb(LuaT::LCL)); } +constexpr bool ttislcf(const TValue* o) noexcept { return checktag(o, LuaT::LCF); } +constexpr bool ttisCclosure(const TValue* o) noexcept { return checktag(o, ctb(LuaT::CCL)); } constexpr bool ttisclosure(const TValue* o) noexcept { return ttisLclosure(o) || ttisCclosure(o); } constexpr bool TValue::isFunction() const noexcept { return checktype(this, LUA_TFUNCTION); } -constexpr bool TValue::isLClosure() const noexcept { return checktag(this, ctb(LUA_VLCL)); } -constexpr bool TValue::isLightCFunction() const noexcept { return checktag(this, LUA_VLCF); } -constexpr bool TValue::isCClosure() const noexcept { return checktag(this, ctb(LUA_VCCL)); } +constexpr bool TValue::isLClosure() const noexcept { return checktag(this, ctb(LuaT::LCL)); } +constexpr bool TValue::isLightCFunction() const noexcept { return checktag(this, LuaT::LCF); } +constexpr bool TValue::isCClosure() const noexcept { return checktag(this, ctb(LuaT::CCL)); } constexpr bool TValue::isClosure() const noexcept { return isLClosure() || isCClosure(); } inline constexpr bool isLfunction(const TValue* o) noexcept { diff --git a/src/objects/lobject.h b/src/objects/lobject.h index d5d3f421..cd361969 100644 --- a/src/objects/lobject.h +++ b/src/objects/lobject.h @@ -97,28 +97,28 @@ constexpr const TValue* s2v(const StackValue* o) noexcept { return &(o)->val; } ** TValue member function implementations ** These must be defined here after all type constants are available */ -inline void TValue::setNil() noexcept { tt_ = LUA_VNIL; } -inline void TValue::setFalse() noexcept { tt_ = LUA_VFALSE; } -inline void TValue::setTrue() noexcept { tt_ = LUA_VTRUE; } +inline void TValue::setNil() noexcept { setType(LuaT::NIL); } +inline void TValue::setFalse() noexcept { setType(LuaT::VFALSE); } +inline void TValue::setTrue() noexcept { setType(LuaT::VTRUE); } inline void TValue::setInt(lua_Integer i) noexcept { value_.i = i; - tt_ = LUA_VNUMINT; + setType(LuaT::NUMINT); } inline void TValue::setFloat(lua_Number n) noexcept { value_.n = n; - tt_ = LUA_VNUMFLT; + setType(LuaT::NUMFLT); } inline void TValue::setPointer(void* p) noexcept { value_.p = p; - tt_ = LUA_VLIGHTUSERDATA; + setType(LuaT::LIGHTUSERDATA); } inline void TValue::setFunction(lua_CFunction f) noexcept { value_.f = f; - tt_ = LUA_VLCF; + setType(LuaT::LCF); } inline void TValue::setString(lua_State* L, TString* s) noexcept { @@ -129,31 +129,31 @@ inline void TValue::setString(lua_State* L, TString* s) noexcept { inline void TValue::setUserdata(lua_State* L, Udata* u) noexcept { value_.gc = reinterpret_cast(u); - tt_ = ctb(LUA_VUSERDATA); + tt_ = ctb(LuaT::USERDATA); (void)L; } inline void TValue::setTable(lua_State* L, Table* t) noexcept { value_.gc = reinterpret_cast(t); - tt_ = ctb(LUA_VTABLE); + tt_ = ctb(LuaT::TABLE); (void)L; } inline void TValue::setLClosure(lua_State* L, LClosure* cl) noexcept { value_.gc = reinterpret_cast(cl); - tt_ = ctb(LUA_VLCL); + tt_ = ctb(LuaT::LCL); (void)L; } inline void TValue::setCClosure(lua_State* L, CClosure* cl) noexcept { value_.gc = reinterpret_cast(cl); - tt_ = ctb(LUA_VCCL); + tt_ = ctb(LuaT::CCL); (void)L; } inline void TValue::setThread(lua_State* L, lua_State* th) noexcept { value_.gc = reinterpret_cast(th); - tt_ = ctb(LUA_VTHREAD); + tt_ = ctb(LuaT::THREAD); (void)L; } @@ -379,17 +379,17 @@ inline bool operator==(const TValue& l, const TValue& r) noexcept { else if (ttypetag(&l) != ttypetag(&r)) { /* Different variants - only numbers and strings can be equal across variants */ switch (ttypetag(&l)) { - case LUA_VNUMINT: { /* int == float? */ + case LuaT::NUMINT: { /* int == float? */ lua_Integer i2; return (luaV_flttointeger(fltvalue(&r), &i2, F2Imod::F2Ieq) && ivalue(&l) == i2); } - case LUA_VNUMFLT: { /* float == int? */ + case LuaT::NUMFLT: { /* float == int? */ lua_Integer i1; return (luaV_flttointeger(fltvalue(&l), &i1, F2Imod::F2Ieq) && i1 == ivalue(&r)); } - case LUA_VSHRSTR: case LUA_VLNGSTR: { + case LuaT::SHRSTR: case LuaT::LNGSTR: { /* Compare strings with different variants */ return tsvalue(&l)->equals(tsvalue(&r)); } @@ -399,21 +399,21 @@ inline bool operator==(const TValue& l, const TValue& r) noexcept { } else { /* same variant */ switch (ttypetag(&l)) { - case LUA_VNIL: case LUA_VFALSE: case LUA_VTRUE: + case LuaT::NIL: case LuaT::VFALSE: case LuaT::VTRUE: return true; - case LUA_VNUMINT: + case LuaT::NUMINT: return ivalue(&l) == ivalue(&r); - case LUA_VNUMFLT: + case LuaT::NUMFLT: return fltvalue(&l) == fltvalue(&r); - case LUA_VLIGHTUSERDATA: + case LuaT::LIGHTUSERDATA: return pvalue(&l) == pvalue(&r); - case LUA_VSHRSTR: + case LuaT::SHRSTR: return eqshrstr(tsvalue(&l), tsvalue(&r)); - case LUA_VLNGSTR: + case LuaT::LNGSTR: return tsvalue(&l)->equals(tsvalue(&r)); - case LUA_VUSERDATA: + case LuaT::USERDATA: return uvalue(&l) == uvalue(&r); - case LUA_VLCF: + case LuaT::LCF: return fvalue(&l) == fvalue(&r); default: /* other collectable types (tables, closures, threads) */ return gcvalue(&l) == gcvalue(&r); diff --git a/src/objects/lobject_core.h b/src/objects/lobject_core.h index 067e618c..a5510b62 100644 --- a/src/objects/lobject_core.h +++ b/src/objects/lobject_core.h @@ -55,16 +55,16 @@ constexpr bool tagisempty(int tag) noexcept { return novariant(tag) == LUA_TNIL; /* macro to test for a standard nil */ -constexpr bool ttisstrictnil(const TValue* o) noexcept { return checktag(o, LUA_VNIL); } +constexpr bool ttisstrictnil(const TValue* o) noexcept { return checktag(o, LuaT::NIL); } -constexpr bool TValue::isStrictNil() const noexcept { return checktag(this, LUA_VNIL); } +constexpr bool TValue::isStrictNil() const noexcept { return checktag(this, LuaT::NIL); } inline void setnilvalue(TValue* obj) noexcept { obj->setNil(); } -constexpr bool isabstkey(const TValue* v) noexcept { return checktag(v, LUA_VABSTKEY); } +constexpr bool isabstkey(const TValue* v) noexcept { return checktag(v, LuaT::ABSTKEY); } -constexpr bool TValue::isAbstKey() const noexcept { return checktag(this, LUA_VABSTKEY); } +constexpr bool TValue::isAbstKey() const noexcept { return checktag(this, LuaT::ABSTKEY); } /* @@ -89,11 +89,11 @@ constexpr bool TValue::isEmpty() const noexcept { return isNil(); } /* macro defining a value corresponding to an absent key */ -#define ABSTKEYCONSTANT {nullptr}, LUA_VABSTKEY +#define ABSTKEYCONSTANT {nullptr}, LuaT::ABSTKEY /* mark an entry as empty */ -inline void setempty(TValue* v) noexcept { settt_(v, LUA_VEMPTY); } +inline void setempty(TValue* v) noexcept { settt_(v, LuaT::EMPTY); } /* }================================================================== */ @@ -106,15 +106,16 @@ inline void setempty(TValue* v) noexcept { settt_(v, LUA_VEMPTY); } */ constexpr bool ttisboolean(const TValue* o) noexcept { return checktype(o, LUA_TBOOLEAN); } -constexpr bool ttisfalse(const TValue* o) noexcept { return checktag(o, LUA_VFALSE); } -constexpr bool ttistrue(const TValue* o) noexcept { return checktag(o, LUA_VTRUE); } +constexpr bool ttisfalse(const TValue* o) noexcept { return checktag(o, LuaT::VFALSE); } +constexpr bool ttistrue(const TValue* o) noexcept { return checktag(o, LuaT::VTRUE); } constexpr bool TValue::isBoolean() const noexcept { return checktype(this, LUA_TBOOLEAN); } -constexpr bool TValue::isFalse() const noexcept { return checktag(this, LUA_VFALSE); } -constexpr bool TValue::isTrue() const noexcept { return checktag(this, LUA_VTRUE); } +constexpr bool TValue::isFalse() const noexcept { return checktag(this, LuaT::VFALSE); } +constexpr bool TValue::isTrue() const noexcept { return checktag(this, LuaT::VTRUE); } constexpr bool l_isfalse(const TValue* o) noexcept { return ttisfalse(o) || ttisnil(o); } -constexpr bool tagisfalse(int t) noexcept { return (t == LUA_VFALSE || novariant(t) == LUA_TNIL); } +constexpr bool tagisfalse(LuaT t) noexcept { return (t == LuaT::VFALSE || novariant(t) == LUA_TNIL); } +constexpr bool tagisfalse(int t) noexcept { return (t == static_cast(LuaT::VFALSE) || novariant(t) == LUA_TNIL); } constexpr bool TValue::isFalseLike() const noexcept { return isFalse() || isNil(); } @@ -133,9 +134,9 @@ inline void setbtvalue(TValue* obj) noexcept { obj->setTrue(); } ** Note: LUA_VTHREAD now defined in ltvalue.h */ -constexpr bool ttisthread(const TValue* o) noexcept { return checktag(o, ctb(LUA_VTHREAD)); } +constexpr bool ttisthread(const TValue* o) noexcept { return checktag(o, ctb(LuaT::THREAD)); } -constexpr bool TValue::isThread() const noexcept { return checktag(this, ctb(LUA_VTHREAD)); } +constexpr bool TValue::isThread() const noexcept { return checktag(this, ctb(LuaT::THREAD)); } inline lua_State* thvalue(const TValue* o) noexcept { return o->threadValue(); } @@ -152,16 +153,16 @@ inline lua_State* thvalue(const TValue* o) noexcept { return o->threadValue(); } */ constexpr bool ttisnumber(const TValue* o) noexcept { return checktype(o, LUA_TNUMBER); } -constexpr bool ttisfloat(const TValue* o) noexcept { return checktag(o, LUA_VNUMFLT); } -constexpr bool ttisinteger(const TValue* o) noexcept { return checktag(o, LUA_VNUMINT); } +constexpr bool ttisfloat(const TValue* o) noexcept { return checktag(o, LuaT::NUMFLT); } +constexpr bool ttisinteger(const TValue* o) noexcept { return checktag(o, LuaT::NUMINT); } constexpr bool TValue::isNumber() const noexcept { return checktype(this, LUA_TNUMBER); } -constexpr bool TValue::isFloat() const noexcept { return checktag(this, LUA_VNUMFLT); } -constexpr bool TValue::isInteger() const noexcept { return checktag(this, LUA_VNUMINT); } +constexpr bool TValue::isFloat() const noexcept { return checktag(this, LuaT::NUMFLT); } +constexpr bool TValue::isInteger() const noexcept { return checktag(this, LuaT::NUMINT); } -// TValue::numberValue() implementation (needs LUA_VNUMINT constant) +// TValue::numberValue() implementation (needs NUMINT constant) inline lua_Number TValue::numberValue() const noexcept { - return (tt_ == LUA_VNUMINT) ? static_cast(value_.i) : value_.n; + return (tt_ == LuaT::NUMINT) ? static_cast(value_.i) : value_.n; } inline lua_Number nvalue(const TValue* o) noexcept { return o->numberValue(); } @@ -190,7 +191,7 @@ constexpr lua_Integer ivalueraw(const Value& v) noexcept { return v.i; } class GCObject { protected: mutable GCObject* next; /* GC list linkage (mutable for GC bookkeeping) */ - lu_byte tt; /* Type tag (immutable) */ + LuaT tt; /* Type tag (immutable) */ mutable lu_byte marked; /* GC mark bits (mutable for GC bookkeeping) */ public: @@ -199,8 +200,9 @@ class GCObject { void setNext(GCObject* n) const noexcept { next = n; } /* const - next is mutable */ // Pointer-to-pointer for efficient GC list manipulation (allows in-place removal) GCObject** getNextPtr() const noexcept { return &next; } /* const - next is mutable */ - lu_byte getType() const noexcept { return tt; } - void setType(lu_byte t) noexcept { tt = t; } + LuaT getType() const noexcept { return tt; } + void setType(LuaT t) noexcept { tt = t; } + void setType(lu_byte t) noexcept { tt = static_cast(t); } /* for legacy code */ lu_byte getMarked() const noexcept { return marked; } void setMarked(lu_byte m) const noexcept { marked = m; } /* const - marked is mutable */ bool isMarked() const noexcept { return marked != 0; } @@ -276,8 +278,9 @@ class GCBase: public GCObject { constexpr GCObject* getNext() const noexcept { return next; } constexpr void setNext(GCObject* n) const noexcept { next = n; } /* const - next is mutable */ - constexpr lu_byte getType() const noexcept { return tt; } - constexpr void setType(lu_byte t) noexcept { tt = t; } + constexpr LuaT getType() const noexcept { return tt; } + constexpr void setType(LuaT t) noexcept { tt = t; } + constexpr void setType(lu_byte t) noexcept { tt = static_cast(t); } /* for legacy code */ constexpr lu_byte getMarked() const noexcept { return marked; } constexpr void setMarked(lu_byte m) const noexcept { marked = m; } /* const - marked is mutable */ @@ -297,9 +300,9 @@ class GCBase: public GCObject { } }; -constexpr bool iscollectable(const TValue* o) noexcept { return (rawtt(o) & BIT_ISCOLLECTABLE) != 0; } +constexpr bool iscollectable(const TValue* o) noexcept { return (static_cast(rawtt(o)) & BIT_ISCOLLECTABLE) != 0; } -constexpr bool TValue::isCollectable() const noexcept { return (tt_ & BIT_ISCOLLECTABLE) != 0; } +constexpr bool TValue::isCollectable() const noexcept { return (static_cast(tt_) & BIT_ISCOLLECTABLE) != 0; } inline GCObject* gcvalue(const TValue* o) noexcept { return o->gcValue(); } @@ -322,11 +325,11 @@ inline bool TValue::hasRightType() const noexcept { return typeTag() == gcValue( ** Note: LUA_VLIGHTUSERDATA, LUA_VUSERDATA now defined in ltvalue.h */ -constexpr bool ttislightuserdata(const TValue* o) noexcept { return checktag(o, LUA_VLIGHTUSERDATA); } -constexpr bool ttisfulluserdata(const TValue* o) noexcept { return checktag(o, ctb(LUA_VUSERDATA)); } +constexpr bool ttislightuserdata(const TValue* o) noexcept { return checktag(o, LuaT::LIGHTUSERDATA); } +constexpr bool ttisfulluserdata(const TValue* o) noexcept { return checktag(o, ctb(LuaT::USERDATA)); } -constexpr bool TValue::isLightUserdata() const noexcept { return checktag(this, LUA_VLIGHTUSERDATA); } -constexpr bool TValue::isFullUserdata() const noexcept { return checktag(this, ctb(LUA_VUSERDATA)); } +constexpr bool TValue::isLightUserdata() const noexcept { return checktag(this, LuaT::LIGHTUSERDATA); } +constexpr bool TValue::isFullUserdata() const noexcept { return checktag(this, ctb(LuaT::USERDATA)); } inline void* pvalue(const TValue* o) noexcept { return o->pointerValue(); } diff --git a/src/objects/lstring.h b/src/objects/lstring.h index 9aa705b0..e077abd8 100644 --- a/src/objects/lstring.h +++ b/src/objects/lstring.h @@ -41,12 +41,12 @@ class global_State; */ constexpr bool ttisstring(const TValue* o) noexcept { return checktype(o, LUA_TSTRING); } -constexpr bool ttisshrstring(const TValue* o) noexcept { return checktag(o, ctb(LUA_VSHRSTR)); } -constexpr bool ttislngstring(const TValue* o) noexcept { return checktag(o, ctb(LUA_VLNGSTR)); } +constexpr bool ttisshrstring(const TValue* o) noexcept { return checktag(o, ctb(LuaT::SHRSTR)); } +constexpr bool ttislngstring(const TValue* o) noexcept { return checktag(o, ctb(LuaT::LNGSTR)); } constexpr bool TValue::isString() const noexcept { return checktype(this, LUA_TSTRING); } -constexpr bool TValue::isShortString() const noexcept { return checktag(this, ctb(LUA_VSHRSTR)); } -constexpr bool TValue::isLongString() const noexcept { return checktag(this, ctb(LUA_VLNGSTR)); } +constexpr bool TValue::isShortString() const noexcept { return checktag(this, ctb(LuaT::SHRSTR)); } +constexpr bool TValue::isLongString() const noexcept { return checktag(this, ctb(LuaT::LNGSTR)); } inline TString* tsvalue(const TValue* o) noexcept { return o->stringValue(); } @@ -302,7 +302,7 @@ inline bool isreserved(const TString* s) noexcept { ** equality for short strings, which are always internalized */ inline bool eqshrstr(const TString* a, const TString* b) noexcept { - return check_exp((a)->getType() == LUA_VSHRSTR, (a) == (b)); + return check_exp((a)->getType() == LuaT::SHRSTR, (a) == (b)); } diff --git a/src/objects/ltable.h b/src/objects/ltable.h index b0a16ad3..1f0c6649 100644 --- a/src/objects/ltable.h +++ b/src/objects/ltable.h @@ -24,9 +24,9 @@ typedef union StackValue *StkId; ** Note: LUA_VTABLE now defined in ltvalue.h */ -constexpr bool ttistable(const TValue* o) noexcept { return checktag(o, ctb(LUA_VTABLE)); } +constexpr bool ttistable(const TValue* o) noexcept { return checktag(o, ctb(LuaT::TABLE)); } -constexpr bool TValue::isTable() const noexcept { return checktag(this, ctb(LUA_VTABLE)); } +constexpr bool TValue::isTable() const noexcept { return checktag(this, ctb(LuaT::TABLE)); } inline Table* hvalue(const TValue* o) noexcept { return o->tableValue(); } @@ -54,7 +54,7 @@ class Node { public: // Default constructor - constexpr Node() noexcept : u{{0}, LUA_VNIL, LUA_TNIL, 0, {0}} {} + constexpr Node() noexcept : u{{0}, static_cast(LuaT::NIL), LUA_TNIL, 0, {0}} {} // Constructor for initializing with explicit values constexpr Node(Value val, lu_byte val_tt, lu_byte key_tt, int next_val, Value key_val) noexcept diff --git a/src/objects/ltvalue.h b/src/objects/ltvalue.h index 921ce436..b39c07e0 100644 --- a/src/objects/ltvalue.h +++ b/src/objects/ltvalue.h @@ -35,7 +35,7 @@ inline constexpr int LUA_TPROTO = (LUA_NUMTYPES+1); /* function prototypes */ ** =================================================================== */ -enum class LuaT : int { +enum class LuaT : lu_byte { /* Nil variants */ NIL = makevariant(LUA_TNIL, 0), EMPTY = makevariant(LUA_TNIL, 1), @@ -76,27 +76,6 @@ enum class LuaT : int { PROTO = makevariant(LUA_TPROTO, 0) }; -/* Backward compatibility constants (to be removed after migration) */ -inline constexpr int LUA_VNIL = static_cast(LuaT::NIL); -inline constexpr int LUA_VEMPTY = static_cast(LuaT::EMPTY); -inline constexpr int LUA_VABSTKEY = static_cast(LuaT::ABSTKEY); -inline constexpr int LUA_VNOTABLE = static_cast(LuaT::NOTABLE); -inline constexpr int LUA_VFALSE = static_cast(LuaT::VFALSE); -inline constexpr int LUA_VTRUE = static_cast(LuaT::VTRUE); -inline constexpr int LUA_VNUMINT = static_cast(LuaT::NUMINT); -inline constexpr int LUA_VNUMFLT = static_cast(LuaT::NUMFLT); -inline constexpr int LUA_VSHRSTR = static_cast(LuaT::SHRSTR); -inline constexpr int LUA_VLNGSTR = static_cast(LuaT::LNGSTR); -inline constexpr int LUA_VTABLE = static_cast(LuaT::TABLE); -inline constexpr int LUA_VLCL = static_cast(LuaT::LCL); -inline constexpr int LUA_VLCF = static_cast(LuaT::LCF); -inline constexpr int LUA_VCCL = static_cast(LuaT::CCL); -inline constexpr int LUA_VLIGHTUSERDATA = static_cast(LuaT::LIGHTUSERDATA); -inline constexpr int LUA_VUSERDATA = static_cast(LuaT::USERDATA); -inline constexpr int LUA_VTHREAD = static_cast(LuaT::THREAD); -inline constexpr int LUA_VUPVAL = static_cast(LuaT::UPVAL); -inline constexpr int LUA_VPROTO = static_cast(LuaT::PROTO); - /* }================================================================== */ @@ -147,17 +126,19 @@ class GCObject; class TValue { private: Value value_; - lu_byte tt_; + LuaT tt_; public: // Constexpr constructor for static initialization - constexpr TValue(Value v, lu_byte t) noexcept : value_(v), tt_(t) {} + constexpr TValue(Value v, LuaT t) noexcept : value_(v), tt_(t) {} + constexpr TValue(Value v, lu_byte t) noexcept : value_(v), tt_(static_cast(t)) {} /* for compatibility */ // Default constructor TValue() = default; // Inline accessors for hot-path access - lu_byte getType() const noexcept { return tt_; } + LuaT getType() const noexcept { return tt_; } + lu_byte getRawType() const noexcept { return static_cast(tt_); } /* for legacy code */ const Value& getValue() const noexcept { return value_; } Value& getValue() noexcept { return value_; } @@ -226,7 +207,8 @@ class TValue { // Low-level field access (for macros during transition) Value& valueField() noexcept { return value_; } const Value& valueField() const noexcept { return value_; } - void setType(lu_byte t) noexcept { tt_ = t; } + void setType(LuaT t) noexcept { tt_ = t; } + void setType(lu_byte t) noexcept { tt_ = static_cast(t); } /* for legacy code */ // Type checking methods (implementations below after constants are defined) // Nil checks @@ -276,9 +258,9 @@ class TValue { bool hasRightType() const noexcept; // GC object has same tag as value // Low-level type accessors - constexpr lu_byte rawType() const noexcept { return tt_; } + constexpr LuaT rawType() const noexcept { return tt_; } constexpr int baseType() const noexcept; - constexpr lu_byte typeTag() const noexcept; + constexpr LuaT typeTag() const noexcept; // Operator overloads (for numeric comparisons - defined after dependencies) // These are declared here but implemented in lobject.h after all type helpers are available @@ -302,32 +284,38 @@ constexpr const Value& valraw(const TValue* o) noexcept { return val_(o); } /* raw type tag of a TValue */ -constexpr lu_byte rawtt(const TValue* o) noexcept { return o->getType(); } +constexpr LuaT rawtt(const TValue* o) noexcept { return o->getType(); } +constexpr lu_byte rawtt_byte(const TValue* o) noexcept { return o->getRawType(); } /* for legacy code */ /* tag with no variants (bits 0-3) */ constexpr int novariant(int t) noexcept { return (t & 0x0F); } +constexpr int novariant(LuaT t) noexcept { return (static_cast(t) & 0x0F); } /* type tag of a TValue (bits 0-3 for tags + variant bits 4-5) */ constexpr int withvariant(int t) noexcept { return (t & 0x3F); } +constexpr LuaT withvariant(LuaT t) noexcept { return static_cast(static_cast(t) & 0x3F); } -constexpr lu_byte ttypetag(const TValue* o) noexcept { return cast_byte(withvariant(rawtt(o))); } +constexpr LuaT ttypetag(const TValue* o) noexcept { return withvariant(rawtt(o)); } +constexpr lu_byte ttypetag_byte(const TValue* o) noexcept { return static_cast(withvariant(rawtt(o))); } /* for legacy code */ /* type of a TValue */ constexpr int ttype(const TValue* o) noexcept { return novariant(rawtt(o)); } // TValue low-level type accessor implementations constexpr int TValue::baseType() const noexcept { return novariant(tt_); } -constexpr lu_byte TValue::typeTag() const noexcept { return cast_byte(withvariant(tt_)); } +constexpr LuaT TValue::typeTag() const noexcept { return withvariant(tt_); } /* Macros to test type */ -constexpr bool checktag(const TValue* o, int t) noexcept { return rawtt(o) == t; } +constexpr bool checktag(const TValue* o, LuaT t) noexcept { return rawtt(o) == t; } +constexpr bool checktag(const TValue* o, lu_byte t) noexcept { return rawtt(o) == static_cast(t); } /* overload for raw bytes */ constexpr bool checktype(const TValue* o, int t) noexcept { return ttype(o) == t; } /* Bit mark for collectable types */ inline constexpr int BIT_ISCOLLECTABLE = (1 << 6); /* mark a tag as collectable */ -constexpr lu_byte ctb(int t) noexcept { return static_cast(t | BIT_ISCOLLECTABLE); } +constexpr LuaT ctb(LuaT t) noexcept { return static_cast(static_cast(t) | BIT_ISCOLLECTABLE); } +constexpr lu_byte ctb(int t) noexcept { return static_cast(t | BIT_ISCOLLECTABLE); } /* overload for base types */ /* Macros for internal tests */ @@ -338,7 +326,8 @@ constexpr lu_byte ctb(int t) noexcept { return static_cast(t | BIT_ISCO /* Macros to set values */ /* set a value's tag */ -inline void settt_(TValue* o, lu_byte t) noexcept { o->setType(t); } +inline void settt_(TValue* o, LuaT t) noexcept { o->setType(t); } +inline void settt_(TValue* o, lu_byte t) noexcept { o->setType(t); } /* overload for raw bytes */ #endif From c08e7c9e3351c036d7e7ecfd739035b910950268 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 22 Nov 2025 12:32:29 +0000 Subject: [PATCH 3/7] 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 --- src/core/lstate.h | 14 +++++----- src/objects/lobject.h | 4 +-- src/objects/lobject_core.h | 1 + src/objects/ltable.h | 54 +++++++++++++++++++------------------- 4 files changed, 37 insertions(+), 36 deletions(-) diff --git a/src/core/lstate.h b/src/core/lstate.h index 273b590e..f27c6251 100644 --- a/src/core/lstate.h +++ b/src/core/lstate.h @@ -1229,17 +1229,17 @@ inline TString* gco2ts(GCObject* o) noexcept { } inline Udata* gco2u(GCObject* o) noexcept { - lua_assert(o->getType() == LUA_VUSERDATA); + lua_assert(o->getType() == ctb(LuaT::USERDATA)); return reinterpret_cast(o); } inline LClosure* gco2lcl(GCObject* o) noexcept { - lua_assert(o->getType() == LUA_VLCL); + lua_assert(o->getType() == ctb(LuaT::LCL)); return reinterpret_cast(o); } inline CClosure* gco2ccl(GCObject* o) noexcept { - lua_assert(o->getType() == LUA_VCCL); + lua_assert(o->getType() == ctb(LuaT::CCL)); return reinterpret_cast(o); } @@ -1249,22 +1249,22 @@ inline Closure* gco2cl(GCObject* o) noexcept { } inline Table* gco2t(GCObject* o) noexcept { - lua_assert(o->getType() == LUA_VTABLE); + lua_assert(o->getType() == ctb(LuaT::TABLE)); return reinterpret_cast(o); } inline Proto* gco2p(GCObject* o) noexcept { - lua_assert(o->getType() == LUA_VPROTO); + lua_assert(o->getType() == ctb(LuaT::PROTO)); return reinterpret_cast(o); } inline lua_State* gco2th(GCObject* o) noexcept { - lua_assert(o->getType() == LUA_VTHREAD); + lua_assert(o->getType() == ctb(LuaT::THREAD)); return reinterpret_cast(o); } inline UpVal* gco2upv(GCObject* o) noexcept { - lua_assert(o->getType() == LUA_VUPVAL); + lua_assert(o->getType() == ctb(LuaT::UPVAL)); return reinterpret_cast(o); } diff --git a/src/objects/lobject.h b/src/objects/lobject.h index cd361969..b1dd904b 100644 --- a/src/objects/lobject.h +++ b/src/objects/lobject.h @@ -487,7 +487,7 @@ inline bool operator!=(const TString& l, const TString& r) noexcept { // Phase 88: Convert luaH_fastgeti and luaH_fastseti macros to inline functions // These are hot-path table access functions used throughout the VM -inline void luaH_fastgeti(Table* t, lua_Integer k, TValue* res, lu_byte& tag) noexcept { +inline void luaH_fastgeti(Table* t, lua_Integer k, TValue* res, LuaT& tag) noexcept { Table* h = t; lua_Unsigned u = l_castS2U(k) - 1u; if (u < h->arraySize()) { @@ -504,7 +504,7 @@ inline void luaH_fastseti(Table* t, lua_Integer k, TValue* val, int& hres) noexc Table* h = t; lua_Unsigned u = l_castS2U(k) - 1u; if (u < h->arraySize()) { - lu_byte* tag = h->getArrayTag(u); + LuaT* tag = h->getArrayTag(u); if (checknoTM(h->getMetatable(), TMS::TM_NEWINDEX) || !tagisempty(*tag)) { fval2arr(h, u, tag, val); hres = HOK; diff --git a/src/objects/lobject_core.h b/src/objects/lobject_core.h index a5510b62..c67e9bc6 100644 --- a/src/objects/lobject_core.h +++ b/src/objects/lobject_core.h @@ -52,6 +52,7 @@ constexpr bool TValue::isNil() const noexcept { return checktype(this, LUA_TNIL) ** simpler to just test whether the value is nil. */ constexpr bool tagisempty(int tag) noexcept { return novariant(tag) == LUA_TNIL; } +constexpr bool tagisempty(LuaT tag) noexcept { return novariant(tag) == LUA_TNIL; } /* macro to test for a standard nil */ diff --git a/src/objects/ltable.h b/src/objects/ltable.h index 1f0c6649..05f60d42 100644 --- a/src/objects/ltable.h +++ b/src/objects/ltable.h @@ -44,8 +44,8 @@ class Node { union { struct { Value value_; /* value */ - lu_byte tt_; /* value type tag */ - lu_byte key_tt; /* key type */ + LuaT tt_; /* value type tag */ + LuaT key_tt; /* key type */ int next; /* for chaining */ Value key_val; /* key value */ } u; @@ -54,10 +54,10 @@ class Node { public: // Default constructor - constexpr Node() noexcept : u{{0}, static_cast(LuaT::NIL), LUA_TNIL, 0, {0}} {} + constexpr Node() noexcept : u{{0}, LuaT::NIL, static_cast(LUA_TNIL), 0, {0}} {} // Constructor for initializing with explicit values - constexpr Node(Value val, lu_byte val_tt, lu_byte key_tt, int next_val, Value key_val) noexcept + constexpr Node(Value val, LuaT val_tt, LuaT key_tt, int next_val, Value key_val) noexcept : u{val, val_tt, key_tt, next_val, key_val} {} // Copy assignment operator (needed because union contains TValue with user-declared operator=) @@ -76,8 +76,8 @@ class Node { void setNext(int n) noexcept { u.next = n; } // Key type access - lu_byte getKeyType() const noexcept { return u.key_tt; } - void setKeyType(lu_byte tt) noexcept { u.key_tt = tt; } + LuaT getKeyType() const noexcept { return u.key_tt; } + void setKeyType(LuaT tt) noexcept { u.key_tt = tt; } // Key value access const Value& getKeyValue() const noexcept { return u.key_val; } @@ -86,23 +86,23 @@ class Node { // Key type checks bool isKeyNil() const noexcept { - return u.key_tt == LUA_TNIL; + return novariant(u.key_tt) == LUA_TNIL; } bool isKeyInteger() const noexcept { - return u.key_tt == LUA_VNUMINT; + return u.key_tt == LuaT::NUMINT; } bool isKeyShrStr() const noexcept { - return u.key_tt == ctb(LUA_VSHRSTR); + return u.key_tt == ctb(LuaT::SHRSTR); } bool isKeyDead() const noexcept { - return u.key_tt == LUA_TDEADKEY; + return novariant(u.key_tt) == LUA_TDEADKEY; } bool isKeyCollectable() const noexcept { - return (u.key_tt & BIT_ISCOLLECTABLE) != 0; + return (static_cast(u.key_tt) & BIT_ISCOLLECTABLE) != 0; } // Key value getters (typed) @@ -124,11 +124,11 @@ class Node { // Key setters void setKeyNil() noexcept { - u.key_tt = LUA_TNIL; + u.key_tt = LuaT::NIL; } void setKeyDead() noexcept { - u.key_tt = LUA_TDEADKEY; + u.key_tt = static_cast(LUA_TDEADKEY); } // Copy TValue to key @@ -244,12 +244,12 @@ class Table : public GCBase { return static_cast(static_cast(array)); } - lu_byte* getArrayTag(lua_Unsigned k) noexcept { - return static_cast(static_cast(array)) + sizeof(unsigned) + k; + LuaT* getArrayTag(lua_Unsigned k) noexcept { + return reinterpret_cast(static_cast(static_cast(array)) + sizeof(unsigned) + k); } - const lu_byte* getArrayTag(lua_Unsigned k) const noexcept { - return static_cast(static_cast(array)) + sizeof(unsigned) + k; + const LuaT* getArrayTag(lua_Unsigned k) const noexcept { + return reinterpret_cast(static_cast(static_cast(array)) + sizeof(unsigned) + k); } Value* getArrayVal(lua_Unsigned k) noexcept { @@ -269,10 +269,10 @@ class Table : public GCBase
{ const Node* getNode(unsigned int i) const noexcept { return &node[i]; } // Method declarations (implemented in ltable.cpp) - lu_byte get(const TValue* key, TValue* res); - lu_byte getInt(lua_Integer key, TValue* res); - lu_byte getShortStr(TString* key, TValue* res); - lu_byte getStr(TString* key, TValue* res); + LuaT get(const TValue* key, TValue* res); + LuaT getInt(lua_Integer key, TValue* res); + LuaT getShortStr(TString* key, TValue* res); + LuaT getStr(TString* key, TValue* res); TValue* HgetShortStr(TString* key); int pset(const TValue* key, TValue* val); @@ -432,20 +432,20 @@ inline void obj2arr(Table* h, lua_Unsigned k, const TValue* val) noexcept { ** following inline functions also move TValues to/from arrays, but receive the ** precomputed tag value or address as an extra argument. */ -inline void farr2val(const Table* h, lua_Unsigned k, lu_byte tag, TValue* res) noexcept { +inline void farr2val(const Table* h, lua_Unsigned k, LuaT tag, TValue* res) noexcept { res->setType(tag); res->valueField() = *h->getArrayVal(k); } -inline void fval2arr(Table* h, lua_Unsigned k, lu_byte* tag, const TValue* val) noexcept { +inline void fval2arr(Table* h, lua_Unsigned k, LuaT* tag, const TValue* val) noexcept { *tag = val->getType(); *h->getArrayVal(k) = val->getValue(); } -LUAI_FUNC lu_byte luaH_get (Table *t, const TValue *key, TValue *res); -LUAI_FUNC lu_byte luaH_getshortstr (Table *t, TString *key, TValue *res); -LUAI_FUNC lu_byte luaH_getstr (Table *t, TString *key, TValue *res); -LUAI_FUNC lu_byte luaH_getint (Table *t, lua_Integer key, TValue *res); +LUAI_FUNC LuaT luaH_get (Table *t, const TValue *key, TValue *res); +LUAI_FUNC LuaT luaH_getshortstr (Table *t, TString *key, TValue *res); +LUAI_FUNC LuaT luaH_getstr (Table *t, TString *key, TValue *res); +LUAI_FUNC LuaT luaH_getint (Table *t, lua_Integer key, TValue *res); /* Special get for metamethods */ LUAI_FUNC const TValue *luaH_Hgetshortstr (Table *t, TString *key); From 47a31200fb34ef84a248ee7125e2de85056a8753 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 22 Nov 2025 12:53:12 +0000 Subject: [PATCH 4/7] Phase 122: Refactor LUA_V* to enum class LuaT (WIP - implementation files) Updated implementation files to use LuaT enum class: - Replaced LUA_V* constants with LuaT::* enum values in 21+ .cpp files - Changed function signatures to use LuaT instead of lu_byte - Updated local variables from lu_byte to LuaT in VM interpreter - Fixed Node constructor and equalkey() switch statement - Added type casts where needed for compatibility Note: Build still has a few remaining type mismatches to fix in ltable.cpp --- src/compiler/lcode.cpp | 14 +++---- src/compiler/llex.cpp | 2 +- src/core/lapi.cpp | 36 +++++++++--------- src/core/ldebug.cpp | 2 +- src/core/ldo.cpp | 12 +++--- src/core/lstate.cpp | 2 +- src/core/lstate.h | 2 +- src/core/ltm.cpp | 4 +- src/core/ltm.h | 2 +- src/memory/gc/gc_core.cpp | 36 +++++++++--------- src/memory/gc/gc_marking.cpp | 30 +++++++-------- src/memory/gc/gc_sweeping.cpp | 4 +- src/memory/gc/gc_weak.cpp | 2 +- src/memory/lgc.cpp | 32 ++++++++-------- src/objects/lfunc.cpp | 10 ++--- src/objects/lstring.cpp | 12 +++--- src/objects/ltable.cpp | 56 ++++++++++++++-------------- src/serialization/ldump.cpp | 14 +++---- src/serialization/lundump.cpp | 16 ++++---- src/testing/ltests.cpp | 70 +++++++++++++++++------------------ src/vm/lvm.cpp | 12 +++--- src/vm/lvm.h | 16 ++++---- src/vm/lvm_comparison.cpp | 26 ++++++------- src/vm/lvm_string.cpp | 6 +-- src/vm/lvm_table.cpp | 10 ++--- 25 files changed, 214 insertions(+), 214 deletions(-) diff --git a/src/compiler/lcode.cpp b/src/compiler/lcode.cpp index 072547b4..7a766768 100644 --- a/src/compiler/lcode.cpp +++ b/src/compiler/lcode.cpp @@ -337,7 +337,7 @@ int FuncState::addk(Proto *proto, TValue *v) { int FuncState::k2proto(TValue *key, TValue *v) { TValue val; Proto *proto = getProto(); - int tag = luaH_get(getKCache(), key, &val); /* query scanner table */ + LuaT tag = luaH_get(getKCache(), key, &val); /* query scanner table */ if (!tagisempty(tag)) { /* is there an index there? */ int k = cast_int(ivalue(&val)); /* collisions can happen only for float keys */ @@ -466,22 +466,22 @@ void FuncState::floatCode(int reg, lua_Number flt) { */ static void const2exp (TValue *v, expdesc *e) { switch (ttypetag(v)) { - case LUA_VNUMINT: + case LuaT::NUMINT: e->setKind(VKINT); e->setIntValue(ivalue(v)); break; - case LUA_VNUMFLT: + case LuaT::NUMFLT: e->setKind(VKFLT); e->setFloatValue(fltvalue(v)); break; - case LUA_VFALSE: + case LuaT::VFALSE: e->setKind(VFALSE); break; - case LUA_VTRUE: + case LuaT::VTRUE: e->setKind(VTRUE); break; - case LUA_VNIL: + case LuaT::NIL: e->setKind(VNIL); break; - case LUA_VSHRSTR: case LUA_VLNGSTR: + case LuaT::SHRSTR: case LuaT::LNGSTR: e->setKind(VKSTR); e->setStringValue(tsvalue(v)); break; default: lua_assert(0); diff --git a/src/compiler/llex.cpp b/src/compiler/llex.cpp index d13a3a78..8241c546 100644 --- a/src/compiler/llex.cpp +++ b/src/compiler/llex.cpp @@ -119,7 +119,7 @@ l_noret LexState::syntaxError(const char *msg) { TString* LexState::anchorStr(TString *ts) { lua_State *luaState = getLuaState(); TValue oldts; - int tag = luaH_getstr(getTable(), ts, &oldts); + LuaT tag = luaH_getstr(getTable(), ts, &oldts); if (!tagisempty(tag)) /* string already present? */ return tsvalue(&oldts); /* use stored value */ else { /* create a new entry */ diff --git a/src/core/lapi.cpp b/src/core/lapi.cpp index 818fc614..e5c092a1 100644 --- a/src/core/lapi.cpp +++ b/src/core/lapi.cpp @@ -383,10 +383,10 @@ LUA_API const char *lua_tolstring (lua_State *L, int idx, size_t *len) { LUA_API lua_Unsigned lua_rawlen (lua_State *L, int idx) { const TValue *o = L->getStackSubsystem().indexToValue(L,idx); switch (ttypetag(o)) { - case LUA_VSHRSTR: return static_cast(tsvalue(o)->length()); - case LUA_VLNGSTR: return static_cast(tsvalue(o)->length()); - case LUA_VUSERDATA: return static_cast(uvalue(o)->getLen()); - case LUA_VTABLE: { + case LuaT::SHRSTR: return static_cast(tsvalue(o)->length()); + case LuaT::LNGSTR: return static_cast(tsvalue(o)->length()); + case LuaT::USERDATA: return static_cast(uvalue(o)->getLen()); + case LuaT::TABLE: { lua_Unsigned res; lua_lock(L); res = luaH_getn(L, hvalue(o)); @@ -438,8 +438,8 @@ LUA_API lua_State *lua_tothread (lua_State *L, int idx) { LUA_API const void *lua_topointer (lua_State *L, int idx) { const TValue *o = L->getStackSubsystem().indexToValue(L,idx); switch (ttypetag(o)) { - case LUA_VLCF: return cast_voidp(cast_sizet(fvalue(o))); - case LUA_VUSERDATA: case LUA_VLIGHTUSERDATA: + case LuaT::LCF: return cast_voidp(cast_sizet(fvalue(o))); + case LuaT::USERDATA: case LuaT::LIGHTUSERDATA: return touserdata(o); default: { if (iscollectable(o)) @@ -612,7 +612,7 @@ LUA_API int lua_pushthread (lua_State *L) { static int auxgetstr (lua_State *L, const TValue *t, const char *k) { - lu_byte tag; + LuaT tag; TString *str = TString::create(L, k); tag = luaV_fastget(t, str, s2v(L->getTop().p), luaH_getstr); if (!tagisempty(tag)) @@ -634,7 +634,7 @@ static int auxgetstr (lua_State *L, const TValue *t, const char *k) { */ static void getGlobalTable (lua_State *L, TValue *gt) { Table *registry = hvalue(G(L)->getRegistry()); - lu_byte tag = luaH_getint(registry, LUA_RIDX_GLOBALS, gt); + LuaT tag = luaH_getint(registry, LUA_RIDX_GLOBALS, gt); (void)tag; /* avoid not-used warnings when checks are off */ api_check(L, novariant(tag) == LUA_TTABLE, "global table must exist"); } @@ -652,7 +652,7 @@ LUA_API int lua_gettable (lua_State *L, int idx) { lua_lock(L); api_checkpop(L, 1); TValue *t = L->getStackSubsystem().indexToValue(L,idx); - lu_byte tag = luaV_fastget(t, s2v(L->getTop().p - 1), s2v(L->getTop().p - 1), luaH_get); + LuaT tag = luaV_fastget(t, s2v(L->getTop().p - 1), s2v(L->getTop().p - 1), luaH_get); if (tagisempty(tag)) tag = luaV_finishget(L, t, s2v(L->getTop().p - 1), L->getTop().p - 1, tag); lua_unlock(L); @@ -669,7 +669,7 @@ LUA_API int lua_getfield (lua_State *L, int idx, const char *k) { LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) { lua_lock(L); TValue *t = L->getStackSubsystem().indexToValue(L,idx); - lu_byte tag; + LuaT tag; luaV_fastgeti(t, n, s2v(L->getTop().p), tag); if (tagisempty(tag)) { TValue key; @@ -682,7 +682,7 @@ LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) { } -static int finishrawget (lua_State *L, lu_byte tag) { +static int finishrawget (lua_State *L, LuaT tag) { if (tagisempty(tag)) /* avoid copying empty items to the stack */ setnilvalue(s2v(L->getTop().p)); api_incr_top(L); @@ -702,7 +702,7 @@ LUA_API int lua_rawget (lua_State *L, int idx) { lua_lock(L); api_checkpop(L, 1); Table *t = gettable(L, idx); - lu_byte tag = luaH_get(t, s2v(L->getTop().p - 1), s2v(L->getTop().p - 1)); + LuaT tag = luaH_get(t, s2v(L->getTop().p - 1), s2v(L->getTop().p - 1)); L->getStackSubsystem().pop(); /* pop key */ return finishrawget(L, tag); } @@ -711,7 +711,7 @@ LUA_API int lua_rawget (lua_State *L, int idx) { LUA_API int lua_rawgeti (lua_State *L, int idx, lua_Integer n) { lua_lock(L); Table *t = gettable(L, idx); - lu_byte tag; + LuaT tag; luaH_fastgeti(t, n, s2v(L->getTop().p), tag); return finishrawget(L, tag); } @@ -1290,7 +1290,7 @@ LUA_API void *lua_newuserdatauv (lua_State *L, size_t size, int nuvalue) { static const char *aux_upvalue (TValue *fi, int n, TValue **val, GCObject **owner) { switch (ttypetag(fi)) { - case LUA_VCCL: { /* C closure */ + case LuaT::CCL: { /* C closure */ CClosure *f = clCvalue(fi); if (!(cast_uint(n) - 1u < cast_uint(f->getNumUpvalues()))) return nullptr; /* 'n' not in [1, f->getNumUpvalues()] */ @@ -1298,7 +1298,7 @@ static const char *aux_upvalue (TValue *fi, int n, TValue **val, if (owner) *owner = obj2gco(f); return ""; } - case LUA_VLCL: { /* Lua closure */ + case LuaT::LCL: { /* Lua closure */ LClosure *f = clLvalue(fi); TString *name; Proto *p = f->getProto(); @@ -1364,16 +1364,16 @@ static UpVal **getupvalref (lua_State *L, int fidx, int n, LClosure **pf) { LUA_API void *lua_upvalueid (lua_State *L, int fidx, int n) { TValue *fi = L->getStackSubsystem().indexToValue(L,fidx); switch (ttypetag(fi)) { - case LUA_VLCL: { /* lua closure */ + case LuaT::LCL: { /* lua closure */ return *getupvalref(L, fidx, n, nullptr); } - case LUA_VCCL: { /* C closure */ + case LuaT::CCL: { /* C closure */ CClosure *f = clCvalue(fi); if (1 <= n && n <= f->getNumUpvalues()) return f->getUpvalue(n - 1); /* else */ } /* FALLTHROUGH */ - case LUA_VLCF: + case LuaT::LCF: return nullptr; /* light C functions have no upvalues */ default: { api_check(L, 0, "function expected"); diff --git a/src/core/ldebug.cpp b/src/core/ldebug.cpp index 4c16dffe..f50ea28f 100644 --- a/src/core/ldebug.cpp +++ b/src/core/ldebug.cpp @@ -33,7 +33,7 @@ /* Both CClosure and LClosure have tt at same offset (from GCBase) */ -#define LuaClosure(f) ((f) != nullptr && (f)->c.getType() == LUA_VLCL) +#define LuaClosure(f) ((f) != nullptr && (f)->c.getType() == LuaT::LCL) static const char strlocal[] = "local"; static const char strupval[] = "upvalue"; diff --git a/src/core/ldo.cpp b/src/core/ldo.cpp index 14100d67..df23ef31 100644 --- a/src/core/ldo.cpp +++ b/src/core/ldo.cpp @@ -582,11 +582,11 @@ int lua_State::preTailCall(CallInfo *ci_arg, StkId func, unsigned status_val = LUA_MULTRET + 1; retry: switch (ttypetag(s2v(func))) { - case LUA_VCCL: /* C closure */ + case LuaT::CCL: /* C closure */ return preCallC(func, status_val, clCvalue(s2v(func))->getFunction()); - case LUA_VLCF: /* light C function */ + case LuaT::LCF: /* light C function */ return preCallC(func, status_val, fvalue(s2v(func))); - case LUA_VLCL: { /* Lua function */ + case LuaT::LCL: { /* Lua function */ Proto *p = clLvalue(s2v(func))->getProto(); int fsize = p->getMaxStackSize(); /* frame size */ int nfixparams = p->getNumParams(); @@ -628,13 +628,13 @@ CallInfo* lua_State::preCall(StkId func, int nresults) { lua_assert(status_val <= MAXRESULTS + 1); retry: switch (ttypetag(s2v(func))) { - case LUA_VCCL: /* C closure */ + case LuaT::CCL: /* C closure */ preCallC(func, status_val, clCvalue(s2v(func))->getFunction()); return nullptr; - case LUA_VLCF: /* light C function */ + case LuaT::LCF: /* light C function */ preCallC(func, status_val, fvalue(s2v(func))); return nullptr; - case LUA_VLCL: { /* Lua function */ + case LuaT::LCL: { /* Lua function */ CallInfo *ci_new; Proto *p = clLvalue(s2v(func))->getProto(); int narg = cast_int(getTop().p - func) - 1; /* number of real arguments */ diff --git a/src/core/lstate.cpp b/src/core/lstate.cpp index 080ed367..30015bbf 100644 --- a/src/core/lstate.cpp +++ b/src/core/lstate.cpp @@ -335,7 +335,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud, unsigned seed) { (*f)(ud, nullptr, LUA_TTHREAD, sizeof(global_State))); if (g == nullptr) return nullptr; L = &g->getMainThread()->l; - L->setType(LUA_VTHREAD); + L->setType(LuaT::THREAD); g->setCurrentWhite(bitmask(WHITE0BIT)); L->setMarked(g->getWhite()); preinit_thread(L, g); diff --git a/src/core/lstate.h b/src/core/lstate.h index f27c6251..d66deac5 100644 --- a/src/core/lstate.h +++ b/src/core/lstate.h @@ -655,7 +655,7 @@ struct lua_State : public GCBase { void finishOp(); void concat(int total); void objlen(StkId ra, const TValue *rb); - lu_byte finishGet(const TValue *t, TValue *key, StkId val, lu_byte tag); + LuaT finishGet(const TValue *t, TValue *key, StkId val, LuaT tag); void finishSet(const TValue *t, TValue *key, TValue *val, int aux); // Arithmetic operation methods (formerly luaV_* functions, implemented in lvm.cpp) diff --git a/src/core/ltm.cpp b/src/core/ltm.cpp index 3ba4b94c..e1e5ad1e 100644 --- a/src/core/ltm.cpp +++ b/src/core/ltm.cpp @@ -117,7 +117,7 @@ void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, } -lu_byte luaT_callTMres (lua_State *L, const TValue *f, const TValue *p1, +LuaT luaT_callTMres (lua_State *L, const TValue *f, const TValue *p1, const TValue *p2, StkId res) { ptrdiff_t result = L->saveStack(res); StkId func = L->getTop().p; @@ -144,7 +144,7 @@ static int callbinTM (lua_State *L, const TValue *p1, const TValue *p2, if (notm(tm)) return -1; /* tag method not found */ else /* call tag method and return the tag of the result */ - return luaT_callTMres(L, tm, p1, p2, res); + return static_cast(luaT_callTMres(L, tm, p1, p2, res)); } diff --git a/src/core/ltm.h b/src/core/ltm.h index 09bbbfc8..e3007220 100644 --- a/src/core/ltm.h +++ b/src/core/ltm.h @@ -96,7 +96,7 @@ LUAI_FUNC void luaT_init (lua_State *L); LUAI_FUNC void luaT_callTM (lua_State *L, const TValue *f, const TValue *p1, const TValue *p2, const TValue *p3); -LUAI_FUNC lu_byte luaT_callTMres (lua_State *L, const TValue *f, +LUAI_FUNC LuaT luaT_callTMres (lua_State *L, const TValue *f, const TValue *p1, const TValue *p2, StkId p3); LUAI_FUNC void luaT_trybinTM (lua_State *L, const TValue *p1, const TValue *p2, StkId res, TMS event); diff --git a/src/memory/gc/gc_core.cpp b/src/memory/gc/gc_core.cpp index a91778fd..3155650a 100644 --- a/src/memory/gc/gc_core.cpp +++ b/src/memory/gc/gc_core.cpp @@ -25,44 +25,44 @@ l_mem GCCore::objsize(GCObject* o) { lu_mem res; switch (o->getType()) { - case LUA_VTABLE: { + case LuaT::TABLE: { res = luaH_size(gco2t(o)); break; } - case LUA_VLCL: { + case LuaT::LCL: { LClosure* cl = gco2lcl(o); res = sizeLclosure(cl->getNumUpvalues()); break; } - case LUA_VCCL: { + case LuaT::CCL: { CClosure* cl = gco2ccl(o); res = sizeCclosure(cl->getNumUpvalues()); break; } - case LUA_VUSERDATA: { + case LuaT::USERDATA: { Udata* u = gco2u(o); res = sizeudata(u->getNumUserValues(), u->getLen()); break; } - case LUA_VPROTO: { + case LuaT::PROTO: { res = gco2p(o)->memorySize(); break; } - case LUA_VTHREAD: { + case LuaT::THREAD: { res = luaE_threadsize(gco2th(o)); break; } - case LUA_VSHRSTR: { + case LuaT::SHRSTR: { TString* ts = gco2ts(o); res = sizestrshr(cast_uint(ts->getShrlen())); break; } - case LUA_VLNGSTR: { + case LuaT::LNGSTR: { TString* ts = gco2ts(o); res = TString::calculateLongStringSize(ts->getLnglen(), ts->getShrlen()); break; } - case LUA_VUPVAL: { + case LuaT::UPVAL: { res = sizeof(UpVal); break; } @@ -78,21 +78,21 @@ l_mem GCCore::objsize(GCObject* o) { */ GCObject** GCCore::getgclist(GCObject* o) { switch (o->getType()) { - case LUA_VTABLE: return gco2t(o)->getGclistPtr(); - case LUA_VLCL: return gco2lcl(o)->getGclistPtr(); - case LUA_VCCL: return gco2ccl(o)->getGclistPtr(); - case LUA_VTHREAD: return gco2th(o)->getGclistPtr(); - case LUA_VPROTO: return gco2p(o)->getGclistPtr(); - case LUA_VUSERDATA: { + case LuaT::TABLE: return gco2t(o)->getGclistPtr(); + case LuaT::LCL: return gco2lcl(o)->getGclistPtr(); + case LuaT::CCL: return gco2ccl(o)->getGclistPtr(); + case LuaT::THREAD: return gco2th(o)->getGclistPtr(); + case LuaT::PROTO: return gco2p(o)->getGclistPtr(); + case LuaT::USERDATA: { Udata* u = gco2u(o); lua_assert(u->getNumUserValues() > 0); return u->getGclistPtr(); } - case LUA_VUPVAL: + case LuaT::UPVAL: /* UpVals use the base GCObject 'next' field for gray list linkage */ return o->getNextPtr(); - case LUA_VSHRSTR: - case LUA_VLNGSTR: + case LuaT::SHRSTR: + case LuaT::LNGSTR: /* Strings are marked black directly and should never be in gray list. * However, with LTO, we've seen strings passed to this function. * Use the 'next' field (from GCObject base) as a fallback. */ diff --git a/src/memory/gc/gc_marking.cpp b/src/memory/gc/gc_marking.cpp index 97f1948f..97756d36 100644 --- a/src/memory/gc/gc_marking.cpp +++ b/src/memory/gc/gc_marking.cpp @@ -217,12 +217,12 @@ l_mem GCMarking::traversethread(global_State* g, lua_State* th) { void GCMarking::reallymarkobject(global_State* g, GCObject* o) { g->setGCMarked(g->getGCMarked() + objsize(o)); switch (o->getType()) { - case LUA_VSHRSTR: - case LUA_VLNGSTR: { + case LuaT::SHRSTR: + case LuaT::LNGSTR: { set2black(o); /* strings have no children */ break; } - case LUA_VUPVAL: { + case LuaT::UPVAL: { UpVal* uv = gco2upv(o); if (uv->isOpen()) set2gray(uv); /* open upvalues kept gray */ @@ -231,7 +231,7 @@ void GCMarking::reallymarkobject(global_State* g, GCObject* o) { markvalue(g, uv->getVP()); break; } - case LUA_VUSERDATA: { + case LuaT::USERDATA: { Udata* u = gco2u(o); if (u->getNumUserValues() == 0) { markobjectN(g, u->getMetatable()); @@ -240,11 +240,11 @@ void GCMarking::reallymarkobject(global_State* g, GCObject* o) { } /* else fall through to add to gray list */ } /* FALLTHROUGH */ - case LUA_VLCL: - case LUA_VCCL: - case LUA_VTABLE: - case LUA_VTHREAD: - case LUA_VPROTO: { + case LuaT::LCL: + case LuaT::CCL: + case LuaT::TABLE: + case LuaT::THREAD: + case LuaT::PROTO: { linkobjgclist(o, *g->getGrayPtr()); /* to be visited later */ break; } @@ -263,17 +263,17 @@ l_mem GCMarking::propagatemark(global_State* g) { nw2black(o); g->setGray(*getgclist(o)); /* remove from 'gray' list */ switch (o->getType()) { - case LUA_VTABLE: + case LuaT::TABLE: return traversetable(g, gco2t(o)); - case LUA_VUSERDATA: + case LuaT::USERDATA: return traverseudata(g, gco2u(o)); - case LUA_VLCL: + case LuaT::LCL: return traverseLclosure(g, gco2lcl(o)); - case LUA_VCCL: + case LuaT::CCL: return traverseCclosure(g, gco2ccl(o)); - case LUA_VPROTO: + case LuaT::PROTO: return traverseproto(g, gco2p(o)); - case LUA_VTHREAD: + case LuaT::THREAD: return traversethread(g, gco2th(o)); default: lua_assert(0); diff --git a/src/memory/gc/gc_sweeping.cpp b/src/memory/gc/gc_sweeping.cpp index ab817428..5b99ede7 100644 --- a/src/memory/gc/gc_sweeping.cpp +++ b/src/memory/gc/gc_sweeping.cpp @@ -137,11 +137,11 @@ void GCSweeping::sweep2old(lua_State* L, GCObject** p) { else { /* all surviving objects become old */ setage(curr, GCAge::Old); - if (curr->getType() == LUA_VTHREAD) { /* threads must be watched */ + if (curr->getType() == LuaT::THREAD) { /* threads must be watched */ lua_State* th = gco2th(curr); linkgclistThread(th, *g->getGrayAgainPtr()); /* insert into 'grayagain' list */ } - else if (curr->getType() == LUA_VUPVAL && gco2upv(curr)->isOpen()) + else if (curr->getType() == LuaT::UPVAL && gco2upv(curr)->isOpen()) set2gray(curr); /* open upvalues are always gray */ else /* everything else is black */ nw2black(curr); diff --git a/src/memory/gc/gc_weak.cpp b/src/memory/gc/gc_weak.cpp index 156a6166..feb8c38f 100644 --- a/src/memory/gc/gc_weak.cpp +++ b/src/memory/gc/gc_weak.cpp @@ -321,7 +321,7 @@ void GCWeak::clearbyvalues(global_State* g, GCObject* l, GCObject* f) { for (i = 0; i < asize; i++) { GCObject* o = gcvalarr(h, i); if (iscleared(g, o)) /* value was collected? */ - *h->getArrayTag(i) = LUA_VEMPTY; /* remove entry */ + *h->getArrayTag(i) = LuaT::EMPTY; /* remove entry */ } for (n = gnode(h, 0); n < limit; n++) { diff --git a/src/memory/lgc.cpp b/src/memory/lgc.cpp index 3c7c72c4..f5cd194c 100644 --- a/src/memory/lgc.cpp +++ b/src/memory/lgc.cpp @@ -264,12 +264,12 @@ GCObject *luaC_newobj (lua_State *L, lu_byte tt, size_t sz) { static void reallymarkobject (global_State *g, GCObject *o) { g->setGCMarked(g->getGCMarked() + objsize(o)); switch (o->getType()) { - case LUA_VSHRSTR: - case LUA_VLNGSTR: { + case LuaT::SHRSTR: + case LuaT::LNGSTR: { set2black(o); /* nothing to visit */ break; } - case LUA_VUPVAL: { + case LuaT::UPVAL: { UpVal *uv = gco2upv(o); if (uv->isOpen()) set2gray(uv); /* open upvalues are kept gray */ @@ -278,7 +278,7 @@ static void reallymarkobject (global_State *g, GCObject *o) { markvalue(g, uv->getVP()); /* mark its content */ break; } - case LUA_VUSERDATA: { + case LuaT::USERDATA: { Udata *u = gco2u(o); if (u->getNumUserValues() == 0) { /* no user values? */ markobjectN(g, u->getMetatable()); /* mark its metatable */ @@ -287,8 +287,8 @@ static void reallymarkobject (global_State *g, GCObject *o) { } /* else... */ } /* FALLTHROUGH */ - case LUA_VLCL: case LUA_VCCL: case LUA_VTABLE: - case LUA_VTHREAD: case LUA_VPROTO: { + case LuaT::LCL: case LuaT::CCL: case LuaT::TABLE: + case LuaT::THREAD: case LuaT::PROTO: { linkobjgclist(o, *g->getGrayPtr()); /* to be visited later */ break; } @@ -391,45 +391,45 @@ static void freeupval(lua_State* L, UpVal* uv) { void freeobj (lua_State *L, GCObject *o) { assert_code(l_mem newmem = G(L)->getTotalBytes() - objsize(o)); switch (o->getType()) { - case LUA_VPROTO: { + case LuaT::PROTO: { Proto *p = gco2p(o); p->free(L); /* Phase 25b - frees internal arrays */ // Proto destructor is trivial, but call it for completeness p->~Proto(); break; } - case LUA_VUPVAL: { + case LuaT::UPVAL: { UpVal *uv = gco2upv(o); freeupval(L, uv); // Note: freeupval calls destructor internally break; } - case LUA_VLCL: { + case LuaT::LCL: { LClosure *cl = gco2lcl(o); cl->~LClosure(); // Call destructor luaM_freemem(L, cl, sizeLclosure(cl->getNumUpvalues())); break; } - case LUA_VCCL: { + case LuaT::CCL: { CClosure *cl = gco2ccl(o); cl->~CClosure(); // Call destructor luaM_freemem(L, cl, sizeCclosure(cl->getNumUpvalues())); break; } - case LUA_VTABLE: { + case LuaT::TABLE: { Table *t = gco2t(o); luaH_free(L, t); // Note: luaH_free calls destroy() which should handle cleanup break; } - case LUA_VTHREAD: + case LuaT::THREAD: luaE_freethread(L, gco2th(o)); break; - case LUA_VUSERDATA: { + case LuaT::USERDATA: { Udata *u = gco2u(o); u->~Udata(); // Call destructor luaM_freemem(L, o, sizeudata(u->getNumUserValues(), u->getLen())); break; } - case LUA_VSHRSTR: { + case LuaT::SHRSTR: { TString *ts = gco2ts(o); size_t sz = sizestrshr(cast_uint(ts->getShrlen())); ts->remove(L); /* use method instead of free function */ @@ -438,7 +438,7 @@ void freeobj (lua_State *L, GCObject *o) { luaM_freemem(L, ts, sz); break; } - case LUA_VLNGSTR: { + case LuaT::LNGSTR: { TString *ts = gco2ts(o); if (ts->getShrlen() == LSTRMEM) /* must free external string? */ (*ts->getFalloc())(ts->getUserData(), ts->getContentsField(), ts->getLnglen() + 1, 0); @@ -589,7 +589,7 @@ static GCObject **correctgraylist (GCObject **p) { setage(curr, GCAge::Touched2); goto remain; /* keep it in the list and go to next element */ } - else if (curr->getType() == LUA_VTHREAD) { + else if (curr->getType() == LuaT::THREAD) { lua_assert(isgray(curr)); goto remain; /* keep non-white threads on the list */ } diff --git a/src/objects/lfunc.cpp b/src/objects/lfunc.cpp index 89b1ec8a..a4843c8d 100644 --- a/src/objects/lfunc.cpp +++ b/src/objects/lfunc.cpp @@ -36,7 +36,7 @@ CClosure::CClosure(int nupvals) { // Factory method CClosure* CClosure::create(lua_State* L, int nupvals) { size_t extra = (nupvals > 0) ? (static_cast(nupvals) - 1) * sizeof(TValue) : 0; - CClosure* c = new (L, LUA_VCCL, extra) CClosure(nupvals); + CClosure* c = new (L, LuaT::CCL, extra) CClosure(nupvals); return c; } @@ -58,7 +58,7 @@ LClosure* LClosure::create(lua_State* L, int nupvals) { // So extra = sizeLclosure(nupvals) - sizeof(LClosure) size_t total_size = sizeLclosure(nupvals); size_t extra = total_size - sizeof(LClosure); - LClosure* c = new (L, LUA_VLCL, extra) LClosure(nupvals); + LClosure* c = new (L, LuaT::LCL, extra) LClosure(nupvals); return c; } @@ -71,7 +71,7 @@ void LClosure::initUpvals(lua_State* L) { int i; for (i = 0; i < nupvalues; i++) { // Use placement new - calls constructor (initializes to closed nil upvalue) - UpVal *uv = new (L, LUA_VUPVAL) UpVal(); + UpVal *uv = new (L, LuaT::UPVAL) UpVal(); uv->setVP(uv->getValueSlot()); /* make it closed */ // Constructor already sets value to nil, but keeping setnilvalue for clarity setnilvalue(uv->getVP()); @@ -88,7 +88,7 @@ void LClosure::initUpvals(lua_State* L) { **/ static UpVal *newupval (lua_State *L, StkId level, UpVal **prev) { // Use placement new - calls constructor - UpVal *uv = new (L, LUA_VUPVAL) UpVal(); + UpVal *uv = new (L, LuaT::UPVAL) UpVal(); UpVal *next = *prev; uv->setVP(s2v(level)); /* current value lives in the stack */ uv->setOpenNext(next); /* link it to list of open upvalues */ @@ -271,7 +271,7 @@ StkId luaF_close (lua_State *L, StkId level, TStatus status, int yy) { // Phase 50: Use placement new to call constructor Proto *luaF_newproto (lua_State *L) { // Use placement new - calls constructor which initializes all fields to safe defaults - Proto *f = new (L, LUA_VPROTO) Proto(); + Proto *f = new (L, LuaT::PROTO) Proto(); // Constructor handles all initialization return f; } diff --git a/src/objects/lstring.cpp b/src/objects/lstring.cpp index 73bebf16..2bbe7273 100644 --- a/src/objects/lstring.cpp +++ b/src/objects/lstring.cpp @@ -194,7 +194,7 @@ static TString *createstrobj (lua_State *L, size_t totalsize, lu_byte tag, // LSTRFIX: allocates 40 bytes (up to but not including falloc) // LSTRREG: allocates 40 + string length (up to but not including falloc) // LSTRMEM: allocates full sizeof(TString) = 56 bytes (includes falloc and ud) - if (tag == LUA_VLNGSTR) { + if (tag == LuaT::LNGSTR) { ts->setContents(nullptr); // DON'T initialize falloc/ud here - they may not exist in allocated memory! // They will be initialized by the caller if needed (e.g., luaS_newextlstr for LSTRMEM) @@ -206,7 +206,7 @@ static TString *createstrobj (lua_State *L, size_t totalsize, lu_byte tag, TString* TString::createLongString(lua_State* L, size_t l) { size_t totalsize = calculateLongStringSize(l, LSTRREG); - TString *ts = createstrobj(L, totalsize, LUA_VLNGSTR, G(L)->getSeed()); + TString *ts = createstrobj(L, totalsize, LuaT::LNGSTR, G(L)->getSeed()); ts->setLnglen(l); ts->setShrlen(LSTRREG); /* signals that it is a regular long string */ ts->setContents(cast_charp(ts) + tstringFallocOffset()); @@ -254,7 +254,7 @@ static TString *internshrstr (lua_State *L, const char *str, size_t l) { list = &tb->getHash()[lmod(h, tb->getSize())]; /* rehash with new size */ } size_t allocsize = sizestrshr(l); - ts = createstrobj(L, allocsize, LUA_VSHRSTR, h); + ts = createstrobj(L, allocsize, LuaT::SHRSTR, h); ts->setShrlen(static_cast(l)); getshrstr(ts)[l] = '\0'; /* ending 0 */ std::copy_n(str, l, getshrstr(ts)); @@ -311,7 +311,7 @@ Udata *luaS_newudata (lua_State *L, size_t s, unsigned short nuvalue) { size_t totalsize = sizeudata(nuvalue, s); // Allocate exactly what we need (may be less than sizeof(Udata) for small data) - GCObject *o = luaC_newobj(L, LUA_VUSERDATA, totalsize); + GCObject *o = luaC_newobj(L, LuaT::USERDATA, totalsize); u = gco2u(o); // Manually initialize fields (can't use constructor reliably for variable-size objects) @@ -343,7 +343,7 @@ struct NewExt { static void f_newext (lua_State *L, void *ud) { NewExt *ne = static_cast(ud); size_t size = TString::calculateLongStringSize(0, ne->kind); - ne->ts = createstrobj(L, size, LUA_VLNGSTR, G(L)->getSeed()); + ne->ts = createstrobj(L, size, LuaT::LNGSTR, G(L)->getSeed()); } @@ -375,7 +375,7 @@ TString* TString::createExternal(lua_State* L, const char* s, size_t len, */ unsigned TString::hashLongStr() { - lua_assert(getType() == LUA_VLNGSTR); + lua_assert(getType() == LuaT::LNGSTR); if (getExtra() == 0) { /* no hash? */ size_t len = getLnglen(); setHash(computeHash(getlngstr(this), len, getHash())); diff --git a/src/objects/ltable.cpp b/src/objects/ltable.cpp index 0133df58..15d8663f 100644 --- a/src/objects/ltable.cpp +++ b/src/objects/ltable.cpp @@ -250,8 +250,8 @@ inline Node* hashpointer(const Table* t, T* p) noexcept { ** (DEADKEY, nullptr) that is different from any valid TValue. */ static Node dummynode_ = Node( - {nullptr}, LUA_VEMPTY, /* value's value and type */ - LUA_TDEADKEY, 0, {nullptr} /* key type, next, and key value */ + {nullptr}, LuaT::EMPTY, /* value's value and type */ + static_cast(LUA_TDEADKEY), 0, {nullptr} /* key type, next, and key value */ ); @@ -309,31 +309,31 @@ static unsigned l_hashfloat (lua_Number n) { */ static Node *mainpositionTV (const Table *t, const TValue *key) { switch (ttypetag(key)) { - case LUA_VNUMINT: { + case LuaT::NUMINT: { lua_Integer i = ivalue(key); return hashint(t, i); } - case LUA_VNUMFLT: { + case LuaT::NUMFLT: { lua_Number n = fltvalue(key); return hashmod(t, l_hashfloat(n)); } - case LUA_VSHRSTR: { + case LuaT::SHRSTR: { TString *ts = tsvalue(key); return hashstr(t, ts); } - case LUA_VLNGSTR: { + case LuaT::LNGSTR: { TString *ts = tsvalue(key); return hashpow2(t, ts->hashLongStr()); } - case LUA_VFALSE: + case LuaT::VFALSE: return hashboolean(t, 0); - case LUA_VTRUE: + case LuaT::VTRUE: return hashboolean(t, 1); - case LUA_VLIGHTUSERDATA: { + case LuaT::LIGHTUSERDATA: { void *p = pvalue(key); return hashpointer(t, p); } - case LUA_VLCF: { + case LuaT::LCF: { lua_CFunction f = fvalue(key); return hashpointer(t, f); } @@ -385,18 +385,18 @@ static bool equalkey (const TValue *k1, const Node *n2, int deadok) { return false; /* otherwise, different variants cannot be equal */ } else { /* equal variants */ - switch (n2->getKeyType()) { - case LUA_VNIL: case LUA_VFALSE: case LUA_VTRUE: + switch (static_cast(n2->getKeyType())) { + case static_cast(LuaT::NIL): case static_cast(LuaT::VFALSE): case static_cast(LuaT::VTRUE): return true; - case LUA_VNUMINT: + case static_cast(LuaT::NUMINT): return (ivalue(k1) == n2->getKeyIntValue()); - case LUA_VNUMFLT: + case static_cast(LuaT::NUMFLT): return luai_numeq(fltvalue(k1), fltvalueraw(n2->getKeyValue())); - case LUA_VLIGHTUSERDATA: + case static_cast(LuaT::LIGHTUSERDATA): return pvalue(k1) == pvalueraw(n2->getKeyValue()); - case LUA_VLCF: + case static_cast(LuaT::LCF): return fvalue(k1) == fvalueraw(n2->getKeyValue()); - case ctb(LUA_VLNGSTR): + case static_cast(ctb(LuaT::LNGSTR)): return tsvalue(k1)->equals(n2->getKeyStrValue()); default: return gcvalue(k1) == gcvalueraw(n2->getKeyValue()); @@ -495,7 +495,7 @@ int luaH_next (lua_State *L, Table *t, StkId key) { unsigned int asize = t->arraySize(); unsigned int i = findindex(L, t, s2v(key), asize); /* find original key */ for (; i < asize; i++) { /* try first array part */ - lu_byte tag = *t->getArrayTag(i); + LuaT tag = *t->getArrayTag(i); if (!tagisempty(tag)) { /* a non-empty entry? */ s2v(key)->setInt(cast_int(i) + 1); farr2val(t, i, tag, s2v(key + 1)); @@ -829,7 +829,7 @@ static void reinsertOldSlice (Table *t, unsigned oldasize, */ static void clearNewSlice (Table *t, unsigned oldasize, unsigned newasize) { for (; oldasize < newasize; oldasize++) - *t->getArrayTag(oldasize) = LUA_VEMPTY; + *t->getArrayTag(oldasize) = LuaT::EMPTY; } @@ -1383,15 +1383,15 @@ Node *luaH_mainposition (const Table *t, const TValue *key) { lu_byte Table::get(const TValue* key, TValue* res) { const TValue *slot; switch (ttypetag(key)) { - case LUA_VSHRSTR: + case LuaT::SHRSTR: slot = HgetShortStr(tsvalue(key)); break; - case LUA_VNUMINT: + case LuaT::NUMINT: return getInt(ivalue(key), res); - case LUA_VNIL: + case LuaT::NIL: slot = &absentkey; break; - case LUA_VNUMFLT: { + case LuaT::NUMFLT: { lua_Integer k; if (luaV_flttointeger(fltvalue(key), &k, F2Imod::F2Ieq)) /* integral index? */ return getInt(k, res); /* use specialized version */ @@ -1441,14 +1441,14 @@ TValue* Table::HgetShortStr(TString* key) { int Table::pset(const TValue* key, TValue* val) { switch (ttypetag(key)) { - case LUA_VSHRSTR: return psetShortStr(tsvalue(key), val); - case LUA_VNUMINT: { + case LuaT::SHRSTR: return psetShortStr(tsvalue(key), val); + case LuaT::NUMINT: { int hres; luaH_fastseti(this, ivalue(key), val, hres); return hres; } - case LUA_VNIL: return HNOTFOUND; - case LUA_VNUMFLT: { + case LuaT::NIL: return HNOTFOUND; + case LuaT::NUMFLT: { lua_Integer k; if (luaV_flttointeger(fltvalue(key), &k, F2Imod::F2Ieq)) { /* integral index? */ int hres; @@ -1578,7 +1578,7 @@ lua_Unsigned Table::getn(lua_State* L) { // Phase 50: Factory pattern with placement new operator Table* Table::create(lua_State* L) { // Use placement new operator - calls constructor from lobject.h - Table *t = new (L, LUA_VTABLE) Table(); + Table *t = new (L, LuaT::TABLE) Table(); // Set non-default values t->setFlags(maskflags); /* table has no metamethod fields */ diff --git a/src/serialization/ldump.cpp b/src/serialization/ldump.cpp index 709d6c06..da08d4c8 100644 --- a/src/serialization/ldump.cpp +++ b/src/serialization/ldump.cpp @@ -186,21 +186,21 @@ static void dumpConstants (DumpState *D, const Proto *f) { auto constants = f->getConstantsSpan(); dumpInt(D, static_cast(constants.size())); for (const auto& constant : constants) { - int tt = ttypetag(&constant); - dumpByte(D, tt); + LuaT tt = ttypetag(&constant); + dumpByte(D, static_cast(tt)); switch (tt) { - case LUA_VNUMFLT: + case LuaT::NUMFLT: dumpNumber(D, fltvalue(&constant)); break; - case LUA_VNUMINT: + case LuaT::NUMINT: dumpInteger(D, ivalue(&constant)); break; - case LUA_VSHRSTR: - case LUA_VLNGSTR: + case LuaT::SHRSTR: + case LuaT::LNGSTR: dumpString(D, tsvalue(&constant)); break; default: - lua_assert(tt == LUA_VNIL || tt == LUA_VFALSE || tt == LUA_VTRUE); + lua_assert(tt == LuaT::NIL || tt == LuaT::VFALSE || tt == LuaT::VTRUE); } } } diff --git a/src/serialization/lundump.cpp b/src/serialization/lundump.cpp index 8d01fba1..96652467 100644 --- a/src/serialization/lundump.cpp +++ b/src/serialization/lundump.cpp @@ -223,25 +223,25 @@ static void loadConstants (LoadState *S, Proto *f) { } for (size_t i = 0; i < static_cast(n); i++) { TValue *o = &constantsSpan[i]; - int t = loadByte(S); + LuaT t = static_cast(loadByte(S)); switch (t) { - case LUA_VNIL: + case LuaT::NIL: setnilvalue(o); break; - case LUA_VFALSE: + case LuaT::VFALSE: setbfvalue(o); break; - case LUA_VTRUE: + case LuaT::VTRUE: setbtvalue(o); break; - case LUA_VNUMFLT: + case LuaT::NUMFLT: o->setFloat(loadNumber(S)); break; - case LUA_VNUMINT: + case LuaT::NUMINT: o->setInt(loadInteger(S)); break; - case LUA_VSHRSTR: - case LUA_VLNGSTR: { + case LuaT::SHRSTR: + case LuaT::LNGSTR: { lua_assert(f->getSource() == nullptr); loadString(S, f, f->getSourcePtr()); /* use 'source' to anchor string */ if (f->getSource() == nullptr) diff --git a/src/testing/ltests.cpp b/src/testing/ltests.cpp index 4a87c4d2..dfd568ee 100644 --- a/src/testing/ltests.cpp +++ b/src/testing/ltests.cpp @@ -326,7 +326,7 @@ static void printobj (global_State *g, GCObject *o) { ttypename(novariant(o->getType())), (void *)o, isdead(g,o) ? 'd' : isblack(o) ? 'b' : iswhite(o) ? 'w' : 'g', "ns01oTt"[static_cast(getage(o))], o->getMarked()); - if (o->getType() == LUA_VSHRSTR || o->getType() == LUA_VLNGSTR) + if (o->getType() == LuaT::SHRSTR || o->getType() == LuaT::LNGSTR) printf(" '%s'", getstr(gco2ts(o))); } @@ -338,36 +338,36 @@ void lua_printobj (lua_State *L, GCObject *o) { void lua_printvalue (TValue *v) { switch (ttypetag(v)) { - case LUA_VNUMINT: case LUA_VNUMFLT: { + case LuaT::NUMINT: case LuaT::NUMFLT: { char buff[LUA_N2SBUFFSZ]; unsigned len = luaO_tostringbuff(v, buff); buff[len] = '\0'; printf("%s", buff); break; } - case LUA_VSHRSTR: + case LuaT::SHRSTR: printf("'%s'", getstr(tsvalue(v))); break; - case LUA_VLNGSTR: + case LuaT::LNGSTR: printf("'%.30s...'", getstr(tsvalue(v))); break; - case LUA_VFALSE: + case LuaT::VFALSE: printf("%s", "false"); break; - case LUA_VTRUE: + case LuaT::VTRUE: printf("%s", "true"); break; - case LUA_VLIGHTUSERDATA: + case LuaT::LIGHTUSERDATA: printf("light udata: %p", pvalue(v)); break; - case LUA_VUSERDATA: + case LuaT::USERDATA: printf("full udata: %p", uvalue(v)); break; - case LUA_VNIL: + case LuaT::NIL: printf("nil"); break; - case LUA_VLCF: + case LuaT::LCF: printf("light C function: %p", fvalue(v)); break; - case LUA_VCCL: + case LuaT::CCL: printf("C closure: %p", clCvalue(v)); break; - case LUA_VLCL: + case LuaT::LCL: printf("Lua function: %p", clLvalue(v)); break; - case LUA_VTHREAD: + case LuaT::THREAD: printf("thread: %p", thvalue(v)); break; - case LUA_VTABLE: + case LuaT::TABLE: printf("table: %p", hvalue(v)); break; default: lua_assert(0); @@ -519,36 +519,36 @@ static void check_stack (global_State *g, lua_State *L1) { static void checkrefs (global_State *g, GCObject *o) { switch (o->getType()) { - case LUA_VUSERDATA: { + case LuaT::USERDATA: { checkudata(g, gco2u(o)); break; } - case LUA_VUPVAL: { + case LuaT::UPVAL: { checkvalref(g, o, gco2upv(o)->getVP()); break; } - case LUA_VTABLE: { + case LuaT::TABLE: { checktable(g, gco2t(o)); break; } - case LUA_VTHREAD: { + case LuaT::THREAD: { check_stack(g, gco2th(o)); break; } - case LUA_VLCL: { + case LuaT::LCL: { checkLclosure(g, gco2lcl(o)); break; } - case LUA_VCCL: { + case LuaT::CCL: { checkCclosure(g, gco2ccl(o)); break; } - case LUA_VPROTO: { + case LuaT::PROTO: { checkproto(g, gco2p(o)); break; } - case LUA_VSHRSTR: - case LUA_VLNGSTR: { + case LuaT::SHRSTR: + case LuaT::LNGSTR: { assert(!isgray(o)); /* strings are never gray */ break; } @@ -582,8 +582,8 @@ static void checkobject (global_State *g, GCObject *o, int maybedead, assert(isblack(o) || getage(o) == GCAge::Touched1 || getage(o) == GCAge::Old0 || - o->getType() == LUA_VTHREAD || - (o->getType() == LUA_VUPVAL && gco2upv(o)->isOpen())); + o->getType() == LuaT::THREAD || + (o->getType() == LuaT::UPVAL && gco2upv(o)->isOpen())); } assert(getage(o) != GCAge::Touched1 || isgray(o)); } @@ -602,12 +602,12 @@ static l_mem checkgraylist (global_State *g, GCObject *o) { o->setMarkedBit(TESTBIT); /* mark that object is in a gray list */ total++; switch (o->getType()) { - case LUA_VTABLE: o = gco2t(o)->getGclist(); break; - case LUA_VLCL: o = gco2lcl(o)->getGclist(); break; - case LUA_VCCL: o = gco2ccl(o)->getGclist(); break; - case LUA_VTHREAD: o = gco2th(o)->getGclist(); break; - case LUA_VPROTO: o = gco2p(o)->getGclist(); break; - case LUA_VUSERDATA: + case LuaT::TABLE: o = gco2t(o)->getGclist(); break; + case LuaT::LCL: o = gco2lcl(o)->getGclist(); break; + case LuaT::CCL: o = gco2ccl(o)->getGclist(); break; + case LuaT::THREAD: o = gco2th(o)->getGclist(); break; + case LuaT::PROTO: o = gco2p(o)->getGclist(); break; + case LuaT::USERDATA: assert(gco2u(o)->getNumUserValues() > 0); o = gco2u(o)->getGclist(); break; @@ -641,7 +641,7 @@ static l_mem checkgrays (global_State *g) { static void incifingray (global_State *g, GCObject *o, l_mem *count) { if (!g->keepInvariant()) return; /* gray lists not being kept in these phases */ - if (o->getType() == LUA_VUPVAL) { + if (o->getType() == LuaT::UPVAL) { /* only open upvalues can be gray */ assert(!isgray(o) || gco2upv(o)->isOpen()); return; /* upvalues are never in gray lists */ @@ -699,7 +699,7 @@ int lua_checkmemory (lua_State *L) { /* check 'fixedgc' list */ for (o = g->getFixedGC(); o != nullptr; o = o->getNext()) { - assert(o->getType() == LUA_VSHRSTR && isgray(o) && getage(o) == GCAge::Old); + assert(o->getType() == LuaT::SHRSTR && isgray(o) && getage(o) == GCAge::Old); } /* check 'allgc' list */ @@ -716,7 +716,7 @@ int lua_checkmemory (lua_State *L) { checkobject(g, o, 0, GCAge::New); incifingray(g, o, &totalshould); assert(tofinalize(o)); - assert(o->getType() == LUA_VUSERDATA || o->getType() == LUA_VTABLE); + assert(o->getType() == LuaT::USERDATA || o->getType() == LuaT::TABLE); } if (g->keepInvariant()) assert(totalin == totalshould); @@ -1089,7 +1089,7 @@ static int hash_query (lua_State *L) { TString *ts; luaL_argcheck(L, lua_type(L, 1) == LUA_TSTRING, 1, "string expected"); ts = tsvalue(obj_at(L, 1)); - if (ts->getType() == LUA_VLNGSTR) + if (ts->getType() == LuaT::LNGSTR) ts->hashLongStr(); /* make sure long string has a hash */ lua_pushinteger(L, cast_int(ts->getHash())); } diff --git a/src/vm/lvm.cpp b/src/vm/lvm.cpp index 1cd4c56f..04b4fe2f 100644 --- a/src/vm/lvm.cpp +++ b/src/vm/lvm.cpp @@ -831,7 +831,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { TValue *upval = cl->getUpval(InstructionView(i).b())->getVP(); TValue *rc = KC(i); TString *key = tsvalue(rc); /* key must be a short string */ - lu_byte tag; + LuaT tag; tag = luaV_fastget(upval, key, s2v(ra), luaH_getshortstr); if (tagisempty(tag)) Protect([&]() { luaV_finishget(L, upval, rc, ra, tag); }); @@ -841,7 +841,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { StkId ra = RA(i); TValue *rb = vRB(i); TValue *rc = vRC(i); - lu_byte tag; + LuaT tag; if (ttisinteger(rc)) { /* fast track for integers? */ luaV_fastgeti(rb, ivalue(rc), s2v(ra), tag); } @@ -855,7 +855,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { StkId ra = RA(i); TValue *rb = vRB(i); int c = InstructionView(i).c(); - lu_byte tag; + LuaT tag; luaV_fastgeti(rb, c, s2v(ra), tag); if (tagisempty(tag)) { TValue key; @@ -869,7 +869,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { TValue *rb = vRB(i); TValue *rc = KC(i); TString *key = tsvalue(rc); /* key must be a short string */ - lu_byte tag; + LuaT tag; tag = luaV_fastget(rb, key, s2v(ra), luaH_getshortstr); if (tagisempty(tag)) Protect([&]() { luaV_finishget(L, rb, rc, ra, tag); }); @@ -956,7 +956,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { } vmcase(OP_SELF) { StkId ra = RA(i); - lu_byte tag; + LuaT tag; TValue *rb = vRB(i); TValue *rc = KC(i); TString *key = tsvalue(rc); /* key must be a short string */ @@ -1512,7 +1512,7 @@ void lua_State::objlen(StkId ra, const TValue *rb) { luaV_objlen(this, ra, rb); } -lu_byte lua_State::finishGet(const TValue *t, TValue *key, StkId val, lu_byte tag) { +LuaT lua_State::finishGet(const TValue *t, TValue *key, StkId val, LuaT tag) { return luaV_finishget(this, t, key, val, tag); } diff --git a/src/vm/lvm.h b/src/vm/lvm.h index 9dde0ff8..825d9710 100644 --- a/src/vm/lvm.h +++ b/src/vm/lvm.h @@ -162,17 +162,17 @@ inline int luaV_rawequalobj(const TValue* t1, const TValue* t2) noexcept { ** fast track for 'gettable' */ template -inline lu_byte luaV_fastget(const TValue* t, const TValue* k, TValue* res, F&& f) noexcept { +inline LuaT luaV_fastget(const TValue* t, const TValue* k, TValue* res, F&& f) noexcept { if (!ttistable(t)) - return LUA_VNOTABLE; + return LuaT::NOTABLE; return f(hvalue(t), k, res); } /* Overload for TString* keys */ template -inline lu_byte luaV_fastget(const TValue* t, TString* k, TValue* res, F&& f) noexcept { +inline LuaT luaV_fastget(const TValue* t, TString* k, TValue* res, F&& f) noexcept { if (!ttistable(t)) - return LUA_VNOTABLE; + return LuaT::NOTABLE; return f(hvalue(t), k, res); } @@ -181,9 +181,9 @@ inline lu_byte luaV_fastget(const TValue* t, TString* k, TValue* res, F&& f) noe ** Special case of 'luaV_fastget' for integers, inlining the fast case ** of 'luaH_getint'. */ -inline void luaV_fastgeti(const TValue* t, lua_Integer k, TValue* res, lu_byte& tag) noexcept { +inline void luaV_fastgeti(const TValue* t, lua_Integer k, TValue* res, LuaT& tag) noexcept { if (!ttistable(t)) - tag = LUA_VNOTABLE; + tag = LuaT::NOTABLE; else luaH_fastgeti(hvalue(t), k, res, tag); } @@ -238,8 +238,8 @@ inline lua_Integer luaV_shiftr(lua_Integer x, lua_Integer y) noexcept { #define luaV_flttointeger_declared LUAI_FUNC int luaV_flttointeger (lua_Number n, lua_Integer *p, F2Imod mode); #endif -LUAI_FUNC lu_byte luaV_finishget (lua_State *L, const TValue *t, TValue *key, - StkId val, lu_byte tag); +LUAI_FUNC LuaT luaV_finishget (lua_State *L, const TValue *t, TValue *key, + StkId val, LuaT tag); LUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key, TValue *val, int aux); LUAI_FUNC void luaV_finishOp (lua_State *L); diff --git a/src/vm/lvm_comparison.cpp b/src/vm/lvm_comparison.cpp index 7115a371..b8fb8678 100644 --- a/src/vm/lvm_comparison.cpp +++ b/src/vm/lvm_comparison.cpp @@ -193,19 +193,19 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { return 0; else if (ttypetag(t1) != ttypetag(t2)) { switch (ttypetag(t1)) { - case LUA_VNUMINT: { /* integer == float? */ + case LuaT::NUMINT: { /* integer == float? */ /* integer and float can only be equal if float has an integer value equal to the integer */ lua_Integer i2; return (luaV_flttointeger(fltvalue(t2), &i2, F2Imod::F2Ieq) && ivalue(t1) == i2); } - case LUA_VNUMFLT: { /* float == integer? */ + case LuaT::NUMFLT: { /* float == integer? */ lua_Integer i1; /* see comment in previous case */ return (luaV_flttointeger(fltvalue(t1), &i1, F2Imod::F2Ieq) && i1 == ivalue(t2)); } - case LUA_VSHRSTR: case LUA_VLNGSTR: { + case LuaT::SHRSTR: case LuaT::LNGSTR: { /* compare two strings with different variants: they can be equal when one string is a short string and the other is an external string */ @@ -219,18 +219,18 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { } else { /* equal variants */ switch (ttypetag(t1)) { - case LUA_VNIL: case LUA_VFALSE: case LUA_VTRUE: + case LuaT::NIL: case LuaT::VFALSE: case LuaT::VTRUE: return 1; - case LUA_VNUMINT: + case LuaT::NUMINT: return (ivalue(t1) == ivalue(t2)); - case LUA_VNUMFLT: + case LuaT::NUMFLT: return (fltvalue(t1) == fltvalue(t2)); - case LUA_VLIGHTUSERDATA: return pvalue(t1) == pvalue(t2); - case LUA_VSHRSTR: + case LuaT::LIGHTUSERDATA: return pvalue(t1) == pvalue(t2); + case LuaT::SHRSTR: return eqshrstr(tsvalue(t1), tsvalue(t2)); - case LUA_VLNGSTR: + case LuaT::LNGSTR: return tsvalue(t1)->equals(tsvalue(t2)); - case LUA_VUSERDATA: { + case LuaT::USERDATA: { if (uvalue(t1) == uvalue(t2)) return 1; else if (L == nullptr) return 0; tm = fasttm(L, uvalue(t1)->getMetatable(), TMS::TM_EQ); @@ -238,7 +238,7 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { tm = fasttm(L, uvalue(t2)->getMetatable(), TMS::TM_EQ); break; /* will try TM */ } - case LUA_VTABLE: { + case LuaT::TABLE: { if (hvalue(t1) == hvalue(t2)) return 1; else if (L == nullptr) return 0; tm = fasttm(L, hvalue(t1)->getMetatable(), TMS::TM_EQ); @@ -246,7 +246,7 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { tm = fasttm(L, hvalue(t2)->getMetatable(), TMS::TM_EQ); break; /* will try TM */ } - case LUA_VLCF: + case LuaT::LCF: return (fvalue(t1) == fvalue(t2)); default: /* functions and threads */ return (gcvalue(t1) == gcvalue(t2)); @@ -254,7 +254,7 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { if (tm == nullptr) /* no TM? */ return 0; /* objects are different */ else { - int tag = luaT_callTMres(L, tm, t1, t2, L->getTop().p); /* call TM */ + LuaT tag = luaT_callTMres(L, tm, t1, t2, L->getTop().p); /* call TM */ return !tagisfalse(tag); } } diff --git a/src/vm/lvm_string.cpp b/src/vm/lvm_string.cpp index 7e3c25e4..82eb8ae7 100644 --- a/src/vm/lvm_string.cpp +++ b/src/vm/lvm_string.cpp @@ -108,18 +108,18 @@ void luaV_concat (lua_State *L, int total) { void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) { const TValue *tm; switch (ttypetag(rb)) { - case LUA_VTABLE: { + case LuaT::TABLE: { Table *h = hvalue(rb); tm = fasttm(L, h->getMetatable(), TMS::TM_LEN); if (tm) break; /* metamethod? break switch to call it */ s2v(ra)->setInt(l_castU2S(luaH_getn(L, h))); /* else primitive len */ return; } - case LUA_VSHRSTR: { + case LuaT::SHRSTR: { s2v(ra)->setInt(static_cast(tsvalue(rb)->length())); return; } - case LUA_VLNGSTR: { + case LuaT::LNGSTR: { s2v(ra)->setInt(cast_st2S(tsvalue(rb)->getLnglen())); return; } diff --git a/src/vm/lvm_table.cpp b/src/vm/lvm_table.cpp index 5b4f194e..5ee97cca 100644 --- a/src/vm/lvm_table.cpp +++ b/src/vm/lvm_table.cpp @@ -46,12 +46,12 @@ inline constexpr int MAXTAGLOOP = 2000; ** PERFORMANCE: This is the slow path. The hot path (direct table access) is ** handled inline in the VM main loop via luaV_fastget macro. */ -lu_byte luaV_finishget (lua_State *L, const TValue *t, TValue *key, - StkId val, lu_byte tag) { +LuaT luaV_finishget (lua_State *L, const TValue *t, TValue *key, + StkId val, LuaT tag) { int loop; /* counter to avoid infinite loops */ const TValue *tm; /* metamethod */ for (loop = 0; loop < MAXTAGLOOP; loop++) { - if (tag == LUA_VNOTABLE) { /* 't' is not a table? */ + if (tag == LuaT::NOTABLE) { /* 't' is not a table? */ lua_assert(!ttistable(t)); tm = luaT_gettmbyobj(L, t, TMS::TM_INDEX); if (l_unlikely(notm(tm))) @@ -62,7 +62,7 @@ lu_byte luaV_finishget (lua_State *L, const TValue *t, TValue *key, tm = fasttm(L, hvalue(t)->getMetatable(), TMS::TM_INDEX); /* table's metamethod */ if (tm == nullptr) { /* no metamethod? */ setnilvalue(s2v(val)); /* result is nil */ - return LUA_VNIL; + return LuaT::NIL; } /* else will try the metamethod */ } @@ -77,7 +77,7 @@ lu_byte luaV_finishget (lua_State *L, const TValue *t, TValue *key, /* else repeat (tail call 'luaV_finishget') */ } luaG_runerror(L, "'__index' chain too long; possible loop"); - return 0; /* to avoid warnings */ + return LuaT::NIL; /* to avoid warnings */ } From cb6178cd4bb4a3acbfe908c146e045726e7bad55 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 22 Nov 2025 13:03:30 +0000 Subject: [PATCH 5/7] Phase 122: Complete LuaT enum class refactoring Fixed all remaining type mismatches from lu_byte to LuaT: - Updated operator new signatures in all GC classes to use LuaT - Changed luaC_newobj/luaC_newobjdt to accept LuaT instead of lu_byte - Updated Table method return types (get, getInt, getShortStr, getStr) - Fixed local variables in ltable.cpp, ldump.cpp, lstate.cpp - Added iscollectable(LuaT) overload for type-safe bit checking - Updated macros in gc_marking.cpp and gc_weak.cpp to use iscollectable() - Changed createstrobj parameter from lu_byte to LuaT All files now use LuaT enum class instead of lu_byte for variant tags. Build successful with zero warnings! --- src/core/lstate.cpp | 2 +- src/memory/gc/gc_marking.cpp | 2 +- src/memory/gc/gc_weak.cpp | 2 +- src/memory/lgc.cpp | 4 ++-- src/memory/lgc.h | 18 +++++++++--------- src/objects/lfunc.h | 6 +++--- src/objects/lobject_core.h | 3 ++- src/objects/lproto.h | 2 +- src/objects/lstring.cpp | 2 +- src/objects/lstring.h | 2 +- src/objects/ltable.cpp | 24 ++++++++++++------------ src/objects/ltable.h | 2 +- src/serialization/ldump.cpp | 2 +- 13 files changed, 36 insertions(+), 35 deletions(-) diff --git a/src/core/lstate.cpp b/src/core/lstate.cpp index 30015bbf..026b40b9 100644 --- a/src/core/lstate.cpp +++ b/src/core/lstate.cpp @@ -272,7 +272,7 @@ LUA_API lua_State *lua_newthread (lua_State *L) { lua_lock(L); luaC_checkGC(L); /* create new thread */ - o = luaC_newobjdt(L, LUA_TTHREAD, sizeof(LX), lxOffset()); + o = luaC_newobjdt(L, LuaT::THREAD, sizeof(LX), lxOffset()); L1 = gco2th(o); /* anchor it on L stack */ setthvalue2s(L, L->getTop().p, L1); diff --git a/src/memory/gc/gc_marking.cpp b/src/memory/gc/gc_marking.cpp index 97756d36..13d32503 100644 --- a/src/memory/gc/gc_marking.cpp +++ b/src/memory/gc/gc_marking.cpp @@ -83,7 +83,7 @@ static inline void linkgclistThread(lua_State* th, GCObject*& p) { ** Access to collectable objects in table array part */ #define gcvalarr(t, i) \ - ((*(t)->getArrayTag(i) & BIT_ISCOLLECTABLE) ? (t)->getArrayVal(i)->gc : nullptr) + (iscollectable(*(t)->getArrayTag(i)) ? (t)->getArrayVal(i)->gc : nullptr) /* diff --git a/src/memory/gc/gc_weak.cpp b/src/memory/gc/gc_weak.cpp index feb8c38f..c3cf4a46 100644 --- a/src/memory/gc/gc_weak.cpp +++ b/src/memory/gc/gc_weak.cpp @@ -38,7 +38,7 @@ /* Access to collectable objects in array part of tables */ #define gcvalarr(t,i) \ - ((*(t)->getArrayTag(i) & BIT_ISCOLLECTABLE) ? (t)->getArrayVal(i)->gc : nullptr) + (iscollectable(*(t)->getArrayTag(i)) ? (t)->getArrayVal(i)->gc : nullptr) /* Note: gcvalueN and valiswhite are now in lgc.h */ /* Note: markkey and markvalue are defined in gc_marking.h */ diff --git a/src/memory/lgc.cpp b/src/memory/lgc.cpp index f5cd194c..0e212376 100644 --- a/src/memory/lgc.cpp +++ b/src/memory/lgc.cpp @@ -219,7 +219,7 @@ void luaC_barrierback_ (lua_State *L, GCObject *o) { ** create a new collectable object (with given type, size, and offset) ** and link it to 'allgc' list. */ -GCObject *luaC_newobjdt (lua_State *L, lu_byte tt, size_t sz, size_t offset) { +GCObject *luaC_newobjdt (lua_State *L, LuaT tt, size_t sz, size_t offset) { global_State *g = G(L); char *p = cast_charp(luaM_newobject(L, novariant(tt), sz)); GCObject *o = reinterpret_cast(p + offset); @@ -234,7 +234,7 @@ GCObject *luaC_newobjdt (lua_State *L, lu_byte tt, size_t sz, size_t offset) { /* ** create a new collectable object with no offset. */ -GCObject *luaC_newobj (lua_State *L, lu_byte tt, size_t sz) { +GCObject *luaC_newobj (lua_State *L, LuaT tt, size_t sz) { return luaC_newobjdt(L, tt, sz, 0); } diff --git a/src/memory/lgc.h b/src/memory/lgc.h index ffcbc705..3fdf7cdf 100644 --- a/src/memory/lgc.h +++ b/src/memory/lgc.h @@ -387,8 +387,8 @@ LUAI_FUNC void luaC_step (lua_State *L); LUAI_FUNC void luaC_runtilstate (lua_State *L, GCState state, int fast); LUAI_FUNC void luaC_fullgc (lua_State *L, int isemergency); LUAI_FUNC void propagateall (global_State *g); /* used by GCCollector */ -LUAI_FUNC GCObject *luaC_newobj (lua_State *L, lu_byte tt, size_t sz); -LUAI_FUNC GCObject *luaC_newobjdt (lua_State *L, lu_byte tt, size_t sz, +LUAI_FUNC GCObject *luaC_newobj (lua_State *L, LuaT tt, size_t sz); +LUAI_FUNC GCObject *luaC_newobjdt (lua_State *L, LuaT tt, size_t sz, size_t offset); LUAI_FUNC void luaC_barrier_ (lua_State *L, GCObject *o, GCObject *v); LUAI_FUNC void luaC_barrierback_ (lua_State *L, GCObject *o); @@ -411,37 +411,37 @@ LUAI_FUNC void freeobj (lua_State *L, GCObject *o); */ // CClosure placement new operator -inline void* CClosure::operator new(size_t size, lua_State* L, lu_byte tt, size_t extra) { +inline void* CClosure::operator new(size_t size, lua_State* L, LuaT tt, size_t extra) { return luaC_newobj(L, tt, size + extra); } // LClosure placement new operator -inline void* LClosure::operator new(size_t size, lua_State* L, lu_byte tt, size_t extra) { +inline void* LClosure::operator new(size_t size, lua_State* L, LuaT tt, size_t extra) { return luaC_newobj(L, tt, size + extra); } // Udata placement new operator -inline void* Udata::operator new(size_t size, lua_State* L, lu_byte tt, size_t extra) { +inline void* Udata::operator new(size_t size, lua_State* L, LuaT tt, size_t extra) { return luaC_newobj(L, tt, size + extra); } // TString placement new operator -inline void* TString::operator new(size_t size, lua_State* L, lu_byte tt, size_t extra) { +inline void* TString::operator new(size_t size, lua_State* L, LuaT tt, size_t extra) { return luaC_newobj(L, tt, size + extra); } // Proto placement new operator -inline void* Proto::operator new(size_t size, lua_State* L, lu_byte tt) { +inline void* Proto::operator new(size_t size, lua_State* L, LuaT tt) { return luaC_newobj(L, tt, size); } // UpVal placement new operator -inline void* UpVal::operator new(size_t size, lua_State* L, lu_byte tt) { +inline void* UpVal::operator new(size_t size, lua_State* L, LuaT tt) { return luaC_newobj(L, tt, size); } // Table placement new operator -inline void* Table::operator new(size_t size, lua_State* L, lu_byte tt) { +inline void* Table::operator new(size_t size, lua_State* L, LuaT tt) { return luaC_newobj(L, tt, size); } diff --git a/src/objects/lfunc.h b/src/objects/lfunc.h index 9b53c07e..7c78e793 100644 --- a/src/objects/lfunc.h +++ b/src/objects/lfunc.h @@ -87,7 +87,7 @@ class UpVal : public GCBase { ~UpVal() noexcept = default; // Phase 50: Placement new operator - integrates with Lua's GC (implemented in lgc.h) - static void* operator new(size_t size, lua_State* L, lu_byte tt); + static void* operator new(size_t size, lua_State* L, LuaT tt); // Disable regular new/delete (must use placement new with GC) static void* operator new(size_t) = delete; @@ -144,7 +144,7 @@ class CClosure : public GCBase { public: // Member placement new operator for GC allocation (defined in lgc.h) - static void* operator new(size_t size, lua_State* L, lu_byte tt, size_t extra = 0); + static void* operator new(size_t size, lua_State* L, LuaT tt, size_t extra = 0); // Constructor CClosure(int nupvals); @@ -182,7 +182,7 @@ class LClosure : public GCBase { public: // Member placement new operator for GC allocation (defined in lgc.h) - static void* operator new(size_t size, lua_State* L, lu_byte tt, size_t extra = 0); + static void* operator new(size_t size, lua_State* L, LuaT tt, size_t extra = 0); // Constructor LClosure(int nupvals); diff --git a/src/objects/lobject_core.h b/src/objects/lobject_core.h index c67e9bc6..804572de 100644 --- a/src/objects/lobject_core.h +++ b/src/objects/lobject_core.h @@ -302,6 +302,7 @@ class GCBase: public GCObject { }; constexpr bool iscollectable(const TValue* o) noexcept { return (static_cast(rawtt(o)) & BIT_ISCOLLECTABLE) != 0; } +constexpr bool iscollectable(LuaT tag) noexcept { return (static_cast(tag) & BIT_ISCOLLECTABLE) != 0; } constexpr bool TValue::isCollectable() const noexcept { return (static_cast(tt_) & BIT_ISCOLLECTABLE) != 0; } @@ -381,7 +382,7 @@ class Udata : public GCBase { } // Phase 50: Placement new operator - integrates with Lua's GC (implemented in lgc.h) - static void* operator new(size_t size, lua_State* L, lu_byte tt, size_t extra = 0); + static void* operator new(size_t size, lua_State* L, LuaT tt, size_t extra = 0); // Disable regular new/delete (must use placement new with GC) static void* operator new(size_t) = delete; diff --git a/src/objects/lproto.h b/src/objects/lproto.h index 893c6f01..fcf45c95 100644 --- a/src/objects/lproto.h +++ b/src/objects/lproto.h @@ -248,7 +248,7 @@ class Proto : public GCBase { ~Proto() noexcept = default; // Phase 50: Placement new operator - integrates with Lua's GC (implemented in lgc.h) - static void* operator new(size_t size, lua_State* L, lu_byte tt); + static void* operator new(size_t size, lua_State* L, LuaT tt); // Disable regular new/delete (must use placement new with GC) static void* operator new(size_t) = delete; diff --git a/src/objects/lstring.cpp b/src/objects/lstring.cpp index 2bbe7273..b4d2a417 100644 --- a/src/objects/lstring.cpp +++ b/src/objects/lstring.cpp @@ -146,7 +146,7 @@ void TString::init(lua_State* L) { ** creates a new string object ** Phase 50: Now uses placement new to call constructor */ -static TString *createstrobj (lua_State *L, size_t totalsize, lu_byte tag, +static TString *createstrobj (lua_State *L, size_t totalsize, LuaT tag, unsigned h) { // For TString, we need to allocate exactly totalsize bytes, not sizeof(TString) // For short strings: totalsize = contentsOffset() + string_length + 1 diff --git a/src/objects/lstring.h b/src/objects/lstring.h index e077abd8..94b0a602 100644 --- a/src/objects/lstring.h +++ b/src/objects/lstring.h @@ -99,7 +99,7 @@ class TString : public GCBase { // Phase 50: Placement new operator - integrates with Lua's GC (implemented in lgc.h) // Note: For TString, this may allocate less than sizeof(TString) for short strings! - static void* operator new(size_t size, lua_State* L, lu_byte tt, size_t extra = 0); + static void* operator new(size_t size, lua_State* L, LuaT tt, size_t extra = 0); // Disable regular new/delete (must use placement new with GC) static void* operator new(size_t) = delete; diff --git a/src/objects/ltable.cpp b/src/objects/ltable.cpp index 15d8663f..f6617af4 100644 --- a/src/objects/ltable.cpp +++ b/src/objects/ltable.cpp @@ -612,7 +612,7 @@ static void countint (lua_Integer key, Counters *ct) { static inline int arraykeyisempty (const Table *t, unsigned key) { - int tag = *t->getArrayTag(key - 1); + LuaT tag = *t->getArrayTag(key - 1); return tagisempty(tag); } @@ -813,7 +813,7 @@ static void exchangehashpart (Table *t1, Table *t2) { static void reinsertOldSlice (Table *t, unsigned oldasize, unsigned newasize) { for (unsigned i = newasize; i < oldasize; i++) { /* traverse vanishing slice */ - lu_byte tag = *t->getArrayTag(i); + LuaT tag = *t->getArrayTag(i); if (!tagisempty(tag)) { /* a non-empty entry? */ TValue key, aux; key.setInt(l_castU2S(i) + 1); /* make the key */ @@ -1128,7 +1128,7 @@ static bool hashkeyisempty (Table *t, lua_Unsigned key) { } -static lu_byte finishnodeget (const TValue *val, TValue *res) { +static LuaT finishnodeget (const TValue *val, TValue *res) { if (!ttisnil(val)) { *res = *val; } @@ -1188,19 +1188,19 @@ static bool rawfinishnodeset (TValue *slot, TValue *val) { ** C API wrapper functions - these forward to Table methods */ -lu_byte luaH_getint (Table *t, lua_Integer key, TValue *res) { +LuaT luaH_getint (Table *t, lua_Integer key, TValue *res) { return t->getInt(key, res); } -lu_byte luaH_getshortstr (Table *t, TString *key, TValue *res) { +LuaT luaH_getshortstr (Table *t, TString *key, TValue *res) { return t->getShortStr(key, res); } -lu_byte luaH_getstr (Table *t, TString *key, TValue *res) { +LuaT luaH_getstr (Table *t, TString *key, TValue *res) { return t->getStr(key, res); } -lu_byte luaH_get (Table *t, const TValue *key, TValue *res) { +LuaT luaH_get (Table *t, const TValue *key, TValue *res) { return t->get(key, res); } @@ -1380,7 +1380,7 @@ Node *luaH_mainposition (const Table *t, const TValue *key) { ** Table method implementations */ -lu_byte Table::get(const TValue* key, TValue* res) { +LuaT Table::get(const TValue* key, TValue* res) { const TValue *slot; switch (ttypetag(key)) { case LuaT::SHRSTR: @@ -1404,10 +1404,10 @@ lu_byte Table::get(const TValue* key, TValue* res) { return finishnodeget(slot, res); } -lu_byte Table::getInt(lua_Integer key, TValue* res) { +LuaT Table::getInt(lua_Integer key, TValue* res) { unsigned k = ikeyinarray(this, key); if (k > 0) { - lu_byte tag = *this->getArrayTag(k - 1); + LuaT tag = *this->getArrayTag(k - 1); if (!tagisempty(tag)) farr2val(this, k - 1, tag, res); return tag; @@ -1416,11 +1416,11 @@ lu_byte Table::getInt(lua_Integer key, TValue* res) { return finishnodeget(getintfromhash(this, key), res); } -lu_byte Table::getShortStr(TString* key, TValue* res) { +LuaT Table::getShortStr(TString* key, TValue* res) { return finishnodeget(HgetShortStr(key), res); } -lu_byte Table::getStr(TString* key, TValue* res) { +LuaT Table::getStr(TString* key, TValue* res) { return finishnodeget(Hgetstr(this, key), res); } diff --git a/src/objects/ltable.h b/src/objects/ltable.h index 05f60d42..2e18fd91 100644 --- a/src/objects/ltable.h +++ b/src/objects/ltable.h @@ -176,7 +176,7 @@ class Table : public GCBase
{ ~Table() noexcept = default; // Phase 50: Placement new operator - integrates with Lua's GC (implemented in lgc.h) - static void* operator new(size_t size, lua_State* L, lu_byte tt); + static void* operator new(size_t size, lua_State* L, LuaT tt); // Disable regular new/delete (must use placement new with GC) static void* operator new(size_t) = delete; diff --git a/src/serialization/ldump.cpp b/src/serialization/ldump.cpp index da08d4c8..eda0805b 100644 --- a/src/serialization/ldump.cpp +++ b/src/serialization/ldump.cpp @@ -150,7 +150,7 @@ static void dumpString (DumpState *D, TString *ts) { dumpSize(D, 0); else { TValue idx; - int tag = luaH_getstr(D->h, ts, &idx); + LuaT tag = luaH_getstr(D->h, ts, &idx); if (!tagisempty(tag)) { /* string already saved? */ dumpVarint(D, 1); /* reuse a saved string */ dumpVarint(D, l_castS2U(ivalue(&idx))); /* index of saved string */ From b9570b39f9c01853e47bcd88d7ab5d5e940c471b Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 22 Nov 2025 13:17:25 +0000 Subject: [PATCH 6/7] Phase 122: Fix collectable bit in LuaT (WIP) Fixed major issue: All GC objects must be created with ctb(LuaT::*) to include the collectable bit. Updated: - All object creation sites (Table, Udata, TString, functions, etc.) - Main thread creation in lua_newstate - Type comparisons in assertions and conditionals - Switch statements in gc_core.cpp (partial) Remaining work: - Fix 7 more switch statements on getType() in: * gc_marking.cpp (2 switches) * lgc.cpp (2 switches) * ltests.cpp (2 switches) * gc_core.cpp (1 more switch) All switches need: static_cast(getType()) and static_cast(ctb(LuaT::*)) for case labels. --- src/core/ldebug.cpp | 2 +- src/core/lstate.cpp | 4 ++-- src/memory/gc/gc_core.cpp | 20 ++++++++++---------- src/memory/gc/gc_sweeping.cpp | 4 ++-- src/memory/lgc.cpp | 2 +- src/objects/lfunc.cpp | 10 +++++----- src/objects/lstring.cpp | 10 +++++----- src/objects/lstring.h | 2 +- src/objects/ltable.cpp | 2 +- src/testing/ltests.cpp | 14 +++++++------- 10 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/core/ldebug.cpp b/src/core/ldebug.cpp index f50ea28f..624bb7fc 100644 --- a/src/core/ldebug.cpp +++ b/src/core/ldebug.cpp @@ -33,7 +33,7 @@ /* Both CClosure and LClosure have tt at same offset (from GCBase) */ -#define LuaClosure(f) ((f) != nullptr && (f)->c.getType() == LuaT::LCL) +#define LuaClosure(f) ((f) != nullptr && (f)->c.getType() == ctb(LuaT::LCL)) static const char strlocal[] = "local"; static const char strupval[] = "upvalue"; diff --git a/src/core/lstate.cpp b/src/core/lstate.cpp index 026b40b9..576309d1 100644 --- a/src/core/lstate.cpp +++ b/src/core/lstate.cpp @@ -272,7 +272,7 @@ LUA_API lua_State *lua_newthread (lua_State *L) { lua_lock(L); luaC_checkGC(L); /* create new thread */ - o = luaC_newobjdt(L, LuaT::THREAD, sizeof(LX), lxOffset()); + o = luaC_newobjdt(L, ctb(LuaT::THREAD), sizeof(LX), lxOffset()); L1 = gco2th(o); /* anchor it on L stack */ setthvalue2s(L, L->getTop().p, L1); @@ -335,7 +335,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud, unsigned seed) { (*f)(ud, nullptr, LUA_TTHREAD, sizeof(global_State))); if (g == nullptr) return nullptr; L = &g->getMainThread()->l; - L->setType(LuaT::THREAD); + L->setType(ctb(LuaT::THREAD)); g->setCurrentWhite(bitmask(WHITE0BIT)); L->setMarked(g->getWhite()); preinit_thread(L, g); diff --git a/src/memory/gc/gc_core.cpp b/src/memory/gc/gc_core.cpp index 3155650a..bb3be2ed 100644 --- a/src/memory/gc/gc_core.cpp +++ b/src/memory/gc/gc_core.cpp @@ -24,45 +24,45 @@ */ l_mem GCCore::objsize(GCObject* o) { lu_mem res; - switch (o->getType()) { - case LuaT::TABLE: { + switch (static_cast(o->getType())) { + case static_cast(ctb(LuaT::TABLE)): { res = luaH_size(gco2t(o)); break; } - case LuaT::LCL: { + case static_cast(ctb(LuaT::LCL)): { LClosure* cl = gco2lcl(o); res = sizeLclosure(cl->getNumUpvalues()); break; } - case LuaT::CCL: { + case static_cast(ctb(LuaT::CCL)): { CClosure* cl = gco2ccl(o); res = sizeCclosure(cl->getNumUpvalues()); break; } - case LuaT::USERDATA: { + case static_cast(ctb(LuaT::USERDATA)): { Udata* u = gco2u(o); res = sizeudata(u->getNumUserValues(), u->getLen()); break; } - case LuaT::PROTO: { + case static_cast(ctb(LuaT::PROTO)): { res = gco2p(o)->memorySize(); break; } - case LuaT::THREAD: { + case static_cast(ctb(LuaT::THREAD)): { res = luaE_threadsize(gco2th(o)); break; } - case LuaT::SHRSTR: { + case static_cast(ctb(LuaT::SHRSTR)): { TString* ts = gco2ts(o); res = sizestrshr(cast_uint(ts->getShrlen())); break; } - case LuaT::LNGSTR: { + case static_cast(ctb(LuaT::LNGSTR)): { TString* ts = gco2ts(o); res = TString::calculateLongStringSize(ts->getLnglen(), ts->getShrlen()); break; } - case LuaT::UPVAL: { + case static_cast(ctb(LuaT::UPVAL)): { res = sizeof(UpVal); break; } diff --git a/src/memory/gc/gc_sweeping.cpp b/src/memory/gc/gc_sweeping.cpp index 5b99ede7..03e893db 100644 --- a/src/memory/gc/gc_sweeping.cpp +++ b/src/memory/gc/gc_sweeping.cpp @@ -137,11 +137,11 @@ void GCSweeping::sweep2old(lua_State* L, GCObject** p) { else { /* all surviving objects become old */ setage(curr, GCAge::Old); - if (curr->getType() == LuaT::THREAD) { /* threads must be watched */ + if (curr->getType() == ctb(LuaT::THREAD)) { /* threads must be watched */ lua_State* th = gco2th(curr); linkgclistThread(th, *g->getGrayAgainPtr()); /* insert into 'grayagain' list */ } - else if (curr->getType() == LuaT::UPVAL && gco2upv(curr)->isOpen()) + else if (curr->getType() == ctb(LuaT::UPVAL) && gco2upv(curr)->isOpen()) set2gray(curr); /* open upvalues are always gray */ else /* everything else is black */ nw2black(curr); diff --git a/src/memory/lgc.cpp b/src/memory/lgc.cpp index 0e212376..c4b467bc 100644 --- a/src/memory/lgc.cpp +++ b/src/memory/lgc.cpp @@ -589,7 +589,7 @@ static GCObject **correctgraylist (GCObject **p) { setage(curr, GCAge::Touched2); goto remain; /* keep it in the list and go to next element */ } - else if (curr->getType() == LuaT::THREAD) { + else if (curr->getType() == ctb(LuaT::THREAD)) { lua_assert(isgray(curr)); goto remain; /* keep non-white threads on the list */ } diff --git a/src/objects/lfunc.cpp b/src/objects/lfunc.cpp index a4843c8d..7d3c9365 100644 --- a/src/objects/lfunc.cpp +++ b/src/objects/lfunc.cpp @@ -36,7 +36,7 @@ CClosure::CClosure(int nupvals) { // Factory method CClosure* CClosure::create(lua_State* L, int nupvals) { size_t extra = (nupvals > 0) ? (static_cast(nupvals) - 1) * sizeof(TValue) : 0; - CClosure* c = new (L, LuaT::CCL, extra) CClosure(nupvals); + CClosure* c = new (L, ctb(LuaT::CCL), extra) CClosure(nupvals); return c; } @@ -58,7 +58,7 @@ LClosure* LClosure::create(lua_State* L, int nupvals) { // So extra = sizeLclosure(nupvals) - sizeof(LClosure) size_t total_size = sizeLclosure(nupvals); size_t extra = total_size - sizeof(LClosure); - LClosure* c = new (L, LuaT::LCL, extra) LClosure(nupvals); + LClosure* c = new (L, ctb(LuaT::LCL), extra) LClosure(nupvals); return c; } @@ -71,7 +71,7 @@ void LClosure::initUpvals(lua_State* L) { int i; for (i = 0; i < nupvalues; i++) { // Use placement new - calls constructor (initializes to closed nil upvalue) - UpVal *uv = new (L, LuaT::UPVAL) UpVal(); + UpVal *uv = new (L, ctb(LuaT::UPVAL)) UpVal(); uv->setVP(uv->getValueSlot()); /* make it closed */ // Constructor already sets value to nil, but keeping setnilvalue for clarity setnilvalue(uv->getVP()); @@ -88,7 +88,7 @@ void LClosure::initUpvals(lua_State* L) { **/ static UpVal *newupval (lua_State *L, StkId level, UpVal **prev) { // Use placement new - calls constructor - UpVal *uv = new (L, LuaT::UPVAL) UpVal(); + UpVal *uv = new (L, ctb(LuaT::UPVAL)) UpVal(); UpVal *next = *prev; uv->setVP(s2v(level)); /* current value lives in the stack */ uv->setOpenNext(next); /* link it to list of open upvalues */ @@ -271,7 +271,7 @@ StkId luaF_close (lua_State *L, StkId level, TStatus status, int yy) { // Phase 50: Use placement new to call constructor Proto *luaF_newproto (lua_State *L) { // Use placement new - calls constructor which initializes all fields to safe defaults - Proto *f = new (L, LuaT::PROTO) Proto(); + Proto *f = new (L, ctb(LuaT::PROTO)) Proto(); // Constructor handles all initialization return f; } diff --git a/src/objects/lstring.cpp b/src/objects/lstring.cpp index b4d2a417..4d1e7650 100644 --- a/src/objects/lstring.cpp +++ b/src/objects/lstring.cpp @@ -206,7 +206,7 @@ static TString *createstrobj (lua_State *L, size_t totalsize, LuaT tag, TString* TString::createLongString(lua_State* L, size_t l) { size_t totalsize = calculateLongStringSize(l, LSTRREG); - TString *ts = createstrobj(L, totalsize, LuaT::LNGSTR, G(L)->getSeed()); + TString *ts = createstrobj(L, totalsize, ctb(LuaT::LNGSTR), G(L)->getSeed()); ts->setLnglen(l); ts->setShrlen(LSTRREG); /* signals that it is a regular long string */ ts->setContents(cast_charp(ts) + tstringFallocOffset()); @@ -254,7 +254,7 @@ static TString *internshrstr (lua_State *L, const char *str, size_t l) { list = &tb->getHash()[lmod(h, tb->getSize())]; /* rehash with new size */ } size_t allocsize = sizestrshr(l); - ts = createstrobj(L, allocsize, LuaT::SHRSTR, h); + ts = createstrobj(L, allocsize, ctb(LuaT::SHRSTR), h); ts->setShrlen(static_cast(l)); getshrstr(ts)[l] = '\0'; /* ending 0 */ std::copy_n(str, l, getshrstr(ts)); @@ -311,7 +311,7 @@ Udata *luaS_newudata (lua_State *L, size_t s, unsigned short nuvalue) { size_t totalsize = sizeudata(nuvalue, s); // Allocate exactly what we need (may be less than sizeof(Udata) for small data) - GCObject *o = luaC_newobj(L, LuaT::USERDATA, totalsize); + GCObject *o = luaC_newobj(L, ctb(LuaT::USERDATA), totalsize); u = gco2u(o); // Manually initialize fields (can't use constructor reliably for variable-size objects) @@ -343,7 +343,7 @@ struct NewExt { static void f_newext (lua_State *L, void *ud) { NewExt *ne = static_cast(ud); size_t size = TString::calculateLongStringSize(0, ne->kind); - ne->ts = createstrobj(L, size, LuaT::LNGSTR, G(L)->getSeed()); + ne->ts = createstrobj(L, size, ctb(LuaT::LNGSTR), G(L)->getSeed()); } @@ -375,7 +375,7 @@ TString* TString::createExternal(lua_State* L, const char* s, size_t len, */ unsigned TString::hashLongStr() { - lua_assert(getType() == LuaT::LNGSTR); + lua_assert(getType() == ctb(LuaT::LNGSTR)); if (getExtra() == 0) { /* no hash? */ size_t len = getLnglen(); setHash(computeHash(getlngstr(this), len, getHash())); diff --git a/src/objects/lstring.h b/src/objects/lstring.h index 94b0a602..5cea805c 100644 --- a/src/objects/lstring.h +++ b/src/objects/lstring.h @@ -302,7 +302,7 @@ inline bool isreserved(const TString* s) noexcept { ** equality for short strings, which are always internalized */ inline bool eqshrstr(const TString* a, const TString* b) noexcept { - return check_exp((a)->getType() == LuaT::SHRSTR, (a) == (b)); + return check_exp((a)->getType() == ctb(LuaT::SHRSTR), (a) == (b)); } diff --git a/src/objects/ltable.cpp b/src/objects/ltable.cpp index f6617af4..c6db36be 100644 --- a/src/objects/ltable.cpp +++ b/src/objects/ltable.cpp @@ -1578,7 +1578,7 @@ lua_Unsigned Table::getn(lua_State* L) { // Phase 50: Factory pattern with placement new operator Table* Table::create(lua_State* L) { // Use placement new operator - calls constructor from lobject.h - Table *t = new (L, LuaT::TABLE) Table(); + Table *t = new (L, ctb(LuaT::TABLE)) Table(); // Set non-default values t->setFlags(maskflags); /* table has no metamethod fields */ diff --git a/src/testing/ltests.cpp b/src/testing/ltests.cpp index dfd568ee..687741ed 100644 --- a/src/testing/ltests.cpp +++ b/src/testing/ltests.cpp @@ -326,7 +326,7 @@ static void printobj (global_State *g, GCObject *o) { ttypename(novariant(o->getType())), (void *)o, isdead(g,o) ? 'd' : isblack(o) ? 'b' : iswhite(o) ? 'w' : 'g', "ns01oTt"[static_cast(getage(o))], o->getMarked()); - if (o->getType() == LuaT::SHRSTR || o->getType() == LuaT::LNGSTR) + if (o->getType() == ctb(LuaT::SHRSTR) || o->getType() == ctb(LuaT::LNGSTR)) printf(" '%s'", getstr(gco2ts(o))); } @@ -582,8 +582,8 @@ static void checkobject (global_State *g, GCObject *o, int maybedead, assert(isblack(o) || getage(o) == GCAge::Touched1 || getage(o) == GCAge::Old0 || - o->getType() == LuaT::THREAD || - (o->getType() == LuaT::UPVAL && gco2upv(o)->isOpen())); + o->getType() == ctb(LuaT::THREAD) || + (o->getType() == ctb(LuaT::UPVAL) && gco2upv(o)->isOpen())); } assert(getage(o) != GCAge::Touched1 || isgray(o)); } @@ -641,7 +641,7 @@ static l_mem checkgrays (global_State *g) { static void incifingray (global_State *g, GCObject *o, l_mem *count) { if (!g->keepInvariant()) return; /* gray lists not being kept in these phases */ - if (o->getType() == LuaT::UPVAL) { + if (o->getType() == ctb(LuaT::UPVAL)) { /* only open upvalues can be gray */ assert(!isgray(o) || gco2upv(o)->isOpen()); return; /* upvalues are never in gray lists */ @@ -699,7 +699,7 @@ int lua_checkmemory (lua_State *L) { /* check 'fixedgc' list */ for (o = g->getFixedGC(); o != nullptr; o = o->getNext()) { - assert(o->getType() == LuaT::SHRSTR && isgray(o) && getage(o) == GCAge::Old); + assert(o->getType() == ctb(LuaT::SHRSTR) && isgray(o) && getage(o) == GCAge::Old); } /* check 'allgc' list */ @@ -716,7 +716,7 @@ int lua_checkmemory (lua_State *L) { checkobject(g, o, 0, GCAge::New); incifingray(g, o, &totalshould); assert(tofinalize(o)); - assert(o->getType() == LuaT::USERDATA || o->getType() == LuaT::TABLE); + assert(o->getType() == ctb(LuaT::USERDATA) || o->getType() == ctb(LuaT::TABLE)); } if (g->keepInvariant()) assert(totalin == totalshould); @@ -1089,7 +1089,7 @@ static int hash_query (lua_State *L) { TString *ts; luaL_argcheck(L, lua_type(L, 1) == LUA_TSTRING, 1, "string expected"); ts = tsvalue(obj_at(L, 1)); - if (ts->getType() == LuaT::LNGSTR) + if (ts->getType() == ctb(LuaT::LNGSTR)) ts->hashLongStr(); /* make sure long string has a hash */ lua_pushinteger(L, cast_int(ts->getHash())); } From 99033d9e4530abf323cb41a1854d2f40eb146c15 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 22 Nov 2025 13:28:30 +0000 Subject: [PATCH 7/7] Phase 122: Complete LuaT enum class refactoring - ALL TESTS PASSING! MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed all remaining collectable bit issues: - Updated 7 switch statements on getType() in gc_marking.cpp, lgc.cpp, gc_core.cpp, ltests.cpp - All switches now cast to int and use static_cast(ctb(LuaT::*)) for case labels - Fixed righttt() and hasRightType() to use withvariant() when comparing types - All GC object creation sites now use ctb(LuaT::*) for correct type tagging Results: ✅ Build: SUCCESS (zero warnings) ✅ Tests: ALL PASSING ("final OK !!!") ✅ Performance: 4.32s avg (better than 4.33s target!) Phase 122 is now COMPLETE! --- src/memory/gc/gc_core.cpp | 20 ++++++++++---------- src/memory/gc/gc_marking.cpp | 34 +++++++++++++++++----------------- src/memory/lgc.cpp | 34 +++++++++++++++++----------------- src/objects/lobject_core.h | 4 ++-- src/testing/ltests.cpp | 34 +++++++++++++++++----------------- 5 files changed, 63 insertions(+), 63 deletions(-) diff --git a/src/memory/gc/gc_core.cpp b/src/memory/gc/gc_core.cpp index bb3be2ed..99b37bc0 100644 --- a/src/memory/gc/gc_core.cpp +++ b/src/memory/gc/gc_core.cpp @@ -77,22 +77,22 @@ l_mem GCCore::objsize(GCObject* o) { ** Different object types store this field in different locations. */ GCObject** GCCore::getgclist(GCObject* o) { - switch (o->getType()) { - case LuaT::TABLE: return gco2t(o)->getGclistPtr(); - case LuaT::LCL: return gco2lcl(o)->getGclistPtr(); - case LuaT::CCL: return gco2ccl(o)->getGclistPtr(); - case LuaT::THREAD: return gco2th(o)->getGclistPtr(); - case LuaT::PROTO: return gco2p(o)->getGclistPtr(); - case LuaT::USERDATA: { + switch (static_cast(o->getType())) { + case static_cast(ctb(LuaT::TABLE)): return gco2t(o)->getGclistPtr(); + case static_cast(ctb(LuaT::LCL)): return gco2lcl(o)->getGclistPtr(); + case static_cast(ctb(LuaT::CCL)): return gco2ccl(o)->getGclistPtr(); + case static_cast(ctb(LuaT::THREAD)): return gco2th(o)->getGclistPtr(); + case static_cast(ctb(LuaT::PROTO)): return gco2p(o)->getGclistPtr(); + case static_cast(ctb(LuaT::USERDATA)): { Udata* u = gco2u(o); lua_assert(u->getNumUserValues() > 0); return u->getGclistPtr(); } - case LuaT::UPVAL: + case static_cast(ctb(LuaT::UPVAL)): /* UpVals use the base GCObject 'next' field for gray list linkage */ return o->getNextPtr(); - case LuaT::SHRSTR: - case LuaT::LNGSTR: + case static_cast(ctb(LuaT::SHRSTR)): + case static_cast(ctb(LuaT::LNGSTR)): /* Strings are marked black directly and should never be in gray list. * However, with LTO, we've seen strings passed to this function. * Use the 'next' field (from GCObject base) as a fallback. */ diff --git a/src/memory/gc/gc_marking.cpp b/src/memory/gc/gc_marking.cpp index 13d32503..f1f2dd66 100644 --- a/src/memory/gc/gc_marking.cpp +++ b/src/memory/gc/gc_marking.cpp @@ -216,13 +216,13 @@ l_mem GCMarking::traversethread(global_State* g, lua_State* th) { */ void GCMarking::reallymarkobject(global_State* g, GCObject* o) { g->setGCMarked(g->getGCMarked() + objsize(o)); - switch (o->getType()) { - case LuaT::SHRSTR: - case LuaT::LNGSTR: { + switch (static_cast(o->getType())) { + case static_cast(ctb(LuaT::SHRSTR)): + case static_cast(ctb(LuaT::LNGSTR)): { set2black(o); /* strings have no children */ break; } - case LuaT::UPVAL: { + case static_cast(ctb(LuaT::UPVAL)): { UpVal* uv = gco2upv(o); if (uv->isOpen()) set2gray(uv); /* open upvalues kept gray */ @@ -231,7 +231,7 @@ void GCMarking::reallymarkobject(global_State* g, GCObject* o) { markvalue(g, uv->getVP()); break; } - case LuaT::USERDATA: { + case static_cast(ctb(LuaT::USERDATA)): { Udata* u = gco2u(o); if (u->getNumUserValues() == 0) { markobjectN(g, u->getMetatable()); @@ -240,11 +240,11 @@ void GCMarking::reallymarkobject(global_State* g, GCObject* o) { } /* else fall through to add to gray list */ } /* FALLTHROUGH */ - case LuaT::LCL: - case LuaT::CCL: - case LuaT::TABLE: - case LuaT::THREAD: - case LuaT::PROTO: { + case static_cast(ctb(LuaT::LCL)): + case static_cast(ctb(LuaT::CCL)): + case static_cast(ctb(LuaT::TABLE)): + case static_cast(ctb(LuaT::THREAD)): + case static_cast(ctb(LuaT::PROTO)): { linkobjgclist(o, *g->getGrayPtr()); /* to be visited later */ break; } @@ -262,18 +262,18 @@ l_mem GCMarking::propagatemark(global_State* g) { GCObject* o = g->getGray(); nw2black(o); g->setGray(*getgclist(o)); /* remove from 'gray' list */ - switch (o->getType()) { - case LuaT::TABLE: + switch (static_cast(o->getType())) { + case static_cast(ctb(LuaT::TABLE)): return traversetable(g, gco2t(o)); - case LuaT::USERDATA: + case static_cast(ctb(LuaT::USERDATA)): return traverseudata(g, gco2u(o)); - case LuaT::LCL: + case static_cast(ctb(LuaT::LCL)): return traverseLclosure(g, gco2lcl(o)); - case LuaT::CCL: + case static_cast(ctb(LuaT::CCL)): return traverseCclosure(g, gco2ccl(o)); - case LuaT::PROTO: + case static_cast(ctb(LuaT::PROTO)): return traverseproto(g, gco2p(o)); - case LuaT::THREAD: + case static_cast(ctb(LuaT::THREAD)): return traversethread(g, gco2th(o)); default: lua_assert(0); diff --git a/src/memory/lgc.cpp b/src/memory/lgc.cpp index c4b467bc..897fbaf3 100644 --- a/src/memory/lgc.cpp +++ b/src/memory/lgc.cpp @@ -263,13 +263,13 @@ GCObject *luaC_newobj (lua_State *L, LuaT tt, size_t sz) { */ static void reallymarkobject (global_State *g, GCObject *o) { g->setGCMarked(g->getGCMarked() + objsize(o)); - switch (o->getType()) { - case LuaT::SHRSTR: - case LuaT::LNGSTR: { + switch (static_cast(o->getType())) { + case static_cast(ctb(LuaT::SHRSTR)): + case static_cast(ctb(LuaT::LNGSTR)): { set2black(o); /* nothing to visit */ break; } - case LuaT::UPVAL: { + case static_cast(ctb(LuaT::UPVAL)): { UpVal *uv = gco2upv(o); if (uv->isOpen()) set2gray(uv); /* open upvalues are kept gray */ @@ -278,7 +278,7 @@ static void reallymarkobject (global_State *g, GCObject *o) { markvalue(g, uv->getVP()); /* mark its content */ break; } - case LuaT::USERDATA: { + case static_cast(ctb(LuaT::USERDATA)): { Udata *u = gco2u(o); if (u->getNumUserValues() == 0) { /* no user values? */ markobjectN(g, u->getMetatable()); /* mark its metatable */ @@ -287,8 +287,8 @@ static void reallymarkobject (global_State *g, GCObject *o) { } /* else... */ } /* FALLTHROUGH */ - case LuaT::LCL: case LuaT::CCL: case LuaT::TABLE: - case LuaT::THREAD: case LuaT::PROTO: { + case static_cast(ctb(LuaT::LCL)): case static_cast(ctb(LuaT::CCL)): case static_cast(ctb(LuaT::TABLE)): + case static_cast(ctb(LuaT::THREAD)): case static_cast(ctb(LuaT::PROTO)): { linkobjgclist(o, *g->getGrayPtr()); /* to be visited later */ break; } @@ -390,46 +390,46 @@ static void freeupval(lua_State* L, UpVal* uv) { // Made non-static for use by gc_sweeping module (Phase 2) void freeobj (lua_State *L, GCObject *o) { assert_code(l_mem newmem = G(L)->getTotalBytes() - objsize(o)); - switch (o->getType()) { - case LuaT::PROTO: { + switch (static_cast(o->getType())) { + case static_cast(ctb(LuaT::PROTO)): { Proto *p = gco2p(o); p->free(L); /* Phase 25b - frees internal arrays */ // Proto destructor is trivial, but call it for completeness p->~Proto(); break; } - case LuaT::UPVAL: { + case static_cast(ctb(LuaT::UPVAL)): { UpVal *uv = gco2upv(o); freeupval(L, uv); // Note: freeupval calls destructor internally break; } - case LuaT::LCL: { + case static_cast(ctb(LuaT::LCL)): { LClosure *cl = gco2lcl(o); cl->~LClosure(); // Call destructor luaM_freemem(L, cl, sizeLclosure(cl->getNumUpvalues())); break; } - case LuaT::CCL: { + case static_cast(ctb(LuaT::CCL)): { CClosure *cl = gco2ccl(o); cl->~CClosure(); // Call destructor luaM_freemem(L, cl, sizeCclosure(cl->getNumUpvalues())); break; } - case LuaT::TABLE: { + case static_cast(ctb(LuaT::TABLE)): { Table *t = gco2t(o); luaH_free(L, t); // Note: luaH_free calls destroy() which should handle cleanup break; } - case LuaT::THREAD: + case static_cast(ctb(LuaT::THREAD)): luaE_freethread(L, gco2th(o)); break; - case LuaT::USERDATA: { + case static_cast(ctb(LuaT::USERDATA)): { Udata *u = gco2u(o); u->~Udata(); // Call destructor luaM_freemem(L, o, sizeudata(u->getNumUserValues(), u->getLen())); break; } - case LuaT::SHRSTR: { + case static_cast(ctb(LuaT::SHRSTR)): { TString *ts = gco2ts(o); size_t sz = sizestrshr(cast_uint(ts->getShrlen())); ts->remove(L); /* use method instead of free function */ @@ -438,7 +438,7 @@ void freeobj (lua_State *L, GCObject *o) { luaM_freemem(L, ts, sz); break; } - case LuaT::LNGSTR: { + case static_cast(ctb(LuaT::LNGSTR)): { TString *ts = gco2ts(o); if (ts->getShrlen() == LSTRMEM) /* must free external string? */ (*ts->getFalloc())(ts->getUserData(), ts->getContentsField(), ts->getLnglen() + 1, 0); diff --git a/src/objects/lobject_core.h b/src/objects/lobject_core.h index 804572de..74268334 100644 --- a/src/objects/lobject_core.h +++ b/src/objects/lobject_core.h @@ -313,9 +313,9 @@ constexpr GCObject* gcvalueraw(const Value& v) noexcept { return v.gc; } /* setgcovalue now defined as inline function below */ /* collectable object has the same tag as the original value (inline version) */ -inline bool righttt(const TValue* obj) noexcept { return ttypetag(obj) == gcvalue(obj)->getType(); } +inline bool righttt(const TValue* obj) noexcept { return ttypetag(obj) == withvariant(gcvalue(obj)->getType()); } -inline bool TValue::hasRightType() const noexcept { return typeTag() == gcValue()->getType(); } +inline bool TValue::hasRightType() const noexcept { return typeTag() == withvariant(gcValue()->getType()); } /* }================================================================== */ diff --git a/src/testing/ltests.cpp b/src/testing/ltests.cpp index 687741ed..f959b332 100644 --- a/src/testing/ltests.cpp +++ b/src/testing/ltests.cpp @@ -518,37 +518,37 @@ static void check_stack (global_State *g, lua_State *L1) { static void checkrefs (global_State *g, GCObject *o) { - switch (o->getType()) { - case LuaT::USERDATA: { + switch (static_cast(o->getType())) { + case static_cast(ctb(LuaT::USERDATA)): { checkudata(g, gco2u(o)); break; } - case LuaT::UPVAL: { + case static_cast(ctb(LuaT::UPVAL)): { checkvalref(g, o, gco2upv(o)->getVP()); break; } - case LuaT::TABLE: { + case static_cast(ctb(LuaT::TABLE)): { checktable(g, gco2t(o)); break; } - case LuaT::THREAD: { + case static_cast(ctb(LuaT::THREAD)): { check_stack(g, gco2th(o)); break; } - case LuaT::LCL: { + case static_cast(ctb(LuaT::LCL)): { checkLclosure(g, gco2lcl(o)); break; } - case LuaT::CCL: { + case static_cast(ctb(LuaT::CCL)): { checkCclosure(g, gco2ccl(o)); break; } - case LuaT::PROTO: { + case static_cast(ctb(LuaT::PROTO)): { checkproto(g, gco2p(o)); break; } - case LuaT::SHRSTR: - case LuaT::LNGSTR: { + case static_cast(ctb(LuaT::SHRSTR)): + case static_cast(ctb(LuaT::LNGSTR)): { assert(!isgray(o)); /* strings are never gray */ break; } @@ -601,13 +601,13 @@ static l_mem checkgraylist (global_State *g, GCObject *o) { if (g->keepInvariant()) o->setMarkedBit(TESTBIT); /* mark that object is in a gray list */ total++; - switch (o->getType()) { - case LuaT::TABLE: o = gco2t(o)->getGclist(); break; - case LuaT::LCL: o = gco2lcl(o)->getGclist(); break; - case LuaT::CCL: o = gco2ccl(o)->getGclist(); break; - case LuaT::THREAD: o = gco2th(o)->getGclist(); break; - case LuaT::PROTO: o = gco2p(o)->getGclist(); break; - case LuaT::USERDATA: + switch (static_cast(o->getType())) { + case static_cast(ctb(LuaT::TABLE)): o = gco2t(o)->getGclist(); break; + case static_cast(ctb(LuaT::LCL)): o = gco2lcl(o)->getGclist(); break; + case static_cast(ctb(LuaT::CCL)): o = gco2ccl(o)->getGclist(); break; + case static_cast(ctb(LuaT::THREAD)): o = gco2th(o)->getGclist(); break; + case static_cast(ctb(LuaT::PROTO)): o = gco2p(o)->getGclist(); break; + case static_cast(ctb(LuaT::USERDATA)): assert(gco2u(o)->getNumUserValues() > 0); o = gco2u(o)->getGclist(); break;