From 3b6f8bfbe688fdd0f1c17bd023140804155624f3 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 29 Jan 2001 13:26:40 -0200 Subject: simpler implementation of for loops --- lcode.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'lcode.c') diff --git a/lcode.c b/lcode.c index 30a25a65..8fb0f70c 100644 --- a/lcode.c +++ b/lcode.c @@ -1,5 +1,5 @@ /* -** $Id: lcode.c,v 1.57 2001/01/19 13:20:30 roberto Exp roberto $ +** $Id: lcode.c,v 1.58 2001/01/29 13:14:49 roberto Exp roberto $ ** Code generator for Lua ** See Copyright Notice in lua.h */ @@ -59,6 +59,17 @@ static void luaK_fixjump (FuncState *fs, int pc, int dest) { } +/* +** prep-for instructions (OP_FORPREP & OP_LFORPREP) have a negated jump, +** as they simulate the real jump... +*/ +void luaK_fixfor (FuncState *fs, int pc, int dest) { + Instruction *jmp = &fs->f->code[pc]; + int offset = dest-(pc+1); + SETARG_S(*jmp, -offset); +} + + static int luaK_getjump (FuncState *fs, int pc) { int offset = GETARG_S(fs->f->code[pc]); if (offset == NO_JUMP) /* point to itself represents end of list */ -- cgit v1.2.3-55-g6feb