Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/compiler/lopcodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "lprefix.h"


#include <array>
#include "lopcodes.h"


Expand All @@ -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 */
Expand Down
4 changes: 3 additions & 1 deletion src/compiler/lopcodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#ifndef lopcodes_h
#define lopcodes_h

#include <array>
#include "llimits.h"
#include "lobject.h"

Expand Down Expand Up @@ -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<lu_byte, NUM_OPCODES>;
LUAI_DDEC(const OpModesArray luaP_opmodes;)

inline OpMode getOpMode(int m) noexcept {
return static_cast<OpMode>(luaP_opmodes[m] & 7);
Expand Down
9 changes: 9 additions & 0 deletions src/compiler/lparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#ifndef lparser_h
#define lparser_h

#include <span>
#include "llimits.h"
#include "lobject.h"
#include "lopcodes.h"
Expand Down Expand Up @@ -277,6 +278,14 @@ class Dyndata {
return &actvar_vec.back();
}

/* Phase 116: std::span accessors for actvar array */
inline std::span<Vardesc> actvarGetSpan() noexcept {
return std::span(actvar_vec.data(), actvar_vec.size());
}
inline std::span<const Vardesc> actvarGetSpan() const noexcept {
return std::span(actvar_vec.data(), actvar_vec.size());
}

/* Legacy accessor interface for backward compatibility */
class ActvarAccessor {
private:
Expand Down
5 changes: 3 additions & 2 deletions src/core/ltm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "lprefix.h"


#include <array>
#include <cstring>

#include "lua.h"
Expand All @@ -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",
Expand All @@ -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<const char*, 25> luaT_eventname = { /* ORDER TM */
"__index", "__newindex",
"__gc", "__mode", "__len", "__eq",
"__add", "__sub", "__mul", "__mod", "__pow",
Expand Down
4 changes: 3 additions & 1 deletion src/core/ltm.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define ltm_h


#include <array>
#include "lobject.h"


Expand Down Expand Up @@ -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<const char*, LUA_TOTALTYPES>;
LUAI_DDEC(const TypeNamesArray luaT_typenames_;)

inline const char* ttypename(int x) noexcept {
return luaT_typenames_[x + 1];
Expand Down
16 changes: 8 additions & 8 deletions src/libraries/lstrlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions src/objects/ltable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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:
Expand Down Expand Up @@ -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);
}
Expand Down
3 changes: 2 additions & 1 deletion src/vm/lopnames.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
#if !defined(lopnames_h)
#define lopnames_h

#include <array>
#include <cstddef>


/* ORDER OP */

static const char *const opnames[] = {
static constexpr std::array<const char*, 84> opnames = {
"MOVE",
"LOADI",
"LOADF",
Expand Down
Loading