Mercurial > vim
comparison src/vim9compile.c @ 22973:4c97c0747017 v8.2.2033
patch 8.2.2033: Vim9: :def without argument gives compilation error
Commit: https://github.com/vim/vim/commit/6abdcf82859e158713a3d5aa6b1012748ea5c2a0
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Nov 22 18:15:44 2020 +0100
patch 8.2.2033: Vim9: :def without argument gives compilation error
Problem: Vim9: :def without argument gives compilation error.
Solution: Add the DEF instruction. (closes https://github.com/vim/vim/issues/7344)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 22 Nov 2020 18:30:05 +0100 |
parents | d3b26055bfa8 |
children | a943b175586a |
comparison
equal
deleted
inserted
replaced
22972:d2b36acb42dd | 22973:4c97c0747017 |
---|---|
1427 if ((isn = generate_instr(cctx, ISN_NEWFUNC)) == NULL) | 1427 if ((isn = generate_instr(cctx, ISN_NEWFUNC)) == NULL) |
1428 return FAIL; | 1428 return FAIL; |
1429 isn->isn_arg.newfunc.nf_lambda = name; | 1429 isn->isn_arg.newfunc.nf_lambda = name; |
1430 isn->isn_arg.newfunc.nf_global = func_name; | 1430 isn->isn_arg.newfunc.nf_global = func_name; |
1431 | 1431 |
1432 return OK; | |
1433 } | |
1434 | |
1435 /* | |
1436 * Generate an ISN_DEF instruction: list functions | |
1437 */ | |
1438 static int | |
1439 generate_DEF(cctx_T *cctx, char_u *name, size_t len) | |
1440 { | |
1441 isn_T *isn; | |
1442 | |
1443 RETURN_OK_IF_SKIP(cctx); | |
1444 if ((isn = generate_instr(cctx, ISN_DEF)) == NULL) | |
1445 return FAIL; | |
1446 if (len > 0) | |
1447 { | |
1448 isn->isn_arg.string = vim_strnsave(name, len); | |
1449 if (isn->isn_arg.string == NULL) | |
1450 return FAIL; | |
1451 } | |
1432 return OK; | 1452 return OK; |
1433 } | 1453 } |
1434 | 1454 |
1435 /* | 1455 /* |
1436 * Generate an ISN_JUMP instruction. | 1456 * Generate an ISN_JUMP instruction. |
4797 | 4817 |
4798 if (eap->forceit) | 4818 if (eap->forceit) |
4799 { | 4819 { |
4800 emsg(_(e_cannot_use_bang_with_nested_def)); | 4820 emsg(_(e_cannot_use_bang_with_nested_def)); |
4801 return NULL; | 4821 return NULL; |
4822 } | |
4823 | |
4824 if (*name_start == '/') | |
4825 { | |
4826 name_end = skip_regexp(name_start + 1, '/', TRUE); | |
4827 if (*name_end == '/') | |
4828 ++name_end; | |
4829 eap->nextcmd = check_nextcmd(name_end); | |
4830 } | |
4831 if (name_end == name_start || *skipwhite(name_end) != '(') | |
4832 { | |
4833 if (!ends_excmd2(name_start, name_end)) | |
4834 { | |
4835 semsg(_(e_invalid_command_str), eap->cmd); | |
4836 return NULL; | |
4837 } | |
4838 | |
4839 // "def" or "def Name": list functions | |
4840 if (generate_DEF(cctx, name_start, name_end - name_start) == FAIL) | |
4841 return NULL; | |
4842 return eap->nextcmd == NULL ? (char_u *)"" : eap->nextcmd; | |
4802 } | 4843 } |
4803 | 4844 |
4804 // Only g:Func() can use a namespace. | 4845 // Only g:Func() can use a namespace. |
4805 if (name_start[1] == ':' && !is_global) | 4846 if (name_start[1] == ':' && !is_global) |
4806 { | 4847 { |
7734 void | 7775 void |
7735 delete_instr(isn_T *isn) | 7776 delete_instr(isn_T *isn) |
7736 { | 7777 { |
7737 switch (isn->isn_type) | 7778 switch (isn->isn_type) |
7738 { | 7779 { |
7780 case ISN_DEF: | |
7739 case ISN_EXEC: | 7781 case ISN_EXEC: |
7782 case ISN_LOADB: | |
7740 case ISN_LOADENV: | 7783 case ISN_LOADENV: |
7741 case ISN_LOADG: | 7784 case ISN_LOADG: |
7742 case ISN_LOADB: | 7785 case ISN_LOADOPT: |
7786 case ISN_LOADT: | |
7743 case ISN_LOADW: | 7787 case ISN_LOADW: |
7744 case ISN_LOADT: | |
7745 case ISN_LOADOPT: | |
7746 case ISN_STRINGMEMBER: | |
7747 case ISN_PUSHEXC: | 7788 case ISN_PUSHEXC: |
7789 case ISN_PUSHFUNC: | |
7748 case ISN_PUSHS: | 7790 case ISN_PUSHS: |
7791 case ISN_STOREB: | |
7749 case ISN_STOREENV: | 7792 case ISN_STOREENV: |
7750 case ISN_STOREG: | 7793 case ISN_STOREG: |
7751 case ISN_STOREB: | 7794 case ISN_STORET: |
7752 case ISN_STOREW: | 7795 case ISN_STOREW: |
7753 case ISN_STORET: | 7796 case ISN_STRINGMEMBER: |
7754 case ISN_PUSHFUNC: | |
7755 vim_free(isn->isn_arg.string); | 7797 vim_free(isn->isn_arg.string); |
7756 break; | 7798 break; |
7757 | 7799 |
7758 case ISN_LOADS: | 7800 case ISN_LOADS: |
7759 case ISN_STORES: | 7801 case ISN_STORES: |