changing {} style to match majority of previous style

This commit is contained in:
Philippe Teuwen 2019-03-10 11:20:22 +01:00
commit 961d929f4d
320 changed files with 5502 additions and 10485 deletions

View file

@ -29,14 +29,12 @@
#define hasjumps(e) ((e)->t != (e)->f)
static int isnumeral(expdesc *e)
{
static int isnumeral(expdesc *e) {
return (e->k == VKNUM && e->t == NO_JUMP && e->f == NO_JUMP);
}
void luaK_nil(FuncState *fs, int from, int n)
{
void luaK_nil(FuncState *fs, int from, int n) {
Instruction *previous;
int l = from + n - 1; /* last register to set nil */
if (fs->pc > fs->lasttarget) { /* no jumps to current position? */
@ -45,7 +43,7 @@ void luaK_nil(FuncState *fs, int from, int n)
int pfrom = GETARG_A(*previous);
int pl = pfrom + GETARG_B(*previous);
if ((pfrom <= from && from <= pl + 1) ||
(from <= pfrom && pfrom <= l + 1)) { /* can connect both? */
(from <= pfrom && pfrom <= l + 1)) { /* can connect both? */
if (pfrom < from) from = pfrom; /* from = min(from, pfrom) */
if (pl > l) l = pl; /* l = max(l, pl) */
SETARG_A(*previous, from);
@ -58,8 +56,7 @@ void luaK_nil(FuncState *fs, int from, int n)
}
int luaK_jump(FuncState *fs)
{
int luaK_jump(FuncState *fs) {
int jpc = fs->jpc; /* save list of jumps to here */
int j;
fs->jpc = NO_JUMP;
@ -69,21 +66,18 @@ int luaK_jump(FuncState *fs)
}
void luaK_ret(FuncState *fs, int first, int nret)
{
void luaK_ret(FuncState *fs, int first, int nret) {
luaK_codeABC(fs, OP_RETURN, first, nret + 1, 0);
}
static int condjump(FuncState *fs, OpCode op, int A, int B, int C)
{
static int condjump(FuncState *fs, OpCode op, int A, int B, int C) {
luaK_codeABC(fs, op, A, B, C);
return luaK_jump(fs);
}
static void fixjump(FuncState *fs, int pc, int dest)
{
static void fixjump(FuncState *fs, int pc, int dest) {
Instruction *jmp = &fs->f->code[pc];
int offset = dest - (pc + 1);
lua_assert(dest != NO_JUMP);
@ -97,15 +91,13 @@ static void fixjump(FuncState *fs, int pc, int dest)
** returns current `pc' and marks it as a jump target (to avoid wrong
** optimizations with consecutive instructions not in the same basic block).
*/
int luaK_getlabel(FuncState *fs)
{
int luaK_getlabel(FuncState *fs) {
fs->lasttarget = fs->pc;
return fs->pc;
}
static int getjump(FuncState *fs, int pc)
{
static int getjump(FuncState *fs, int pc) {
int offset = GETARG_sBx(fs->f->code[pc]);
if (offset == NO_JUMP) /* point to itself represents end of list */
return NO_JUMP; /* end of list */
@ -114,8 +106,7 @@ static int getjump(FuncState *fs, int pc)
}
static Instruction *getjumpcontrol(FuncState *fs, int pc)
{
static Instruction *getjumpcontrol(FuncState *fs, int pc) {
Instruction *pi = &fs->f->code[pc];
if (pc >= 1 && testTMode(GET_OPCODE(*(pi - 1))))
return pi - 1;
@ -128,8 +119,7 @@ static Instruction *getjumpcontrol(FuncState *fs, int pc)
** check whether list has any jump that do not produce a value
** (or produce an inverted value)
*/
static int need_value(FuncState *fs, int list)
{
static int need_value(FuncState *fs, int list) {
for (; list != NO_JUMP; list = getjump(fs, list)) {
Instruction i = *getjumpcontrol(fs, list);
if (GET_OPCODE(i) != OP_TESTSET) return 1;
@ -138,8 +128,7 @@ static int need_value(FuncState *fs, int list)
}
static int patchtestreg(FuncState *fs, int node, int reg)
{
static int patchtestreg(FuncState *fs, int node, int reg) {
Instruction *i = getjumpcontrol(fs, node);
if (GET_OPCODE(*i) != OP_TESTSET)
return 0; /* cannot patch other instructions */
@ -152,16 +141,14 @@ static int patchtestreg(FuncState *fs, int node, int reg)
}
static void removevalues(FuncState *fs, int list)
{
static void removevalues(FuncState *fs, int list) {
for (; list != NO_JUMP; list = getjump(fs, list))
patchtestreg(fs, list, NO_REG);
}
static void patchlistaux(FuncState *fs, int list, int vtarget, int reg,
int dtarget)
{
int dtarget) {
while (list != NO_JUMP) {
int next = getjump(fs, list);
if (patchtestreg(fs, list, reg))
@ -173,15 +160,13 @@ static void patchlistaux(FuncState *fs, int list, int vtarget, int reg,
}
static void dischargejpc(FuncState *fs)
{
static void dischargejpc(FuncState *fs) {
patchlistaux(fs, fs->jpc, fs->pc, NO_REG, fs->pc);
fs->jpc = NO_JUMP;
}
void luaK_patchlist(FuncState *fs, int list, int target)
{
void luaK_patchlist(FuncState *fs, int list, int target) {
if (target == fs->pc)
luaK_patchtohere(fs, list);
else {
@ -191,8 +176,7 @@ void luaK_patchlist(FuncState *fs, int list, int target)
}
LUAI_FUNC void luaK_patchclose(FuncState *fs, int list, int level)
{
LUAI_FUNC void luaK_patchclose(FuncState *fs, int list, int level) {
level++; /* argument is +1 to reserve 0 as non-op */
while (list != NO_JUMP) {
int next = getjump(fs, list);
@ -205,15 +189,13 @@ LUAI_FUNC void luaK_patchclose(FuncState *fs, int list, int level)
}
void luaK_patchtohere(FuncState *fs, int list)
{
void luaK_patchtohere(FuncState *fs, int list) {
luaK_getlabel(fs);
luaK_concat(fs, &fs->jpc, list);
}
void luaK_concat(FuncState *fs, int *l1, int l2)
{
void luaK_concat(FuncState *fs, int *l1, int l2) {
if (l2 == NO_JUMP) return;
else if (*l1 == NO_JUMP)
*l1 = l2;
@ -227,8 +209,7 @@ void luaK_concat(FuncState *fs, int *l1, int l2)
}
static int luaK_code(FuncState *fs, Instruction i)
{
static int luaK_code(FuncState *fs, Instruction i) {
Proto *f = fs->f;
dischargejpc(fs); /* `pc' will change */
/* put new instruction in code array */
@ -243,8 +224,7 @@ static int luaK_code(FuncState *fs, Instruction i)
}
int luaK_codeABC(FuncState *fs, OpCode o, int a, int b, int c)
{
int luaK_codeABC(FuncState *fs, OpCode o, int a, int b, int c) {
lua_assert(getOpMode(o) == iABC);
lua_assert(getBMode(o) != OpArgN || b == 0);
lua_assert(getCMode(o) != OpArgN || c == 0);
@ -253,8 +233,7 @@ int luaK_codeABC(FuncState *fs, OpCode o, int a, int b, int c)
}
int luaK_codeABx(FuncState *fs, OpCode o, int a, unsigned int bc)
{
int luaK_codeABx(FuncState *fs, OpCode o, int a, unsigned int bc) {
lua_assert(getOpMode(o) == iABx || getOpMode(o) == iAsBx);
lua_assert(getCMode(o) == OpArgN);
lua_assert(a <= MAXARG_A && bc <= MAXARG_Bx);
@ -262,15 +241,13 @@ int luaK_codeABx(FuncState *fs, OpCode o, int a, unsigned int bc)
}
static int codeextraarg(FuncState *fs, int a)
{
static int codeextraarg(FuncState *fs, int a) {
lua_assert(a <= MAXARG_Ax);
return luaK_code(fs, CREATE_Ax(OP_EXTRAARG, a));
}
int luaK_codek(FuncState *fs, int reg, int k)
{
int luaK_codek(FuncState *fs, int reg, int k) {
if (k <= MAXARG_Bx)
return luaK_codeABx(fs, OP_LOADK, reg, k);
else {
@ -281,8 +258,7 @@ int luaK_codek(FuncState *fs, int reg, int k)
}
void luaK_checkstack(FuncState *fs, int n)
{
void luaK_checkstack(FuncState *fs, int n) {
int newstack = fs->freereg + n;
if (newstack > fs->f->maxstacksize) {
if (newstack >= MAXSTACK)
@ -292,15 +268,13 @@ void luaK_checkstack(FuncState *fs, int n)
}
void luaK_reserveregs(FuncState *fs, int n)
{
void luaK_reserveregs(FuncState *fs, int n) {
luaK_checkstack(fs, n);
fs->freereg += n;
}
static void freereg(FuncState *fs, int reg)
{
static void freereg(FuncState *fs, int reg) {
if (!ISK(reg) && reg >= fs->nactvar) {
fs->freereg--;
lua_assert(reg == fs->freereg);
@ -308,15 +282,13 @@ static void freereg(FuncState *fs, int reg)
}
static void freeexp(FuncState *fs, expdesc *e)
{
static void freeexp(FuncState *fs, expdesc *e) {
if (e->k == VNONRELOC)
freereg(fs, e->u.info);
}
static int addk(FuncState *fs, TValue *key, TValue *v)
{
static int addk(FuncState *fs, TValue *key, TValue *v) {
lua_State *L = fs->ls->L;
TValue *idx = luaH_set(L, fs->h, key);
Proto *f = fs->f;
@ -344,16 +316,14 @@ static int addk(FuncState *fs, TValue *key, TValue *v)
}
int luaK_stringK(FuncState *fs, TString *s)
{
int luaK_stringK(FuncState *fs, TString *s) {
TValue o;
setsvalue(fs->ls->L, &o, s);
return addk(fs, &o, &o);
}
int luaK_numberK(FuncState *fs, lua_Number r)
{
int luaK_numberK(FuncState *fs, lua_Number r) {
int n;
lua_State *L = fs->ls->L;
TValue o;
@ -369,16 +339,14 @@ int luaK_numberK(FuncState *fs, lua_Number r)
}
static int boolK(FuncState *fs, int b)
{
static int boolK(FuncState *fs, int b) {
TValue o;
setbvalue(&o, b);
return addk(fs, &o, &o);
}
static int nilK(FuncState *fs)
{
static int nilK(FuncState *fs) {
TValue k, v;
setnilvalue(&v);
/* cannot use nil as key; instead use table itself to represent nil */
@ -387,8 +355,7 @@ static int nilK(FuncState *fs)
}
void luaK_setreturns(FuncState *fs, expdesc *e, int nresults)
{
void luaK_setreturns(FuncState *fs, expdesc *e, int nresults) {
if (e->k == VCALL) { /* expression is an open function call? */
SETARG_C(getcode(fs, e), nresults + 1);
} else if (e->k == VVARARG) {
@ -399,8 +366,7 @@ void luaK_setreturns(FuncState *fs, expdesc *e, int nresults)
}
void luaK_setoneret(FuncState *fs, expdesc *e)
{
void luaK_setoneret(FuncState *fs, expdesc *e) {
if (e->k == VCALL) { /* expression is an open function call? */
e->k = VNONRELOC;
e->u.info = GETARG_A(getcode(fs, e));
@ -411,8 +377,7 @@ void luaK_setoneret(FuncState *fs, expdesc *e)
}
void luaK_dischargevars(FuncState *fs, expdesc *e)
{
void luaK_dischargevars(FuncState *fs, expdesc *e) {
switch (e->k) {
case VLOCAL: {
e->k = VNONRELOC;
@ -445,15 +410,13 @@ void luaK_dischargevars(FuncState *fs, expdesc *e)
}
static int code_label(FuncState *fs, int A, int b, int jump)
{
static int code_label(FuncState *fs, int A, int b, int jump) {
luaK_getlabel(fs); /* those instructions may be jump targets */
return luaK_codeABC(fs, OP_LOADBOOL, A, b, jump);
}
static void discharge2reg(FuncState *fs, expdesc *e, int reg)
{
static void discharge2reg(FuncState *fs, expdesc *e, int reg) {
luaK_dischargevars(fs, e);
switch (e->k) {
case VNIL: {
@ -493,8 +456,7 @@ static void discharge2reg(FuncState *fs, expdesc *e, int reg)
}
static void discharge2anyreg(FuncState *fs, expdesc *e)
{
static void discharge2anyreg(FuncState *fs, expdesc *e) {
if (e->k != VNONRELOC) {
luaK_reserveregs(fs, 1);
discharge2reg(fs, e, fs->freereg - 1);
@ -502,8 +464,7 @@ static void discharge2anyreg(FuncState *fs, expdesc *e)
}
static void exp2reg(FuncState *fs, expdesc *e, int reg)
{
static void exp2reg(FuncState *fs, expdesc *e, int reg) {
discharge2reg(fs, e, reg);
if (e->k == VJMP)
luaK_concat(fs, &e->t, e->u.info); /* put this jump in `t' list */
@ -527,8 +488,7 @@ static void exp2reg(FuncState *fs, expdesc *e, int reg)
}
void luaK_exp2nextreg(FuncState *fs, expdesc *e)
{
void luaK_exp2nextreg(FuncState *fs, expdesc *e) {
luaK_dischargevars(fs, e);
freeexp(fs, e);
luaK_reserveregs(fs, 1);
@ -536,8 +496,7 @@ void luaK_exp2nextreg(FuncState *fs, expdesc *e)
}
int luaK_exp2anyreg(FuncState *fs, expdesc *e)
{
int luaK_exp2anyreg(FuncState *fs, expdesc *e) {
luaK_dischargevars(fs, e);
if (e->k == VNONRELOC) {
if (!hasjumps(e)) return e->u.info; /* exp is already in a register */
@ -551,15 +510,13 @@ int luaK_exp2anyreg(FuncState *fs, expdesc *e)
}
void luaK_exp2anyregup(FuncState *fs, expdesc *e)
{
void luaK_exp2anyregup(FuncState *fs, expdesc *e) {
if (e->k != VUPVAL || hasjumps(e))
luaK_exp2anyreg(fs, e);
}
void luaK_exp2val(FuncState *fs, expdesc *e)
{
void luaK_exp2val(FuncState *fs, expdesc *e) {
if (hasjumps(e))
luaK_exp2anyreg(fs, e);
else
@ -567,8 +524,7 @@ void luaK_exp2val(FuncState *fs, expdesc *e)
}
int luaK_exp2RK(FuncState *fs, expdesc *e)
{
int luaK_exp2RK(FuncState *fs, expdesc *e) {
luaK_exp2val(fs, e);
switch (e->k) {
case VTRUE:
@ -598,8 +554,7 @@ int luaK_exp2RK(FuncState *fs, expdesc *e)
}
void luaK_storevar(FuncState *fs, expdesc *var, expdesc *ex)
{
void luaK_storevar(FuncState *fs, expdesc *var, expdesc *ex) {
switch (var->k) {
case VLOCAL: {
freeexp(fs, ex);
@ -626,8 +581,7 @@ void luaK_storevar(FuncState *fs, expdesc *var, expdesc *ex)
}
void luaK_self(FuncState *fs, expdesc *e, expdesc *key)
{
void luaK_self(FuncState *fs, expdesc *e, expdesc *key) {
int ereg;
luaK_exp2anyreg(fs, e);
ereg = e->u.info; /* register where 'e' was placed */
@ -640,8 +594,7 @@ void luaK_self(FuncState *fs, expdesc *e, expdesc *key)
}
static void invertjump(FuncState *fs, expdesc *e)
{
static void invertjump(FuncState *fs, expdesc *e) {
Instruction *pc = getjumpcontrol(fs, e->u.info);
lua_assert(testTMode(GET_OPCODE(*pc)) && GET_OPCODE(*pc) != OP_TESTSET &&
GET_OPCODE(*pc) != OP_TEST);
@ -649,8 +602,7 @@ static void invertjump(FuncState *fs, expdesc *e)
}
static int jumponcond(FuncState *fs, expdesc *e, int cond)
{
static int jumponcond(FuncState *fs, expdesc *e, int cond) {
if (e->k == VRELOCABLE) {
Instruction ie = getcode(fs, e);
if (GET_OPCODE(ie) == OP_NOT) {
@ -665,8 +617,7 @@ static int jumponcond(FuncState *fs, expdesc *e, int cond)
}
void luaK_goiftrue(FuncState *fs, expdesc *e)
{
void luaK_goiftrue(FuncState *fs, expdesc *e) {
int pc; /* pc of last jump */
luaK_dischargevars(fs, e);
switch (e->k) {
@ -692,8 +643,7 @@ void luaK_goiftrue(FuncState *fs, expdesc *e)
}
void luaK_goiffalse(FuncState *fs, expdesc *e)
{
void luaK_goiffalse(FuncState *fs, expdesc *e) {
int pc; /* pc of last jump */
luaK_dischargevars(fs, e);
switch (e->k) {
@ -717,8 +667,7 @@ void luaK_goiffalse(FuncState *fs, expdesc *e)
}
static void codenot(FuncState *fs, expdesc *e)
{
static void codenot(FuncState *fs, expdesc *e) {
luaK_dischargevars(fs, e);
switch (e->k) {
case VNIL:
@ -756,8 +705,7 @@ static void codenot(FuncState *fs, expdesc *e)
}
void luaK_indexed(FuncState *fs, expdesc *t, expdesc *k)
{
void luaK_indexed(FuncState *fs, expdesc *t, expdesc *k) {
lua_assert(!hasjumps(t));
t->u.ind.t = t->u.info;
t->u.ind.idx = luaK_exp2RK(fs, k);
@ -767,8 +715,7 @@ void luaK_indexed(FuncState *fs, expdesc *t, expdesc *k)
}
static int constfolding(OpCode op, expdesc *e1, expdesc *e2)
{
static int constfolding(OpCode op, expdesc *e1, expdesc *e2) {
lua_Number r;
if (!isnumeral(e1) || !isnumeral(e2)) return 0;
if ((op == OP_DIV || op == OP_MOD) && e2->u.nval == 0)
@ -780,8 +727,7 @@ static int constfolding(OpCode op, expdesc *e1, expdesc *e2)
static void codearith(FuncState *fs, OpCode op,
expdesc *e1, expdesc *e2, int line)
{
expdesc *e1, expdesc *e2, int line) {
if (constfolding(op, e1, e2))
return;
else {
@ -802,8 +748,7 @@ static void codearith(FuncState *fs, OpCode op,
static void codecomp(FuncState *fs, OpCode op, int cond, expdesc *e1,
expdesc *e2)
{
expdesc *e2) {
int o1 = luaK_exp2RK(fs, e1);
int o2 = luaK_exp2RK(fs, e2);
freeexp(fs, e2);
@ -820,8 +765,7 @@ static void codecomp(FuncState *fs, OpCode op, int cond, expdesc *e1,
}
void luaK_prefix(FuncState *fs, UnOpr op, expdesc *e, int line)
{
void luaK_prefix(FuncState *fs, UnOpr op, expdesc *e, int line) {
expdesc e2;
e2.t = e2.f = NO_JUMP;
e2.k = VKNUM;
@ -850,8 +794,7 @@ void luaK_prefix(FuncState *fs, UnOpr op, expdesc *e, int line)
}
void luaK_infix(FuncState *fs, BinOpr op, expdesc *v)
{
void luaK_infix(FuncState *fs, BinOpr op, expdesc *v) {
switch (op) {
case OPR_AND: {
luaK_goiftrue(fs, v);
@ -883,8 +826,7 @@ void luaK_infix(FuncState *fs, BinOpr op, expdesc *v)
void luaK_posfix(FuncState *fs, BinOpr op,
expdesc *e1, expdesc *e2, int line)
{
expdesc *e1, expdesc *e2, int line) {
switch (op) {
case OPR_AND: {
lua_assert(e1->t == NO_JUMP); /* list must be closed */
@ -941,14 +883,12 @@ void luaK_posfix(FuncState *fs, BinOpr op,
}
void luaK_fixline(FuncState *fs, int line)
{
void luaK_fixline(FuncState *fs, int line) {
fs->f->lineinfo[fs->pc - 1] = line;
}
void luaK_setlist(FuncState *fs, int base, int nelems, int tostore)
{
void luaK_setlist(FuncState *fs, int base, int nelems, int tostore) {
int c = (nelems - 1) / LFIELDS_PER_FLUSH + 1;
int b = (tostore == LUA_MULTRET) ? 0 : tostore;
lua_assert(tostore != 0);