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
23 changes: 12 additions & 11 deletions src/compiler/funcstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ short FuncState::registerlocalvar(TString *varname) {
int oldsize = proto->getLocVarsSize();
luaM_growvector(getLexState()->getLuaState(), proto->getLocVarsRef(), getNumDebugVars(), proto->getLocVarsSizeRef(),
LocVar, SHRT_MAX, "local variables");
while (oldsize < proto->getLocVarsSize())
proto->getLocVars()[oldsize++].setVarName(nullptr);
proto->getLocVars()[getNumDebugVars()].setVarName(varname);
proto->getLocVars()[getNumDebugVars()].setStartPC(getPC());
auto locVarsSpan = proto->getDebugInfo().getLocVarsSpan();
while (oldsize < static_cast<int>(locVarsSpan.size()))
locVarsSpan[oldsize++].setVarName(nullptr);
locVarsSpan[getNumDebugVars()].setVarName(varname);
locVarsSpan[getNumDebugVars()].setStartPC(getPC());
luaC_objbarrier(getLexState()->getLuaState(), proto, varname);
return postIncrementNumDebugVars();
}
Expand Down Expand Up @@ -181,10 +182,9 @@ void FuncState::removevars(int tolevel) {
** with the given 'name'.
*/
int FuncState::searchupvalue(TString *name) {
int i;
Upvaldesc *up = getProto()->getUpvalues();
for (i = 0; i < getNumUpvalues(); i++) {
if (eqstr(up[i].getName(), name)) return i;
auto upvaluesSpan = getProto()->getUpvaluesSpan();
for (size_t i = 0; i < static_cast<size_t>(getNumUpvalues()); i++) {
if (eqstr(upvaluesSpan[i].getName(), name)) return static_cast<int>(i);
}
return -1; /* not found */
}
Expand All @@ -196,9 +196,10 @@ Upvaldesc *FuncState::allocupvalue() {
checklimit(getNumUpvalues() + 1, MAXUPVAL, "upvalues");
luaM_growvector(getLexState()->getLuaState(), proto->getUpvaluesRef(), getNumUpvalues(), proto->getUpvaluesSizeRef(),
Upvaldesc, MAXUPVAL, "upvalues");
while (oldsize < proto->getUpvaluesSize())
proto->getUpvalues()[oldsize++].setName(nullptr);
return &proto->getUpvalues()[getNumUpvaluesRef()++];
auto upvaluesSpan = proto->getUpvaluesSpan();
while (oldsize < static_cast<int>(upvaluesSpan.size()))
upvaluesSpan[oldsize++].setName(nullptr);
return &upvaluesSpan[getNumUpvaluesRef()++];
}


Expand Down
14 changes: 8 additions & 6 deletions src/compiler/lcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,10 @@ int FuncState::addk(Proto *proto, TValue *v) {
int oldsize = proto->getConstantsSize();
int k = getNK();
luaM_growvector(L, proto->getConstantsRef(), k, proto->getConstantsSizeRef(), TValue, MAXARG_Ax, "constants");
while (oldsize < proto->getConstantsSize())
setnilvalue(&proto->getConstants()[oldsize++]);
proto->getConstants()[k] = *v;
auto constantsSpan = proto->getConstantsSpan();
while (oldsize < static_cast<int>(constantsSpan.size()))
setnilvalue(&constantsSpan[oldsize++]);
constantsSpan[k] = *v;
incrementNK();
luaC_barrier(L, proto, v);
return k;
Expand Down Expand Up @@ -1071,10 +1072,10 @@ void FuncState::codeconcat(expdesc *e1, expdesc *e2, int line) {
** return the final target of a jump (skipping jumps to jumps)
*/
int FuncState::finaltarget(int i) {
Instruction *code = getProto()->getCode();
auto codeSpan = getProto()->getCodeSpan();
int count;
for (count = 0; count < 100; count++) { /* avoid infinite loops */
Instruction instr = code[i];
Instruction instr = codeSpan[i];
if (InstructionView(instr).opcode() != OP_JMP)
break;
else
Expand Down Expand Up @@ -1654,8 +1655,9 @@ void FuncState::setlist(int base, int nelems, int tostore) {
void FuncState::finish() {
int i;
Proto *p = getProto();
auto codeSpan = p->getCodeSpan();
for (i = 0; i < getPC(); i++) {
Instruction *instr = &p->getCode()[i];
Instruction *instr = &codeSpan[i];
/* avoid "not used" warnings when assert is off (for 'onelua.c') */
(void)luaP_isOT; (void)luaP_isIT;
lua_assert(i == 0 || luaP_isOT(*(instr - 1)) == luaP_isIT(*instr));
Expand Down
7 changes: 4 additions & 3 deletions src/compiler/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,10 +412,11 @@ Proto *Parser::addprototype() {
if (funcstate->getNP() >= proto->getProtosSize()) {
int oldsize = proto->getProtosSize();
luaM_growvector(state, proto->getProtosRef(), funcstate->getNP(), proto->getProtosSizeRef(), Proto *, MAXARG_Bx, "functions");
while (oldsize < proto->getProtosSize())
proto->getProtos()[oldsize++] = nullptr;
auto protosSpan = proto->getProtosSpan();
while (oldsize < static_cast<int>(protosSpan.size()))
protosSpan[oldsize++] = nullptr;
}
proto->getProtos()[funcstate->getNPRef()++] = clp = luaF_newproto(state);
proto->getProtosSpan()[funcstate->getNPRef()++] = clp = luaF_newproto(state);
luaC_objbarrier(state, proto, clp);
return clp;
}
Expand Down
6 changes: 3 additions & 3 deletions src/memory/gc/gc_weak.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@
** For other objects: if really collected, cannot keep them; for objects
** being finalized, keep them in keys, but not in values.
*/
static int iscleared(global_State* g, const GCObject* o) {
if (o == nullptr) return 0; /* non-collectable value */
static bool iscleared(global_State* g, const GCObject* o) {
if (o == nullptr) return false; /* non-collectable value */
else if (novariant(o->getType()) == LUA_TSTRING) {
markobject(g, o); /* strings are 'values', so are never weak */
return 0;
return false;
}
else return iswhite(o);
}
Expand Down
10 changes: 6 additions & 4 deletions src/objects/lfunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,12 +319,14 @@ void luaF_freeproto (lua_State *L, Proto *f) {
** Returns nullptr if not found.
*/
const char* Proto::getLocalName(int local_number, int pc) const {
int i;
for (i = 0; i<getLocVarsSize() && getLocVars()[i].getStartPC() <= pc; i++) {
if (pc < getLocVars()[i].getEndPC()) { /* is variable active? */
auto locVarsSpan = getDebugInfo().getLocVarsSpan();
for (const auto& locvar : locVarsSpan) {
if (locvar.getStartPC() > pc)
break;
if (pc < locvar.getEndPC()) { /* is variable active? */
local_number--;
if (local_number == 0)
return getstr(getLocVars()[i].getVarName());
return getstr(locvar.getVarName());
}
}
return nullptr; /* not found */
Expand Down
6 changes: 3 additions & 3 deletions src/objects/lobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,10 @@ lu_byte luaO_hexavalue (int c) {
}


static int isneg (const char **s) {
if (**s == '-') { (*s)++; return 1; }
static bool isneg (const char **s) {
if (**s == '-') { (*s)++; return true; }
else if (**s == '+') (*s)++;
return 0;
return false;
}


Expand Down
8 changes: 4 additions & 4 deletions src/objects/ltable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1184,12 +1184,12 @@ static int finishnodeset (Table *t, TValue *slot, TValue *val) {
}


static int rawfinishnodeset (TValue *slot, TValue *val) {
static bool rawfinishnodeset (TValue *slot, TValue *val) {
if (isabstkey(slot))
return 0; /* no slot with that key */
return false; /* no slot with that key */
else {
*slot = *val;
return 1; /* success */
return true; /* success */
}
}

Expand Down Expand Up @@ -1522,7 +1522,7 @@ void Table::setInt(lua_State* L, lua_Integer key, TValue* value) {
if (ik > 0)
obj2arr(this, ik - 1, value);
else {
int ok = rawfinishnodeset(getintfromhash(this, key), value);
bool ok = rawfinishnodeset(getintfromhash(this, key), value);
if (!ok) {
TValue k;
setivalue(&k, key);
Expand Down
6 changes: 3 additions & 3 deletions src/serialization/lzio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ void luaZ_init (lua_State *L, ZIO *z, lua_Reader reader, void *data) {

/* --------------------------------------------------------------- read --- */

static int checkbuffer (ZIO *z) {
static bool checkbuffer (ZIO *z) {
if (z->n == 0) { /* no bytes in buffer? */
if (luaZ_fill(z) == EOZ) /* try to read more */
return 0; /* no more input */
return false; /* no more input */
else {
z->n++; /* luaZ_fill consumed first byte; put it back */
z->p--;
}
}
return 1; /* now buffer has something */
return true; /* now buffer has something */
}


Expand Down
55 changes: 34 additions & 21 deletions src/testing/ltests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,19 +443,18 @@ static void checkudata (global_State *g, Udata *u) {


static void checkproto (global_State *g, Proto *f) {
int i;
GCObject *fgc = obj2gco(f);
checkobjrefN(g, fgc, f->getSource());
for (i=0; i<f->getConstantsSize(); i++) {
if (iscollectable(f->getConstants() + i))
checkobjref(g, fgc, gcvalue(f->getConstants() + i));
for (const auto& constant : f->getConstantsSpan()) {
if (iscollectable(&constant))
checkobjref(g, fgc, gcvalue(&constant));
}
for (i=0; i<f->getUpvaluesSize(); i++)
checkobjrefN(g, fgc, f->getUpvalues()[i].getName());
for (i=0; i<f->getProtosSize(); i++)
checkobjrefN(g, fgc, f->getProtos()[i]);
for (i=0; i<f->getLocVarsSize(); i++)
checkobjrefN(g, fgc, f->getLocVars()[i].getVarName());
for (const auto& upval : f->getUpvaluesSpan())
checkobjrefN(g, fgc, upval.getName());
for (Proto* proto : f->getProtosSpan())
checkobjrefN(g, fgc, proto);
for (const auto& locvar : f->getDebugInfo().getLocVarsSpan())
checkobjrefN(g, fgc, locvar.getVarName());
}


Expand Down Expand Up @@ -487,8 +486,10 @@ static int lua_checkpc (CallInfo *ci) {
else {
StkId f = ci->funcRef().p;
Proto *p = clLvalue(s2v(f))->getProto();
return p->getCode() <= ci->getSavedPC() &&
ci->getSavedPC() <= p->getCode() + p->getCodeSize();
auto codeSpan = p->getCodeSpan();
const Instruction* savedPC = ci->getSavedPC();
return codeSpan.data() <= savedPC &&
savedPC <= codeSpan.data() + codeSpan.size();
}
}

Expand Down Expand Up @@ -781,11 +782,14 @@ static int listcode (lua_State *L) {
lua_newtable(L);
setnameval(L, "maxstack", p->getMaxStackSize());
setnameval(L, "numparams", p->getNumParams());
for (pc=0; pc<p->getCodeSize(); pc++) {
pc = 0;
for (const auto& instr : p->getCodeSpan()) {
(void)instr; /* unused */
char buff[100];
lua_pushinteger(L, pc+1);
lua_pushstring(L, buildop(p, pc, buff));
lua_settable(L, -3);
pc++;
}
return 1;
}
Expand All @@ -799,9 +803,12 @@ static int printcode (lua_State *L) {
p = getproto(obj_at(L, 1));
printf("maxstack: %d\n", p->getMaxStackSize());
printf("numparams: %d\n", p->getNumParams());
for (pc=0; pc<p->getCodeSize(); pc++) {
pc = 0;
for (const auto& instr : p->getCodeSpan()) {
(void)instr; /* unused */
char buff[100];
printf("%s\n", buildop(p, pc, buff));
pc++;
}
return 0;
}
Expand All @@ -813,10 +820,13 @@ static int listk (lua_State *L) {
luaL_argcheck(L, lua_isfunction(L, 1) && !lua_iscfunction(L, 1),
1, "Lua function expected");
p = getproto(obj_at(L, 1));
lua_createtable(L, p->getConstantsSize(), 0);
for (i=0; i<p->getConstantsSize(); i++) {
pushobject(L, p->getConstants()+i);
auto constantsSpan = p->getConstantsSpan();
lua_createtable(L, static_cast<int>(constantsSpan.size()), 0);
i = 0;
for (const auto& constant : constantsSpan) {
pushobject(L, &constant);
lua_rawseti(L, -2, i+1);
i++;
}
return 1;
}
Expand All @@ -829,12 +839,15 @@ static int listabslineinfo (lua_State *L) {
1, "Lua function expected");
p = getproto(obj_at(L, 1));
luaL_argcheck(L, p->getAbsLineInfo() != nullptr, 1, "function has no debug info");
lua_createtable(L, 2 * p->getAbsLineInfoSize(), 0);
for (i=0; i < p->getAbsLineInfoSize(); i++) {
lua_pushinteger(L, p->getAbsLineInfo()[i].getPC());
auto absLineInfoSpan = p->getDebugInfo().getAbsLineInfoSpan();
lua_createtable(L, 2 * static_cast<int>(absLineInfoSpan.size()), 0);
i = 0;
for (const auto& absline : absLineInfoSpan) {
lua_pushinteger(L, absline.getPC());
lua_rawseti(L, -2, 2 * i + 1);
lua_pushinteger(L, p->getAbsLineInfo()[i].getLine());
lua_pushinteger(L, absline.getLine());
lua_rawseti(L, -2, 2 * i + 2);
i++;
}
return 1;
}
Expand Down
15 changes: 8 additions & 7 deletions src/vm/lvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,18 +135,19 @@ inline constexpr int MAXTAGLOOP = 2000;
** its upvalues.
*/
void lua_State::pushClosure(Proto *p, UpVal **encup, StkId base, StkId ra) {
int nup = p->getUpvaluesSize();
Upvaldesc *uv = p->getUpvalues();
int i;
auto upvaluesSpan = p->getUpvaluesSpan();
int nup = static_cast<int>(upvaluesSpan.size());
int i = 0;
LClosure *ncl = LClosure::create(this, nup);
ncl->setProto(p);
setclLvalue2s(this, ra, ncl); /* anchor new closure in stack */
for (i = 0; i < nup; i++) { /* fill in its upvalues */
if (uv[i].isInStack()) /* upvalue refers to local variable? */
ncl->setUpval(i, luaF_findupval(this, base + uv[i].getIndex()));
for (const auto& uv : upvaluesSpan) { /* fill in its upvalues */
if (uv.isInStack()) /* upvalue refers to local variable? */
ncl->setUpval(i, luaF_findupval(this, base + uv.getIndex()));
else /* get upvalue from enclosing function */
ncl->setUpval(i, encup[uv[i].getIndex()]);
ncl->setUpval(i, encup[uv.getIndex()]);
luaC_objbarrier(this, ncl, ncl->getUpval(i));
i++;
}
}

Expand Down
Loading