diff --git a/lcode.c b/lcode.c index caac6ba3..914d8cd0 100644 --- a/lcode.c +++ b/lcode.c @@ -1849,7 +1849,7 @@ void luaK_finish (FuncState *fs) { lua_assert(i == 0 || isOT(*(pc - 1)) == isIT(*pc)); switch (GET_OPCODE(*pc)) { case OP_RETURN0: case OP_RETURN1: { - if (!(fs->needclose || p->is_vararg)) + if (!(fs->needclose || (p->flag & PF_ISVARARG))) break; /* no extra work */ /* else use OP_RETURN to do the extra work */ SET_OPCODE(*pc, OP_RETURN); @@ -1857,7 +1857,7 @@ void luaK_finish (FuncState *fs) { case OP_RETURN: case OP_TAILCALL: { if (fs->needclose) SETARG_k(*pc, 1); /* signal that it needs to close */ - if (p->is_vararg) + if (p->flag & PF_ISVARARG) SETARG_C(*pc, p->numparams + 1); /* signal that it is vararg */ break; } diff --git a/ldebug.c b/ldebug.c index 690ac38f..1b789520 100644 --- a/ldebug.c +++ b/ldebug.c @@ -182,7 +182,7 @@ static const char *upvalname (const Proto *p, int uv) { static const char *findvararg (CallInfo *ci, int n, StkId *pos) { - if (clLvalue(s2v(ci->func.p))->p->is_vararg) { + if (clLvalue(s2v(ci->func.p))->p->flag & PF_ISVARARG) { int nextra = ci->u.l.nextraargs; if (n >= -nextra) { /* 'n' is negative */ *pos = ci->func.p - nextra - (n + 1); @@ -301,7 +301,7 @@ static void collectvalidlines (lua_State *L, Closure *f) { sethvalue2s(L, L->top.p, t); /* push it on stack */ api_incr_top(L); setbtvalue(&v); /* boolean 'true' to be the value of all indices */ - if (!p->is_vararg) /* regular function? */ + if (!(p->flag & PF_ISVARARG)) /* regular function? */ i = 0; /* consider all instructions */ else { /* vararg function */ lua_assert(GET_OPCODE(p->code[0]) == OP_VARARGPREP); @@ -344,7 +344,7 @@ static int auxgetinfo (lua_State *L, const char *what, lua_Debug *ar, ar->nparams = 0; } else { - ar->isvararg = f->l.p->is_vararg; + ar->isvararg = f->l.p->flag & PF_ISVARARG; ar->nparams = f->l.p->numparams; } break; @@ -878,7 +878,7 @@ int luaG_tracecall (lua_State *L) { Proto *p = ci_func(ci)->p; ci->u.l.trap = 1; /* ensure hooks will be checked */ if (ci->u.l.savedpc == p->code) { /* first instruction (not resuming)? */ - if (p->is_vararg) + if (p->flag & PF_ISVARARG) return 0; /* hooks will start at VARARGPREP instruction */ else if (!(ci->callstatus & CIST_HOOKYIELD)) /* not yieded? */ luaD_hookcall(L, ci); /* check 'call' hook */ diff --git a/ldo.c b/ldo.c index 3df6a4b8..a0e00229 100644 --- a/ldo.c +++ b/ldo.c @@ -391,7 +391,7 @@ static void rethook (lua_State *L, CallInfo *ci, int nres) { int ftransfer; if (isLua(ci)) { Proto *p = ci_func(ci)->p; - if (p->is_vararg) + if (p->flag & PF_ISVARARG) delta = ci->u.l.nextraargs + p->numparams + 1; } ci->func.p += delta; /* if vararg, back to virtual 'func' */ diff --git a/ldump.c b/ldump.c index 50d09f9a..bb15e45f 100644 --- a/ldump.c +++ b/ldump.c @@ -224,7 +224,7 @@ static void dumpFunction (DumpState *D, const Proto *f) { dumpInt(D, f->linedefined); dumpInt(D, f->lastlinedefined); dumpByte(D, f->numparams); - dumpByte(D, f->is_vararg); + dumpByte(D, f->flag); dumpByte(D, f->maxstacksize); dumpCode(D, f); dumpConstants(D, f); diff --git a/lfunc.c b/lfunc.c index 0945f241..9866a2d5 100644 --- a/lfunc.c +++ b/lfunc.c @@ -253,7 +253,7 @@ Proto *luaF_newproto (lua_State *L) { f->upvalues = NULL; f->sizeupvalues = 0; f->numparams = 0; - f->is_vararg = 0; + f->flag = 0; f->maxstacksize = 0; f->locvars = NULL; f->sizelocvars = 0; diff --git a/lobject.h b/lobject.h index 79dc6b1c..0e4924f5 100644 --- a/lobject.h +++ b/lobject.h @@ -544,13 +544,20 @@ typedef struct AbsLineInfo { int line; } AbsLineInfo; + +/* +** Flags in Prototypes +*/ +#define PF_ISVARARG 1 + + /* ** Function Prototypes */ typedef struct Proto { CommonHeader; lu_byte numparams; /* number of fixed (named) parameters */ - lu_byte is_vararg; + lu_byte flag; lu_byte maxstacksize; /* number of registers needed by this function */ int sizeupvalues; /* size of 'upvalues' */ int sizek; /* size of 'k' */ diff --git a/lparser.c b/lparser.c index 81c6df22..a1164510 100644 --- a/lparser.c +++ b/lparser.c @@ -959,7 +959,7 @@ static void constructor (LexState *ls, expdesc *t) { static void setvararg (FuncState *fs, int nparams) { - fs->f->is_vararg = 1; + fs->f->flag |= PF_ISVARARG; luaK_codeABC(fs, OP_VARARGPREP, nparams, 0, 0); } @@ -1177,7 +1177,7 @@ static void simpleexp (LexState *ls, expdesc *v) { } case TK_DOTS: { /* vararg */ FuncState *fs = ls->fs; - check_condition(ls, fs->f->is_vararg, + check_condition(ls, fs->f->flag & PF_ISVARARG, "cannot use '...' outside a vararg function"); init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 0, 1)); break; diff --git a/lundump.c b/lundump.c index 674bf21f..07c42e62 100644 --- a/lundump.c +++ b/lundump.c @@ -287,7 +287,7 @@ static void loadFunction (LoadState *S, Proto *f) { f->linedefined = loadInt(S); f->lastlinedefined = loadInt(S); f->numparams = loadByte(S); - f->is_vararg = loadByte(S); + f->flag = loadByte(S) & PF_ISVARARG; /* keep only the meaningful flags */ f->maxstacksize = loadByte(S); loadCode(S, f); loadConstants(S, f);