diff --git a/src/compiler/lopcodes.cpp b/src/compiler/lopcodes.cpp index dadfe345..22960f9c 100644 --- a/src/compiler/lopcodes.cpp +++ b/src/compiler/lopcodes.cpp @@ -10,6 +10,7 @@ #include "lprefix.h" +#include #include "lopcodes.h" @@ -19,7 +20,7 @@ /* ORDER OP */ -LUAI_DDEF const lu_byte luaP_opmodes[NUM_OPCODES] = { +LUAI_DDEF const OpModesArray luaP_opmodes = { /* MM OT IT T A mode opcode */ opmode(0, 0, 0, 0, 1, OpMode::iABC) /* OP_MOVE */ ,opmode(0, 0, 0, 0, 1, OpMode::iAsBx) /* OP_LOADI */ diff --git a/src/compiler/lopcodes.h b/src/compiler/lopcodes.h index f021ff36..b8d1fb62 100644 --- a/src/compiler/lopcodes.h +++ b/src/compiler/lopcodes.h @@ -7,6 +7,7 @@ #ifndef lopcodes_h #define lopcodes_h +#include #include "llimits.h" #include "lobject.h" @@ -548,7 +549,8 @@ inline constexpr int NUM_OPCODES = ((int)(OP_EXTRAARG) + 1); ** bit 7: instruction is an MM instruction (call a metamethod) */ -LUAI_DDEC(const lu_byte luaP_opmodes[NUM_OPCODES];) +using OpModesArray = std::array; +LUAI_DDEC(const OpModesArray luaP_opmodes;) inline OpMode getOpMode(int m) noexcept { return static_cast(luaP_opmodes[m] & 7); diff --git a/src/compiler/lparser.h b/src/compiler/lparser.h index 8f552525..506f22f0 100644 --- a/src/compiler/lparser.h +++ b/src/compiler/lparser.h @@ -7,6 +7,7 @@ #ifndef lparser_h #define lparser_h +#include #include "llimits.h" #include "lobject.h" #include "lopcodes.h" @@ -277,6 +278,14 @@ class Dyndata { return &actvar_vec.back(); } + /* Phase 116: std::span accessors for actvar array */ + inline std::span actvarGetSpan() noexcept { + return std::span(actvar_vec.data(), actvar_vec.size()); + } + inline std::span actvarGetSpan() const noexcept { + return std::span(actvar_vec.data(), actvar_vec.size()); + } + /* Legacy accessor interface for backward compatibility */ class ActvarAccessor { private: diff --git a/src/core/ltm.cpp b/src/core/ltm.cpp index c64845af..e68ca9e2 100644 --- a/src/core/ltm.cpp +++ b/src/core/ltm.cpp @@ -10,6 +10,7 @@ #include "lprefix.h" +#include #include #include "lua.h" @@ -27,7 +28,7 @@ static const char udatatypename[] = "userdata"; -LUAI_DDEF const char *const luaT_typenames_[LUA_TOTALTYPES] = { +LUAI_DDEF const TypeNamesArray luaT_typenames_ = { "no value", "nil", "boolean", udatatypename, "number", "string", "table", "function", udatatypename, "thread", @@ -36,7 +37,7 @@ LUAI_DDEF const char *const luaT_typenames_[LUA_TOTALTYPES] = { void luaT_init (lua_State *L) { - static const char *const luaT_eventname[] = { /* ORDER TM */ + static constexpr std::array luaT_eventname = { /* ORDER TM */ "__index", "__newindex", "__gc", "__mode", "__len", "__eq", "__add", "__sub", "__mul", "__mod", "__pow", diff --git a/src/core/ltm.h b/src/core/ltm.h index 3976d4d3..09bbbfc8 100644 --- a/src/core/ltm.h +++ b/src/core/ltm.h @@ -8,6 +8,7 @@ #define ltm_h +#include #include "lobject.h" @@ -78,7 +79,8 @@ struct lua_State; inline const TValue* gfasttm(global_State* g, const Table* mt, TMS e) noexcept; inline const TValue* fasttm(lua_State* l, const Table* mt, TMS e) noexcept; -LUAI_DDEC(const char *const luaT_typenames_[LUA_TOTALTYPES];) +using TypeNamesArray = std::array; +LUAI_DDEC(const TypeNamesArray luaT_typenames_;) inline const char* ttypename(int x) noexcept { return luaT_typenames_[x + 1]; diff --git a/src/libraries/lstrlib.cpp b/src/libraries/lstrlib.cpp index 834b16d3..0851b48b 100644 --- a/src/libraries/lstrlib.cpp +++ b/src/libraries/lstrlib.cpp @@ -420,8 +420,8 @@ static const char *classend (MatchState *ms, const char *p) { } -static int match_class (int c, int cl) { - int res; +static bool match_class (int c, int cl) { + bool res; switch (tolower(cl)) { case 'a' : res = isalpha(c); break; case 'c' : res = iscntrl(c); break; @@ -440,10 +440,10 @@ static int match_class (int c, int cl) { } -static int matchbracketclass (int c, const char *p, const char *ec) { - int sig = 1; +static bool matchbracketclass (int c, const char *p, const char *ec) { + bool sig = true; if (*(p+1) == '^') { - sig = 0; + sig = false; p++; /* skip the '^' */ } while (++p < ec) { @@ -463,14 +463,14 @@ static int matchbracketclass (int c, const char *p, const char *ec) { } -static int singlematch (MatchState *ms, const char *s, const char *p, +static bool singlematch (MatchState *ms, const char *s, const char *p, const char *ep) { if (s >= ms->src_end) - return 0; + return false; else { int c = cast_uchar(*s); switch (*p) { - case '.': return 1; /* matches any char */ + case '.': return true; /* matches any char */ case L_ESC: return match_class(c, cast_uchar(*(p+1))); case '[': return matchbracketclass(c, p, ep-1); default: return (cast_uchar(*p) == c); diff --git a/src/objects/ltable.cpp b/src/objects/ltable.cpp index 60cb8ccb..0fc889be 100644 --- a/src/objects/ltable.cpp +++ b/src/objects/ltable.cpp @@ -371,7 +371,7 @@ static inline Node *mainpositionfromnode (const Table *t, Node *nd) { ** anything. (In particular, 'next' will return some other valid item ** on the table or nil.) */ -static int equalkey (const TValue *k1, const Node *n2, int deadok) { +static bool equalkey (const TValue *k1, const Node *n2, int deadok) { if (rawtt(k1) != n2->getKeyType()) { /* not the same variants? */ if (n2->isKeyShrStr() && ttislngstring(k1)) { /* an external string can be equal to a short-string key */ @@ -382,12 +382,12 @@ static int equalkey (const TValue *k1, const Node *n2, int deadok) { return gcvalue(k1) == gcvalueraw(n2->getKeyValue()); } else - return 0; /* otherwise, different variants cannot be equal */ + return false; /* otherwise, different variants cannot be equal */ } else { /* equal variants */ switch (n2->getKeyType()) { case LUA_VNIL: case LUA_VFALSE: case LUA_VTRUE: - return 1; + return true; case LUA_VNUMINT: return (ivalue(k1) == n2->getKeyIntValue()); case LUA_VNUMFLT: @@ -1132,7 +1132,7 @@ static TValue *getintfromhash (Table *t, lua_Integer key) { } -static int hashkeyisempty (Table *t, lua_Unsigned key) { +static bool hashkeyisempty (Table *t, lua_Unsigned key) { const TValue *val = getintfromhash(t, l_castU2S(key)); return isempty(val); } diff --git a/src/vm/lopnames.h b/src/vm/lopnames.h index bc172693..2e4d82b5 100644 --- a/src/vm/lopnames.h +++ b/src/vm/lopnames.h @@ -7,12 +7,13 @@ #if !defined(lopnames_h) #define lopnames_h +#include #include /* ORDER OP */ -static const char *const opnames[] = { +static constexpr std::array opnames = { "MOVE", "LOADI", "LOADF",