@@ -222,40 +222,40 @@ inline lua_State* thvalue(const TValue* o) noexcept { return o->threadValue(); }
222222/* Common type for all collectable objects */
223223class GCObject {
224224protected:
225- GCObject* next;
226- lu_byte tt;
227- lu_byte marked;
225+ mutable GCObject* next; /* GC list linkage (mutable for GC bookkeeping) */
226+ lu_byte tt; /* Type tag (immutable) */
227+ mutable lu_byte marked; /* GC mark bits (mutable for GC bookkeeping) */
228228
229229public:
230230 // Inline accessors
231231 GCObject* getNext () const noexcept { return next; }
232- void setNext (GCObject* n) noexcept { next = n; }
232+ void setNext (GCObject* n) const noexcept { next = n; } /* const - next is mutable */
233233 // Pointer-to-pointer for efficient GC list manipulation (allows in-place removal)
234- GCObject** getNextPtr () noexcept { return &next; }
234+ GCObject** getNextPtr () const noexcept { return &next; } /* const - next is mutable */
235235 lu_byte getType () const noexcept { return tt; }
236236 void setType (lu_byte t) noexcept { tt = t; }
237237 lu_byte getMarked () const noexcept { return marked; }
238- void setMarked (lu_byte m) noexcept { marked = m; }
238+ void setMarked (lu_byte m) const noexcept { marked = m; } /* const - marked is mutable */
239239 bool isMarked () const noexcept { return marked != 0 ; }
240240
241- // Marked field bit manipulation methods
242- void setMarkedBit (int bit) noexcept { marked |= cast_byte (1 << bit); }
243- void clearMarkedBit (int bit) noexcept { marked &= cast_byte (~(1 << bit)); }
244- void clearMarkedBits (int mask) noexcept { marked &= cast_byte (~mask); }
241+ // Marked field bit manipulation methods (const - marked is mutable)
242+ void setMarkedBit (int bit) const noexcept { marked |= cast_byte (1 << bit); }
243+ void clearMarkedBit (int bit) const noexcept { marked &= cast_byte (~(1 << bit)); }
244+ void clearMarkedBits (int mask) const noexcept { marked &= cast_byte (~mask); }
245245
246246 // Marked field bit manipulation helpers (for backward compatibility)
247- lu_byte& getMarkedRef () noexcept { return marked; }
247+ lu_byte& getMarkedRef () const noexcept { return marked; } /* const - marked is mutable */
248248
249249 // GC color and age methods (defined in lgc.h after constants are available)
250250 inline bool isWhite () const noexcept ;
251251 inline bool isBlack () const noexcept ;
252252 inline bool isGray () const noexcept ;
253253 inline GCAge getAge () const noexcept ;
254- inline void setAge (GCAge age) noexcept ;
254+ inline void setAge (GCAge age) const noexcept ; /* const - marked is mutable */
255255 inline bool isOld () const noexcept ;
256256
257257 // GC operations (implemented in lgc.cpp)
258- void fix (lua_State* L);
258+ void fix (lua_State* L) const ; /* const - only modifies mutable GC fields */
259259 void checkFinalizer (lua_State* L, Table* mt);
260260};
261261
@@ -301,18 +301,18 @@ class GCBase: public GCObject {
301301public:
302302 // Accessor methods (preferred over direct field access)
303303 constexpr GCObject* getNext () const noexcept { return next; }
304- constexpr void setNext (GCObject* n) noexcept { next = n; }
304+ constexpr void setNext (GCObject* n) const noexcept { next = n; } /* const - next is mutable */
305305
306306 constexpr lu_byte getType () const noexcept { return tt; }
307307 constexpr void setType (lu_byte t) noexcept { tt = t; }
308308
309309 constexpr lu_byte getMarked () const noexcept { return marked; }
310- constexpr void setMarked (lu_byte m) noexcept { marked = m; }
310+ constexpr void setMarked (lu_byte m) const noexcept { marked = m; } /* const - marked is mutable */
311311
312312 constexpr bool isMarked () const noexcept { return marked != 0 ; }
313313
314314 // GC color and age methods (defined in lgc.h after constants)
315- inline void setAge (GCAge age) noexcept ;
315+ inline void setAge (GCAge age) const noexcept ; /* const - marked is mutable */
316316 inline bool isOld () const noexcept ;
317317
318318 // Cast to GCObject* for compatibility
@@ -1545,7 +1545,7 @@ class Node {
15451545// Table inherits from GCBase (CRTP)
15461546class Table : public GCBase <Table> {
15471547private:
1548- lu_byte flags; /* 1<<p means tagmethod(p) is not present */
1548+ mutable lu_byte flags; /* 1<<p means tagmethod(p) is not present (mutable for metamethod caching) */
15491549 lu_byte lsizenode; /* log2 of number of slots of 'node' array */
15501550 unsigned int asize; /* number of slots in 'array' array */
15511551 Value *array; /* array part */
@@ -1579,9 +1579,9 @@ class Table : public GCBase<Table> {
15791579 lu_byte getFlags () const noexcept { return flags; }
15801580 void setFlags (lu_byte f) noexcept { flags = f; }
15811581
1582- // Flags field bit manipulation methods
1583- void setFlagBits (int mask) noexcept { flags |= cast_byte (mask); }
1584- void clearFlagBits (int mask) noexcept { flags &= cast_byte (~mask); }
1582+ // Flags field bit manipulation methods (const - flags is mutable)
1583+ void setFlagBits (int mask) const noexcept { flags |= cast_byte (mask); }
1584+ void clearFlagBits (int mask) const noexcept { flags &= cast_byte (~mask); }
15851585
15861586 // Flags field reference accessor (for backward compatibility)
15871587 lu_byte& getFlagsRef () noexcept { return flags; }
0 commit comments