Mercurial > vim
comparison src/vim9compile.c @ 22703:f2bfee4ac356 v8.2.1900
patch 8.2.1900: Vim9: command modifiers do not work
Commit: https://github.com/vim/vim/commit/02194d2bd54eacd0b7b9a017a3fe1702ecb80971
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Oct 24 23:08:38 2020 +0200
patch 8.2.1900: Vim9: command modifiers do not work
Problem: Vim9: command modifiers do not work.
Solution: Make most command modifiers work.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 24 Oct 2020 23:15:04 +0200 |
parents | e82579016863 |
children | 02b782e80ee4 |
comparison
equal
deleted
inserted
replaced
22702:81d7d3860786 | 22703:f2bfee4ac356 |
---|---|
140 int ctx_outer_used; // var in ctx_outer was used | 140 int ctx_outer_used; // var in ctx_outer was used |
141 | 141 |
142 garray_T ctx_type_stack; // type of each item on the stack | 142 garray_T ctx_type_stack; // type of each item on the stack |
143 garray_T *ctx_type_list; // list of pointers to allocated types | 143 garray_T *ctx_type_list; // list of pointers to allocated types |
144 | 144 |
145 int ctx_silent; // set when ISN_SILENT was generated | 145 int ctx_has_cmdmod; // ISN_CMDMOD was generated |
146 }; | 146 }; |
147 | 147 |
148 static void delete_def_function_contents(dfunc_T *dfunc); | 148 static void delete_def_function_contents(dfunc_T *dfunc); |
149 | 149 |
150 /* | 150 /* |
1821 isn->isn_arg.number = count; | 1821 isn->isn_arg.number = count; |
1822 return OK; | 1822 return OK; |
1823 } | 1823 } |
1824 | 1824 |
1825 /* | 1825 /* |
1826 * Generate any instructions for side effects of "cmdmod". | 1826 * Generate an instruction for any command modifiers. |
1827 */ | 1827 */ |
1828 static int | 1828 static int |
1829 generate_cmdmods(cctx_T *cctx, cmdmod_T *cmod) | 1829 generate_cmdmods(cctx_T *cctx, cmdmod_T *cmod) |
1830 { | 1830 { |
1831 isn_T *isn; | 1831 isn_T *isn; |
1832 | 1832 |
1833 // TODO: use more modifiers in the command | 1833 if (cmod->cmod_flags != 0 |
1834 if (cmod->cmod_flags & (CMOD_SILENT | CMOD_ERRSILENT)) | 1834 || cmod->cmod_split != 0 |
1835 { | 1835 || cmod->cmod_verbose != 0 |
1836 if ((isn = generate_instr(cctx, ISN_SILENT)) == NULL) | 1836 || cmod->cmod_tab != 0 |
1837 || cmod->cmod_filter_regmatch.regprog != NULL) | |
1838 { | |
1839 cctx->ctx_has_cmdmod = TRUE; | |
1840 | |
1841 if ((isn = generate_instr(cctx, ISN_CMDMOD)) == NULL) | |
1837 return FAIL; | 1842 return FAIL; |
1838 isn->isn_arg.number = (cmod->cmod_flags & CMOD_ERRSILENT) != 0; | 1843 isn->isn_arg.cmdmod.cf_cmdmod = ALLOC_ONE(cmdmod_T); |
1839 cctx->ctx_silent = (cmod->cmod_flags & CMOD_ERRSILENT) ? 2 : 1; | 1844 if (isn->isn_arg.cmdmod.cf_cmdmod == NULL) |
1840 } | 1845 return FAIL; |
1846 mch_memmove(isn->isn_arg.cmdmod.cf_cmdmod, cmod, sizeof(cmdmod_T)); | |
1847 // filter progam now belongs to the instruction | |
1848 cmod->cmod_filter_regmatch.regprog = NULL; | |
1849 } | |
1850 | |
1841 return OK; | 1851 return OK; |
1842 } | 1852 } |
1843 | 1853 |
1844 static int | 1854 static int |
1845 generate_restore_cmdmods(cctx_T *cctx) | 1855 generate_undo_cmdmods(cctx_T *cctx) |
1846 { | 1856 { |
1847 isn_T *isn; | 1857 isn_T *isn; |
1848 | 1858 |
1849 if (cctx->ctx_silent > 0) | 1859 if (cctx->ctx_has_cmdmod) |
1850 { | 1860 { |
1851 if ((isn = generate_instr(cctx, ISN_UNSILENT)) == NULL) | 1861 if ((isn = generate_instr(cctx, ISN_CMDMOD_REV)) == NULL) |
1852 return FAIL; | 1862 return FAIL; |
1853 isn->isn_arg.number = cctx->ctx_silent == 2; | 1863 } |
1854 cctx->ctx_silent = 0; | 1864 |
1855 } | |
1856 return OK; | 1865 return OK; |
1857 } | 1866 } |
1858 | 1867 |
1859 /* | 1868 /* |
1860 * Reserve space for a local variable. | 1869 * Reserve space for a local variable. |
7090 * Loop over all the lines of the function and generate instructions. | 7099 * Loop over all the lines of the function and generate instructions. |
7091 */ | 7100 */ |
7092 for (;;) | 7101 for (;;) |
7093 { | 7102 { |
7094 exarg_T ea; | 7103 exarg_T ea; |
7095 cmdmod_T local_cmdmod; | |
7096 int starts_with_colon = FALSE; | 7104 int starts_with_colon = FALSE; |
7097 char_u *cmd; | 7105 char_u *cmd; |
7106 cmdmod_T local_cmdmod; | |
7098 | 7107 |
7099 // Bail out on the first error to avoid a flood of errors and report | 7108 // Bail out on the first error to avoid a flood of errors and report |
7100 // the right line number when inside try/catch. | 7109 // the right line number when inside try/catch. |
7101 if (emsg_before != called_emsg) | 7110 if (emsg_before != called_emsg) |
7102 goto erret; | 7111 goto erret; |
7173 } | 7182 } |
7174 | 7183 |
7175 /* | 7184 /* |
7176 * COMMAND MODIFIERS | 7185 * COMMAND MODIFIERS |
7177 */ | 7186 */ |
7178 CLEAR_FIELD(local_cmdmod); | 7187 cctx.ctx_has_cmdmod = FALSE; |
7179 if (parse_command_modifiers(&ea, &errormsg, &local_cmdmod, FALSE) | 7188 if (parse_command_modifiers(&ea, &errormsg, &local_cmdmod, FALSE) |
7180 == FAIL) | 7189 == FAIL) |
7181 { | 7190 { |
7182 if (errormsg != NULL) | 7191 if (errormsg != NULL) |
7183 goto erret; | 7192 goto erret; |
7495 if (line == NULL) | 7504 if (line == NULL) |
7496 goto erret; | 7505 goto erret; |
7497 line = skipwhite(line); | 7506 line = skipwhite(line); |
7498 | 7507 |
7499 // Undo any command modifiers. | 7508 // Undo any command modifiers. |
7500 generate_restore_cmdmods(&cctx); | 7509 generate_undo_cmdmods(&cctx); |
7501 | 7510 |
7502 if (cctx.ctx_type_stack.ga_len < 0) | 7511 if (cctx.ctx_type_stack.ga_len < 0) |
7503 { | 7512 { |
7504 iemsg("Type stack underflow"); | 7513 iemsg("Type stack underflow"); |
7505 goto erret; | 7514 goto erret; |
7740 | 7749 |
7741 case ISN_CHECKTYPE: | 7750 case ISN_CHECKTYPE: |
7742 free_type(isn->isn_arg.type.ct_type); | 7751 free_type(isn->isn_arg.type.ct_type); |
7743 break; | 7752 break; |
7744 | 7753 |
7754 case ISN_CMDMOD: | |
7755 vim_regfree(isn->isn_arg.cmdmod.cf_cmdmod | |
7756 ->cmod_filter_regmatch.regprog); | |
7757 vim_free(isn->isn_arg.cmdmod.cf_cmdmod); | |
7758 break; | |
7759 | |
7745 case ISN_2BOOL: | 7760 case ISN_2BOOL: |
7746 case ISN_2STRING: | 7761 case ISN_2STRING: |
7747 case ISN_2STRING_ANY: | 7762 case ISN_2STRING_ANY: |
7748 case ISN_ADDBLOB: | 7763 case ISN_ADDBLOB: |
7749 case ISN_ADDLIST: | 7764 case ISN_ADDLIST: |
7752 case ISN_BCALL: | 7767 case ISN_BCALL: |
7753 case ISN_BLOBAPPEND: | 7768 case ISN_BLOBAPPEND: |
7754 case ISN_CATCH: | 7769 case ISN_CATCH: |
7755 case ISN_CHECKLEN: | 7770 case ISN_CHECKLEN: |
7756 case ISN_CHECKNR: | 7771 case ISN_CHECKNR: |
7772 case ISN_CMDMOD_REV: | |
7757 case ISN_COMPAREANY: | 7773 case ISN_COMPAREANY: |
7758 case ISN_COMPAREBLOB: | 7774 case ISN_COMPAREBLOB: |
7759 case ISN_COMPAREBOOL: | 7775 case ISN_COMPAREBOOL: |
7760 case ISN_COMPAREDICT: | 7776 case ISN_COMPAREDICT: |
7761 case ISN_COMPAREFLOAT: | 7777 case ISN_COMPAREFLOAT: |
7803 case ISN_PUSHNR: | 7819 case ISN_PUSHNR: |
7804 case ISN_PUSHSPEC: | 7820 case ISN_PUSHSPEC: |
7805 case ISN_PUT: | 7821 case ISN_PUT: |
7806 case ISN_RETURN: | 7822 case ISN_RETURN: |
7807 case ISN_SHUFFLE: | 7823 case ISN_SHUFFLE: |
7808 case ISN_SILENT: | |
7809 case ISN_SLICE: | 7824 case ISN_SLICE: |
7810 case ISN_STORE: | 7825 case ISN_STORE: |
7811 case ISN_STOREDICT: | 7826 case ISN_STOREDICT: |
7812 case ISN_STORELIST: | 7827 case ISN_STORELIST: |
7813 case ISN_STORENR: | 7828 case ISN_STORENR: |
7817 case ISN_STOREV: | 7832 case ISN_STOREV: |
7818 case ISN_STRINDEX: | 7833 case ISN_STRINDEX: |
7819 case ISN_STRSLICE: | 7834 case ISN_STRSLICE: |
7820 case ISN_THROW: | 7835 case ISN_THROW: |
7821 case ISN_TRY: | 7836 case ISN_TRY: |
7822 case ISN_UNSILENT: | |
7823 // nothing allocated | 7837 // nothing allocated |
7824 break; | 7838 break; |
7825 } | 7839 } |
7826 } | 7840 } |
7827 | 7841 |