Mercurial > vim
comparison src/vim9execute.c @ 21828:af5db9b6d210
patch 8.2.1463: Vim9: list slice not supported yet
Commit: https://github.com/vim/vim/commit/ed5918771fcf9877d8445e74c62ab1ce6b8e28c1
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Aug 15 22:14:53 2020 +0200
patch 8.2.1463: Vim9: list slice not supported yet
Problem: Vim9: list slice not supported yet.
Solution: Add support for list slicing.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 15 Aug 2020 22:15:03 +0200 |
parents | ccad66ac6c3e |
children | 21c552fb7da5 |
comparison
equal
deleted
inserted
replaced
21827:fbafd1638f76 | 21828:af5db9b6d210 |
---|---|
2284 tv->vval.v_string = res; | 2284 tv->vval.v_string = res; |
2285 } | 2285 } |
2286 break; | 2286 break; |
2287 | 2287 |
2288 case ISN_LISTINDEX: | 2288 case ISN_LISTINDEX: |
2289 { | 2289 case ISN_LISTSLICE: |
2290 { | |
2291 int is_slice = iptr->isn_type == ISN_LISTSLICE; | |
2290 list_T *list; | 2292 list_T *list; |
2291 varnumber_T n; | 2293 varnumber_T n1, n2; |
2292 listitem_T *li; | 2294 listitem_T *li; |
2293 typval_T temp_tv; | |
2294 | 2295 |
2295 // list index: list is at stack-2, index at stack-1 | 2296 // list index: list is at stack-2, index at stack-1 |
2296 tv = STACK_TV_BOT(-2); | 2297 // list slice: list is at stack-3, indexes at stack-2 and |
2298 // stack-1 | |
2299 tv = is_slice ? STACK_TV_BOT(-3) : STACK_TV_BOT(-2); | |
2297 if (tv->v_type != VAR_LIST) | 2300 if (tv->v_type != VAR_LIST) |
2298 { | 2301 { |
2299 SOURCING_LNUM = iptr->isn_lnum; | 2302 SOURCING_LNUM = iptr->isn_lnum; |
2300 emsg(_(e_listreq)); | 2303 emsg(_(e_listreq)); |
2301 goto on_error; | 2304 goto on_error; |
2307 { | 2310 { |
2308 SOURCING_LNUM = iptr->isn_lnum; | 2311 SOURCING_LNUM = iptr->isn_lnum; |
2309 emsg(_(e_number_exp)); | 2312 emsg(_(e_number_exp)); |
2310 goto on_error; | 2313 goto on_error; |
2311 } | 2314 } |
2312 n = tv->vval.v_number; | 2315 n1 = n2 = tv->vval.v_number; |
2313 clear_tv(tv); | 2316 clear_tv(tv); |
2314 if ((li = list_find(list, n)) == NULL) | 2317 |
2315 { | 2318 if (is_slice) |
2316 SOURCING_LNUM = iptr->isn_lnum; | 2319 { |
2317 semsg(_(e_listidx), n); | 2320 tv = STACK_TV_BOT(-2); |
2321 if (tv->v_type != VAR_NUMBER) | |
2322 { | |
2323 SOURCING_LNUM = iptr->isn_lnum; | |
2324 emsg(_(e_number_exp)); | |
2325 goto on_error; | |
2326 } | |
2327 n1 = tv->vval.v_number; | |
2328 clear_tv(tv); | |
2329 } | |
2330 | |
2331 ectx.ec_stack.ga_len -= is_slice ? 2 : 1; | |
2332 tv = STACK_TV_BOT(-1); | |
2333 if (list_slice_or_index(list, is_slice, n1, n2, tv, TRUE) | |
2334 == FAIL) | |
2318 goto on_error; | 2335 goto on_error; |
2319 } | |
2320 --ectx.ec_stack.ga_len; | |
2321 // Clear the list after getting the item, to avoid that it | |
2322 // makes the item invalid. | |
2323 tv = STACK_TV_BOT(-1); | |
2324 temp_tv = *tv; | |
2325 copy_tv(&li->li_tv, tv); | |
2326 clear_tv(&temp_tv); | |
2327 } | 2336 } |
2328 break; | 2337 break; |
2329 | 2338 |
2330 case ISN_SLICE: | 2339 case ISN_SLICE: |
2331 { | 2340 { |
3160 // expression operations | 3169 // expression operations |
3161 case ISN_CONCAT: smsg("%4d CONCAT", current); break; | 3170 case ISN_CONCAT: smsg("%4d CONCAT", current); break; |
3162 case ISN_STRINDEX: smsg("%4d STRINDEX", current); break; | 3171 case ISN_STRINDEX: smsg("%4d STRINDEX", current); break; |
3163 case ISN_STRSLICE: smsg("%4d STRSLICE", current); break; | 3172 case ISN_STRSLICE: smsg("%4d STRSLICE", current); break; |
3164 case ISN_LISTINDEX: smsg("%4d LISTINDEX", current); break; | 3173 case ISN_LISTINDEX: smsg("%4d LISTINDEX", current); break; |
3174 case ISN_LISTSLICE: smsg("%4d LISTSLICE", current); break; | |
3165 case ISN_SLICE: smsg("%4d SLICE %lld", | 3175 case ISN_SLICE: smsg("%4d SLICE %lld", |
3166 current, iptr->isn_arg.number); break; | 3176 current, iptr->isn_arg.number); break; |
3167 case ISN_GETITEM: smsg("%4d ITEM %lld", | 3177 case ISN_GETITEM: smsg("%4d ITEM %lld", |
3168 current, iptr->isn_arg.number); break; | 3178 current, iptr->isn_arg.number); break; |
3169 case ISN_MEMBER: smsg("%4d MEMBER", current); break; | 3179 case ISN_MEMBER: smsg("%4d MEMBER", current); break; |