diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-11-22 18:15:44 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-11-22 18:15:44 +0100 |
commit | 6abdcf82859e158713a3d5aa6b1012748ea5c2a0 (patch) | |
tree | 622b31927858c892ef03ea59bd41d93175c546fd /src/vim9compile.c | |
parent | dcbab75db3ba5e812f119e08cda6a02c6b028a14 (diff) | |
download | vim-git-6abdcf82859e158713a3d5aa6b1012748ea5c2a0.tar.gz |
patch 8.2.2033: Vim9: :def without argument gives compilation errorv8.2.2033
Problem: Vim9: :def without argument gives compilation error.
Solution: Add the DEF instruction. (closes #7344)
Diffstat (limited to 'src/vim9compile.c')
-rw-r--r-- | src/vim9compile.c | 56 |
1 files changed, 49 insertions, 7 deletions
diff --git a/src/vim9compile.c b/src/vim9compile.c index 7102d488f..b870023ea 100644 --- a/src/vim9compile.c +++ b/src/vim9compile.c @@ -1433,6 +1433,26 @@ generate_NEWFUNC(cctx_T *cctx, char_u *lambda_name, char_u *func_name) } /* + * Generate an ISN_DEF instruction: list functions + */ + static int +generate_DEF(cctx_T *cctx, char_u *name, size_t len) +{ + isn_T *isn; + + RETURN_OK_IF_SKIP(cctx); + if ((isn = generate_instr(cctx, ISN_DEF)) == NULL) + return FAIL; + if (len > 0) + { + isn->isn_arg.string = vim_strnsave(name, len); + if (isn->isn_arg.string == NULL) + return FAIL; + } + return OK; +} + +/* * Generate an ISN_JUMP instruction. */ static int @@ -4801,6 +4821,27 @@ compile_nested_function(exarg_T *eap, cctx_T *cctx) return NULL; } + if (*name_start == '/') + { + name_end = skip_regexp(name_start + 1, '/', TRUE); + if (*name_end == '/') + ++name_end; + eap->nextcmd = check_nextcmd(name_end); + } + if (name_end == name_start || *skipwhite(name_end) != '(') + { + if (!ends_excmd2(name_start, name_end)) + { + semsg(_(e_invalid_command_str), eap->cmd); + return NULL; + } + + // "def" or "def Name": list functions + if (generate_DEF(cctx, name_start, name_end - name_start) == FAIL) + return NULL; + return eap->nextcmd == NULL ? (char_u *)"" : eap->nextcmd; + } + // Only g:Func() can use a namespace. if (name_start[1] == ':' && !is_global) { @@ -7736,22 +7777,23 @@ delete_instr(isn_T *isn) { switch (isn->isn_type) { + case ISN_DEF: case ISN_EXEC: + case ISN_LOADB: case ISN_LOADENV: case ISN_LOADG: - case ISN_LOADB: - case ISN_LOADW: - case ISN_LOADT: case ISN_LOADOPT: - case ISN_STRINGMEMBER: + case ISN_LOADT: + case ISN_LOADW: case ISN_PUSHEXC: + case ISN_PUSHFUNC: case ISN_PUSHS: + case ISN_STOREB: case ISN_STOREENV: case ISN_STOREG: - case ISN_STOREB: - case ISN_STOREW: case ISN_STORET: - case ISN_PUSHFUNC: + case ISN_STOREW: + case ISN_STRINGMEMBER: vim_free(isn->isn_arg.string); break; |