comparison src/vim9cmds.c @ 30291:61a688be1899 v9.0.0481

patch 9.0.0481: in :def function all closures in loop get the same variables Commit: https://github.com/vim/vim/commit/8fa745e7be3a791ac25f93ef0227bbc48ade8a37 Author: Bram Moolenaar <Bram@vim.org> Date: Fri Sep 16 19:04:24 2022 +0100 patch 9.0.0481: in :def function all closures in loop get the same variables Problem: In a :def function all closures in a loop get the same variables. Solution: Use a separate list of variables for LOADOUTER and STOREOUTER. Not copied at end of loop yet.
author Bram Moolenaar <Bram@vim.org>
date Fri, 16 Sep 2022 20:15:03 +0200
parents 42a6345b91fd
children bee38b1d323c
comparison
equal deleted inserted replaced
30290:e5d24015e8c5 30291:61a688be1899
1244 1244
1245 return arg; 1245 return arg;
1246 } 1246 }
1247 1247
1248 /* 1248 /*
1249 * Get the current information about variables declared inside a loop.
1250 * Returns zero if there are none, otherwise the count.
1251 * "loop_var_idx" is then set to the index of the first variable.
1252 */
1253 short
1254 get_loop_var_info(cctx_T *cctx, short *loop_var_idx)
1255 {
1256 scope_T *scope = cctx->ctx_scope;
1257 int start_local_count;
1258
1259 while (scope != NULL && scope->se_type != WHILE_SCOPE
1260 && scope->se_type != FOR_SCOPE)
1261 scope = scope->se_outer;
1262 if (scope == NULL)
1263 return 0;
1264
1265 if (scope->se_type == WHILE_SCOPE)
1266 start_local_count = scope->se_u.se_while.ws_local_count;
1267 else
1268 start_local_count = scope->se_u.se_for.fs_local_count;
1269 if (cctx->ctx_locals.ga_len > start_local_count)
1270 {
1271 *loop_var_idx = (short)start_local_count;
1272 return (short)(cctx->ctx_locals.ga_len - start_local_count);
1273 }
1274 return 0;
1275 }
1276
1277 /*
1278 * Get the index of the first variable in a loop, if any.
1279 * Returns -1 if none.
1280 */
1281 int
1282 get_loop_var_idx(cctx_T *cctx)
1283 {
1284 short loop_var_idx;
1285
1286 if (get_loop_var_info(cctx, &loop_var_idx) > 0)
1287 return loop_var_idx;
1288 return -1;
1289 }
1290
1291 /*
1249 * compile "continue" 1292 * compile "continue"
1250 */ 1293 */
1251 char_u * 1294 char_u *
1252 compile_continue(char_u *arg, cctx_T *cctx) 1295 compile_continue(char_u *arg, cctx_T *cctx)
1253 { 1296 {