diff --git a/src/compiler/lcode.cpp b/src/compiler/lcode.cpp index 7a766768..7d994a6f 100644 --- a/src/compiler/lcode.cpp +++ b/src/compiler/lcode.cpp @@ -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 @@ -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"); @@ -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 @@ -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()) @@ -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 @@ -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::max(), "lines"); @@ -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 */ @@ -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)); @@ -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; } @@ -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); } @@ -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(constantsSpan.size())) @@ -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); @@ -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; } @@ -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 */ @@ -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); } @@ -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); } @@ -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); @@ -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 */ @@ -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 */ @@ -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); diff --git a/src/compiler/parser.cpp b/src/compiler/parser.cpp index a973c79b..95041648 100644 --- a/src/compiler/parser.cpp +++ b/src/compiler/parser.cpp @@ -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); @@ -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)); @@ -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 */ @@ -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); } @@ -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(protosSpan.size())) @@ -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; @@ -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(); @@ -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); @@ -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(RESERVED::TK_DO)); block(); @@ -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(RESERVED::TK_UNTIL), static_cast(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 */ diff --git a/src/core/lapi.cpp b/src/core/lapi.cpp index e5c092a1..89802c58 100644 --- a/src/core/lapi.cpp +++ b/src/core/lapi.cpp @@ -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"); @@ -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 */ diff --git a/src/core/ldo.cpp b/src/core/ldo.cpp index df23ef31..be0a0c75 100644 --- a/src/core/ldo.cpp +++ b/src/core/ldo.cpp @@ -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; } @@ -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 */ @@ -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 */ diff --git a/src/vm/lvm.cpp b/src/vm/lvm.cpp index 04b4fe2f..3844c28f 100644 --- a/src/vm/lvm.cpp +++ b/src/vm/lvm.cpp @@ -616,7 +616,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { auto op_arithf_aux = [&](const TValue *v1, const TValue *v2, auto fop, Instruction i) { lua_Number n1, n2; if (tonumberns(v1, n1) && tonumberns(v2, n2)) { - StkId ra = RA(i); + auto ra = RA(i); pc++; s2v(ra)->setFloat(fop(L, n1, n2)); } }; @@ -639,9 +639,9 @@ void luaV_execute (lua_State *L, CallInfo *ci) { // Lambda: Auxiliary for arithmetic operations over integers and floats auto op_arith_aux = [&](const TValue *v1, const TValue *v2, auto iop, auto fop, Instruction i) { if (ttisinteger(v1) && ttisinteger(v2)) { - StkId ra = RA(i); - lua_Integer i1 = ivalue(v1); - lua_Integer i2 = ivalue(v2); + auto ra = RA(i); + auto i1 = ivalue(v1); + auto i2 = ivalue(v2); pc++; s2v(ra)->setInt(iop(L, i1, i2)); } else { @@ -666,23 +666,23 @@ void luaV_execute (lua_State *L, CallInfo *ci) { // Lambda: Bitwise operations with constant operand auto op_bitwiseK = [&](auto op, Instruction i) { - TValue *v1 = vRB(i); - TValue *v2 = KC(i); + auto *v1 = vRB(i); + auto *v2 = KC(i); lua_Integer i1; - lua_Integer i2 = ivalue(v2); + auto i2 = ivalue(v2); if (tointegerns(v1, &i1)) { - StkId ra = RA(i); + auto ra = RA(i); pc++; s2v(ra)->setInt(op(i1, i2)); } }; // Lambda: Bitwise operations with register operands auto op_bitwise = [&](auto op, Instruction i) { - TValue *v1 = vRB(i); - TValue *v2 = vRC(i); + auto *v1 = vRB(i); + auto *v2 = vRC(i); lua_Integer i1, i2; if (tointegerns(v1, &i1) && tointegerns(v2, &i2)) { - StkId ra = RA(i); + auto ra = RA(i); pc++; s2v(ra)->setInt(op(i1, i2)); } }; @@ -761,76 +761,76 @@ void luaV_execute (lua_State *L, CallInfo *ci) { lua_assert(luaP_isIT(i) || (cast_void(L->getStackSubsystem().setTopPtr(base)), 1)); vmdispatch (InstructionView(i).opcode()) { vmcase(OP_MOVE) { - StkId ra = RA(i); + auto ra = RA(i); *s2v(ra) = *s2v(RB(i)); /* Use operator= for move */ vmbreak; } vmcase(OP_LOADI) { - StkId ra = RA(i); - lua_Integer b = InstructionView(i).sbx(); + auto ra = RA(i); + auto b = InstructionView(i).sbx(); s2v(ra)->setInt(b); vmbreak; } vmcase(OP_LOADF) { - StkId ra = RA(i); - int b = InstructionView(i).sbx(); + auto ra = RA(i); + auto b = InstructionView(i).sbx(); s2v(ra)->setFloat(cast_num(b)); vmbreak; } vmcase(OP_LOADK) { - StkId ra = RA(i); - TValue *rb = k + InstructionView(i).bx(); + auto ra = RA(i); + auto *rb = k + InstructionView(i).bx(); L->getStackSubsystem().setSlot(ra, rb); vmbreak; } vmcase(OP_LOADKX) { - StkId ra = RA(i); - TValue *rb = k + InstructionView(*pc).ax(); pc++; + auto ra = RA(i); + auto *rb = k + InstructionView(*pc).ax(); pc++; L->getStackSubsystem().setSlot(ra, rb); vmbreak; } vmcase(OP_LOADFALSE) { - StkId ra = RA(i); + auto ra = RA(i); setbfvalue(s2v(ra)); vmbreak; } vmcase(OP_LFALSESKIP) { - StkId ra = RA(i); + auto ra = RA(i); setbfvalue(s2v(ra)); pc++; /* skip next instruction */ vmbreak; } vmcase(OP_LOADTRUE) { - StkId ra = RA(i); + auto ra = RA(i); setbtvalue(s2v(ra)); vmbreak; } vmcase(OP_LOADNIL) { - StkId ra = RA(i); - int b = InstructionView(i).b(); + auto ra = RA(i); + auto b = InstructionView(i).b(); do { setnilvalue(s2v(ra++)); } while (b--); vmbreak; } vmcase(OP_GETUPVAL) { - StkId ra = RA(i); - int b = InstructionView(i).b(); + auto ra = RA(i); + auto b = InstructionView(i).b(); L->getStackSubsystem().setSlot(ra, cl->getUpval(b)->getVP()); vmbreak; } vmcase(OP_SETUPVAL) { - StkId ra = RA(i); - UpVal *uv = cl->getUpval(InstructionView(i).b()); + auto ra = RA(i); + auto *uv = cl->getUpval(InstructionView(i).b()); *uv->getVP() = *s2v(ra); luaC_barrier(L, uv, s2v(ra)); vmbreak; } vmcase(OP_GETTABUP) { - StkId ra = RA(i); - TValue *upval = cl->getUpval(InstructionView(i).b())->getVP(); - TValue *rc = KC(i); - TString *key = tsvalue(rc); /* key must be a short string */ + auto ra = RA(i); + auto *upval = cl->getUpval(InstructionView(i).b())->getVP(); + auto *rc = KC(i); + auto *key = tsvalue(rc); /* key must be a short string */ LuaT tag; tag = luaV_fastget(upval, key, s2v(ra), luaH_getshortstr); if (tagisempty(tag)) @@ -838,9 +838,9 @@ void luaV_execute (lua_State *L, CallInfo *ci) { vmbreak; } vmcase(OP_GETTABLE) { - StkId ra = RA(i); - TValue *rb = vRB(i); - TValue *rc = vRC(i); + auto ra = RA(i); + auto *rb = vRB(i); + auto *rc = vRC(i); LuaT tag; if (ttisinteger(rc)) { /* fast track for integers? */ luaV_fastgeti(rb, ivalue(rc), s2v(ra), tag); @@ -852,9 +852,9 @@ void luaV_execute (lua_State *L, CallInfo *ci) { vmbreak; } vmcase(OP_GETI) { - StkId ra = RA(i); - TValue *rb = vRB(i); - int c = InstructionView(i).c(); + auto ra = RA(i); + auto *rb = vRB(i); + auto c = InstructionView(i).c(); LuaT tag; luaV_fastgeti(rb, c, s2v(ra), tag); if (tagisempty(tag)) { @@ -865,10 +865,10 @@ void luaV_execute (lua_State *L, CallInfo *ci) { vmbreak; } vmcase(OP_GETFIELD) { - StkId ra = RA(i); - TValue *rb = vRB(i); - TValue *rc = KC(i); - TString *key = tsvalue(rc); /* key must be a short string */ + auto ra = RA(i); + auto *rb = vRB(i); + auto *rc = KC(i); + auto *key = tsvalue(rc); /* key must be a short string */ LuaT tag; tag = luaV_fastget(rb, key, s2v(ra), luaH_getshortstr); if (tagisempty(tag)) @@ -876,12 +876,11 @@ void luaV_execute (lua_State *L, CallInfo *ci) { vmbreak; } vmcase(OP_SETTABUP) { - int hres; - TValue *upval = cl->getUpval(InstructionView(i).a())->getVP(); - TValue *rb = KB(i); - TValue *rc = RKC(i); - TString *key = tsvalue(rb); /* key must be a short string */ - hres = luaV_fastset(upval, key, rc, luaH_psetshortstr); + auto *upval = cl->getUpval(InstructionView(i).a())->getVP(); + auto *rb = KB(i); + auto *rc = RKC(i); + auto *key = tsvalue(rb); /* key must be a short string */ + auto hres = luaV_fastset(upval, key, rc, luaH_psetshortstr); if (hres == HOK) luaV_finishfastset(L, upval, rc); else @@ -889,10 +888,10 @@ void luaV_execute (lua_State *L, CallInfo *ci) { vmbreak; } vmcase(OP_SETTABLE) { - StkId ra = RA(i); + auto ra = RA(i); + auto *rb = vRB(i); /* key (table is in 'ra') */ + auto *rc = RKC(i); /* value */ int hres; - TValue *rb = vRB(i); /* key (table is in 'ra') */ - TValue *rc = RKC(i); /* value */ if (ttisinteger(rb)) { /* fast track for integers? */ luaV_fastseti(s2v(ra), ivalue(rb), rc, hres); } @@ -906,10 +905,10 @@ void luaV_execute (lua_State *L, CallInfo *ci) { vmbreak; } vmcase(OP_SETI) { - StkId ra = RA(i); + auto ra = RA(i); + auto b = InstructionView(i).b(); + auto *rc = RKC(i); int hres; - int b = InstructionView(i).b(); - TValue *rc = RKC(i); luaV_fastseti(s2v(ra), b, rc, hres); if (hres == HOK) luaV_finishfastset(L, s2v(ra), rc); @@ -921,12 +920,11 @@ void luaV_execute (lua_State *L, CallInfo *ci) { vmbreak; } vmcase(OP_SETFIELD) { - StkId ra = RA(i); - int hres; - TValue *rb = KB(i); - TValue *rc = RKC(i); - TString *key = tsvalue(rb); /* key must be a short string */ - hres = luaV_fastset(s2v(ra), key, rc, luaH_psetshortstr); + auto ra = RA(i); + auto *rb = KB(i); + auto *rc = RKC(i); + auto *key = tsvalue(rb); /* key must be a short string */ + auto hres = luaV_fastset(s2v(ra), key, rc, luaH_psetshortstr); if (hres == HOK) luaV_finishfastset(L, s2v(ra), rc); else @@ -934,10 +932,9 @@ void luaV_execute (lua_State *L, CallInfo *ci) { vmbreak; } vmcase(OP_NEWTABLE) { - StkId ra = RA(i); - unsigned b = cast_uint(InstructionView(i).vb()); /* log2(hash size) + 1 */ - unsigned c = cast_uint(InstructionView(i).vc()); /* array size */ - Table *t; + auto ra = RA(i); + auto b = cast_uint(InstructionView(i).vb()); /* log2(hash size) + 1 */ + auto c = cast_uint(InstructionView(i).vc()); /* array size */ if (b > 0) b = 1u << (b - 1); /* hash size is 2^(b - 1) */ if (InstructionView(i).testk()) { /* non-zero extra argument? */ @@ -947,7 +944,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { } pc++; /* skip extra argument */ L->getStackSubsystem().setTopPtr(ra + 1); /* correct top in case of emergency GC */ - t = luaH_new(L); /* memory allocation */ + auto *t = luaH_new(L); /* memory allocation */ sethvalue2s(L, ra, t); if (b != 0 || c != 0) luaH_resize(L, t, c, b); /* idem */ @@ -955,13 +952,12 @@ void luaV_execute (lua_State *L, CallInfo *ci) { vmbreak; } vmcase(OP_SELF) { - StkId ra = RA(i); - LuaT tag; - TValue *rb = vRB(i); - TValue *rc = KC(i); - TString *key = tsvalue(rc); /* key must be a short string */ + auto ra = RA(i); + auto *rb = vRB(i); + auto *rc = KC(i); + auto *key = tsvalue(rc); /* key must be a short string */ L->getStackSubsystem().setSlot(ra + 1, rb); - tag = luaV_fastget(rb, key, s2v(ra), luaH_getshortstr); + LuaT tag = luaV_fastget(rb, key, s2v(ra), luaH_getshortstr); if (tagisempty(tag)) Protect([&]() { luaV_finishget(L, rb, rc, ra, tag); }); vmbreak; @@ -1013,9 +1009,9 @@ void luaV_execute (lua_State *L, CallInfo *ci) { vmbreak; } vmcase(OP_SHLI) { - StkId ra = RA(i); - TValue *rb = vRB(i); - int ic = InstructionView(i).sc(); + auto ra = RA(i); + auto *rb = vRB(i); + auto ic = InstructionView(i).sc(); lua_Integer ib; if (tointegerns(rb, &ib)) { pc++; s2v(ra)->setInt(luaV_shiftl(ic, ib)); @@ -1023,9 +1019,9 @@ void luaV_execute (lua_State *L, CallInfo *ci) { vmbreak; } vmcase(OP_SHRI) { - StkId ra = RA(i); - TValue *rb = vRB(i); - int ic = InstructionView(i).sc(); + auto ra = RA(i); + auto *rb = vRB(i); + auto ic = InstructionView(i).sc(); lua_Integer ib; if (tointegerns(rb, &ib)) { pc++; s2v(ra)->setInt(luaV_shiftl(ib, -ic)); @@ -1083,41 +1079,41 @@ void luaV_execute (lua_State *L, CallInfo *ci) { vmbreak; } vmcase(OP_MMBIN) { - StkId ra = RA(i); - Instruction pi = *(pc - 2); /* original arith. expression */ - TValue *rb = vRB(i); - TMS tm = (TMS)InstructionView(i).c(); - StkId result = RA(pi); + auto ra = RA(i); + auto pi = *(pc - 2); /* original arith. expression */ + auto *rb = vRB(i); + auto tm = static_cast(InstructionView(i).c()); + auto result = RA(pi); lua_assert(OP_ADD <= InstructionView(pi).opcode() && InstructionView(pi).opcode() <= OP_SHR); Protect([&]() { luaT_trybinTM(L, s2v(ra), rb, result, tm); }); vmbreak; } vmcase(OP_MMBINI) { - StkId ra = RA(i); - Instruction pi = *(pc - 2); /* original arith. expression */ - int imm = InstructionView(i).sb(); - TMS tm = (TMS)InstructionView(i).c(); - int flip = InstructionView(i).k(); - StkId result = RA(pi); + auto ra = RA(i); + auto pi = *(pc - 2); /* original arith. expression */ + auto imm = InstructionView(i).sb(); + auto tm = static_cast(InstructionView(i).c()); + auto flip = InstructionView(i).k(); + auto result = RA(pi); Protect([&]() { luaT_trybiniTM(L, s2v(ra), imm, flip, result, tm); }); vmbreak; } vmcase(OP_MMBINK) { - StkId ra = RA(i); - Instruction pi = *(pc - 2); /* original arith. expression */ - TValue *imm = KB(i); - TMS tm = (TMS)InstructionView(i).c(); - int flip = InstructionView(i).k(); - StkId result = RA(pi); + auto ra = RA(i); + auto pi = *(pc - 2); /* original arith. expression */ + auto *imm = KB(i); + auto tm = static_cast(InstructionView(i).c()); + auto flip = InstructionView(i).k(); + auto result = RA(pi); Protect([&]() { luaT_trybinassocTM(L, s2v(ra), imm, flip, result, tm); }); vmbreak; } vmcase(OP_UNM) { - StkId ra = RA(i); - TValue *rb = vRB(i); + auto ra = RA(i); + auto *rb = vRB(i); lua_Number nb; if (ttisinteger(rb)) { - lua_Integer ib = ivalue(rb); + auto ib = ivalue(rb); s2v(ra)->setInt(intop(-, 0, ib)); } else if (tonumberns(rb, nb)) { @@ -1128,8 +1124,8 @@ void luaV_execute (lua_State *L, CallInfo *ci) { vmbreak; } vmcase(OP_BNOT) { - StkId ra = RA(i); - TValue *rb = vRB(i); + auto ra = RA(i); + auto *rb = vRB(i); lua_Integer ib; if (tointegerns(rb, &ib)) { s2v(ra)->setInt(intop(^, ~l_castS2U(0), ib)); @@ -1139,8 +1135,8 @@ void luaV_execute (lua_State *L, CallInfo *ci) { vmbreak; } vmcase(OP_NOT) { - StkId ra = RA(i); - TValue *rb = vRB(i); + auto ra = RA(i); + auto *rb = vRB(i); if (l_isfalse(rb)) setbtvalue(s2v(ra)); else @@ -1148,26 +1144,26 @@ void luaV_execute (lua_State *L, CallInfo *ci) { vmbreak; } vmcase(OP_LEN) { - StkId ra = RA(i); + auto ra = RA(i); Protect([&]() { luaV_objlen(L, ra, vRB(i)); }); vmbreak; } vmcase(OP_CONCAT) { - StkId ra = RA(i); - int n = InstructionView(i).b(); /* number of elements to concatenate */ + auto ra = RA(i); + auto n = InstructionView(i).b(); /* number of elements to concatenate */ L->getStackSubsystem().setTopPtr(ra + n); /* mark the end of concat operands */ ProtectNT([&]() { luaV_concat(L, n); }); checkGC(L, L->getTop().p); /* 'luaV_concat' ensures correct top */ vmbreak; } vmcase(OP_CLOSE) { - StkId ra = RA(i); + auto ra = RA(i); lua_assert(!InstructionView(i).b()); /* 'close must be alive */ Protect([&]() { luaF_close(L, ra, LUA_OK, 1); }); vmbreak; } vmcase(OP_TBC) { - StkId ra = RA(i); + auto ra = RA(i); /* create new to-be-closed upvalue */ halfProtect([&]() { luaF_newtbcupval(L, ra); }); vmbreak; @@ -1177,9 +1173,9 @@ void luaV_execute (lua_State *L, CallInfo *ci) { vmbreak; } vmcase(OP_EQ) { - StkId ra = RA(i); + auto ra = RA(i); + auto *rb = vRB(i); int cond; - TValue *rb = vRB(i); Protect([&]() { cond = luaV_equalobj(L, s2v(ra), rb); }); docondjump(cond, ci, i); vmbreak; @@ -1193,17 +1189,17 @@ void luaV_execute (lua_State *L, CallInfo *ci) { vmbreak; } vmcase(OP_EQK) { - StkId ra = RA(i); - TValue *rb = KB(i); + auto ra = RA(i); + auto *rb = KB(i); /* basic types do not use '__eq'; we can use raw equality */ - int cond = (*s2v(ra) == *rb); /* Use operator== for cleaner syntax */ + auto cond = (*s2v(ra) == *rb); /* Use operator== for cleaner syntax */ docondjump(cond, ci, i); vmbreak; } vmcase(OP_EQI) { - StkId ra = RA(i); + auto ra = RA(i); + auto im = InstructionView(i).sb(); int cond; - int im = InstructionView(i).sb(); if (ttisinteger(s2v(ra))) cond = (ivalue(s2v(ra)) == im); else if (ttisfloat(s2v(ra))) @@ -1230,14 +1226,14 @@ void luaV_execute (lua_State *L, CallInfo *ci) { vmbreak; } vmcase(OP_TEST) { - StkId ra = RA(i); - int cond = !l_isfalse(s2v(ra)); + auto ra = RA(i); + auto cond = !l_isfalse(s2v(ra)); docondjump(cond, ci, i); vmbreak; } vmcase(OP_TESTSET) { - StkId ra = RA(i); - TValue *rb = vRB(i); + auto ra = RA(i); + auto *rb = vRB(i); if (l_isfalse(rb) == InstructionView(i).k()) pc++; else { @@ -1247,14 +1243,14 @@ void luaV_execute (lua_State *L, CallInfo *ci) { vmbreak; } vmcase(OP_CALL) { - StkId ra = RA(i); - CallInfo *newci; - int b = InstructionView(i).b(); - int nresults = InstructionView(i).c() - 1; + auto ra = RA(i); + auto b = InstructionView(i).b(); + auto nresults = InstructionView(i).c() - 1; if (b != 0) /* fixed number of arguments? */ L->getStackSubsystem().setTopPtr(ra + b); /* top signals number of arguments */ /* else previous instruction set top */ savepc(ci); /* in case of errors */ + CallInfo *newci; if ((newci = L->preCall( ra, nresults)) == nullptr) updatetrap(ci); /* C call; nothing else to be done */ else { /* Lua call: run function in this same C frame */ @@ -1264,12 +1260,11 @@ void luaV_execute (lua_State *L, CallInfo *ci) { vmbreak; } vmcase(OP_TAILCALL) { - StkId ra = RA(i); - int b = InstructionView(i).b(); /* number of arguments + 1 (function) */ - int n; /* number of results when calling a C function */ - int nparams1 = InstructionView(i).c(); + auto ra = RA(i); + auto b = InstructionView(i).b(); /* number of arguments + 1 (function) */ + auto nparams1 = InstructionView(i).c(); /* delta is virtual 'func' - real 'func' (vararg functions) */ - int delta = (nparams1) ? ci->getExtraArgs() + nparams1 : 0; + auto delta = (nparams1) ? ci->getExtraArgs() + nparams1 : 0; if (b != 0) L->getStackSubsystem().setTopPtr(ra + b); else /* previous instruction set top */ @@ -1280,6 +1275,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { lua_assert(L->getTbclist().p < base); /* no pending tbc variables */ lua_assert(base == ci->funcRef().p + 1); } + int n; /* number of results when calling a C function */ if ((n = L->preTailCall( ci, ra, b, delta)) < 0) /* Lua function? */ goto startfunc; /* execute the callee */ else { /* C function? */ @@ -1290,9 +1286,9 @@ void luaV_execute (lua_State *L, CallInfo *ci) { } } vmcase(OP_RETURN) { - StkId ra = RA(i); - int n = InstructionView(i).b() - 1; /* number of results */ - int nparams1 = InstructionView(i).c(); + auto ra = RA(i); + auto n = InstructionView(i).b() - 1; /* number of results */ + auto nparams1 = InstructionView(i).c(); if (n < 0) /* not fixed? */ n = cast_int(L->getTop().p - ra); /* get what is available */ savepc(ci); @@ -1313,14 +1309,14 @@ void luaV_execute (lua_State *L, CallInfo *ci) { } vmcase(OP_RETURN0) { if (l_unlikely(L->getHookMask())) { - StkId ra = RA(i); + auto ra = RA(i); L->getStackSubsystem().setTopPtr(ra); savepc(ci); L->postCall( ci, 0); /* no hurry... */ trap = 1; } else { /* do the 'poscall' here */ - int nres = CallInfo::getNResults(ci->getCallStatus()); + auto nres = CallInfo::getNResults(ci->getCallStatus()); L->setCI(ci->getPrevious()); /* back to caller */ L->getStackSubsystem().setTopPtr(base - 1); for (; l_unlikely(nres > 0); nres--) { @@ -1332,19 +1328,19 @@ void luaV_execute (lua_State *L, CallInfo *ci) { } vmcase(OP_RETURN1) { if (l_unlikely(L->getHookMask())) { - StkId ra = RA(i); + auto ra = RA(i); L->getStackSubsystem().setTopPtr(ra + 1); savepc(ci); L->postCall( ci, 1); /* no hurry... */ trap = 1; } else { /* do the 'poscall' here */ - int nres = CallInfo::getNResults(ci->getCallStatus()); + auto nres = CallInfo::getNResults(ci->getCallStatus()); L->setCI(ci->getPrevious()); /* back to caller */ if (nres == 0) L->getStackSubsystem().setTopPtr(base - 1); /* asked for no results */ else { - StkId ra = RA(i); + auto ra = RA(i); *s2v(base - 1) = *s2v(ra); /* at least this result (operator=) */ L->getStackSubsystem().setTopPtr(base); for (; l_unlikely(nres > 1); nres--) { @@ -1362,12 +1358,12 @@ void luaV_execute (lua_State *L, CallInfo *ci) { } } vmcase(OP_FORLOOP) { - StkId ra = RA(i); + auto ra = RA(i); if (ttisinteger(s2v(ra + 1))) { /* integer loop? */ - lua_Unsigned count = l_castS2U(ivalue(s2v(ra))); + auto count = l_castS2U(ivalue(s2v(ra))); if (count > 0) { /* still more iterations? */ - lua_Integer step = ivalue(s2v(ra + 1)); - lua_Integer idx = ivalue(s2v(ra + 2)); /* control variable */ + auto step = ivalue(s2v(ra + 1)); + auto idx = ivalue(s2v(ra + 2)); /* control variable */ s2v(ra)->changeInt(l_castU2S(count - 1)); /* update counter */ idx = intop(+, idx, step); /* add step to index */ s2v(ra + 2)->changeInt(idx); /* update control variable */ @@ -1380,7 +1376,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { vmbreak; } vmcase(OP_FORPREP) { - StkId ra = RA(i); + auto ra = RA(i); savestate(L, ci); /* in case of errors */ if (L->forPrep(ra)) pc += InstructionView(i).bx() + 1; /* skip the loop */ @@ -1393,7 +1389,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { control and the closing variables and marks the closing variable as to-be-closed. */ - StkId ra = RA(i); + auto ra = RA(i); TValue temp; /* to swap control and closing variables */ temp = *s2v(ra + 3); /* Use operator= for temp assignment */ *s2v(ra + 3) = *s2v(ra + 2); /* Use operator= */ @@ -1413,7 +1409,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { so that it preserves the first three values, and the first return will be the new value for the control variable. */ - StkId ra = RA(i); + auto ra = RA(i); *s2v(ra + 5) = *s2v(ra + 3); /* copy the control variable (operator=) */ *s2v(ra + 4) = *s2v(ra + 1); /* copy state (operator=) */ *s2v(ra + 3) = *s2v(ra); /* copy function (operator=) */ @@ -1426,16 +1422,16 @@ void luaV_execute (lua_State *L, CallInfo *ci) { }} vmcase(OP_TFORLOOP) { l_tforloop: { - StkId ra = RA(i); + auto ra = RA(i); if (!ttisnil(s2v(ra + 3))) /* continue loop? */ pc -= InstructionView(i).bx(); /* jump back */ vmbreak; }} vmcase(OP_SETLIST) { - StkId ra = RA(i); - unsigned n = cast_uint(InstructionView(i).vb()); - unsigned last = cast_uint(InstructionView(i).vc()); - Table *h = hvalue(s2v(ra)); + auto ra = RA(i); + auto n = cast_uint(InstructionView(i).vb()); + auto last = cast_uint(InstructionView(i).vc()); + auto *h = hvalue(s2v(ra)); if (n == 0) n = cast_uint(L->getTop().p - ra) - 1; /* get up to the top */ else @@ -1452,7 +1448,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { luaH_resizearray(L, h, last); /* preallocate it at once */ } for (; n > 0; n--) { - TValue *val = s2v(ra + n); + auto *val = s2v(ra + n); obj2arr(h, last - 1, val); last--; luaC_barrierback(L, obj2gco(h), val); @@ -1460,15 +1456,15 @@ void luaV_execute (lua_State *L, CallInfo *ci) { vmbreak; } vmcase(OP_CLOSURE) { - StkId ra = RA(i); - Proto *p = cl->getProto()->getProtos()[InstructionView(i).bx()]; + auto ra = RA(i); + auto *p = cl->getProto()->getProtos()[InstructionView(i).bx()]; halfProtect([&]() { L->pushClosure(p, cl->getUpvalPtr(0), base, ra); }); checkGC(L, ra + 1); vmbreak; } vmcase(OP_VARARG) { - StkId ra = RA(i); - int n = InstructionView(i).c() - 1; /* required results */ + auto ra = RA(i); + auto n = InstructionView(i).c() - 1; /* required results */ Protect([&]() { luaT_getvarargs(L, ci, ra, n); }); vmbreak; } diff --git a/src/vm/lvm_arithmetic.cpp b/src/vm/lvm_arithmetic.cpp index 6af09abb..224b5fc8 100644 --- a/src/vm/lvm_arithmetic.cpp +++ b/src/vm/lvm_arithmetic.cpp @@ -31,7 +31,7 @@ lua_Integer luaV_idiv (lua_State *L, lua_Integer m, lua_Integer n) { return intop(-, 0, m); /* n==-1; avoid overflow with 0x80000...//-1 */ } else { - lua_Integer q = m / n; /* perform C division */ + auto q = m / n; /* perform C division */ if ((m ^ n) < 0 && m % n != 0) /* 'm/n' would be negative non-integer? */ q -= 1; /* correct result for different rounding */ return q; @@ -51,7 +51,7 @@ lua_Integer luaV_mod (lua_State *L, lua_Integer m, lua_Integer n) { return 0; /* m % -1 == 0; avoid overflow with 0x80000...%-1 */ } else { - lua_Integer r = m % n; + auto r = m % n; if (r != 0 && (r ^ n) < 0) /* 'm/n' would be non-integer negative? */ r += n; /* correct result for different rounding */ return r; diff --git a/src/vm/lvm_comparison.cpp b/src/vm/lvm_comparison.cpp index b8fb8678..d458d980 100644 --- a/src/vm/lvm_comparison.cpp +++ b/src/vm/lvm_comparison.cpp @@ -33,16 +33,16 @@ */ [[nodiscard]] int l_strcmp (const TString *ts1, const TString *ts2) { size_t rl1; /* real length */ - const char *s1 = getlstr(ts1, rl1); + auto *s1 = getlstr(ts1, rl1); size_t rl2; - const char *s2 = getlstr(ts2, rl2); + auto *s2 = getlstr(ts2, rl2); for (;;) { /* for each segment */ - int temp = strcoll(s1, s2); + auto temp = strcoll(s1, s2); if (temp != 0) /* not equal? */ return temp; /* done */ else { /* strings are equal up to a '\0' */ - size_t zl1 = strlen(s1); /* index of first '\0' in 's1' */ - size_t zl2 = strlen(s2); /* index of first '\0' in 's2' */ + auto zl1 = strlen(s1); /* index of first '\0' in 's1' */ + auto zl2 = strlen(s2); /* index of first '\0' in 's2' */ if (zl2 == rl2) /* 's2' is finished? */ return (zl1 == rl1) ? 0 : 1; /* check 's1' */ else if (zl1 == rl1) /* 's1' is finished? */ @@ -254,7 +254,7 @@ int luaV_equalobj (lua_State *L, const TValue *t1, const TValue *t2) { if (tm == nullptr) /* no TM? */ return 0; /* objects are different */ else { - LuaT tag = luaT_callTMres(L, tm, t1, t2, L->getTop().p); /* call TM */ + auto tag = luaT_callTMres(L, tm, t1, t2, L->getTop().p); /* call TM */ return !tagisfalse(tag); } } diff --git a/src/vm/lvm_loops.cpp b/src/vm/lvm_loops.cpp index 1b687180..c8193b35 100644 --- a/src/vm/lvm_loops.cpp +++ b/src/vm/lvm_loops.cpp @@ -68,12 +68,12 @@ int lua_State::forLimit(lua_Integer init, const TValue *lim, ** ra + 2 : control variable */ int lua_State::forPrep(StkId ra) { - TValue *pinit = s2v(ra); - TValue *plimit = s2v(ra + 1); - TValue *pstep = s2v(ra + 2); + auto *pinit = s2v(ra); + auto *plimit = s2v(ra + 1); + auto *pstep = s2v(ra + 2); if (ttisinteger(pinit) && ttisinteger(pstep)) { /* integer loop? */ - lua_Integer init = ivalue(pinit); - lua_Integer step = ivalue(pstep); + auto init = ivalue(pinit); + auto step = ivalue(pstep); lua_Integer limit; if (step == 0) luaG_runerror(this, "'for' step is zero"); @@ -105,7 +105,7 @@ int lua_State::forPrep(StkId ra) { } } else { /* try making all values floats */ - lua_Number init; lua_Number limit; lua_Number step; + lua_Number init, limit, step; if (l_unlikely(!tonumber(plimit, &limit))) luaG_forerror(this, plimit, "limit"); if (l_unlikely(!tonumber(pstep, &step))) @@ -134,9 +134,9 @@ int lua_State::forPrep(StkId ra) { ** written online with opcode OP_FORLOOP, for performance.) */ int lua_State::floatForLoop(StkId ra) { - lua_Number step = fltvalue(s2v(ra + 1)); - lua_Number limit = fltvalue(s2v(ra)); - lua_Number idx = fltvalue(s2v(ra + 2)); /* control variable */ + auto step = fltvalue(s2v(ra + 1)); + auto limit = fltvalue(s2v(ra)); + auto idx = fltvalue(s2v(ra + 2)); /* control variable */ idx = luai_numadd(this, idx, step); /* increment index */ if (luai_numlt(0, step) ? luai_numle(idx, limit) : luai_numle(limit, idx)) { diff --git a/src/vm/lvm_string.cpp b/src/vm/lvm_string.cpp index 82eb8ae7..1a7e7054 100644 --- a/src/vm/lvm_string.cpp +++ b/src/vm/lvm_string.cpp @@ -36,11 +36,11 @@ inline bool isemptystr(const TValue* o) noexcept { /* copy strings in stack from top - n up to top - 1 to buffer */ static void copy2buff (StkId top, int n, char *buff) { - size_t tl = 0; /* size already copied */ + auto tl = size_t{0}; /* size already copied */ do { - TString *st = tsvalue(s2v(top - n)); + auto *st = tsvalue(s2v(top - n)); size_t l; /* length of string being copied */ - const char *s = getlstr(st, l); + auto *s = getlstr(st, l); std::copy_n(s, l, buff + tl); tl += l; } while (--n > 0); @@ -55,8 +55,8 @@ void luaV_concat (lua_State *L, int total) { if (total == 1) return; /* "all" values already concatenated */ do { - StkId top = L->getTop().p; - int n = 2; /* number of elements handled in this pass (at least 2) */ + auto top = L->getTop().p; + auto n = 2; /* number of elements handled in this pass (at least 2) */ if (!(ttisstring(s2v(top - 2)) || cvt2str(s2v(top - 2))) || !tostring(L, s2v(top - 1))) { luaT_tryconcatTM(L); /* may invalidate 'top' */ @@ -71,12 +71,12 @@ void luaV_concat (lua_State *L, int total) { } else { /* at least two non-empty string values; get as many as possible */ - size_t tl = tsslen(tsvalue(s2v(top - 1))); + auto tl = tsslen(tsvalue(s2v(top - 1))); TString *ts; /* collect total length and number of strings */ for (n = 1; n < total && tostring(L, s2v(top - n - 1)); n++) { top = L->getTop().p; /* recapture after tostring() which can trigger GC */ - size_t l = tsslen(tsvalue(s2v(top - n - 1))); + auto l = tsslen(tsvalue(s2v(top - n - 1))); if (l_unlikely(l >= MAX_SIZE - sizeof(TString) - tl)) { L->getStackSubsystem().setTopPtr(top - total); /* pop strings to avoid wasting stack */ luaG_runerror(L, "string length overflow"); diff --git a/src/vm/lvm_table.cpp b/src/vm/lvm_table.cpp index 5ee97cca..03bfc782 100644 --- a/src/vm/lvm_table.cpp +++ b/src/vm/lvm_table.cpp @@ -48,9 +48,8 @@ inline constexpr int MAXTAGLOOP = 2000; */ LuaT luaV_finishget (lua_State *L, const TValue *t, TValue *key, StkId val, LuaT tag) { - int loop; /* counter to avoid infinite loops */ const TValue *tm; /* metamethod */ - for (loop = 0; loop < MAXTAGLOOP; loop++) { + for (int loop = 0; loop < MAXTAGLOOP; loop++) { if (tag == LuaT::NOTABLE) { /* 't' is not a table? */ lua_assert(!ttistable(t)); tm = luaT_gettmbyobj(L, t, TMS::TM_INDEX); @@ -103,11 +102,10 @@ LuaT luaV_finishget (lua_State *L, const TValue *t, TValue *key, */ void luaV_finishset (lua_State *L, const TValue *t, TValue *key, TValue *val, int hres) { - int loop; /* counter to avoid infinite loops */ - for (loop = 0; loop < MAXTAGLOOP; loop++) { + for (int loop = 0; loop < MAXTAGLOOP; loop++) { const TValue *tm; /* '__newindex' metamethod */ if (hres != HNOTATABLE) { /* is 't' a table? */ - Table *h = hvalue(t); /* save 't' table */ + auto *h = hvalue(t); /* save 't' table */ tm = fasttm(L, h->getMetatable(), TMS::TM_NEWINDEX); /* get metamethod */ if (tm == nullptr) { /* no metamethod? */ sethvalue2s(L, L->getTop().p, h); /* anchor 't' */