Mercurial > vim
comparison src/vim9compile.c @ 21393:320581a133d9 v8.2.1247
patch 8.2.1247: Vim9: cannot index a character in a string
Commit: https://github.com/vim/vim/commit/bf9d8c3765a5255c0a0b577ca2e25d70a8bcb688
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Jul 19 17:55:44 2020 +0200
patch 8.2.1247: Vim9: cannot index a character in a string
Problem: Vim9: cannot index a character in a string.
Solution: Add ISN_STRINDEX instruction. (closes https://github.com/vim/vim/issues/6478)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 19 Jul 2020 18:00:04 +0200 |
parents | 8b882afa8ed2 |
children | 5cb6e676defd |
comparison
equal
deleted
inserted
replaced
21392:6b34289ace89 | 21393:320581a133d9 |
---|---|
3750 type_T **typep; | 3750 type_T **typep; |
3751 vartype_T vtype; | 3751 vartype_T vtype; |
3752 | 3752 |
3753 // list index: list[123] | 3753 // list index: list[123] |
3754 // dict member: dict[key] | 3754 // dict member: dict[key] |
3755 // string index: text[123] | |
3755 // TODO: blob index | 3756 // TODO: blob index |
3756 // TODO: more arguments | 3757 // TODO: more arguments |
3757 // TODO: recognize list or dict at runtime | 3758 // TODO: recognize list or dict at runtime |
3758 if (generate_ppconst(cctx, ppconst) == FAIL) | 3759 if (generate_ppconst(cctx, ppconst) == FAIL) |
3759 return FAIL; | 3760 return FAIL; |
3797 if (may_generate_2STRING(-1, cctx) == FAIL) | 3798 if (may_generate_2STRING(-1, cctx) == FAIL) |
3798 return FAIL; | 3799 return FAIL; |
3799 if (generate_instr_drop(cctx, ISN_MEMBER, 1) == FAIL) | 3800 if (generate_instr_drop(cctx, ISN_MEMBER, 1) == FAIL) |
3800 return FAIL; | 3801 return FAIL; |
3801 } | 3802 } |
3803 else if (vtype == VAR_STRING) | |
3804 { | |
3805 *typep = &t_number; | |
3806 if (generate_instr_drop(cctx, ISN_STRINDEX, 1) == FAIL) | |
3807 return FAIL; | |
3808 } | |
3802 else if (vtype == VAR_LIST || *typep == &t_any) | 3809 else if (vtype == VAR_LIST || *typep == &t_any) |
3803 { | 3810 { |
3804 if ((*typep)->tt_type == VAR_LIST) | 3811 if ((*typep)->tt_type == VAR_LIST) |
3805 *typep = (*typep)->tt_member; | 3812 *typep = (*typep)->tt_member; |
3806 if (generate_instr_drop(cctx, ISN_INDEX, 1) == FAIL) | 3813 if (generate_instr_drop(cctx, ISN_LISTINDEX, 1) == FAIL) |
3807 return FAIL; | 3814 return FAIL; |
3808 } | 3815 } |
3809 else | 3816 else |
3810 { | 3817 { |
3811 emsg(_(e_listdictblobreq)); | 3818 emsg(_(e_listdictblobreq)); |
7540 case ISN_ECHOMSG: | 7547 case ISN_ECHOMSG: |
7541 case ISN_ENDTRY: | 7548 case ISN_ENDTRY: |
7542 case ISN_EXECCONCAT: | 7549 case ISN_EXECCONCAT: |
7543 case ISN_EXECUTE: | 7550 case ISN_EXECUTE: |
7544 case ISN_FOR: | 7551 case ISN_FOR: |
7545 case ISN_INDEX: | 7552 case ISN_LISTINDEX: |
7553 case ISN_STRINDEX: | |
7546 case ISN_GETITEM: | 7554 case ISN_GETITEM: |
7547 case ISN_SLICE: | 7555 case ISN_SLICE: |
7548 case ISN_MEMBER: | 7556 case ISN_MEMBER: |
7549 case ISN_JUMP: | 7557 case ISN_JUMP: |
7550 case ISN_LOAD: | 7558 case ISN_LOAD: |