Skip to content

Conversation

@NiceAndPeter
Copy link
Owner

No description provided.

- 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
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
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
…iles)

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
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!
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<int>(getType()) and
static_cast<int>(ctb(LuaT::*)) for case labels.
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<int>(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!
@NiceAndPeter NiceAndPeter merged commit 99366a0 into main Nov 22, 2025
11 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants