aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-08-30 10:44:28 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2023-08-30 10:44:28 -0300
commit96f77142374da8a4a7d4e5e8afd559fbaf0430e8 (patch)
tree5514ffbf943c95bd5eed14b096a370fefe6586e6
parent05545816057cfdc54bb58199388a2d8878ae5542 (diff)
downloadlua-96f77142374da8a4a7d4e5e8afd559fbaf0430e8.tar.gz
lua-96f77142374da8a4a7d4e5e8afd559fbaf0430e8.tar.bz2
lua-96f77142374da8a4a7d4e5e8afd559fbaf0430e8.zip
Field 'Proto.is_vararg' uses only one bit
So that the other bits can be used for other purposes.
Diffstat (limited to '')
-rw-r--r--lcode.c4
-rw-r--r--ldebug.c8
-rw-r--r--ldo.c2
-rw-r--r--ldump.c2
-rw-r--r--lfunc.c2
-rw-r--r--lobject.h9
-rw-r--r--lparser.c4
-rw-r--r--lundump.c2
8 files changed, 20 insertions, 13 deletions
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) {
1849 lua_assert(i == 0 || isOT(*(pc - 1)) == isIT(*pc)); 1849 lua_assert(i == 0 || isOT(*(pc - 1)) == isIT(*pc));
1850 switch (GET_OPCODE(*pc)) { 1850 switch (GET_OPCODE(*pc)) {
1851 case OP_RETURN0: case OP_RETURN1: { 1851 case OP_RETURN0: case OP_RETURN1: {
1852 if (!(fs->needclose || p->is_vararg)) 1852 if (!(fs->needclose || (p->flag & PF_ISVARARG)))
1853 break; /* no extra work */ 1853 break; /* no extra work */
1854 /* else use OP_RETURN to do the extra work */ 1854 /* else use OP_RETURN to do the extra work */
1855 SET_OPCODE(*pc, OP_RETURN); 1855 SET_OPCODE(*pc, OP_RETURN);
@@ -1857,7 +1857,7 @@ void luaK_finish (FuncState *fs) {
1857 case OP_RETURN: case OP_TAILCALL: { 1857 case OP_RETURN: case OP_TAILCALL: {
1858 if (fs->needclose) 1858 if (fs->needclose)
1859 SETARG_k(*pc, 1); /* signal that it needs to close */ 1859 SETARG_k(*pc, 1); /* signal that it needs to close */
1860 if (p->is_vararg) 1860 if (p->flag & PF_ISVARARG)
1861 SETARG_C(*pc, p->numparams + 1); /* signal that it is vararg */ 1861 SETARG_C(*pc, p->numparams + 1); /* signal that it is vararg */
1862 break; 1862 break;
1863 } 1863 }
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) {
182 182
183 183
184static const char *findvararg (CallInfo *ci, int n, StkId *pos) { 184static const char *findvararg (CallInfo *ci, int n, StkId *pos) {
185 if (clLvalue(s2v(ci->func.p))->p->is_vararg) { 185 if (clLvalue(s2v(ci->func.p))->p->flag & PF_ISVARARG) {
186 int nextra = ci->u.l.nextraargs; 186 int nextra = ci->u.l.nextraargs;
187 if (n >= -nextra) { /* 'n' is negative */ 187 if (n >= -nextra) { /* 'n' is negative */
188 *pos = ci->func.p - nextra - (n + 1); 188 *pos = ci->func.p - nextra - (n + 1);
@@ -301,7 +301,7 @@ static void collectvalidlines (lua_State *L, Closure *f) {
301 sethvalue2s(L, L->top.p, t); /* push it on stack */ 301 sethvalue2s(L, L->top.p, t); /* push it on stack */
302 api_incr_top(L); 302 api_incr_top(L);
303 setbtvalue(&v); /* boolean 'true' to be the value of all indices */ 303 setbtvalue(&v); /* boolean 'true' to be the value of all indices */
304 if (!p->is_vararg) /* regular function? */ 304 if (!(p->flag & PF_ISVARARG)) /* regular function? */
305 i = 0; /* consider all instructions */ 305 i = 0; /* consider all instructions */
306 else { /* vararg function */ 306 else { /* vararg function */
307 lua_assert(GET_OPCODE(p->code[0]) == OP_VARARGPREP); 307 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,
344 ar->nparams = 0; 344 ar->nparams = 0;
345 } 345 }
346 else { 346 else {
347 ar->isvararg = f->l.p->is_vararg; 347 ar->isvararg = f->l.p->flag & PF_ISVARARG;
348 ar->nparams = f->l.p->numparams; 348 ar->nparams = f->l.p->numparams;
349 } 349 }
350 break; 350 break;
@@ -878,7 +878,7 @@ int luaG_tracecall (lua_State *L) {
878 Proto *p = ci_func(ci)->p; 878 Proto *p = ci_func(ci)->p;
879 ci->u.l.trap = 1; /* ensure hooks will be checked */ 879 ci->u.l.trap = 1; /* ensure hooks will be checked */
880 if (ci->u.l.savedpc == p->code) { /* first instruction (not resuming)? */ 880 if (ci->u.l.savedpc == p->code) { /* first instruction (not resuming)? */
881 if (p->is_vararg) 881 if (p->flag & PF_ISVARARG)
882 return 0; /* hooks will start at VARARGPREP instruction */ 882 return 0; /* hooks will start at VARARGPREP instruction */
883 else if (!(ci->callstatus & CIST_HOOKYIELD)) /* not yieded? */ 883 else if (!(ci->callstatus & CIST_HOOKYIELD)) /* not yieded? */
884 luaD_hookcall(L, ci); /* check 'call' hook */ 884 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) {
391 int ftransfer; 391 int ftransfer;
392 if (isLua(ci)) { 392 if (isLua(ci)) {
393 Proto *p = ci_func(ci)->p; 393 Proto *p = ci_func(ci)->p;
394 if (p->is_vararg) 394 if (p->flag & PF_ISVARARG)
395 delta = ci->u.l.nextraargs + p->numparams + 1; 395 delta = ci->u.l.nextraargs + p->numparams + 1;
396 } 396 }
397 ci->func.p += delta; /* if vararg, back to virtual 'func' */ 397 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) {
224 dumpInt(D, f->linedefined); 224 dumpInt(D, f->linedefined);
225 dumpInt(D, f->lastlinedefined); 225 dumpInt(D, f->lastlinedefined);
226 dumpByte(D, f->numparams); 226 dumpByte(D, f->numparams);
227 dumpByte(D, f->is_vararg); 227 dumpByte(D, f->flag);
228 dumpByte(D, f->maxstacksize); 228 dumpByte(D, f->maxstacksize);
229 dumpCode(D, f); 229 dumpCode(D, f);
230 dumpConstants(D, f); 230 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) {
253 f->upvalues = NULL; 253 f->upvalues = NULL;
254 f->sizeupvalues = 0; 254 f->sizeupvalues = 0;
255 f->numparams = 0; 255 f->numparams = 0;
256 f->is_vararg = 0; 256 f->flag = 0;
257 f->maxstacksize = 0; 257 f->maxstacksize = 0;
258 f->locvars = NULL; 258 f->locvars = NULL;
259 f->sizelocvars = 0; 259 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 {
544 int line; 544 int line;
545} AbsLineInfo; 545} AbsLineInfo;
546 546
547
548/*
549** Flags in Prototypes
550*/
551#define PF_ISVARARG 1
552
553
547/* 554/*
548** Function Prototypes 555** Function Prototypes
549*/ 556*/
550typedef struct Proto { 557typedef struct Proto {
551 CommonHeader; 558 CommonHeader;
552 lu_byte numparams; /* number of fixed (named) parameters */ 559 lu_byte numparams; /* number of fixed (named) parameters */
553 lu_byte is_vararg; 560 lu_byte flag;
554 lu_byte maxstacksize; /* number of registers needed by this function */ 561 lu_byte maxstacksize; /* number of registers needed by this function */
555 int sizeupvalues; /* size of 'upvalues' */ 562 int sizeupvalues; /* size of 'upvalues' */
556 int sizek; /* size of 'k' */ 563 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) {
959 959
960 960
961static void setvararg (FuncState *fs, int nparams) { 961static void setvararg (FuncState *fs, int nparams) {
962 fs->f->is_vararg = 1; 962 fs->f->flag |= PF_ISVARARG;
963 luaK_codeABC(fs, OP_VARARGPREP, nparams, 0, 0); 963 luaK_codeABC(fs, OP_VARARGPREP, nparams, 0, 0);
964} 964}
965 965
@@ -1177,7 +1177,7 @@ static void simpleexp (LexState *ls, expdesc *v) {
1177 } 1177 }
1178 case TK_DOTS: { /* vararg */ 1178 case TK_DOTS: { /* vararg */
1179 FuncState *fs = ls->fs; 1179 FuncState *fs = ls->fs;
1180 check_condition(ls, fs->f->is_vararg, 1180 check_condition(ls, fs->f->flag & PF_ISVARARG,
1181 "cannot use '...' outside a vararg function"); 1181 "cannot use '...' outside a vararg function");
1182 init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 0, 1)); 1182 init_exp(v, VVARARG, luaK_codeABC(fs, OP_VARARG, 0, 0, 1));
1183 break; 1183 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) {
287 f->linedefined = loadInt(S); 287 f->linedefined = loadInt(S);
288 f->lastlinedefined = loadInt(S); 288 f->lastlinedefined = loadInt(S);
289 f->numparams = loadByte(S); 289 f->numparams = loadByte(S);
290 f->is_vararg = loadByte(S); 290 f->flag = loadByte(S) & PF_ISVARARG; /* keep only the meaningful flags */
291 f->maxstacksize = loadByte(S); 291 f->maxstacksize = loadByte(S);
292 loadCode(S, f); 292 loadCode(S, f);
293 loadConstants(S, f); 293 loadConstants(S, f);