mirror of
https://github.com/lua/lua
synced 2024-12-24 19:36:50 +03:00
some cleaning
This commit is contained in:
parent
690efef3de
commit
9e58e0df8f
4
lcode.h
4
lcode.h
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lcode.h,v 1.47 2005/11/08 19:44:31 roberto Exp roberto $
|
** $Id: lcode.h,v 1.48 2006/03/21 19:28:03 roberto Exp roberto $
|
||||||
** Code generator for Lua
|
** Code generator for Lua
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -42,6 +42,8 @@ typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr;
|
|||||||
|
|
||||||
#define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET)
|
#define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET)
|
||||||
|
|
||||||
|
#define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t)
|
||||||
|
|
||||||
LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx);
|
LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx);
|
||||||
LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C);
|
LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C);
|
||||||
LUAI_FUNC void luaK_fixline (FuncState *fs, int line);
|
LUAI_FUNC void luaK_fixline (FuncState *fs, int line);
|
||||||
|
24
lparser.c
24
lparser.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lparser.c,v 2.57 2008/04/02 17:19:22 roberto Exp roberto $
|
** $Id: lparser.c,v 2.58 2008/05/08 15:44:51 roberto Exp roberto $
|
||||||
** Lua Parser
|
** Lua Parser
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -1008,7 +1008,7 @@ static void whilestat (LexState *ls, int line) {
|
|||||||
enterblock(fs, &bl, 1);
|
enterblock(fs, &bl, 1);
|
||||||
checknext(ls, TK_DO);
|
checknext(ls, TK_DO);
|
||||||
block(ls);
|
block(ls);
|
||||||
luaK_patchlist(fs, luaK_jump(fs), whileinit);
|
luaK_jumpto(fs, whileinit);
|
||||||
check_match(ls, TK_END, TK_WHILE, line);
|
check_match(ls, TK_END, TK_WHILE, line);
|
||||||
leaveblock(fs);
|
leaveblock(fs);
|
||||||
luaK_patchtohere(fs, condexit); /* false conditions finish the loop */
|
luaK_patchtohere(fs, condexit); /* false conditions finish the loop */
|
||||||
@ -1029,13 +1029,13 @@ static void repeatstat (LexState *ls, int line) {
|
|||||||
condexit = cond(ls); /* read condition (inside scope block) */
|
condexit = cond(ls); /* read condition (inside scope block) */
|
||||||
if (!bl2.upval) { /* no upvalues? */
|
if (!bl2.upval) { /* no upvalues? */
|
||||||
leaveblock(fs); /* finish scope */
|
leaveblock(fs); /* finish scope */
|
||||||
luaK_patchlist(ls->fs, condexit, repeat_init); /* close the loop */
|
luaK_patchlist(fs, condexit, repeat_init); /* close the loop */
|
||||||
}
|
}
|
||||||
else { /* complete semantics when there are upvalues */
|
else { /* complete semantics when there are upvalues */
|
||||||
breakstat(ls); /* if condition then break */
|
breakstat(ls); /* if condition then break */
|
||||||
luaK_patchtohere(ls->fs, condexit); /* else... */
|
luaK_patchtohere(ls->fs, condexit); /* else... */
|
||||||
leaveblock(fs); /* finish scope... */
|
leaveblock(fs); /* finish scope... */
|
||||||
luaK_patchlist(ls->fs, luaK_jump(fs), repeat_init); /* and repeat */
|
luaK_jumpto(fs, repeat_init); /* and repeat */
|
||||||
}
|
}
|
||||||
leaveblock(fs); /* finish loop */
|
leaveblock(fs); /* finish loop */
|
||||||
}
|
}
|
||||||
@ -1055,7 +1055,7 @@ static void forbody (LexState *ls, int base, int line, int nvars, int isnum) {
|
|||||||
/* forbody -> DO block */
|
/* forbody -> DO block */
|
||||||
BlockCnt bl;
|
BlockCnt bl;
|
||||||
FuncState *fs = ls->fs;
|
FuncState *fs = ls->fs;
|
||||||
int prep, endfor;
|
int prep;
|
||||||
adjustlocalvars(ls, 3); /* control variables */
|
adjustlocalvars(ls, 3); /* control variables */
|
||||||
checknext(ls, TK_DO);
|
checknext(ls, TK_DO);
|
||||||
prep = isnum ? luaK_codeAsBx(fs, OP_FORPREP, base, NO_JUMP) : luaK_jump(fs);
|
prep = isnum ? luaK_codeAsBx(fs, OP_FORPREP, base, NO_JUMP) : luaK_jump(fs);
|
||||||
@ -1065,10 +1065,16 @@ static void forbody (LexState *ls, int base, int line, int nvars, int isnum) {
|
|||||||
block(ls);
|
block(ls);
|
||||||
leaveblock(fs); /* end of scope for declared variables */
|
leaveblock(fs); /* end of scope for declared variables */
|
||||||
luaK_patchtohere(fs, prep);
|
luaK_patchtohere(fs, prep);
|
||||||
endfor = (isnum) ? luaK_codeAsBx(fs, OP_FORLOOP, base, NO_JUMP) :
|
if (isnum) { /* numeric for? */
|
||||||
luaK_codeABC(fs, OP_TFORLOOP, base, 0, nvars);
|
int endfor = luaK_codeAsBx(fs, OP_FORLOOP, base, NO_JUMP);
|
||||||
luaK_fixline(fs, line); /* pretend that `OP_FOR' starts the loop */
|
luaK_patchlist(fs, endfor, prep + 1);
|
||||||
luaK_patchlist(fs, (isnum ? endfor : luaK_jump(fs)), prep + 1);
|
}
|
||||||
|
else { /* generic for */
|
||||||
|
luaK_codeABC(fs, OP_TFORLOOP, base, 0, nvars);
|
||||||
|
luaK_fixline(fs, line);
|
||||||
|
luaK_jumpto(fs, prep + 1);
|
||||||
|
}
|
||||||
|
luaK_fixline(fs, line);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user