Mercurial > vim
comparison src/vim9compile.c @ 26729:b969fdb8cd46 v8.2.3893
patch 8.2.3893: Vim9: many local variables are initialized with an instruction
Commit: https://github.com/vim/vim/commit/5cd647935d0834b3064aa36384b8f6730fadadd6
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Dec 25 18:23:24 2021 +0000
patch 8.2.3893: Vim9: many local variables are initialized with an instruction
Problem: Vim9: many local variables are initialized with an instruction.
Solution: Initialize local variables to zero to avoid the instructions.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 25 Dec 2021 19:30:03 +0100 |
parents | 1b288eb2fcdc |
children | a8a4e1e7b111 |
comparison
equal
deleted
inserted
replaced
26728:71ae885c1426 | 26729:b969fdb8cd46 |
---|---|
1961 var_start = arg; | 1961 var_start = arg; |
1962 for (var_idx = 0; var_idx == 0 || var_idx < var_count; var_idx++) | 1962 for (var_idx = 0; var_idx == 0 || var_idx < var_count; var_idx++) |
1963 { | 1963 { |
1964 int instr_count = -1; | 1964 int instr_count = -1; |
1965 int save_lnum; | 1965 int save_lnum; |
1966 int skip_store = FALSE; | |
1966 | 1967 |
1967 if (var_start[0] == '_' && !eval_isnamec(var_start[1])) | 1968 if (var_start[0] == '_' && !eval_isnamec(var_start[1])) |
1968 { | 1969 { |
1969 // Ignore underscore in "[a, _, b] = list". | 1970 // Ignore underscore in "[a, _, b] = list". |
1970 if (var_count > 0) | 1971 if (var_count > 0) |
2184 case VAR_ANY: | 2185 case VAR_ANY: |
2185 case VAR_PARTIAL: | 2186 case VAR_PARTIAL: |
2186 case VAR_VOID: | 2187 case VAR_VOID: |
2187 case VAR_INSTR: | 2188 case VAR_INSTR: |
2188 case VAR_SPECIAL: // cannot happen | 2189 case VAR_SPECIAL: // cannot happen |
2189 generate_PUSHNR(cctx, 0); | 2190 // This is skipped for local variables, they are |
2191 // always initialized to zero. | |
2192 if (lhs.lhs_dest == dest_local) | |
2193 skip_store = TRUE; | |
2194 else | |
2195 generate_PUSHNR(cctx, 0); | |
2190 break; | 2196 break; |
2191 } | 2197 } |
2192 } | 2198 } |
2193 if (var_count == 0) | 2199 if (var_count == 0) |
2194 end = p; | 2200 end = p; |
2276 // Set the type in the list or dict, so that it can be checked, | 2282 // Set the type in the list or dict, so that it can be checked, |
2277 // also in legacy script. Not for "list<any> = val", then the | 2283 // also in legacy script. Not for "list<any> = val", then the |
2278 // type of "val" is used. | 2284 // type of "val" is used. |
2279 generate_SETTYPE(cctx, lhs.lhs_type); | 2285 generate_SETTYPE(cctx, lhs.lhs_type); |
2280 | 2286 |
2281 if (generate_store_lhs(cctx, &lhs, instr_count) == FAIL) | 2287 if (!skip_store && generate_store_lhs(cctx, &lhs, |
2288 instr_count, is_decl) == FAIL) | |
2282 { | 2289 { |
2283 cctx->ctx_lnum = save_lnum; | 2290 cctx->ctx_lnum = save_lnum; |
2284 goto theend; | 2291 goto theend; |
2285 } | 2292 } |
2286 } | 2293 } |