Clearer code for controlling maximum registers

Plus, added a test to check that limit.
This commit is contained in:
Roberto Ierusalimschy
2024-06-26 14:46:44 -03:00
parent c1dc08e8e8
commit fb7e5b76c9
3 changed files with 28 additions and 10 deletions

View File

@@ -31,10 +31,6 @@
#include "lvm.h"
/* Maximum number of registers in a Lua function (must fit in 8 bits) */
#define MAXREGS 255
#define hasjumps(e) ((e)->t != (e)->f)
@@ -466,7 +462,7 @@ static int luaK_codek (FuncState *fs, int reg, int k) {
void luaK_checkstack (FuncState *fs, int n) {
int newstack = fs->freereg + n;
if (newstack > fs->f->maxstacksize) {
if (newstack >= MAXREGS)
if (newstack > MAX_FSTACK)
luaX_syntaxerror(fs->ls,
"function or expression needs too many registers");
fs->f->maxstacksize = cast_byte(newstack);