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
62 changes: 31 additions & 31 deletions src/compiler/lcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ Instruction *FuncState::previousinstruction() {
** a list of jumps.
*/
int FuncState::getjump(int position) {
int offset = InstructionView(getProto()->getCode()[position]).sj();
auto offset = InstructionView(getProto()->getCode()[position]).sj();
if (offset == NO_JUMP) /* point to itself represents end of list */
return NO_JUMP; /* end of list */
else
Expand All @@ -101,8 +101,8 @@ int FuncState::getjump(int position) {
** (Jump addresses are relative in Lua)
*/
void FuncState::fixjump(int position, int dest) {
Instruction *jmp = &getProto()->getCode()[position];
int offset = dest - (position + 1);
auto *jmp = &getProto()->getCode()[position];
auto offset = dest - (position + 1);
lua_assert(dest != NO_JUMP);
if (!(-OFFSET_sJ <= offset && offset <= MAXARG_sJ - OFFSET_sJ))
getLexState()->syntaxError("control structure too long");
Expand All @@ -125,7 +125,7 @@ int FuncState::condjump(OpCode o, int A, int B, int C, int k) {
** unconditional.
*/
Instruction *FuncState::getjumpcontrol(int position) {
Instruction *pi = &getProto()->getCode()[position];
auto *pi = &getProto()->getCode()[position];
if (position >= 1 && InstructionView(*(pi-1)).testTMode())
return pi-1;
else
Expand All @@ -140,7 +140,7 @@ Instruction *FuncState::getjumpcontrol(int position) {
** no register value)
*/
int FuncState::patchtestreg(int node, int reg) {
Instruction *i = getjumpcontrol(node);
auto *i = getjumpcontrol(node);
if (InstructionView(*i).opcode() != OP_TESTSET)
return 0; /* cannot patch other instructions */
if (reg != NO_REG && reg != InstructionView(*i).b())
Expand Down Expand Up @@ -169,7 +169,7 @@ int FuncState::removevalues(int list) {
*/
void FuncState::patchlistaux(int list, int vtarget, int reg, int dtarget) {
while (list != NO_JUMP) {
int next = getjump(list);
auto next = getjump(list);
if (patchtestreg(list, reg))
fixjump(list, vtarget);
else
Expand All @@ -189,8 +189,8 @@ void FuncState::patchlistaux(int list, int vtarget, int reg, int dtarget) {
** Otherwise, store the difference from last line in 'lineinfo'.
*/
void FuncState::savelineinfo(Proto *proto, int line) {
int linedif = line - getPreviousLine();
int pcval = getPC() - 1; /* last instruction coded */
auto linedif = line - getPreviousLine();
auto pcval = getPC() - 1; /* last instruction coded */
if (abs(linedif) >= LIMLINEDIFF || postIncrementInstructionsWithAbs() >= MAXIWTHABS) {
luaM_growvector(getLexState()->getLuaState(), proto->getAbsLineInfoRef(), getNAbsLineInfo(),
proto->getAbsLineInfoSizeRef(), AbsLineInfo, std::numeric_limits<int>::max(), "lines");
Expand All @@ -212,8 +212,8 @@ void FuncState::savelineinfo(Proto *proto, int line) {
** absolute line info, too.
*/
void FuncState::removelastlineinfo() {
Proto *proto = getProto();
int pcval = getPC() - 1; /* last instruction coded */
auto *proto = getProto();
auto pcval = getPC() - 1; /* last instruction coded */
if (proto->getLineInfo()[pcval] != ABSLINEINFO) { /* relative line info? */
setPreviousLine(getPreviousLine() - proto->getLineInfo()[pcval]); /* correct last line saved */
decrementInstructionsWithAbs(); /* undo previous increment */
Expand All @@ -238,7 +238,7 @@ void FuncState::removelastinstruction() {
** Format and emit an 'iAsBx' instruction.
*/
int FuncState::codeAsBx(OpCode o, int A, int Bc) {
int b = Bc + OFFSET_sBx;
auto b = Bc + OFFSET_sBx;
lua_assert(getOpMode(o) == OpMode::iAsBx);
lua_assert(A <= MAXARG_A && b <= MAXARG_Bx);
return code(CREATE_ABx(o, A, b));
Expand All @@ -261,7 +261,7 @@ int FuncState::codek(int reg, int k) {
if (k <= MAXARG_Bx)
return codeABx(OP_LOADK, reg, k);
else {
int p = codeABx(OP_LOADKX, reg, 0);
auto p = codeABx(OP_LOADKX, reg, 0);
codeextraarg(k);
return p;
}
Expand Down Expand Up @@ -306,8 +306,8 @@ void FuncState::freeExpression(expdesc *e) {
** order.
*/
void FuncState::freeExpressions(expdesc *e1, expdesc *e2) {
int r1 = (e1->getKind() == VNONRELOC) ? e1->getInfo() : -1;
int r2 = (e2->getKind() == VNONRELOC) ? e2->getInfo() : -1;
auto r1 = (e1->getKind() == VNONRELOC) ? e1->getInfo() : -1;
auto r2 = (e2->getKind() == VNONRELOC) ? e2->getInfo() : -1;
freeRegisters(r1, r2);
}

Expand All @@ -316,8 +316,8 @@ void FuncState::freeExpressions(expdesc *e1, expdesc *e2) {
*/
int FuncState::addk(Proto *proto, TValue *v) {
lua_State *L = getLexState()->getLuaState();
int oldsize = proto->getConstantsSize();
int k = getNK();
auto oldsize = proto->getConstantsSize();
auto k = getNK();
luaM_growvector(L, proto->getConstantsRef(), k, proto->getConstantsSizeRef(), TValue, MAXARG_Ax, "constants");
auto constantsSpan = proto->getConstantsSpan();
while (oldsize < static_cast<int>(constantsSpan.size()))
Expand All @@ -339,13 +339,13 @@ int FuncState::k2proto(TValue *key, TValue *v) {
Proto *proto = getProto();
LuaT tag = luaH_get(getKCache(), key, &val); /* query scanner table */
if (!tagisempty(tag)) { /* is there an index there? */
int k = cast_int(ivalue(&val));
auto k = cast_int(ivalue(&val));
/* collisions can happen only for float keys */
lua_assert(ttisfloat(key) || luaV_rawequalobj(&proto->getConstants()[k], v));
return k; /* reuse index */
}
else { /* constant not found; create a new entry */
int k = addk(proto, v);
auto k = addk(proto, v);
/* cache it for reuse; numerical value does not need GC barrier;
table is not a metatable, so it does not need to invalidate cache */
val.setInt(k);
Expand Down Expand Up @@ -398,7 +398,7 @@ int FuncState::numberK(lua_Number r) {
lua_Integer ik;
kv.setFloat(k); /* key as a TValue */
if (!luaV_flttointeger(k, &ik, F2Imod::F2Ieq)) { /* not an integer value? */
int n = k2proto(&kv, &o); /* use key */
auto n = k2proto(&kv, &o); /* use key */
if (luaV_rawequalobj(&getProto()->getConstants()[n], &o)) /* correct value? */
return n;
}
Expand Down Expand Up @@ -575,7 +575,7 @@ int FuncState::code_loadbool(int A, OpCode op) {
*/
int FuncState::need_value(int list) {
for (; list != NO_JUMP; list = getjump(list)) {
Instruction i = *getjumpcontrol(list);
auto i = *getjumpcontrol(list);
if (InstructionView(i).opcode() != OP_TESTSET) return 1;
}
return 0; /* not found */
Expand All @@ -593,16 +593,16 @@ void FuncState::exp2reg(expdesc *e, int reg) {
if (e->getKind() == VJMP) /* expression itself is a test? */
concat(e->getTrueListRef(), e->getInfo()); /* put this jump in 't' list */
if (hasjumps(e)) {
int p_f = NO_JUMP; /* position of an eventual LOAD false */
int p_t = NO_JUMP; /* position of an eventual LOAD true */
auto p_f = NO_JUMP; /* position of an eventual LOAD false */
auto p_t = NO_JUMP; /* position of an eventual LOAD true */
if (need_value(e->getTrueList()) || need_value(e->getFalseList())) {
int fj = (e->getKind() == VJMP) ? NO_JUMP : jump();
auto fj = (e->getKind() == VJMP) ? NO_JUMP : jump();
p_f = code_loadbool(reg, OP_LFALSESKIP); /* skip next inst. */
p_t = code_loadbool(reg, OP_LOADTRUE);
/* jump around these booleans if 'e' is not a test */
patchtohere(fj);
}
int final = getlabel(); /* position after whole expression */
auto final = getlabel(); /* position after whole expression */
patchlistaux(e->getFalseList(), final, reg, p_f);
patchlistaux(e->getTrueList(), final, reg, p_t);
}
Expand Down Expand Up @@ -654,7 +654,7 @@ int FuncState::exp2RK(expdesc *e) {
}

void FuncState::codeABRK(OpCode o, int A, int B, expdesc *ec) {
int k = exp2RK(ec);
auto k = exp2RK(ec);
codeABCk(o, A, B, ec->getInfo(), k);
}

Expand All @@ -677,7 +677,7 @@ void FuncState::negatecondition(expdesc *e) {
*/
int FuncState::jumponcond(expdesc *e, int cond) {
if (e->getKind() == VRELOC) {
Instruction ie = getinstruction(this, e);
auto ie = getinstruction(this, e);
if (InstructionView(ie).opcode() == OP_NOT) {
removelastinstruction(); /* remove previous OP_NOT */
return condjump(OP_TEST, InstructionView(ie).b(), 0, 0, !cond);
Expand Down Expand Up @@ -848,7 +848,7 @@ static inline TMS binopr2TM (BinOpr opr) {
** Expression to produce final result will be encoded in 'e'.
*/
void FuncState::codeunexpval(OpCode op, expdesc *e, int line) {
int r = exp2anyreg(e); /* opcodes operate only on registers */
auto r = exp2anyreg(e); /* opcodes operate only on registers */
freeExpression(e);
e->setInfo(codeABC(op, 0, r, 0)); /* generate opcode */
e->setKind(VRELOC); /* all those operations are relocatable */
Expand All @@ -863,8 +863,8 @@ void FuncState::codeunexpval(OpCode op, expdesc *e, int line) {
*/
void FuncState::finishbinexpval(expdesc *e1, expdesc *e2, OpCode op, int v2,
int flip, int line, OpCode mmop, TMS event) {
int v1 = exp2anyreg(e1);
int instrPos = codeABCk(op, 0, v1, v2, 0);
auto v1 = exp2anyreg(e1);
auto instrPos = codeABCk(op, 0, v1, v2, 0);
freeExpressions(e1, e2);
e1->setInfo(instrPos);
e1->setKind(VRELOC); /* all those operations are relocatable */
Expand All @@ -878,8 +878,8 @@ void FuncState::finishbinexpval(expdesc *e1, expdesc *e2, OpCode op, int v2,
** two registers.
*/
void FuncState::codebinexpval(BinOpr opr, expdesc *e1, expdesc *e2, int line) {
OpCode op = binopr2op(opr, BinOpr::OPR_ADD, OP_ADD);
int v2 = exp2anyreg(e2); /* make sure 'e2' is in a register */
auto op = binopr2op(opr, BinOpr::OPR_ADD, OP_ADD);
auto v2 = exp2anyreg(e2); /* make sure 'e2' is in a register */
/* 'e1' must be already in a register or it is a constant */
lua_assert((VNIL <= e1->getKind() && e1->getKind() <= VKSTR) ||
e1->getKind() == VNONRELOC || e1->getKind() == VRELOC);
Expand Down
30 changes: 15 additions & 15 deletions src/compiler/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,9 +309,9 @@ void Parser::check_readonly(expdesc *e) {
*/
void Parser::adjustlocalvars(int nvars) {
// FuncState passed as parameter
int regLevel = fs->nvarstack();
auto regLevel = fs->nvarstack();
for (int i = 0; i < nvars; i++) {
int vidx = fs->getNumActiveVarsRef()++;
auto vidx = fs->getNumActiveVarsRef()++;
Vardesc *var = fs->getlocalvardesc(vidx);
var->vd.ridx = cast_byte(regLevel++);
var->vd.pidx = fs->registerlocalvar(var->vd.name);
Expand Down Expand Up @@ -345,7 +345,7 @@ void Parser::buildvar(TString *varname, expdesc *var) {
var->init(VGLOBAL, -1); /* global by default */
fs->singlevaraux(varname, var, 1);
if (var->getKind() == VGLOBAL) { /* global name? */
int info = var->getInfo();
auto info = var->getInfo();
/* global by default in the scope of a global declaration? */
if (info == -2)
ls->semerror("variable '%s' not declared", getstr(varname));
Expand All @@ -369,9 +369,9 @@ void Parser::singlevar(expdesc *var) {
*/
void Parser::adjust_assign(int nvars, int nexps, expdesc *e) {
// FuncState passed as parameter
int needed = nvars - nexps; /* extra values needed */
auto needed = nvars - nexps; /* extra values needed */
if (hasmultret(e->getKind())) { /* last expression has multiple returns? */
int extra = needed + 1; /* discount last expression itself */
auto extra = needed + 1; /* discount last expression itself */
if (extra < 0)
extra = 0;
fs->setreturns(e, extra); /* last exp. provides the difference */
Expand All @@ -391,7 +391,7 @@ void Parser::adjust_assign(int nvars, int nexps, expdesc *e) {

int Parser::newgotoentry(TString *name, int line) {
// FuncState passed as parameter
int pc = fs->jump(); /* create jump */
auto pc = fs->jump(); /* create jump */
fs->codeABC(OP_CLOSE, 0, 1, 0); /* spaceholder, marked as dead */
return ls->newlabelentry(fs, &ls->getDyndata()->gt, name, line, pc);
}
Expand All @@ -410,7 +410,7 @@ Proto *Parser::addprototype() {
FuncState *funcstate = fs;
Proto *proto = funcstate->getProto(); /* prototype of current function */
if (funcstate->getNP() >= proto->getProtosSize()) {
int oldsize = proto->getProtosSize();
auto oldsize = proto->getProtosSize();
luaM_growvector(state, proto->getProtosRef(), funcstate->getNP(), proto->getProtosSizeRef(), Proto *, MAXARG_Bx, "functions");
auto protosSpan = proto->getProtosSpan();
while (oldsize < static_cast<int>(protosSpan.size()))
Expand Down Expand Up @@ -607,8 +607,8 @@ void Parser::constructor( expdesc *table_exp) {
/* constructor -> '{' [ field { sep field } [sep] ] '}'
sep -> ',' | ';' */
FuncState *funcstate = fs;
int line = ls->getLineNumber();
int pc = funcstate->codevABCk(OP_NEWTABLE, 0, 0, 0, 0);
auto line = ls->getLineNumber();
auto pc = funcstate->codevABCk(OP_NEWTABLE, 0, 0, 0, 0);
ConsControl cc;
funcstate->code(0); /* space for extra arg. */
cc.na = cc.nh = cc.tostore = 0;
Expand Down Expand Up @@ -704,7 +704,7 @@ void Parser::funcargs( expdesc *f) {
FuncState *funcstate = fs;
expdesc args;
int base, nparams;
int line = ls->getLineNumber();
auto line = ls->getLineNumber();
switch (ls->getToken()) {
case '(': { /* funcargs -> '(' [ explist ] ')' */
ls->nextToken();
Expand Down Expand Up @@ -761,7 +761,7 @@ void Parser::primaryexp( expdesc *v) {
/* primaryexp -> NAME | '(' expr ')' */
switch (ls->getToken()) {
case '(': {
int line = ls->getLineNumber();
auto line = ls->getLineNumber();
ls->nextToken();
expr(v);
check_match( ')', '(', line);
Expand Down Expand Up @@ -1061,8 +1061,8 @@ void Parser::whilestat( int line) {
FuncState *funcstate = fs;
BlockCnt bl;
ls->nextToken(); /* skip WHILE */
int whileinit = funcstate->getlabel();
int condexit = cond();
auto whileinit = funcstate->getlabel();
auto condexit = cond();
funcstate->enterblock(&bl, 1);
checknext(static_cast<int>(RESERVED::TK_DO));
block();
Expand All @@ -1076,14 +1076,14 @@ void Parser::whilestat( int line) {
void Parser::repeatstat( int line) {
/* repeatstat -> REPEAT block UNTIL cond */
FuncState *funcstate = fs;
int repeat_init = funcstate->getlabel();
auto repeat_init = funcstate->getlabel();
BlockCnt bl1, bl2;
funcstate->enterblock(&bl1, 1); /* loop block */
funcstate->enterblock(&bl2, 0); /* scope block */
ls->nextToken(); /* skip REPEAT */
statlist();
check_match(static_cast<int>(RESERVED::TK_UNTIL), static_cast<int>(RESERVED::TK_REPEAT), line);
int condexit = cond(); /* read condition (inside scope block) */
auto condexit = cond(); /* read condition (inside scope block) */
funcstate->leaveblock(); /* finish scope */
if (bl2.upval) { /* upvalues? */
int exit = funcstate->jump(); /* normal exit must jump over fix */
Expand Down
8 changes: 4 additions & 4 deletions src/core/lapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ LUA_API int lua_gettop (lua_State *L) {
LUA_API void lua_settop (lua_State *L, int idx) {
lua_lock(L);
CallInfo *ci = L->getCI();
StkId func = ci->funcRef().p;
auto func = ci->funcRef().p;
ptrdiff_t diff; /* difference for new top */
if (idx >= 0) {
api_check(L, idx <= ci->topRef().p - (func + 1), "new top too large");
Expand Down Expand Up @@ -187,11 +187,11 @@ static void reverse (lua_State *L, StkId from, StkId to) {
*/
LUA_API void lua_rotate (lua_State *L, int idx, int n) {
lua_lock(L);
StkId t = L->getTop().p - 1; /* end of stack segment being rotated */
StkId p = L->getStackSubsystem().indexToStack(L, idx); /* start of segment */
auto t = L->getTop().p - 1; /* end of stack segment being rotated */
auto p = L->getStackSubsystem().indexToStack(L, idx); /* start of segment */
api_check(L, L->getTbclist().p < p, "moving a to-be-closed slot");
api_check(L, (n >= 0 ? n : -n) <= (t - p + 1), "invalid 'n'");
StkId m = (n >= 0 ? t - n : p - n - 1); /* end of prefix */
auto m = (n >= 0 ? t - n : p - n - 1); /* end of prefix */
reverse(L, p, m); /* reverse the prefix with length 'n' */
reverse(L, m + 1, t); /* reverse the suffix */
reverse(L, p, t); /* reverse the entire segment */
Expand Down
16 changes: 8 additions & 8 deletions src/core/ldo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,15 +393,15 @@ void lua_State::hookCall(CallInfo *ci_arg) {
void lua_State::retHook(CallInfo *ci_arg, int nres) {
if (getHookMask() & LUA_MASKRET) { /* is return hook on? */
lua_assert(getTop().p >= getStack().p + nres); /* ensure nres is in bounds */
StkId firstres = getTop().p - nres; /* index of first result */
int delta = 0; /* correction for vararg functions */
auto firstres = getTop().p - nres; /* index of first result */
auto delta = 0; /* correction for vararg functions */
if (ci_arg->isLua()) {
Proto *p = ci_arg->getFunc()->getProto();
if (p->getFlag() & PF_ISVARARG)
delta = ci_arg->getExtraArgs() + p->getNumParams() + 1;
}
ci_arg->funcRef().p += delta; /* if vararg, back to virtual 'func' */
int ftransfer = cast_int(firstres - ci_arg->funcRef().p);
auto ftransfer = cast_int(firstres - ci_arg->funcRef().p);
callHook(LUA_HOOKRET, -1, ftransfer, nres); /* call it */
ci_arg->funcRef().p -= delta;
}
Expand Down Expand Up @@ -588,8 +588,8 @@ int lua_State::preTailCall(CallInfo *ci_arg, StkId func,
return preCallC(func, status_val, fvalue(s2v(func)));
case LuaT::LCL: { /* Lua function */
Proto *p = clLvalue(s2v(func))->getProto();
int fsize = p->getMaxStackSize(); /* frame size */
int nfixparams = p->getNumParams();
auto fsize = p->getMaxStackSize(); /* frame size */
auto nfixparams = p->getNumParams();
checkstackp(this, fsize - delta, func);
ci_arg->funcRef().p -= delta; /* restore 'func' (if vararg) */
for (int i = 0; i < narg1; i++) /* move down function and arguments */
Expand Down Expand Up @@ -637,9 +637,9 @@ CallInfo* lua_State::preCall(StkId func, int nresults) {
case LuaT::LCL: { /* Lua function */
CallInfo *ci_new;
Proto *p = clLvalue(s2v(func))->getProto();
int narg = cast_int(getTop().p - func) - 1; /* number of real arguments */
int nfixparams = p->getNumParams();
int fsize = p->getMaxStackSize(); /* frame size */
auto narg = cast_int(getTop().p - func) - 1; /* number of real arguments */
auto nfixparams = p->getNumParams();
auto fsize = p->getMaxStackSize(); /* frame size */
checkstackp(this, fsize, func);
ci_new = setCI(prepareCallInfo(func, status_val, func + 1 + fsize));
ci_new->setSavedPC(p->getCode()); /* starting point */
Expand Down
Loading
Loading