diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2008-10-28 10:55:00 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2008-10-28 10:55:00 -0200 |
commit | 9e58e0df8f1d9abe7d9506b9685fb2362acf2b31 (patch) | |
tree | d31191a7b138f8f296542495d3230b134a4e312c | |
parent | 690efef3dee98ff05414b80ae6fa33a115ba6cdc (diff) | |
download | lua-9e58e0df8f1d9abe7d9506b9685fb2362acf2b31.tar.gz lua-9e58e0df8f1d9abe7d9506b9685fb2362acf2b31.tar.bz2 lua-9e58e0df8f1d9abe7d9506b9685fb2362acf2b31.zip |
some cleaning
-rw-r--r-- | lcode.h | 4 | ||||
-rw-r--r-- | lparser.c | 24 |
2 files changed, 18 insertions, 10 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lcode.h,v 1.47 2005/11/08 19:44:31 roberto Exp roberto $ | 2 | ** $Id: lcode.h,v 1.48 2006/03/21 19:28:03 roberto Exp roberto $ |
3 | ** Code generator for Lua | 3 | ** Code generator for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -42,6 +42,8 @@ typedef enum UnOpr { OPR_MINUS, OPR_NOT, OPR_LEN, OPR_NOUNOPR } UnOpr; | |||
42 | 42 | ||
43 | #define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) | 43 | #define luaK_setmultret(fs,e) luaK_setreturns(fs, e, LUA_MULTRET) |
44 | 44 | ||
45 | #define luaK_jumpto(fs,t) luaK_patchlist(fs, luaK_jump(fs), t) | ||
46 | |||
45 | LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); | 47 | LUAI_FUNC int luaK_codeABx (FuncState *fs, OpCode o, int A, unsigned int Bx); |
46 | LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); | 48 | LUAI_FUNC int luaK_codeABC (FuncState *fs, OpCode o, int A, int B, int C); |
47 | LUAI_FUNC void luaK_fixline (FuncState *fs, int line); | 49 | LUAI_FUNC void luaK_fixline (FuncState *fs, int line); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lparser.c,v 2.57 2008/04/02 17:19:22 roberto Exp roberto $ | 2 | ** $Id: lparser.c,v 2.58 2008/05/08 15:44:51 roberto Exp roberto $ |
3 | ** Lua Parser | 3 | ** Lua Parser |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -1008,7 +1008,7 @@ static void whilestat (LexState *ls, int line) { | |||
1008 | enterblock(fs, &bl, 1); | 1008 | enterblock(fs, &bl, 1); |
1009 | checknext(ls, TK_DO); | 1009 | checknext(ls, TK_DO); |
1010 | block(ls); | 1010 | block(ls); |
1011 | luaK_patchlist(fs, luaK_jump(fs), whileinit); | 1011 | luaK_jumpto(fs, whileinit); |
1012 | check_match(ls, TK_END, TK_WHILE, line); | 1012 | check_match(ls, TK_END, TK_WHILE, line); |
1013 | leaveblock(fs); | 1013 | leaveblock(fs); |
1014 | luaK_patchtohere(fs, condexit); /* false conditions finish the loop */ | 1014 | luaK_patchtohere(fs, condexit); /* false conditions finish the loop */ |
@@ -1029,13 +1029,13 @@ static void repeatstat (LexState *ls, int line) { | |||
1029 | condexit = cond(ls); /* read condition (inside scope block) */ | 1029 | condexit = cond(ls); /* read condition (inside scope block) */ |
1030 | if (!bl2.upval) { /* no upvalues? */ | 1030 | if (!bl2.upval) { /* no upvalues? */ |
1031 | leaveblock(fs); /* finish scope */ | 1031 | leaveblock(fs); /* finish scope */ |
1032 | luaK_patchlist(ls->fs, condexit, repeat_init); /* close the loop */ | 1032 | luaK_patchlist(fs, condexit, repeat_init); /* close the loop */ |
1033 | } | 1033 | } |
1034 | else { /* complete semantics when there are upvalues */ | 1034 | else { /* complete semantics when there are upvalues */ |
1035 | breakstat(ls); /* if condition then break */ | 1035 | breakstat(ls); /* if condition then break */ |
1036 | luaK_patchtohere(ls->fs, condexit); /* else... */ | 1036 | luaK_patchtohere(ls->fs, condexit); /* else... */ |
1037 | leaveblock(fs); /* finish scope... */ | 1037 | leaveblock(fs); /* finish scope... */ |
1038 | luaK_patchlist(ls->fs, luaK_jump(fs), repeat_init); /* and repeat */ | 1038 | luaK_jumpto(fs, repeat_init); /* and repeat */ |
1039 | } | 1039 | } |
1040 | leaveblock(fs); /* finish loop */ | 1040 | leaveblock(fs); /* finish loop */ |
1041 | } | 1041 | } |
@@ -1055,7 +1055,7 @@ static void forbody (LexState *ls, int base, int line, int nvars, int isnum) { | |||
1055 | /* forbody -> DO block */ | 1055 | /* forbody -> DO block */ |
1056 | BlockCnt bl; | 1056 | BlockCnt bl; |
1057 | FuncState *fs = ls->fs; | 1057 | FuncState *fs = ls->fs; |
1058 | int prep, endfor; | 1058 | int prep; |
1059 | adjustlocalvars(ls, 3); /* control variables */ | 1059 | adjustlocalvars(ls, 3); /* control variables */ |
1060 | checknext(ls, TK_DO); | 1060 | checknext(ls, TK_DO); |
1061 | prep = isnum ? luaK_codeAsBx(fs, OP_FORPREP, base, NO_JUMP) : luaK_jump(fs); | 1061 | 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) { | |||
1065 | block(ls); | 1065 | block(ls); |
1066 | leaveblock(fs); /* end of scope for declared variables */ | 1066 | leaveblock(fs); /* end of scope for declared variables */ |
1067 | luaK_patchtohere(fs, prep); | 1067 | luaK_patchtohere(fs, prep); |
1068 | endfor = (isnum) ? luaK_codeAsBx(fs, OP_FORLOOP, base, NO_JUMP) : | 1068 | if (isnum) { /* numeric for? */ |
1069 | luaK_codeABC(fs, OP_TFORLOOP, base, 0, nvars); | 1069 | int endfor = luaK_codeAsBx(fs, OP_FORLOOP, base, NO_JUMP); |
1070 | luaK_fixline(fs, line); /* pretend that `OP_FOR' starts the loop */ | 1070 | luaK_patchlist(fs, endfor, prep + 1); |
1071 | luaK_patchlist(fs, (isnum ? endfor : luaK_jump(fs)), prep + 1); | 1071 | } |
1072 | else { /* generic for */ | ||
1073 | luaK_codeABC(fs, OP_TFORLOOP, base, 0, nvars); | ||
1074 | luaK_fixline(fs, line); | ||
1075 | luaK_jumpto(fs, prep + 1); | ||
1076 | } | ||
1077 | luaK_fixline(fs, line); | ||
1072 | } | 1078 | } |
1073 | 1079 | ||
1074 | 1080 | ||