From dd547c55c85ba48f481836ba76ecdfe69960bcd0 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Tue, 1 Feb 2011 16:03:10 -0200 Subject: new scheme to close upvalues in 'break'; jump instructions may do the close, avoiding the need for a OP_CLOSE instruction --- lcode.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'lcode.c') diff --git a/lcode.c b/lcode.c index 23969a69..b0edeafe 100644 --- a/lcode.c +++ b/lcode.c @@ -1,5 +1,5 @@ /* -** $Id: lcode.c,v 2.49 2010/07/07 16:27:29 roberto Exp roberto $ +** $Id: lcode.c,v 2.50 2011/01/31 14:28:41 roberto Exp roberto $ ** Code generator for Lua ** See Copyright Notice in lua.h */ @@ -171,6 +171,19 @@ void luaK_patchlist (FuncState *fs, int list, int target) { } +LUAI_FUNC void luaK_patchclose (FuncState *fs, int list, int level) { + level++; /* argument is +1 to reserve 0 as non-op */ + while (list != NO_JUMP) { + int next = getjump(fs, list); + lua_assert(GET_OPCODE(fs->f->code[list]) == OP_JMP && + (GETARG_A(fs->f->code[list]) == 0 || + GETARG_A(fs->f->code[list]) >= level)); + SETARG_A(fs->f->code[list], level); + list = next; + } +} + + void luaK_patchtohere (FuncState *fs, int list) { luaK_getlabel(fs); luaK_concat(fs, &fs->jpc, list); -- cgit v1.2.3-55-g6feb