Browse Source

Field 'Proto.is_vararg' uses only one bit

So that the other bits can be used for other purposes.
pull/33/head
Roberto Ierusalimschy 1 year ago
parent
commit
96f7714237
  1. 4
      lcode.c
  2. 8
      ldebug.c
  3. 2
      ldo.c
  4. 2
      ldump.c
  5. 2
      lfunc.c
  6. 9
      lobject.h
  7. 4
      lparser.c
  8. 2
      lundump.c

4
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;
}

8
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 */

2
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' */

2
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);

2
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;

9
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' */

4
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;

2
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);

Loading…
Cancel
Save