From e57c357738f88ee10ee46abd2d8ad190aa31c8ec Mon Sep 17 00:00:00 2001 From: Laurence Tratt Date: Tue, 7 Apr 2026 21:27:06 +0100 Subject: [PATCH] Put the location immediately after `FORPREP`. With the slight rejig in the Lua VM, this is as likely (or as unlikely!) to form a loop as putting things at `FORLOOP`, but means we don't have to go through one iteration of the interpreter to get to the jump to machine code. --- src/lparser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lparser.c b/src/lparser.c index 18a4b5d..b255bec 100644 --- a/src/lparser.c +++ b/src/lparser.c @@ -922,7 +922,7 @@ void ykifyCode(lua_State *L, Proto *f, int num_insts) { loc_pc = GETARG_sJ(i) + pc + 2 - 1; } else if ((GET_OPCODE(i) == OP_FORLOOP) || (GET_OPCODE(i) == OP_TFORLOOP)) { lua_assert(pc - GETARG_Bx(i) + 2 - 1 < pc); - loc_pc = pc; + loc_pc = pc - GETARG_Bx(i) + 2 - 1; } else { continue; }