| 1170 | |
| 1171 | |
| 1172 | static void forstat (LexState *ls, int line) { |
| 1173 | /* forstat -> FOR (fornum | forlist) END */ |
| 1174 | FuncState *fs = ls->fs; |
| 1175 | TString *varname; |
| 1176 | BlockCnt bl; |
| 1177 | enterblock(fs, &bl, 1); /* scope for loop and control variables */ |
| 1178 | luaX_next(ls); /* skip `for' */ |
| 1179 | varname = str_checkname(ls); /* first variable name */ |
| 1180 | switch (ls->t.token) { |
| 1181 | case '=': fornum(ls, varname, line); break; |
| 1182 | case ',': case TK_IN: forlist(ls, varname); break; |
| 1183 | default: luaX_syntaxerror(ls, LUA_QL("=") " or " LUA_QL("in") " expected"); |
| 1184 | } |
| 1185 | check_match(ls, TK_END, TK_FOR, line); |
| 1186 | leaveblock(fs); /* loop scope (`break' jumps to this point) */ |
| 1187 | } |
| 1188 | |
| 1189 | |
| 1190 | static int test_then_block (LexState *ls) { |
| 1191 | /* test_then_block -> [IF | ELSEIF] cond THEN block */ |
| 1192 | int condexit; |
| 1193 | luaX_next(ls); /* skip IF or ELSEIF */ |
| 1194 | condexit = cond(ls); |
| 1195 | checknext(ls, TK_THEN); |
| 1196 | block(ls); /* `then' part */ |
| 1197 | return condexit; |
| 1198 | } |
| 1199 | |
| 1200 | |
| 1201 | static void ifstat (LexState *ls, int line) { |
| 1202 | /* ifstat -> IF cond THEN block {ELSEIF cond THEN block} [ELSE block] END */ |
| 1203 | FuncState *fs = ls->fs; |
| 1204 | int flist; |
| 1205 | int escapelist = NO_JUMP; |
| 1206 | flist = test_then_block(ls); /* IF cond THEN block */ |
| 1207 | while (ls->t.token == TK_ELSEIF) { |
| 1208 | luaK_concat(fs, &escapelist, luaK_jump(fs)); |
| 1209 | luaK_patchtohere(fs, flist); |
| 1210 | flist = test_then_block(ls); /* ELSEIF cond THEN block */ |
| 1211 | } |
| 1212 | if (ls->t.token == TK_ELSE) { |
| 1213 | luaK_concat(fs, &escapelist, luaK_jump(fs)); |
| 1214 | luaK_patchtohere(fs, flist); |
| 1215 | luaX_next(ls); /* skip ELSE (after patch, for correct line info) */ |
| 1216 | block(ls); /* `else' part */ |
| 1217 | } |
| 1218 | else |
| 1219 | luaK_concat(fs, &escapelist, flist); |
| 1220 | luaK_patchtohere(fs, escapelist); |
| 1221 | check_match(ls, TK_END, TK_IF, line); |
| 1222 | } |
| 1223 | |
| 1224 | |
| 1225 | static void localfunc (LexState *ls) { |
| 1226 | expdesc v, b; |
| 1227 | FuncState *fs = ls->fs; |
| 1228 | new_localvar(ls, str_checkname(ls), 0); |
| 1229 | init_exp(&v, VLOCAL, fs->freereg); |
no test coverage detected