annotate src/userfunc.c @ 19826:293a22b677a8 v8.2.0469

patch 8.2.0469: Vim9: no error for missing ] after list Commit: https://github.com/vim/vim/commit/ee619e5bc0992e818f2d9540b093b769b9c27651 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Mar 28 21:38:06 2020 +0100 patch 8.2.0469: Vim9: no error for missing ] after list Problem: Vim9: no error for missing ] after list. Solution: Add error message. Add more tests.
author Bram Moolenaar <Bram@vim.org>
date Sat, 28 Mar 2020 21:45:06 +0100
parents d64f403289db
children 4d033d36ba23
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10042
4aead6a9b7a9 commit https://github.com/vim/vim/commit/edf3f97ae2af024708ebb4ac614227327033ca47
Christian Brabandt <cb@256bit.org>
parents: 9951
diff changeset
1 /* vi:set ts=8 sts=4 sw=4 noet:
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2 *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 * VIM - Vi IMproved by Bram Moolenaar
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 * Do ":help uganda" in Vim to read copying and usage conditions.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 * Do ":help credits" in Vim to see a list of people who contributed.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 * See README.txt for an overview of the Vim source code.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 /*
18265
fe5afdc03bd2 patch 8.1.2127: the indent.c file is a bit big
Bram Moolenaar <Bram@vim.org>
parents: 18104
diff changeset
11 * userfunc.c: User defined function support
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 #include "vim.h"
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 #if defined(FEAT_EVAL) || defined(PROTO)
14323
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
17 // flags used in uf_flags
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
18 #define FC_ABORT 0x01 // abort function on error
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
19 #define FC_RANGE 0x02 // function accepts range
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
20 #define FC_DICT 0x04 // Dict function, uses "self"
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
21 #define FC_CLOSURE 0x08 // closure, uses outer scope variables
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
22 #define FC_DELETED 0x10 // :delfunction used while uf_refcount > 0
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
23 #define FC_REMOVED 0x20 // function redefined while uf_refcount > 0
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
24 #define FC_SANDBOX 0x40 // function defined in the sandbox
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
25 #define FC_DEAD 0x80 // function kept only for reference to dfunc
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
26 #define FC_EXPORT 0x100 // "export def Func()"
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 * All user-defined functions are found in this hashtable.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 static hashtab_T func_hashtab;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
33 // Used by get_func_tv()
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 static garray_T funcargs = GA_EMPTY;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
36 // pointer to funccal for currently active function
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
37 static funccall_T *current_funccal = NULL;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
38
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
39 // Pointer to list of previously used funccal, still around because some
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
40 // item in it is still being used.
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
41 static funccall_T *previous_funccal = NULL;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 static char *e_funcexts = N_("E122: Function %s already exists, add ! to replace it");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 static char *e_funcdict = N_("E717: Dictionary entry already exists");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 static char *e_funcref = N_("E718: Funcref required");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 static char *e_nofunc = N_("E130: Unknown function: %s");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47
9735
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
48 static void funccal_unref(funccall_T *fc, ufunc_T *fp, int force);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51 func_init()
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
52 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
53 hash_init(&func_hashtab);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
54 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
55
9597
3ca0fd9709b1 commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents: 9593
diff changeset
56 /*
17381
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
57 * Return the function hash table
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
58 */
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
59 hashtab_T *
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
60 func_tbl_get(void)
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
61 {
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
62 return &func_hashtab;
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
63 }
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
64
8f44c630c366 patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17370
diff changeset
65 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
66 * Get one function argument and an optional type: "arg: type".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
67 * Return a pointer to after the type.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
68 * When something is wrong return "arg".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
69 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
70 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
71 one_function_arg(char_u *arg, garray_T *newargs, garray_T *argtypes, int skip)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
72 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
73 char_u *p = arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
74
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
75 while (ASCII_ISALNUM(*p) || *p == '_')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
76 ++p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
77 if (arg == p || isdigit(*arg)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
78 || (p - arg == 9 && STRNCMP(arg, "firstline", 9) == 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
79 || (p - arg == 8 && STRNCMP(arg, "lastline", 8) == 0))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
80 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
81 if (!skip)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
82 semsg(_("E125: Illegal argument: %s"), arg);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
83 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
84 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
85 if (newargs != NULL && ga_grow(newargs, 1) == FAIL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
86 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
87 if (newargs != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
88 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
89 char_u *arg_copy;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
90 int c;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
91 int i;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
92
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
93 c = *p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
94 *p = NUL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
95 arg_copy = vim_strsave(arg);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
96 if (arg_copy == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
97 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
98 *p = c;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
99 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
100 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
101
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
102 // Check for duplicate argument name.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
103 for (i = 0; i < newargs->ga_len; ++i)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
104 if (STRCMP(((char_u **)(newargs->ga_data))[i], arg_copy) == 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
105 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
106 semsg(_("E853: Duplicate argument name: %s"), arg_copy);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
107 vim_free(arg_copy);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
108 return arg;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
109 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
110 ((char_u **)(newargs->ga_data))[newargs->ga_len] = arg_copy;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
111 newargs->ga_len++;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
112
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
113 *p = c;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
114 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
115
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
116 // get any type from "arg: type"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
117 if (argtypes != NULL && ga_grow(argtypes, 1) == OK)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
118 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
119 char_u *type = NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
120
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
121 if (*p == ':')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
122 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
123 type = skipwhite(p + 1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
124 p = skip_type(type);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
125 type = vim_strnsave(type, p - type);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
126 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
127 else if (*skipwhite(p) == ':')
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
128 emsg(_("E1059: No white space allowed before :"));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
129 ((char_u **)argtypes->ga_data)[argtypes->ga_len++] = type;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
130 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
131
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
132 return p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
133 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
134
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
135 /*
9597
3ca0fd9709b1 commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents: 9593
diff changeset
136 * Get function arguments.
3ca0fd9709b1 commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents: 9593
diff changeset
137 */
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
138 int
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
139 get_function_args(
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
140 char_u **argp,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
141 char_u endchar,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
142 garray_T *newargs,
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
143 garray_T *argtypes, // NULL unless using :def
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
144 int *varargs,
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
145 garray_T *default_args,
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
146 int skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
147 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
148 int mustend = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
149 char_u *arg = *argp;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
150 char_u *p = arg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
151 int c;
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
152 int any_default = FALSE;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
153 char_u *expr;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
154
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
155 if (newargs != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
156 ga_init2(newargs, (int)sizeof(char_u *), 3);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
157 if (argtypes != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
158 ga_init2(argtypes, (int)sizeof(char_u *), 3);
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
159 if (default_args != NULL)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
160 ga_init2(default_args, (int)sizeof(char_u *), 3);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
161
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
162 if (varargs != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
163 *varargs = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
164
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
165 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
166 * Isolate the arguments: "arg1, arg2, ...)"
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
167 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
168 while (*p != endchar)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
169 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
170 if (p[0] == '.' && p[1] == '.' && p[2] == '.')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
171 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
172 if (varargs != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
173 *varargs = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
174 p += 3;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
175 mustend = TRUE;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
176
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
177 if (argtypes != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
178 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
179 // ...name: list<type>
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
180 if (!ASCII_ISALPHA(*p))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
181 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
182 emsg(_("E1055: Missing name after ..."));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
183 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
184 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
185
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
186 arg = p;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
187 p = one_function_arg(p, newargs, argtypes, skip);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
188 if (p == arg)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
189 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
190 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
191 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
192 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
193 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
194 arg = p;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
195 p = one_function_arg(p, newargs, argtypes, skip);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
196 if (p == arg)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
197 break;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
198
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
199 if (*skipwhite(p) == '=' && default_args != NULL)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
200 {
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
201 typval_T rettv;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
202
19328
e99e6d794597 patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents: 19297
diff changeset
203 // find the end of the expression (doesn't evaluate it)
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
204 any_default = TRUE;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
205 p = skipwhite(p) + 1;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
206 p = skipwhite(p);
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
207 expr = p;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
208 if (eval1(&p, &rettv, FALSE) != FAIL)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
209 {
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
210 if (ga_grow(default_args, 1) == FAIL)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
211 goto err_ret;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
212
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
213 // trim trailing whitespace
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
214 while (p > expr && VIM_ISWHITE(p[-1]))
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
215 p--;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
216 c = *p;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
217 *p = NUL;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
218 expr = vim_strsave(expr);
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
219 if (expr == NULL)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
220 {
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
221 *p = c;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
222 goto err_ret;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
223 }
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
224 ((char_u **)(default_args->ga_data))
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
225 [default_args->ga_len] = expr;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
226 default_args->ga_len++;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
227 *p = c;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
228 }
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
229 else
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
230 mustend = TRUE;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
231 }
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
232 else if (any_default)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
233 {
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
234 emsg(_("E989: Non-default argument follows default argument"));
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
235 mustend = TRUE;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
236 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
237 if (*p == ',')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
238 ++p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
239 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
240 mustend = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
241 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
242 p = skipwhite(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
243 if (mustend && *p != endchar)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
244 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
245 if (!skip)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
246 semsg(_(e_invarg2), *argp);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
247 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
248 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
249 }
9597
3ca0fd9709b1 commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents: 9593
diff changeset
250 if (*p != endchar)
3ca0fd9709b1 commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents: 9593
diff changeset
251 goto err_ret;
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
252 ++p; // skip "endchar"
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
253
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
254 *argp = p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
255 return OK;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
256
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
257 err_ret:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
258 if (newargs != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
259 ga_clear_strings(newargs);
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
260 if (default_args != NULL)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
261 ga_clear_strings(default_args);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
262 return FAIL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
263 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
264
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
265 /*
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
266 * Register function "fp" as using "current_funccal" as its scope.
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
267 */
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
268 static int
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
269 register_closure(ufunc_T *fp)
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
270 {
9733
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
271 if (fp->uf_scoped == current_funccal)
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
272 // no change
9733
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
273 return OK;
9735
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
274 funccal_unref(fp->uf_scoped, fp, FALSE);
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
275 fp->uf_scoped = current_funccal;
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
276 current_funccal->fc_refcount++;
9733
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
277
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
278 if (ga_grow(&current_funccal->fc_funcs, 1) == FAIL)
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
279 return FAIL;
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
280 ((ufunc_T **)current_funccal->fc_funcs.ga_data)
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
281 [current_funccal->fc_funcs.ga_len++] = fp;
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
282 return OK;
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
283 }
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
284
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
285 static void
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
286 set_ufunc_name(ufunc_T *fp, char_u *name)
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
287 {
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
288 STRCPY(fp->uf_name, name);
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
289
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
290 if (name[0] == K_SPECIAL)
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
291 {
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
292 fp->uf_name_exp = alloc(STRLEN(name) + 3);
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
293 if (fp->uf_name_exp != NULL)
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
294 {
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
295 STRCPY(fp->uf_name_exp, "<SNR>");
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
296 STRCAT(fp->uf_name_exp, fp->uf_name + 3);
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
297 }
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
298 }
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
299 }
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
300
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
301 /*
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
302 * Parse a lambda expression and get a Funcref from "*arg".
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
303 * Return OK or FAIL. Returns NOTDONE for dict or {expr}.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
304 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
305 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
306 get_lambda_tv(char_u **arg, typval_T *rettv, int evaluate)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
307 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
308 garray_T newargs;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
309 garray_T newlines;
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
310 garray_T *pnewargs;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
311 ufunc_T *fp = NULL;
15820
bd75c9df2a14 patch 8.1.0917: double free when running out of memory
Bram Moolenaar <Bram@vim.org>
parents: 15780
diff changeset
312 partial_T *pt = NULL;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
313 int varargs;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
314 int ret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
315 char_u *start = skipwhite(*arg + 1);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
316 char_u *s, *e;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
317 static int lambda_no = 0;
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
318 int *old_eval_lavars = eval_lavars_used;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
319 int eval_lavars = FALSE;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
320
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
321 ga_init(&newargs);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
322 ga_init(&newlines);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
323
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
324 // First, check if this is a lambda expression. "->" must exist.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
325 ret = get_function_args(&start, '-', NULL, NULL, NULL, NULL, TRUE);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
326 if (ret == FAIL || *start != '>')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
327 return NOTDONE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
328
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
329 // Parse the arguments again.
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
330 if (evaluate)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
331 pnewargs = &newargs;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
332 else
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
333 pnewargs = NULL;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
334 *arg = skipwhite(*arg + 1);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
335 // TODO: argument types
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
336 ret = get_function_args(arg, '-', pnewargs, NULL, &varargs, NULL, FALSE);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
337 if (ret == FAIL || **arg != '>')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
338 goto errret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
339
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
340 // Set up a flag for checking local variables and arguments.
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
341 if (evaluate)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
342 eval_lavars_used = &eval_lavars;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
343
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
344 // Get the start and the end of the expression.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
345 *arg = skipwhite(*arg + 1);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
346 s = *arg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
347 ret = skip_expr(arg);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
348 if (ret == FAIL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
349 goto errret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
350 e = *arg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
351 *arg = skipwhite(*arg);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
352 if (**arg != '}')
19826
293a22b677a8 patch 8.2.0469: Vim9: no error for missing ] after list
Bram Moolenaar <Bram@vim.org>
parents: 19685
diff changeset
353 {
293a22b677a8 patch 8.2.0469: Vim9: no error for missing ] after list
Bram Moolenaar <Bram@vim.org>
parents: 19685
diff changeset
354 semsg(_("E451: Expected }: %s"), *arg);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
355 goto errret;
19826
293a22b677a8 patch 8.2.0469: Vim9: no error for missing ] after list
Bram Moolenaar <Bram@vim.org>
parents: 19685
diff changeset
356 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
357 ++*arg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
358
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
359 if (evaluate)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
360 {
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
361 int len, flags = 0;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
362 char_u *p;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
363 char_u name[20];
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
364
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
365 sprintf((char*)name, "<lambda>%d", ++lambda_no);
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
366
17659
121bdff812b4 patch 8.1.1827: allocating more memory than needed for extended structs
Bram Moolenaar <Bram@vim.org>
parents: 17646
diff changeset
367 fp = alloc_clear(offsetof(ufunc_T, uf_name) + STRLEN(name) + 1);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
368 if (fp == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
369 goto errret;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
370 fp->uf_dfunc_idx = -1;
16825
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
371 pt = ALLOC_CLEAR_ONE(partial_T);
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
372 if (pt == NULL)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
373 goto errret;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
374
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
375 ga_init2(&newlines, (int)sizeof(char_u *), 1);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
376 if (ga_grow(&newlines, 1) == FAIL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
377 goto errret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
378
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
379 // Add "return " before the expression.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
380 len = 7 + e - s + 1;
16825
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
381 p = alloc(len);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
382 if (p == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
383 goto errret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
384 ((char_u **)(newlines.ga_data))[newlines.ga_len++] = p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
385 STRCPY(p, "return ");
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
386 vim_strncpy(p + 7, s, e - s);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
387
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
388 fp->uf_refcount = 1;
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
389 set_ufunc_name(fp, name);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
390 hash_add(&func_hashtab, UF2HIKEY(fp));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
391 fp->uf_args = newargs;
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
392 ga_init(&fp->uf_def_args);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
393 fp->uf_lines = newlines;
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
394 if (current_funccal != NULL && eval_lavars)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
395 {
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
396 flags |= FC_CLOSURE;
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
397 if (register_closure(fp) == FAIL)
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
398 goto errret;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
399 }
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
400 else
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
401 fp->uf_scoped = NULL;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
402
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
403 #ifdef FEAT_PROFILE
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
404 if (prof_def_func())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
405 func_do_profile(fp);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
406 #endif
14323
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
407 if (sandbox)
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
408 flags |= FC_SANDBOX;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
409 // can be called with more args than uf_args.ga_len
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
410 fp->uf_varargs = TRUE;
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
411 fp->uf_flags = flags;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
412 fp->uf_calls = 0;
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14430
diff changeset
413 fp->uf_script_ctx = current_sctx;
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
414 fp->uf_script_ctx.sc_lnum += SOURCING_LNUM - newlines.ga_len;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
415
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
416 pt->pt_func = fp;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
417 pt->pt_refcount = 1;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
418 rettv->vval.v_partial = pt;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
419 rettv->v_type = VAR_PARTIAL;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
420 }
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
421
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
422 eval_lavars_used = old_eval_lavars;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
423 return OK;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
424
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
425 errret:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
426 ga_clear_strings(&newargs);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
427 ga_clear_strings(&newlines);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
428 vim_free(fp);
15820
bd75c9df2a14 patch 8.1.0917: double free when running out of memory
Bram Moolenaar <Bram@vim.org>
parents: 15780
diff changeset
429 vim_free(pt);
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
430 eval_lavars_used = old_eval_lavars;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
431 return FAIL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
432 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
433
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
434 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
435 * Check if "name" is a variable of type VAR_FUNC. If so, return the function
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
436 * name it contains, otherwise return "name".
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
437 * If "partialp" is not NULL, and "name" is of type VAR_PARTIAL also set
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
438 * "partialp".
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
439 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
440 char_u *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
441 deref_func_name(char_u *name, int *lenp, partial_T **partialp, int no_autoload)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
442 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
443 dictitem_T *v;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
444 int cc;
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
445 char_u *s;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
446
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
447 if (partialp != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
448 *partialp = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
449
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
450 cc = name[*lenp];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
451 name[*lenp] = NUL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
452 v = find_var(name, NULL, no_autoload);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
453 name[*lenp] = cc;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
454 if (v != NULL && v->di_tv.v_type == VAR_FUNC)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
455 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
456 if (v->di_tv.vval.v_string == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
457 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
458 *lenp = 0;
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
459 return (char_u *)""; // just in case
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
460 }
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
461 s = v->di_tv.vval.v_string;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
462 *lenp = (int)STRLEN(s);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
463 return s;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
464 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
465
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
466 if (v != NULL && v->di_tv.v_type == VAR_PARTIAL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
467 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
468 partial_T *pt = v->di_tv.vval.v_partial;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
469
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
470 if (pt == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
471 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
472 *lenp = 0;
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
473 return (char_u *)""; // just in case
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
474 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
475 if (partialp != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
476 *partialp = pt;
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
477 s = partial_name(pt);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
478 *lenp = (int)STRLEN(s);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
479 return s;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
480 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
481
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
482 return name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
483 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
484
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
485 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
486 * Give an error message with a function name. Handle <SNR> things.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
487 * "ermsg" is to be passed without translation, use N_() instead of _().
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
488 */
18576
e9675870c480 patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents: 18572
diff changeset
489 void
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
490 emsg_funcname(char *ermsg, char_u *name)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
491 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
492 char_u *p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
493
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
494 if (*name == K_SPECIAL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
495 p = concat_str((char_u *)"<SNR>", name + 3);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
496 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
497 p = name;
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
498 semsg(_(ermsg), p);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
499 if (p != name)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
500 vim_free(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
501 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
502
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
503 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
504 * Allocate a variable for the result of a function.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
505 * Return OK or FAIL.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
506 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
507 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
508 get_func_tv(
16634
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
509 char_u *name, // name of the function
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
510 int len, // length of "name" or -1 to use strlen()
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
511 typval_T *rettv,
16634
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
512 char_u **arg, // argument, pointing to the '('
17606
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
513 funcexe_T *funcexe) // various values
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
514 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
515 char_u *argp;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
516 int ret = OK;
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
517 typval_T argvars[MAX_FUNC_ARGS + 1]; // vars for arguments
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
518 int argcount = 0; // number of arguments found
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
519
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
520 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
521 * Get the arguments.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
522 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
523 argp = *arg;
17606
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
524 while (argcount < MAX_FUNC_ARGS - (funcexe->partial == NULL ? 0
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
525 : funcexe->partial->pt_argc))
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
526 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
527 argp = skipwhite(argp + 1); // skip the '(' or ','
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
528 if (*argp == ')' || *argp == ',' || *argp == NUL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
529 break;
17606
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
530 if (eval1(&argp, &argvars[argcount], funcexe->evaluate) == FAIL)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
531 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
532 ret = FAIL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
533 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
534 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
535 ++argcount;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
536 if (*argp != ',')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
537 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
538 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
539 if (*argp == ')')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
540 ++argp;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
541 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
542 ret = FAIL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
543
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
544 if (ret == OK)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
545 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
546 int i = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
547
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
548 if (get_vim_var_nr(VV_TESTING))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
549 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
550 // Prepare for calling test_garbagecollect_now(), need to know
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
551 // what variables are used on the call stack.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
552 if (funcargs.ga_itemsize == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
553 ga_init2(&funcargs, (int)sizeof(typval_T *), 50);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
554 for (i = 0; i < argcount; ++i)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
555 if (ga_grow(&funcargs, 1) == OK)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
556 ((typval_T **)funcargs.ga_data)[funcargs.ga_len++] =
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
557 &argvars[i];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
558 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
559
17606
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
560 ret = call_func(name, len, rettv, argcount, argvars, funcexe);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
561
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
562 funcargs.ga_len -= i;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
563 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
564 else if (!aborting())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
565 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
566 if (argcount == MAX_FUNC_ARGS)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
567 emsg_funcname(N_("E740: Too many arguments for function %s"), name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
568 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
569 emsg_funcname(N_("E116: Invalid arguments for function %s"), name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
570 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
571
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
572 while (--argcount >= 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
573 clear_tv(&argvars[argcount]);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
574
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
575 *arg = skipwhite(argp);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
576 return ret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
577 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
578
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
579 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
580 * Return TRUE if "p" starts with "<SID>" or "s:".
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
581 * Only works if eval_fname_script() returned non-zero for "p"!
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
582 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
583 static int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
584 eval_fname_sid(char_u *p)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
585 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
586 return (*p == 's' || TOUPPER_ASC(p[2]) == 'I');
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
587 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
588
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
589 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
590 * In a script change <SID>name() and s:name() to K_SNR 123_name().
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
591 * Change <SNR>123_name() to K_SNR 123_name().
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
592 * Use "fname_buf[FLEN_FIXED + 1]" when it fits, otherwise allocate memory
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
593 * (slow).
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
594 */
19330
9c8b803fe598 patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents: 19328
diff changeset
595 char_u *
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
596 fname_trans_sid(char_u *name, char_u *fname_buf, char_u **tofree, int *error)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
597 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
598 int llen;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
599 char_u *fname;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
600 int i;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
601
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
602 llen = eval_fname_script(name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
603 if (llen > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
604 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
605 fname_buf[0] = K_SPECIAL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
606 fname_buf[1] = KS_EXTRA;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
607 fname_buf[2] = (int)KE_SNR;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
608 i = 3;
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
609 if (eval_fname_sid(name)) // "<SID>" or "s:"
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
610 {
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14430
diff changeset
611 if (current_sctx.sc_sid <= 0)
19013
dd9ab0674eec patch 8.2.0067: ERROR_UNKNOWN clashes on some systems
Bram Moolenaar <Bram@vim.org>
parents: 18991
diff changeset
612 *error = FCERR_SCRIPT;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
613 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
614 {
16378
3d6b282e2d6e patch 8.1.1194: typos and small problems in source files
Bram Moolenaar <Bram@vim.org>
parents: 16003
diff changeset
615 sprintf((char *)fname_buf + 3, "%ld_",
3d6b282e2d6e patch 8.1.1194: typos and small problems in source files
Bram Moolenaar <Bram@vim.org>
parents: 16003
diff changeset
616 (long)current_sctx.sc_sid);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
617 i = (int)STRLEN(fname_buf);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
618 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
619 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
620 if (i + STRLEN(name + llen) < FLEN_FIXED)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
621 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
622 STRCPY(fname_buf + i, name + llen);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
623 fname = fname_buf;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
624 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
625 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
626 {
16764
ef00b6bc186b patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents: 16708
diff changeset
627 fname = alloc(i + STRLEN(name + llen) + 1);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
628 if (fname == NULL)
19013
dd9ab0674eec patch 8.2.0067: ERROR_UNKNOWN clashes on some systems
Bram Moolenaar <Bram@vim.org>
parents: 18991
diff changeset
629 *error = FCERR_OTHER;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
630 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
631 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
632 *tofree = fname;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
633 mch_memmove(fname, fname_buf, (size_t)i);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
634 STRCPY(fname + i, name + llen);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
635 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
636 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
637 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
638 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
639 fname = name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
640 return fname;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
641 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
642
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
643 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
644 * Find a function "name" in script "sid".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
645 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
646 static ufunc_T *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
647 find_func_with_sid(char_u *name, int sid)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
648 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
649 hashitem_T *hi;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
650 char_u buffer[200];
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
651
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
652 buffer[0] = K_SPECIAL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
653 buffer[1] = KS_EXTRA;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
654 buffer[2] = (int)KE_SNR;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
655 vim_snprintf((char *)buffer + 3, sizeof(buffer) - 3, "%ld_%s",
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
656 (long)sid, name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
657 hi = hash_find(&func_hashtab, buffer);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
658 if (!HASHITEM_EMPTY(hi))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
659 return HI2UF(hi);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
660
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
661 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
662 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
663
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
664 /*
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
665 * Find a function by name, return pointer to it in ufuncs.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
666 * Return NULL for unknown function.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
667 */
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
668 static ufunc_T *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
669 find_func_even_dead(char_u *name, cctx_T *cctx)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
670 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
671 hashitem_T *hi;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
672 ufunc_T *func;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
673 imported_T *imported;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
674
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
675 if (in_vim9script())
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
676 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
677 // Find script-local function before global one.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
678 func = find_func_with_sid(name, current_sctx.sc_sid);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
679 if (func != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
680 return func;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
681
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
682 // Find imported funcion before global one.
19285
86665583dc83 patch 8.2.0201: cannot assign to an imported variable
Bram Moolenaar <Bram@vim.org>
parents: 19281
diff changeset
683 imported = find_imported(name, 0, cctx);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
684 if (imported != NULL && imported->imp_funcname != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
685 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
686 hi = hash_find(&func_hashtab, imported->imp_funcname);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
687 if (!HASHITEM_EMPTY(hi))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
688 return HI2UF(hi);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
689 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
690 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
691
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
692 hi = hash_find(&func_hashtab, name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
693 if (!HASHITEM_EMPTY(hi))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
694 return HI2UF(hi);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
695
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
696 return NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
697 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
698
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
699 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
700 * Find a function by name, return pointer to it in ufuncs.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
701 * "cctx" is passed in a :def function to find imported functions.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
702 * Return NULL for unknown or dead function.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
703 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
704 ufunc_T *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
705 find_func(char_u *name, cctx_T *cctx)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
706 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
707 ufunc_T *fp = find_func_even_dead(name, cctx);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
708
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
709 if (fp != NULL && (fp->uf_flags & FC_DEAD) == 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
710 return fp;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
711 return NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
712 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
713
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
714 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
715 * Copy the function name of "fp" to buffer "buf".
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
716 * "buf" must be able to hold the function name plus three bytes.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
717 * Takes care of script-local function names.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
718 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
719 static void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
720 cat_func_name(char_u *buf, ufunc_T *fp)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
721 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
722 if (fp->uf_name[0] == K_SPECIAL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
723 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
724 STRCPY(buf, "<SNR>");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
725 STRCAT(buf, fp->uf_name + 3);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
726 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
727 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
728 STRCPY(buf, fp->uf_name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
729 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
730
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
731 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
732 * Add a number variable "name" to dict "dp" with value "nr".
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
733 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
734 static void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
735 add_nr_var(
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
736 dict_T *dp,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
737 dictitem_T *v,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
738 char *name,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
739 varnumber_T nr)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
740 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
741 STRCPY(v->di_key, name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
742 v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
743 hash_add(&dp->dv_hashtab, DI2HIKEY(v));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
744 v->di_tv.v_type = VAR_NUMBER;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
745 v->di_tv.v_lock = VAR_FIXED;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
746 v->di_tv.vval.v_number = nr;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
747 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
748
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
749 /*
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
750 * Free "fc".
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
751 */
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
752 static void
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
753 free_funccal(funccall_T *fc)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
754 {
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
755 int i;
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
756
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
757 for (i = 0; i < fc->fc_funcs.ga_len; ++i)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
758 {
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
759 ufunc_T *fp = ((ufunc_T **)(fc->fc_funcs.ga_data))[i];
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
760
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
761 // When garbage collecting a funccall_T may be freed before the
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
762 // function that references it, clear its uf_scoped field.
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
763 // The function may have been redefined and point to another
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
764 // funccall_T, don't clear it then.
9735
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
765 if (fp != NULL && fp->uf_scoped == fc)
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
766 fp->uf_scoped = NULL;
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
767 }
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
768 ga_clear(&fc->fc_funcs);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
769
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
770 func_ptr_unref(fc->func);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
771 vim_free(fc);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
772 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
773
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
774 /*
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
775 * Free "fc" and what it contains.
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
776 * Can be called only when "fc" is kept beyond the period of it called,
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
777 * i.e. after cleanup_function_call(fc).
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
778 */
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
779 static void
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
780 free_funccal_contents(funccall_T *fc)
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
781 {
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
782 listitem_T *li;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
783
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
784 // Free all l: variables.
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
785 vars_clear(&fc->l_vars.dv_hashtab);
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
786
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
787 // Free all a: variables.
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
788 vars_clear(&fc->l_avars.dv_hashtab);
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
789
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
790 // Free the a:000 variables.
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
791 for (li = fc->l_varlist.lv_first; li != NULL; li = li->li_next)
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
792 clear_tv(&li->li_tv);
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
793
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
794 free_funccal(fc);
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
795 }
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
796
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
797 /*
11299
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
798 * Handle the last part of returning from a function: free the local hashtable.
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
799 * Unless it is still in use by a closure.
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
800 */
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
801 static void
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
802 cleanup_function_call(funccall_T *fc)
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
803 {
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
804 int may_free_fc = fc->fc_refcount <= 0;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
805 int free_fc = TRUE;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
806
11299
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
807 current_funccal = fc->caller;
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
808
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
809 // Free all l: variables if not referred.
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
810 if (may_free_fc && fc->l_vars.dv_refcount == DO_NOT_FREE_CNT)
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
811 vars_clear(&fc->l_vars.dv_hashtab);
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
812 else
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
813 free_fc = FALSE;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
814
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
815 // If the a:000 list and the l: and a: dicts are not referenced and
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
816 // there is no closure using it, we can free the funccall_T and what's
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
817 // in it.
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
818 if (may_free_fc && fc->l_avars.dv_refcount == DO_NOT_FREE_CNT)
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
819 vars_clear_ext(&fc->l_avars.dv_hashtab, FALSE);
11299
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
820 else
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
821 {
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
822 int todo;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
823 hashitem_T *hi;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
824 dictitem_T *di;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
825
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
826 free_fc = FALSE;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
827
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
828 // Make a copy of the a: variables, since we didn't do that above.
11299
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
829 todo = (int)fc->l_avars.dv_hashtab.ht_used;
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
830 for (hi = fc->l_avars.dv_hashtab.ht_array; todo > 0; ++hi)
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
831 {
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
832 if (!HASHITEM_EMPTY(hi))
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
833 {
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
834 --todo;
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
835 di = HI2DI(hi);
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
836 copy_tv(&di->di_tv, &di->di_tv);
11299
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
837 }
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
838 }
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
839 }
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
840
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
841 if (may_free_fc && fc->l_varlist.lv_refcount == DO_NOT_FREE_CNT)
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
842 fc->l_varlist.lv_first = NULL;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
843 else
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
844 {
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
845 listitem_T *li;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
846
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
847 free_fc = FALSE;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
848
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
849 // Make a copy of the a:000 items, since we didn't do that above.
11299
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
850 for (li = fc->l_varlist.lv_first; li != NULL; li = li->li_next)
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
851 copy_tv(&li->li_tv, &li->li_tv);
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
852 }
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
853
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
854 if (free_fc)
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
855 free_funccal(fc);
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
856 else
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
857 {
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
858 static int made_copy = 0;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
859
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
860 // "fc" is still in use. This can happen when returning "a:000",
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
861 // assigning "l:" to a global variable or defining a closure.
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
862 // Link "fc" in the list for garbage collection later.
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
863 fc->caller = previous_funccal;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
864 previous_funccal = fc;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
865
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
866 if (want_garbage_collect)
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
867 // If garbage collector is ready, clear count.
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
868 made_copy = 0;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
869 else if (++made_copy >= (int)((4096 * 1024) / sizeof(*fc)))
15585
6ca8f0350723 patch 8.1.0800: may use a lot of memory when a function refers itself
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
870 {
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
871 // We have made a lot of copies, worth 4 Mbyte. This can happen
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
872 // when repetitively calling a function that creates a reference to
15721
e84eb23f4670 patch 8.1.0868: crash if triggering garbage collector after a function call
Bram Moolenaar <Bram@vim.org>
parents: 15636
diff changeset
873 // itself somehow. Call the garbage collector soon to avoid using
15585
6ca8f0350723 patch 8.1.0800: may use a lot of memory when a function refers itself
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
874 // too much memory.
6ca8f0350723 patch 8.1.0800: may use a lot of memory when a function refers itself
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
875 made_copy = 0;
15721
e84eb23f4670 patch 8.1.0868: crash if triggering garbage collector after a function call
Bram Moolenaar <Bram@vim.org>
parents: 15636
diff changeset
876 want_garbage_collect = TRUE;
15585
6ca8f0350723 patch 8.1.0800: may use a lot of memory when a function refers itself
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
877 }
11299
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
878 }
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
879 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
880 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
881 * Unreference "fc": decrement the reference count and free it when it
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
882 * becomes zero. "fp" is detached from "fc".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
883 * When "force" is TRUE we are exiting.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
884 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
885 static void
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
886 funccal_unref(funccall_T *fc, ufunc_T *fp, int force)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
887 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
888 funccall_T **pfc;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
889 int i;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
890
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
891 if (fc == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
892 return;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
893
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
894 if (--fc->fc_refcount <= 0 && (force || (
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
895 fc->l_varlist.lv_refcount == DO_NOT_FREE_CNT
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
896 && fc->l_vars.dv_refcount == DO_NOT_FREE_CNT
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
897 && fc->l_avars.dv_refcount == DO_NOT_FREE_CNT)))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
898 for (pfc = &previous_funccal; *pfc != NULL; pfc = &(*pfc)->caller)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
899 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
900 if (fc == *pfc)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
901 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
902 *pfc = fc->caller;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
903 free_funccal_contents(fc);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
904 return;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
905 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
906 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
907 for (i = 0; i < fc->fc_funcs.ga_len; ++i)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
908 if (((ufunc_T **)(fc->fc_funcs.ga_data))[i] == fp)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
909 ((ufunc_T **)(fc->fc_funcs.ga_data))[i] = NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
910 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
911
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
912 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
913 * Remove the function from the function hashtable. If the function was
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
914 * deleted while it still has references this was already done.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
915 * Return TRUE if the entry was deleted, FALSE if it wasn't found.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
916 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
917 static int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
918 func_remove(ufunc_T *fp)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
919 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
920 hashitem_T *hi;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
921
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
922 // Return if it was already virtually deleted.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
923 if (fp->uf_flags & FC_DEAD)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
924 return FALSE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
925
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
926 hi = hash_find(&func_hashtab, UF2HIKEY(fp));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
927 if (!HASHITEM_EMPTY(hi))
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
928 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
929 // When there is a def-function index do not actually remove the
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
930 // function, so we can find the index when defining the function again.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
931 if (fp->uf_dfunc_idx >= 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
932 fp->uf_flags |= FC_DEAD;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
933 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
934 hash_remove(&func_hashtab, hi);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
935 return TRUE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
936 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
937 return FALSE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
938 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
939
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
940 static void
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
941 func_clear_items(ufunc_T *fp)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
942 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
943 ga_clear_strings(&(fp->uf_args));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
944 ga_clear_strings(&(fp->uf_def_args));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
945 ga_clear_strings(&(fp->uf_lines));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
946 VIM_CLEAR(fp->uf_name_exp);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
947 VIM_CLEAR(fp->uf_arg_types);
19685
d64f403289db patch 8.2.0399: various memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
948 VIM_CLEAR(fp->uf_def_arg_idx);
d64f403289db patch 8.2.0399: various memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
949 VIM_CLEAR(fp->uf_va_name);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
950 ga_clear(&fp->uf_type_list);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
951 #ifdef FEAT_PROFILE
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
952 VIM_CLEAR(fp->uf_tml_count);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
953 VIM_CLEAR(fp->uf_tml_total);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
954 VIM_CLEAR(fp->uf_tml_self);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
955 #endif
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
956 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
957
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
958 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
959 * Free all things that a function contains. Does not free the function
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
960 * itself, use func_free() for that.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
961 * When "force" is TRUE we are exiting.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
962 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
963 static void
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
964 func_clear(ufunc_T *fp, int force)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
965 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
966 if (fp->uf_cleared)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
967 return;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
968 fp->uf_cleared = TRUE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
969
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
970 // clear this function
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
971 func_clear_items(fp);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
972 funccal_unref(fp->uf_scoped, fp, force);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
973 delete_def_function(fp);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
974 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
975
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
976 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
977 * Free a function and remove it from the list of functions. Does not free
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
978 * what a function contains, call func_clear() first.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
979 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
980 static void
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
981 func_free(ufunc_T *fp)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
982 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
983 // Only remove it when not done already, otherwise we would remove a newer
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
984 // version of the function with the same name.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
985 if ((fp->uf_flags & (FC_DELETED | FC_REMOVED)) == 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
986 func_remove(fp);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
987
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
988 if ((fp->uf_flags & FC_DEAD) == 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
989 vim_free(fp);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
990 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
991
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
992 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
993 * Free all things that a function contains and free the function itself.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
994 * When "force" is TRUE we are exiting.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
995 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
996 static void
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
997 func_clear_free(ufunc_T *fp, int force)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
998 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
999 func_clear(fp, force);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1000 func_free(fp);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1001 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1002
11299
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
1003
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
1004 /*
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1005 * Call a user function.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1006 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1007 static void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1008 call_user_func(
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1009 ufunc_T *fp, // pointer to function
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1010 int argcount, // nr of args
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1011 typval_T *argvars, // arguments
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1012 typval_T *rettv, // return value
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1013 linenr_T firstline, // first line of range
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1014 linenr_T lastline, // last line of range
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1015 dict_T *selfdict) // Dictionary for "self"
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1016 {
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14430
diff changeset
1017 sctx_T save_current_sctx;
14323
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1018 int using_sandbox = FALSE;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1019 funccall_T *fc;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1020 int save_did_emsg;
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1021 int default_arg_err = FALSE;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1022 static int depth = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1023 dictitem_T *v;
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1024 int fixvar_idx = 0; // index in fixvar[]
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1025 int i;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1026 int ai;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1027 int islambda = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1028 char_u numbuf[NUMBUFLEN];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1029 char_u *name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1030 #ifdef FEAT_PROFILE
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1031 proftime_T wait_start;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1032 proftime_T call_start;
14226
706b57cd1b00 patch 8.1.0130: ":profdel func" does not work if func was called already
Christian Brabandt <cb@256bit.org>
parents: 14002
diff changeset
1033 int started_profiling = FALSE;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1034 #endif
19075
af1eca322b9e patch 8.2.0098: exe stack length can be wrong without being detected
Bram Moolenaar <Bram@vim.org>
parents: 19035
diff changeset
1035 ESTACK_CHECK_DECLARATION
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1036
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1037 // If depth of calling is getting too high, don't execute the function
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1038 if (depth >= p_mfd)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1039 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
1040 emsg(_("E132: Function call depth is higher than 'maxfuncdepth'"));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1041 rettv->v_type = VAR_NUMBER;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1042 rettv->vval.v_number = -1;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1043 return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1044 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1045 ++depth;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1046
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1047 line_breakcheck(); // check for CTRL-C hit
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1048
16825
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
1049 fc = ALLOC_CLEAR_ONE(funccall_T);
15585
6ca8f0350723 patch 8.1.0800: may use a lot of memory when a function refers itself
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1050 if (fc == NULL)
6ca8f0350723 patch 8.1.0800: may use a lot of memory when a function refers itself
Bram Moolenaar <Bram@vim.org>
parents: 15555
diff changeset
1051 return;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1052 fc->caller = current_funccal;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1053 current_funccal = fc;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1054 fc->func = fp;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1055 fc->rettv = rettv;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1056 fc->level = ex_nesting_level;
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1057 // Check if this function has a breakpoint.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1058 fc->breakpoint = dbg_find_breakpoint(FALSE, fp->uf_name, (linenr_T)0);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1059 fc->dbg_tick = debug_tick;
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1060 // Set up fields for closure.
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1061 ga_init2(&fc->fc_funcs, sizeof(ufunc_T *), 1);
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1062 func_ptr_ref(fp);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1063
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1064 if (fp->uf_dfunc_idx >= 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1065 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1066 estack_push_ufunc(ETYPE_UFUNC, fp, 1);
19281
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
1067 save_current_sctx = current_sctx;
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
1068 current_sctx = fp->uf_script_ctx;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1069
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1070 // Execute the compiled function.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1071 call_def_function(fp, argcount, argvars, rettv);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1072 --depth;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1073 current_funccal = fc->caller;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1074
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1075 estack_pop();
19281
9fcdeaa18bd1 patch 8.2.0199: Vim9 script commands not sufficiently tested
Bram Moolenaar <Bram@vim.org>
parents: 19253
diff changeset
1076 current_sctx = save_current_sctx;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1077 free_funccal(fc);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1078 return;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1079 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1080
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1081 if (STRNCMP(fp->uf_name, "<lambda>", 8) == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1082 islambda = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1083
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1084 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1085 * Note about using fc->fixvar[]: This is an array of FIXVAR_CNT variables
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1086 * with names up to VAR_SHORT_LEN long. This avoids having to alloc/free
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1087 * each argument variable and saves a lot of time.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1088 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1089 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1090 * Init l: variables.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1091 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1092 init_var_dict(&fc->l_vars, &fc->l_vars_var, VAR_DEF_SCOPE);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1093 if (selfdict != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1094 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1095 // Set l:self to "selfdict". Use "name" to avoid a warning from
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1096 // some compiler that checks the destination size.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1097 v = &fc->fixvar[fixvar_idx++].var;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1098 name = v->di_key;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1099 STRCPY(name, "self");
15762
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15721
diff changeset
1100 v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1101 hash_add(&fc->l_vars.dv_hashtab, DI2HIKEY(v));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1102 v->di_tv.v_type = VAR_DICT;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1103 v->di_tv.v_lock = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1104 v->di_tv.vval.v_dict = selfdict;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1105 ++selfdict->dv_refcount;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1106 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1107
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1108 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1109 * Init a: variables.
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1110 * Set a:0 to "argcount" less number of named arguments, if >= 0.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1111 * Set a:000 to a list with room for the "..." arguments.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1112 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1113 init_var_dict(&fc->l_avars, &fc->l_avars_var, VAR_SCOPE);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1114 add_nr_var(&fc->l_avars, &fc->fixvar[fixvar_idx++].var, "0",
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1115 (varnumber_T)(argcount >= fp->uf_args.ga_len
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1116 ? argcount - fp->uf_args.ga_len : 0));
15762
dff66c4670b1 patch 8.1.0888: the a: dict is not immutable as documented
Bram Moolenaar <Bram@vim.org>
parents: 15721
diff changeset
1117 fc->l_avars.dv_lock = VAR_FIXED;
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1118 // Use "name" to avoid a warning from some compiler that checks the
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1119 // destination size.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1120 v = &fc->fixvar[fixvar_idx++].var;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1121 name = v->di_key;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1122 STRCPY(name, "000");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1123 v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1124 hash_add(&fc->l_avars.dv_hashtab, DI2HIKEY(v));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1125 v->di_tv.v_type = VAR_LIST;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1126 v->di_tv.v_lock = VAR_FIXED;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1127 v->di_tv.vval.v_list = &fc->l_varlist;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1128 vim_memset(&fc->l_varlist, 0, sizeof(list_T));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1129 fc->l_varlist.lv_refcount = DO_NOT_FREE_CNT;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1130 fc->l_varlist.lv_lock = VAR_FIXED;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1131
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1132 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1133 * Set a:firstline to "firstline" and a:lastline to "lastline".
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1134 * Set a:name to named arguments.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1135 * Set a:N to the "..." arguments.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1136 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1137 add_nr_var(&fc->l_avars, &fc->fixvar[fixvar_idx++].var, "firstline",
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1138 (varnumber_T)firstline);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1139 add_nr_var(&fc->l_avars, &fc->fixvar[fixvar_idx++].var, "lastline",
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1140 (varnumber_T)lastline);
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1141 for (i = 0; i < argcount || i < fp->uf_args.ga_len; ++i)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1142 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1143 int addlocal = FALSE;
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1144 typval_T def_rettv;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1145 int isdefault = FALSE;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1146
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1147 ai = i - fp->uf_args.ga_len;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1148 if (ai < 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1149 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1150 // named argument a:name
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1151 name = FUNCARG(fp, i);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1152 if (islambda)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1153 addlocal = TRUE;
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1154
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1155 // evaluate named argument default expression
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1156 isdefault = ai + fp->uf_def_args.ga_len >= 0
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1157 && (i >= argcount || (argvars[i].v_type == VAR_SPECIAL
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1158 && argvars[i].vval.v_number == VVAL_NONE));
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1159 if (isdefault)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1160 {
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1161 char_u *default_expr = NULL;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1162 def_rettv.v_type = VAR_NUMBER;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1163 def_rettv.vval.v_number = -1;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1164
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1165 default_expr = ((char_u **)(fp->uf_def_args.ga_data))
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1166 [ai + fp->uf_def_args.ga_len];
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1167 if (eval1(&default_expr, &def_rettv, TRUE) == FAIL)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1168 {
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1169 default_arg_err = 1;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1170 break;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1171 }
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1172 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1173 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1174 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1175 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1176 // "..." argument a:1, a:2, etc.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1177 sprintf((char *)numbuf, "%d", ai + 1);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1178 name = numbuf;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1179 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1180 if (fixvar_idx < FIXVAR_CNT && STRLEN(name) <= VAR_SHORT_LEN)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1181 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1182 v = &fc->fixvar[fixvar_idx++].var;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1183 v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX;
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
1184 STRCPY(v->di_key, name);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1185 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1186 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1187 {
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
1188 v = dictitem_alloc(name);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1189 if (v == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1190 break;
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
1191 v->di_flags |= DI_FLAGS_RO | DI_FLAGS_FIX;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1192 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1193
17127
d244a9be99db patch 8.1.1563: crash when using closures
Bram Moolenaar <Bram@vim.org>
parents: 16969
diff changeset
1194 // Note: the values are copied directly to avoid alloc/free.
d244a9be99db patch 8.1.1563: crash when using closures
Bram Moolenaar <Bram@vim.org>
parents: 16969
diff changeset
1195 // "argvars" must have VAR_FIXED for v_lock.
d244a9be99db patch 8.1.1563: crash when using closures
Bram Moolenaar <Bram@vim.org>
parents: 16969
diff changeset
1196 v->di_tv = isdefault ? def_rettv : argvars[i];
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1197 v->di_tv.v_lock = VAR_FIXED;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1198
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1199 if (addlocal)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1200 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1201 // Named arguments should be accessed without the "a:" prefix in
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1202 // lambda expressions. Add to the l: dict.
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1203 copy_tv(&v->di_tv, &v->di_tv);
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1204 hash_add(&fc->l_vars.dv_hashtab, DI2HIKEY(v));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1205 }
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1206 else
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1207 hash_add(&fc->l_avars.dv_hashtab, DI2HIKEY(v));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1208
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1209 if (ai >= 0 && ai < MAX_FUNC_ARGS)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1210 {
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
1211 listitem_T *li = &fc->l_listitems[ai];
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
1212
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
1213 li->li_tv = argvars[i];
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
1214 li->li_tv.v_lock = VAR_FIXED;
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
1215 list_append(&fc->l_varlist, li);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1216 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1217 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1218
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1219 // Don't redraw while executing the function.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1220 ++RedrawingDisabled;
14323
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1221
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1222 if (fp->uf_flags & FC_SANDBOX)
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1223 {
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1224 using_sandbox = TRUE;
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1225 ++sandbox;
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1226 }
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1227
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1228 estack_push_ufunc(ETYPE_UFUNC, fp, 1);
19075
af1eca322b9e patch 8.2.0098: exe stack length can be wrong without being detected
Bram Moolenaar <Bram@vim.org>
parents: 19035
diff changeset
1229 ESTACK_CHECK_SETUP
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1230 if (p_verbose >= 12)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1231 {
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1232 ++no_wait_return;
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1233 verbose_enter_scroll();
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1234
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1235 smsg(_("calling %s"), SOURCING_NAME);
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1236 if (p_verbose >= 14)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1237 {
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1238 char_u buf[MSG_BUF_LEN];
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1239 char_u numbuf2[NUMBUFLEN];
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1240 char_u *tofree;
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1241 char_u *s;
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1242
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1243 msg_puts("(");
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1244 for (i = 0; i < argcount; ++i)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1245 {
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1246 if (i > 0)
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1247 msg_puts(", ");
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1248 if (argvars[i].v_type == VAR_NUMBER)
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1249 msg_outnum((long)argvars[i].vval.v_number);
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1250 else
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1251 {
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1252 // Do not want errors such as E724 here.
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1253 ++emsg_off;
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1254 s = tv2string(&argvars[i], &tofree, numbuf2, 0);
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1255 --emsg_off;
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1256 if (s != NULL)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1257 {
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1258 if (vim_strsize(s) > MSG_BUF_CLEN)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1259 {
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1260 trunc_string(s, buf, MSG_BUF_CLEN, MSG_BUF_LEN);
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1261 s = buf;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1262 }
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1263 msg_puts((char *)s);
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1264 vim_free(tofree);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1265 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1266 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1267 }
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1268 msg_puts(")");
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1269 }
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1270 msg_puts("\n"); // don't overwrite this either
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1271
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1272 verbose_leave_scroll();
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1273 --no_wait_return;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1274 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1275 #ifdef FEAT_PROFILE
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1276 if (do_profiling == PROF_YES)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1277 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1278 if (!fp->uf_profiling && has_profiling(FALSE, fp->uf_name, NULL))
14226
706b57cd1b00 patch 8.1.0130: ":profdel func" does not work if func was called already
Christian Brabandt <cb@256bit.org>
parents: 14002
diff changeset
1279 {
706b57cd1b00 patch 8.1.0130: ":profdel func" does not work if func was called already
Christian Brabandt <cb@256bit.org>
parents: 14002
diff changeset
1280 started_profiling = TRUE;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1281 func_do_profile(fp);
14226
706b57cd1b00 patch 8.1.0130: ":profdel func" does not work if func was called already
Christian Brabandt <cb@256bit.org>
parents: 14002
diff changeset
1282 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1283 if (fp->uf_profiling
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1284 || (fc->caller != NULL && fc->caller->func->uf_profiling))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1285 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1286 ++fp->uf_tm_count;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1287 profile_start(&call_start);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1288 profile_zero(&fp->uf_tm_children);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1289 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1290 script_prof_save(&wait_start);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1291 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1292 #endif
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1293
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14430
diff changeset
1294 save_current_sctx = current_sctx;
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14430
diff changeset
1295 current_sctx = fp->uf_script_ctx;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1296 save_did_emsg = did_emsg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1297 did_emsg = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1298
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1299 if (default_arg_err && (fp->uf_flags & FC_ABORT))
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1300 did_emsg = TRUE;
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1301 else
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1302 // call do_cmdline() to execute the lines
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1303 do_cmdline(NULL, get_func_line, (void *)fc,
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1304 DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1305
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1306 --RedrawingDisabled;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1307
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1308 // when the function was aborted because of an error, return -1
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1309 if ((did_emsg && (fp->uf_flags & FC_ABORT)) || rettv->v_type == VAR_UNKNOWN)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1310 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1311 clear_tv(rettv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1312 rettv->v_type = VAR_NUMBER;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1313 rettv->vval.v_number = -1;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1314 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1315
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1316 #ifdef FEAT_PROFILE
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1317 if (do_profiling == PROF_YES && (fp->uf_profiling
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1318 || (fc->caller != NULL && fc->caller->func->uf_profiling)))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1319 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1320 profile_end(&call_start);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1321 profile_sub_wait(&wait_start, &call_start);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1322 profile_add(&fp->uf_tm_total, &call_start);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1323 profile_self(&fp->uf_tm_self, &call_start, &fp->uf_tm_children);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1324 if (fc->caller != NULL && fc->caller->func->uf_profiling)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1325 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1326 profile_add(&fc->caller->func->uf_tm_children, &call_start);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1327 profile_add(&fc->caller->func->uf_tml_children, &call_start);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1328 }
14226
706b57cd1b00 patch 8.1.0130: ":profdel func" does not work if func was called already
Christian Brabandt <cb@256bit.org>
parents: 14002
diff changeset
1329 if (started_profiling)
706b57cd1b00 patch 8.1.0130: ":profdel func" does not work if func was called already
Christian Brabandt <cb@256bit.org>
parents: 14002
diff changeset
1330 // make a ":profdel func" stop profiling the function
706b57cd1b00 patch 8.1.0130: ":profdel func" does not work if func was called already
Christian Brabandt <cb@256bit.org>
parents: 14002
diff changeset
1331 fp->uf_profiling = FALSE;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1332 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1333 #endif
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1334
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1335 // when being verbose, mention the return value
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1336 if (p_verbose >= 12)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1337 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1338 ++no_wait_return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1339 verbose_enter_scroll();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1340
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1341 if (aborting())
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1342 smsg(_("%s aborted"), SOURCING_NAME);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1343 else if (fc->rettv->v_type == VAR_NUMBER)
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1344 smsg(_("%s returning #%ld"), SOURCING_NAME,
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1345 (long)fc->rettv->vval.v_number);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1346 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1347 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1348 char_u buf[MSG_BUF_LEN];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1349 char_u numbuf2[NUMBUFLEN];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1350 char_u *tofree;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1351 char_u *s;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1352
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1353 // The value may be very long. Skip the middle part, so that we
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1354 // have some idea how it starts and ends. smsg() would always
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1355 // truncate it at the end. Don't want errors such as E724 here.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1356 ++emsg_off;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1357 s = tv2string(fc->rettv, &tofree, numbuf2, 0);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1358 --emsg_off;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1359 if (s != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1360 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1361 if (vim_strsize(s) > MSG_BUF_CLEN)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1362 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1363 trunc_string(s, buf, MSG_BUF_CLEN, MSG_BUF_LEN);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1364 s = buf;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1365 }
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1366 smsg(_("%s returning %s"), SOURCING_NAME, s);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1367 vim_free(tofree);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1368 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1369 }
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1370 msg_puts("\n"); // don't overwrite this either
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1371
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1372 verbose_leave_scroll();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1373 --no_wait_return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1374 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1375
19075
af1eca322b9e patch 8.2.0098: exe stack length can be wrong without being detected
Bram Moolenaar <Bram@vim.org>
parents: 19035
diff changeset
1376 ESTACK_CHECK_NOW
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1377 estack_pop();
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14430
diff changeset
1378 current_sctx = save_current_sctx;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1379 #ifdef FEAT_PROFILE
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1380 if (do_profiling == PROF_YES)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1381 script_prof_restore(&wait_start);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1382 #endif
14323
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1383 if (using_sandbox)
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
1384 --sandbox;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1385
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1386 if (p_verbose >= 12 && SOURCING_NAME != NULL)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1387 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1388 ++no_wait_return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1389 verbose_enter_scroll();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1390
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
1391 smsg(_("continuing in %s"), SOURCING_NAME);
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1392 msg_puts("\n"); // don't overwrite this either
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1393
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1394 verbose_leave_scroll();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1395 --no_wait_return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1396 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1397
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1398 did_emsg |= save_did_emsg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1399 --depth;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1400
11299
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
1401 cleanup_function_call(fc);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1402 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1403
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1404 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1405 * Call a user function after checking the arguments.
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
1406 */
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1407 int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1408 call_user_func_check(
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1409 ufunc_T *fp,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1410 int argcount,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1411 typval_T *argvars,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1412 typval_T *rettv,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1413 funcexe_T *funcexe,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1414 dict_T *selfdict)
14430
2fba714294b9 patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents: 14323
diff changeset
1415 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1416 int error;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1417 int regular_args = fp->uf_args.ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1418
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1419 if (fp->uf_flags & FC_RANGE && funcexe->doesrange != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1420 *funcexe->doesrange = TRUE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1421 if (argcount < regular_args - fp->uf_def_args.ga_len)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1422 error = FCERR_TOOFEW;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1423 else if (!has_varargs(fp) && argcount > regular_args)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1424 error = FCERR_TOOMANY;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1425 else if ((fp->uf_flags & FC_DICT) && selfdict == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1426 error = FCERR_DICT;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1427 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1428 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1429 int did_save_redo = FALSE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1430 save_redo_T save_redo;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1431
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1432 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1433 * Call the user function.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1434 * Save and restore search patterns, script variables and
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1435 * redo buffer.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1436 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1437 save_search_patterns();
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1438 if (!ins_compl_active())
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1439 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1440 saveRedobuff(&save_redo);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1441 did_save_redo = TRUE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1442 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1443 ++fp->uf_calls;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1444 call_user_func(fp, argcount, argvars, rettv,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1445 funcexe->firstline, funcexe->lastline,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1446 (fp->uf_flags & FC_DICT) ? selfdict : NULL);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1447 if (--fp->uf_calls <= 0 && fp->uf_refcount <= 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1448 // Function was unreferenced while being used, free it now.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1449 func_clear_free(fp, FALSE);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1450 if (did_save_redo)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1451 restoreRedobuff(&save_redo);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1452 restore_search_patterns();
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1453 error = FCERR_NONE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1454 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1455 return error;
10815
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1456 }
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1457
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1458 /*
9844
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1459 * There are two kinds of function names:
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1460 * 1. ordinary names, function defined with :function
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1461 * 2. numbered functions and lambdas
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1462 * For the first we only count the name stored in func_hashtab as a reference,
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1463 * using function() does not count as a reference, because the function is
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1464 * looked up by name.
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1465 */
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1466 static int
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1467 func_name_refcount(char_u *name)
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1468 {
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1469 return isdigit(*name) || *name == '<';
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1470 }
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1471
14927
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1472 static funccal_entry_T *funccal_stack = NULL;
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1473
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1474 /*
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1475 * Save the current function call pointer, and set it to NULL.
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1476 * Used when executing autocommands and for ":source".
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1477 */
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1478 void
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1479 save_funccal(funccal_entry_T *entry)
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1480 {
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1481 entry->top_funccal = current_funccal;
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1482 entry->next = funccal_stack;
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1483 funccal_stack = entry;
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1484 current_funccal = NULL;
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1485 }
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1486
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1487 void
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1488 restore_funccal(void)
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1489 {
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1490 if (funccal_stack == NULL)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
1491 iemsg("INTERNAL: restore_funccal()");
14927
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1492 else
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1493 {
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1494 current_funccal = funccal_stack->top_funccal;
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1495 funccal_stack = funccal_stack->next;
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1496 }
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1497 }
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1498
17370
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17251
diff changeset
1499 funccall_T *
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17251
diff changeset
1500 get_current_funccal(void)
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17251
diff changeset
1501 {
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17251
diff changeset
1502 return current_funccal;
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17251
diff changeset
1503 }
ba06a1c42274 patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents: 17251
diff changeset
1504
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1505 #if defined(EXITFREE) || defined(PROTO)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1506 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1507 free_all_functions(void)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1508 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1509 hashitem_T *hi;
9844
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1510 ufunc_T *fp;
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1511 long_u skipped = 0;
10815
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1512 long_u todo = 1;
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1513 long_u used;
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1514
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1515 // Clean up the current_funccal chain and the funccal stack.
11299
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
1516 while (current_funccal != NULL)
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
1517 {
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
1518 clear_tv(current_funccal->rettv);
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
1519 cleanup_function_call(current_funccal);
14927
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1520 if (current_funccal == NULL && funccal_stack != NULL)
162d79d273e6 patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents: 14706
diff changeset
1521 restore_funccal();
11299
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
1522 }
4ae86195f559 patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents: 11158
diff changeset
1523
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1524 // First clear what the functions contain. Since this may lower the
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1525 // reference count of a function, it may also free a function and change
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1526 // the hash table. Restart if that happens.
10815
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1527 while (todo > 0)
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1528 {
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1529 todo = func_hashtab.ht_used;
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1530 for (hi = func_hashtab.ht_array; todo > 0; ++hi)
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1531 if (!HASHITEM_EMPTY(hi))
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1532 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1533 // clear the def function index now
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1534 fp = HI2UF(hi);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1535 fp->uf_flags &= ~FC_DEAD;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1536 fp->uf_dfunc_idx = -1;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1537
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1538 // Only free functions that are not refcounted, those are
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1539 // supposed to be freed when no longer referenced.
10815
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1540 if (func_name_refcount(fp->uf_name))
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1541 ++skipped;
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1542 else
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1543 {
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1544 used = func_hashtab.ht_used;
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1545 func_clear(fp, TRUE);
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1546 if (used != func_hashtab.ht_used)
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1547 {
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1548 skipped = 0;
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1549 break;
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1550 }
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1551 }
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1552 --todo;
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1553 }
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1554 }
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1555
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1556 // Now actually free the functions. Need to start all over every time,
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1557 // because func_free() may change the hash table.
10815
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1558 skipped = 0;
9844
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1559 while (func_hashtab.ht_used > skipped)
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1560 {
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1561 todo = func_hashtab.ht_used;
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1562 for (hi = func_hashtab.ht_array; todo > 0; ++hi)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1563 if (!HASHITEM_EMPTY(hi))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1564 {
9844
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1565 --todo;
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1566 // Only free functions that are not refcounted, those are
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1567 // supposed to be freed when no longer referenced.
9844
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1568 fp = HI2UF(hi);
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1569 if (func_name_refcount(fp->uf_name))
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1570 ++skipped;
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1571 else
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1572 {
10815
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
1573 func_free(fp);
9844
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1574 skipped = 0;
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1575 break;
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1576 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1577 }
9844
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1578 }
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1579 if (skipped == 0)
9ce5941b77d3 commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents: 9735
diff changeset
1580 hash_clear(&func_hashtab);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1581
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1582 free_def_functions();
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1583 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1584 #endif
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1585
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1586 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1587 * Return TRUE if "name" looks like a builtin function name: starts with a
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1588 * lower case letter and doesn't contain AUTOLOAD_CHAR.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1589 * "len" is the length of "name", or -1 for NUL terminated.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1590 */
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1591 int
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1592 builtin_function(char_u *name, int len)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1593 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1594 char_u *p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1595
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1596 if (!ASCII_ISLOWER(name[0]))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1597 return FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1598 p = vim_strchr(name, AUTOLOAD_CHAR);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1599 return p == NULL || (len > 0 && p > name + len);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1600 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1601
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1602 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1603 func_call(
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1604 char_u *name,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1605 typval_T *args,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1606 partial_T *partial,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1607 dict_T *selfdict,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1608 typval_T *rettv)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1609 {
19201
e7b4fff348dd patch 8.2.0159: non-materialized range() list causes problems
Bram Moolenaar <Bram@vim.org>
parents: 19183
diff changeset
1610 list_T *l = args->vval.v_list;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1611 listitem_T *item;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1612 typval_T argv[MAX_FUNC_ARGS + 1];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1613 int argc = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1614 int r = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1615
19201
e7b4fff348dd patch 8.2.0159: non-materialized range() list causes problems
Bram Moolenaar <Bram@vim.org>
parents: 19183
diff changeset
1616 range_list_materialize(l);
e7b4fff348dd patch 8.2.0159: non-materialized range() list causes problems
Bram Moolenaar <Bram@vim.org>
parents: 19183
diff changeset
1617 for (item = l->lv_first; item != NULL; item = item->li_next)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1618 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1619 if (argc == MAX_FUNC_ARGS - (partial == NULL ? 0 : partial->pt_argc))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1620 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
1621 emsg(_("E699: Too many arguments"));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1622 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1623 }
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1624 // Make a copy of each argument. This is needed to be able to set
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1625 // v_lock to VAR_FIXED in the copy without changing the original list.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1626 copy_tv(&item->li_tv, &argv[argc++]);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1627 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1628
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1629 if (item == NULL)
17606
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
1630 {
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
1631 funcexe_T funcexe;
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
1632
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
1633 vim_memset(&funcexe, 0, sizeof(funcexe));
17606
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
1634 funcexe.firstline = curwin->w_cursor.lnum;
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
1635 funcexe.lastline = curwin->w_cursor.lnum;
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
1636 funcexe.evaluate = TRUE;
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
1637 funcexe.partial = partial;
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
1638 funcexe.selfdict = selfdict;
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
1639 r = call_func(name, -1, rettv, argc, argv, &funcexe);
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
1640 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1641
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1642 // Free the arguments.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1643 while (argc > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1644 clear_tv(&argv[--argc]);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1645
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1646 return r;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1647 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1648
18104
e59ff7b5d7a7 patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents: 17883
diff changeset
1649 static int callback_depth = 0;
e59ff7b5d7a7 patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents: 17883
diff changeset
1650
e59ff7b5d7a7 patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents: 17883
diff changeset
1651 int
e59ff7b5d7a7 patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents: 17883
diff changeset
1652 get_callback_depth(void)
e59ff7b5d7a7 patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents: 17883
diff changeset
1653 {
e59ff7b5d7a7 patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents: 17883
diff changeset
1654 return callback_depth;
e59ff7b5d7a7 patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents: 17883
diff changeset
1655 }
e59ff7b5d7a7 patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents: 17883
diff changeset
1656
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1657 /*
16872
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1658 * Invoke call_func() with a callback.
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1659 */
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1660 int
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1661 call_callback(
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1662 callback_T *callback,
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1663 int len, // length of "name" or -1 to use strlen()
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1664 typval_T *rettv, // return value goes here
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1665 int argcount, // number of "argvars"
17606
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
1666 typval_T *argvars) // vars for arguments, must have "argcount"
16872
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1667 // PLUS ONE elements!
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1668 {
17606
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
1669 funcexe_T funcexe;
18104
e59ff7b5d7a7 patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents: 17883
diff changeset
1670 int ret;
17606
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
1671
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
1672 vim_memset(&funcexe, 0, sizeof(funcexe));
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
1673 funcexe.evaluate = TRUE;
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
1674 funcexe.partial = callback->cb_partial;
18104
e59ff7b5d7a7 patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents: 17883
diff changeset
1675 ++callback_depth;
e59ff7b5d7a7 patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents: 17883
diff changeset
1676 ret = call_func(callback->cb_name, len, rettv, argcount, argvars, &funcexe);
e59ff7b5d7a7 patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents: 17883
diff changeset
1677 --callback_depth;
e59ff7b5d7a7 patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents: 17883
diff changeset
1678 return ret;
16872
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1679 }
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1680
a836d122231a patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents: 16825
diff changeset
1681 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1682 * Give an error message for the result of a function.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1683 * Nothing if "error" is FCERR_NONE.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1684 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1685 void
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1686 user_func_error(int error, char_u *name)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1687 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1688 switch (error)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1689 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1690 case FCERR_UNKNOWN:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1691 emsg_funcname(e_unknownfunc, name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1692 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1693 case FCERR_NOTMETHOD:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1694 emsg_funcname(
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1695 N_("E276: Cannot use function as a method: %s"), name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1696 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1697 case FCERR_DELETED:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1698 emsg_funcname(N_(e_func_deleted), name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1699 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1700 case FCERR_TOOMANY:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1701 emsg_funcname((char *)e_toomanyarg, name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1702 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1703 case FCERR_TOOFEW:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1704 emsg_funcname((char *)e_toofewarg, name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1705 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1706 case FCERR_SCRIPT:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1707 emsg_funcname(
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1708 N_("E120: Using <SID> not in a script context: %s"), name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1709 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1710 case FCERR_DICT:
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1711 emsg_funcname(
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1712 N_("E725: Calling dict function without Dictionary: %s"),
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1713 name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1714 break;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1715 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1716 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1717
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1718 /*
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1719 * Call a function with its resolved parameters
9626
172131507c85 commit https://github.com/vim/vim/commit/df48fb456fb6bf63d94cad9b302ff01d8ee8d311
Christian Brabandt <cb@256bit.org>
parents: 9612
diff changeset
1720 *
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1721 * Return FAIL when the function can't be called, OK otherwise.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1722 * Also returns OK when an error was encountered while executing the function.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1723 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1724 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1725 call_func(
16634
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
1726 char_u *funcname, // name of the function
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
1727 int len, // length of "name" or -1 to use strlen()
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
1728 typval_T *rettv, // return value goes here
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
1729 int argcount_in, // number of "argvars"
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
1730 typval_T *argvars_in, // vars for arguments, must have "argcount"
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
1731 // PLUS ONE elements!
17606
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
1732 funcexe_T *funcexe) // more arguments
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1733 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1734 int ret = FAIL;
19013
dd9ab0674eec patch 8.2.0067: ERROR_UNKNOWN clashes on some systems
Bram Moolenaar <Bram@vim.org>
parents: 18991
diff changeset
1735 int error = FCERR_NONE;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1736 int i;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1737 ufunc_T *fp;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1738 char_u fname_buf[FLEN_FIXED + 1];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1739 char_u *tofree = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1740 char_u *fname;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1741 char_u *name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1742 int argcount = argcount_in;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1743 typval_T *argvars = argvars_in;
17606
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
1744 dict_T *selfdict = funcexe->selfdict;
17638
9ffec4eb8d33 patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents: 17612
diff changeset
1745 typval_T argv[MAX_FUNC_ARGS + 1]; // used when "partial" or
9ffec4eb8d33 patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents: 17612
diff changeset
1746 // "funcexe->basetv" is not NULL
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1747 int argv_clear = 0;
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1748 int argv_base = 0;
17606
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
1749 partial_T *partial = funcexe->partial;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1750
17883
6249953b0609 patch 8.1.1938: may crash when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
1751 // Initialize rettv so that it is safe for caller to invoke clear_tv(rettv)
6249953b0609 patch 8.1.1938: may crash when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
1752 // even when call_func() returns FAIL.
6249953b0609 patch 8.1.1938: may crash when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
1753 rettv->v_type = VAR_UNKNOWN;
6249953b0609 patch 8.1.1938: may crash when out of memory
Bram Moolenaar <Bram@vim.org>
parents: 17809
diff changeset
1754
16634
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
1755 // Make a copy of the name, if it comes from a funcref variable it could
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
1756 // be changed or deleted in the called function.
a1ba0bd74e7d patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents: 16615
diff changeset
1757 name = len > 0 ? vim_strnsave(funcname, len) : vim_strsave(funcname);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1758 if (name == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1759 return ret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1760
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1761 fname = fname_trans_sid(name, fname_buf, &tofree, &error);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1762
17606
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
1763 if (funcexe->doesrange != NULL)
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
1764 *funcexe->doesrange = FALSE;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1765
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1766 if (partial != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1767 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1768 // When the function has a partial with a dict and there is a dict
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1769 // argument, use the dict argument. That is backwards compatible.
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1770 // When the dict was bound explicitly use the one from the partial.
17606
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
1771 if (partial->pt_dict != NULL && (selfdict == NULL || !partial->pt_auto))
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1772 selfdict = partial->pt_dict;
19013
dd9ab0674eec patch 8.2.0067: ERROR_UNKNOWN clashes on some systems
Bram Moolenaar <Bram@vim.org>
parents: 18991
diff changeset
1773 if (error == FCERR_NONE && partial->pt_argc > 0)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1774 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1775 for (argv_clear = 0; argv_clear < partial->pt_argc; ++argv_clear)
18576
e9675870c480 patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents: 18572
diff changeset
1776 {
e9675870c480 patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents: 18572
diff changeset
1777 if (argv_clear + argcount_in >= MAX_FUNC_ARGS)
e9675870c480 patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents: 18572
diff changeset
1778 {
19013
dd9ab0674eec patch 8.2.0067: ERROR_UNKNOWN clashes on some systems
Bram Moolenaar <Bram@vim.org>
parents: 18991
diff changeset
1779 error = FCERR_TOOMANY;
18576
e9675870c480 patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents: 18572
diff changeset
1780 goto theend;
e9675870c480 patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents: 18572
diff changeset
1781 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1782 copy_tv(&partial->pt_argv[argv_clear], &argv[argv_clear]);
18576
e9675870c480 patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents: 18572
diff changeset
1783 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1784 for (i = 0; i < argcount_in; ++i)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1785 argv[i + argv_clear] = argvars_in[i];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1786 argvars = argv;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1787 argcount = partial->pt_argc + argcount_in;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1788 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1789 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1790
19013
dd9ab0674eec patch 8.2.0067: ERROR_UNKNOWN clashes on some systems
Bram Moolenaar <Bram@vim.org>
parents: 18991
diff changeset
1791 if (error == FCERR_NONE && funcexe->evaluate)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1792 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1793 char_u *rfname = fname;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1794
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1795 // Ignore "g:" before a function name.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1796 if (fname[0] == 'g' && fname[1] == ':')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1797 rfname = fname + 2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1798
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1799 rettv->v_type = VAR_NUMBER; // default rettv is number zero
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1800 rettv->vval.v_number = 0;
19013
dd9ab0674eec patch 8.2.0067: ERROR_UNKNOWN clashes on some systems
Bram Moolenaar <Bram@vim.org>
parents: 18991
diff changeset
1801 error = FCERR_UNKNOWN;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1802
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1803 if (!builtin_function(rfname, -1))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1804 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1805 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1806 * User defined function.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1807 */
17638
9ffec4eb8d33 patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents: 17612
diff changeset
1808 if (partial != NULL && partial->pt_func != NULL)
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1809 fp = partial->pt_func;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1810 else
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1811 fp = find_func(rfname, NULL);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1812
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1813 // Trigger FuncUndefined event, may load the function.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1814 if (fp == NULL
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1815 && apply_autocmds(EVENT_FUNCUNDEFINED,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1816 rfname, rfname, TRUE, NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1817 && !aborting())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1818 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1819 // executed an autocommand, search for the function again
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1820 fp = find_func(rfname, NULL);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1821 }
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1822 // Try loading a package.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1823 if (fp == NULL && script_autoload(rfname, TRUE) && !aborting())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1824 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
1825 // loaded a package, search for the function again
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1826 fp = find_func(rfname, NULL);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1827 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1828
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1829 if (fp != NULL && (fp->uf_flags & FC_DELETED))
19013
dd9ab0674eec patch 8.2.0067: ERROR_UNKNOWN clashes on some systems
Bram Moolenaar <Bram@vim.org>
parents: 18991
diff changeset
1830 error = FCERR_DELETED;
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
1831 else if (fp != NULL)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1832 {
17606
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
1833 if (funcexe->argv_func != NULL)
18572
23fef64352a1 patch 8.1.2280: crash when passing partial to substitute()
Bram Moolenaar <Bram@vim.org>
parents: 18536
diff changeset
1834 // postponed filling in the arguments, do it now
23fef64352a1 patch 8.1.2280: crash when passing partial to substitute()
Bram Moolenaar <Bram@vim.org>
parents: 18536
diff changeset
1835 argcount = funcexe->argv_func(argcount, argvars, argv_clear,
17606
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
1836 fp->uf_args.ga_len);
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
1837
17638
9ffec4eb8d33 patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents: 17612
diff changeset
1838 if (funcexe->basetv != NULL)
9ffec4eb8d33 patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents: 17612
diff changeset
1839 {
9ffec4eb8d33 patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents: 17612
diff changeset
1840 // Method call: base->Method()
9ffec4eb8d33 patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents: 17612
diff changeset
1841 mch_memmove(&argv[1], argvars, sizeof(typval_T) * argcount);
9ffec4eb8d33 patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents: 17612
diff changeset
1842 argv[0] = *funcexe->basetv;
9ffec4eb8d33 patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents: 17612
diff changeset
1843 argcount++;
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1844 argvars = argv;
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1845 argv_base = 1;
17638
9ffec4eb8d33 patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents: 17612
diff changeset
1846 }
9ffec4eb8d33 patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents: 17612
diff changeset
1847
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1848 error = call_user_func_check(fp, argcount, argvars, rettv,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1849 funcexe, selfdict);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1850 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1851 }
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
1852 else if (funcexe->basetv != NULL)
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
1853 {
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
1854 /*
17638
9ffec4eb8d33 patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents: 17612
diff changeset
1855 * expr->method(): Find the method name in the table, call its
9ffec4eb8d33 patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents: 17612
diff changeset
1856 * implementation with the base as one of the arguments.
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
1857 */
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
1858 error = call_internal_method(fname, argcount, argvars, rettv,
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
1859 funcexe->basetv);
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
1860 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1861 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1862 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1863 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1864 * Find the function name in the table, call its implementation.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1865 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1866 error = call_internal_func(fname, argcount, argvars, rettv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1867 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1868 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1869 * The function call (or "FuncUndefined" autocommand sequence) might
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1870 * have been aborted by an error, an interrupt, or an explicitly thrown
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1871 * exception that has not been caught so far. This situation can be
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1872 * tested for by calling aborting(). For an error in an internal
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1873 * function or for the "E132" error in call_user_func(), however, the
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1874 * throw point at which the "force_abort" flag (temporarily reset by
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1875 * emsg()) is normally updated has not been reached yet. We need to
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1876 * update that flag first to make aborting() reliable.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1877 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1878 update_force_abort();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1879 }
19013
dd9ab0674eec patch 8.2.0067: ERROR_UNKNOWN clashes on some systems
Bram Moolenaar <Bram@vim.org>
parents: 18991
diff changeset
1880 if (error == FCERR_NONE)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1881 ret = OK;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1882
18576
e9675870c480 patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents: 18572
diff changeset
1883 theend:
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1884 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1885 * Report an error unless the argument evaluation or function call has been
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1886 * cancelled due to an aborting error, an interrupt, or an exception.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1887 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1888 if (!aborting())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1889 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1890 user_func_error(error, name);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1891 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1892
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1893 // clear the copies made from the partial
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1894 while (argv_clear > 0)
17646
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1895 clear_tv(&argv[--argv_clear + argv_base]);
e5397617d6ca patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents: 17638
diff changeset
1896
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1897 vim_free(tofree);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1898 vim_free(name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1899
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1900 return ret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1901 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1902
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1903 static char_u *
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1904 printable_func_name(ufunc_T *fp)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1905 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1906 return fp->uf_name_exp != NULL ? fp->uf_name_exp : fp->uf_name;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1907 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1908
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1909 /*
19579
aae19dd172c0 patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
1910 * List the head of the function: "function name(arg1, arg2)".
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1911 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1912 static void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1913 list_func_head(ufunc_T *fp, int indent)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1914 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1915 int j;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1916
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1917 msg_start();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1918 if (indent)
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1919 msg_puts(" ");
19579
aae19dd172c0 patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
1920 if (fp->uf_dfunc_idx >= 0)
aae19dd172c0 patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
1921 msg_puts("def ");
aae19dd172c0 patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
1922 else
aae19dd172c0 patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
1923 msg_puts("function ");
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1924 msg_puts((char *)printable_func_name(fp));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1925 msg_putchar('(');
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1926 for (j = 0; j < fp->uf_args.ga_len; ++j)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1927 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1928 if (j)
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1929 msg_puts(", ");
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1930 msg_puts((char *)FUNCARG(fp, j));
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1931 if (fp->uf_arg_types != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1932 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1933 char *tofree;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1934
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1935 msg_puts(": ");
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1936 msg_puts(type_name(fp->uf_arg_types[j], &tofree));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1937 vim_free(tofree);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1938 }
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1939 if (j >= fp->uf_args.ga_len - fp->uf_def_args.ga_len)
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1940 {
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1941 msg_puts(" = ");
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1942 msg_puts(((char **)(fp->uf_def_args.ga_data))
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1943 [j - fp->uf_args.ga_len + fp->uf_def_args.ga_len]);
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
1944 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1945 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1946 if (fp->uf_varargs)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1947 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1948 if (j)
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1949 msg_puts(", ");
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1950 msg_puts("...");
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1951 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1952 if (fp->uf_va_name != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1953 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1954 if (j)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1955 msg_puts(", ");
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1956 msg_puts("...");
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1957 msg_puts((char *)fp->uf_va_name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1958 if (fp->uf_va_type)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1959 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1960 char *tofree;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1961
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1962 msg_puts(": ");
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1963 msg_puts(type_name(fp->uf_va_type, &tofree));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1964 vim_free(tofree);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1965 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
1966 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1967 msg_putchar(')');
19579
aae19dd172c0 patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
1968
aae19dd172c0 patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
1969 if (fp->uf_dfunc_idx >= 0)
aae19dd172c0 patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
1970 {
aae19dd172c0 patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
1971 if (fp->uf_ret_type != &t_void)
aae19dd172c0 patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
1972 {
aae19dd172c0 patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
1973 char *tofree;
aae19dd172c0 patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
1974
aae19dd172c0 patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
1975 msg_puts(": ");
aae19dd172c0 patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
1976 msg_puts(type_name(fp->uf_ret_type, &tofree));
aae19dd172c0 patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
1977 vim_free(tofree);
aae19dd172c0 patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
1978 }
aae19dd172c0 patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
1979 }
aae19dd172c0 patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents: 19443
diff changeset
1980 else if (fp->uf_flags & FC_ABORT)
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1981 msg_puts(" abort");
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1982 if (fp->uf_flags & FC_RANGE)
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1983 msg_puts(" range");
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1984 if (fp->uf_flags & FC_DICT)
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1985 msg_puts(" dict");
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
1986 if (fp->uf_flags & FC_CLOSURE)
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
1987 msg_puts(" closure");
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1988 msg_clr_eos();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1989 if (p_verbose > 0)
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14430
diff changeset
1990 last_set_msg(fp->uf_script_ctx);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1991 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1992
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1993 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1994 * Get a function name, translating "<SID>" and "<SNR>".
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1995 * Also handles a Funcref in a List or Dictionary.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1996 * Returns the function name in allocated memory, or NULL for failure.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1997 * flags:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1998 * TFN_INT: internal function name OK
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1999 * TFN_QUIET: be quiet
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2000 * TFN_NO_AUTOLOAD: do not use script autoloading
9717
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
2001 * TFN_NO_DEREF: do not dereference a Funcref
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2002 * Advances "pp" to just after the function name (if no error).
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2003 */
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2004 char_u *
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2005 trans_function_name(
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2006 char_u **pp,
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2007 int skip, // only find the end, don't evaluate
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2008 int flags,
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2009 funcdict_T *fdp, // return: info about dictionary used
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2010 partial_T **partial) // return: partial of a FuncRef
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2011 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2012 char_u *name = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2013 char_u *start;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2014 char_u *end;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2015 int lead;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2016 char_u sid_buf[20];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2017 int len;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2018 int extra = 0;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2019 lval_T lv;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2020 int vim9script;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2021
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2022 if (fdp != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2023 vim_memset(fdp, 0, sizeof(funcdict_T));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2024 start = *pp;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2025
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2026 // Check for hard coded <SNR>: already translated function ID (from a user
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2027 // command).
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2028 if ((*pp)[0] == K_SPECIAL && (*pp)[1] == KS_EXTRA
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2029 && (*pp)[2] == (int)KE_SNR)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2030 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2031 *pp += 3;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2032 len = get_id_len(pp) + 3;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2033 return vim_strnsave(start, len);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2034 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2035
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2036 // A name starting with "<SID>" or "<SNR>" is local to a script. But
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2037 // don't skip over "s:", get_lval() needs it for "s:dict.func".
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2038 lead = eval_fname_script(start);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2039 if (lead > 2)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2040 start += lead;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2041
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2042 // Note that TFN_ flags use the same values as GLV_ flags.
13002
f7b2ecaeb79c patch 8.0.1377: cannot call a dict function in autoloaded dict
Christian Brabandt <cb@256bit.org>
parents: 11569
diff changeset
2043 end = get_lval(start, NULL, &lv, FALSE, skip, flags | GLV_READ_ONLY,
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2044 lead > 2 ? 0 : FNE_CHECK_START);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2045 if (end == start)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2046 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2047 if (!skip)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
2048 emsg(_("E129: Function name required"));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2049 goto theend;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2050 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2051 if (end == NULL || (lv.ll_tv != NULL && (lead > 2 || lv.ll_range)))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2052 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2053 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2054 * Report an invalid expression in braces, unless the expression
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2055 * evaluation has been cancelled due to an aborting error, an
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2056 * interrupt, or an exception.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2057 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2058 if (!aborting())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2059 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2060 if (end != NULL)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
2061 semsg(_(e_invarg2), start);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2062 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2063 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2064 *pp = find_name_end(start, NULL, NULL, FNE_INCL_BR);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2065 goto theend;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2066 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2067
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2068 if (lv.ll_tv != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2069 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2070 if (fdp != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2071 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2072 fdp->fd_dict = lv.ll_dict;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2073 fdp->fd_newkey = lv.ll_newkey;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2074 lv.ll_newkey = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2075 fdp->fd_di = lv.ll_di;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2076 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2077 if (lv.ll_tv->v_type == VAR_FUNC && lv.ll_tv->vval.v_string != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2078 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2079 name = vim_strsave(lv.ll_tv->vval.v_string);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2080 *pp = end;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2081 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2082 else if (lv.ll_tv->v_type == VAR_PARTIAL
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2083 && lv.ll_tv->vval.v_partial != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2084 {
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2085 name = vim_strsave(partial_name(lv.ll_tv->vval.v_partial));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2086 *pp = end;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2087 if (partial != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2088 *partial = lv.ll_tv->vval.v_partial;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2089 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2090 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2091 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2092 if (!skip && !(flags & TFN_QUIET) && (fdp == NULL
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2093 || lv.ll_dict == NULL || fdp->fd_newkey == NULL))
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
2094 emsg(_(e_funcref));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2095 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2096 *pp = end;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2097 name = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2098 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2099 goto theend;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2100 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2101
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2102 if (lv.ll_name == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2103 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2104 // Error found, but continue after the function name.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2105 *pp = end;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2106 goto theend;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2107 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2108
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2109 // Check if the name is a Funcref. If so, use the value.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2110 if (lv.ll_exp_name != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2111 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2112 len = (int)STRLEN(lv.ll_exp_name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2113 name = deref_func_name(lv.ll_exp_name, &len, partial,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2114 flags & TFN_NO_AUTOLOAD);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2115 if (name == lv.ll_exp_name)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2116 name = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2117 }
9717
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
2118 else if (!(flags & TFN_NO_DEREF))
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2119 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2120 len = (int)(end - *pp);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2121 name = deref_func_name(*pp, &len, partial, flags & TFN_NO_AUTOLOAD);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2122 if (name == *pp)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2123 name = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2124 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2125 if (name != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2126 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2127 name = vim_strsave(name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2128 *pp = end;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2129 if (STRNCMP(name, "<SNR>", 5) == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2130 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2131 // Change "<SNR>" to the byte sequence.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2132 name[0] = K_SPECIAL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2133 name[1] = KS_EXTRA;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2134 name[2] = (int)KE_SNR;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2135 mch_memmove(name + 3, name + 5, STRLEN(name + 5) + 1);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2136 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2137 goto theend;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2138 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2139
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2140 if (lv.ll_exp_name != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2141 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2142 len = (int)STRLEN(lv.ll_exp_name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2143 if (lead <= 2 && lv.ll_name == lv.ll_exp_name
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2144 && STRNCMP(lv.ll_name, "s:", 2) == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2145 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2146 // When there was "s:" already or the name expanded to get a
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2147 // leading "s:" then remove it.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2148 lv.ll_name += 2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2149 len -= 2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2150 lead = 2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2151 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2152 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2153 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2154 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2155 // skip over "s:" and "g:"
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2156 if (lead == 2 || (lv.ll_name[0] == 'g' && lv.ll_name[1] == ':'))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2157 lv.ll_name += 2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2158 len = (int)(end - lv.ll_name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2159 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2160
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2161 // In Vim9 script a user function is script-local by default.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2162 vim9script = ASCII_ISUPPER(*start)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2163 && current_sctx.sc_version == SCRIPT_VERSION_VIM9;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2164
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2165 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2166 * Copy the function name to allocated memory.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2167 * Accept <SID>name() inside a script, translate into <SNR>123_name().
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2168 * Accept <SNR>123_name() outside a script.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2169 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2170 if (skip)
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2171 lead = 0; // do nothing
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2172 else if (lead > 0 || vim9script)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2173 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2174 if (!vim9script)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2175 lead = 3;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2176 if (vim9script || (lv.ll_exp_name != NULL
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2177 && eval_fname_sid(lv.ll_exp_name))
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2178 || eval_fname_sid(*pp))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2179 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2180 // It's script-local, "s:" or "<SID>"
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14430
diff changeset
2181 if (current_sctx.sc_sid <= 0)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2182 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
2183 emsg(_(e_usingsid));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2184 goto theend;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2185 }
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14430
diff changeset
2186 sprintf((char *)sid_buf, "%ld_", (long)current_sctx.sc_sid);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2187 if (vim9script)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2188 extra = 3 + (int)STRLEN(sid_buf);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2189 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2190 lead += (int)STRLEN(sid_buf);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2191 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2192 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2193 else if (!(flags & TFN_INT) && builtin_function(lv.ll_name, len))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2194 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
2195 semsg(_("E128: Function name must start with a capital or \"s:\": %s"),
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2196 start);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2197 goto theend;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2198 }
9717
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
2199 if (!skip && !(flags & TFN_QUIET) && !(flags & TFN_NO_DEREF))
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2200 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2201 char_u *cp = vim_strchr(lv.ll_name, ':');
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2202
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2203 if (cp != NULL && cp < end)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2204 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
2205 semsg(_("E884: Function name cannot contain a colon: %s"), start);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2206 goto theend;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2207 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2208 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2209
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2210 name = alloc(len + lead + extra + 1);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2211 if (name != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2212 {
19225
77cd94083850 patch 8.2.0171: Coverity warning for using uninitialized buffer
Bram Moolenaar <Bram@vim.org>
parents: 19201
diff changeset
2213 if (!skip && (lead > 0 || vim9script))
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2214 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2215 name[0] = K_SPECIAL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2216 name[1] = KS_EXTRA;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2217 name[2] = (int)KE_SNR;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2218 if (vim9script || lead > 3) // If it's "<SID>"
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2219 STRCPY(name + 3, sid_buf);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2220 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2221 mch_memmove(name + lead + extra, lv.ll_name, (size_t)len);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2222 name[lead + extra + len] = NUL;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2223 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2224 *pp = end;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2225
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2226 theend:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2227 clear_lval(&lv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2228 return name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2229 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2230
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2231 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2232 * ":function"
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2233 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2234 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2235 ex_function(exarg_T *eap)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2236 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2237 char_u *theline;
11569
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2238 char_u *line_to_free = NULL;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2239 int j;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2240 int c;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2241 int saved_did_emsg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2242 int saved_wait_return = need_wait_return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2243 char_u *name = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2244 char_u *p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2245 char_u *arg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2246 char_u *line_arg = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2247 garray_T newargs;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2248 garray_T argtypes;
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
2249 garray_T default_args;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2250 garray_T newlines;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2251 int varargs = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2252 int flags = 0;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2253 char_u *ret_type = NULL;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2254 ufunc_T *fp;
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2255 int overwrite = FALSE;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2256 int indent;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2257 int nesting;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2258 #define MAX_FUNC_NESTING 50
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2259 char nesting_def[MAX_FUNC_NESTING];
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2260 dictitem_T *v;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2261 funcdict_T fudi;
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2262 static int func_nr = 0; // number for nameless function
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2263 int paren;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2264 int todo;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2265 hashitem_T *hi;
17178
40c4cb095d53 patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents: 17168
diff changeset
2266 int do_concat = TRUE;
17251
984eef966002 patch 8.1.1625: script line numbers are not exactly right
Bram Moolenaar <Bram@vim.org>
parents: 17178
diff changeset
2267 linenr_T sourcing_lnum_off;
984eef966002 patch 8.1.1625: script line numbers are not exactly right
Bram Moolenaar <Bram@vim.org>
parents: 17178
diff changeset
2268 linenr_T sourcing_lnum_top;
17462
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2269 int is_heredoc = FALSE;
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2270 char_u *skip_until = NULL;
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2271 char_u *heredoc_trimmed = NULL;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2272
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2273 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2274 * ":function" without argument: list functions.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2275 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2276 if (ends_excmd(*eap->arg))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2277 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2278 if (!eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2279 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2280 todo = (int)func_hashtab.ht_used;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2281 for (hi = func_hashtab.ht_array; todo > 0 && !got_int; ++hi)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2282 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2283 if (!HASHITEM_EMPTY(hi))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2284 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2285 --todo;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2286 fp = HI2UF(hi);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2287 if ((fp->uf_flags & FC_DEAD)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2288 || message_filtered(fp->uf_name))
14968
c5ec5ddbe814 patch 8.1.0495: :filter only supports some commands
Bram Moolenaar <Bram@vim.org>
parents: 14927
diff changeset
2289 continue;
9735
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
2290 if (!func_name_refcount(fp->uf_name))
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2291 list_func_head(fp, FALSE);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2292 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2293 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2294 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2295 eap->nextcmd = check_nextcmd(eap->arg);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2296 return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2297 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2298
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2299 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2300 * ":function /pat": list functions matching pattern.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2301 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2302 if (*eap->arg == '/')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2303 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2304 p = skip_regexp(eap->arg + 1, '/', TRUE, NULL);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2305 if (!eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2306 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2307 regmatch_T regmatch;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2308
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2309 c = *p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2310 *p = NUL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2311 regmatch.regprog = vim_regcomp(eap->arg + 1, RE_MAGIC);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2312 *p = c;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2313 if (regmatch.regprog != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2314 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2315 regmatch.rm_ic = p_ic;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2316
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2317 todo = (int)func_hashtab.ht_used;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2318 for (hi = func_hashtab.ht_array; todo > 0 && !got_int; ++hi)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2319 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2320 if (!HASHITEM_EMPTY(hi))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2321 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2322 --todo;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2323 fp = HI2UF(hi);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2324 if ((fp->uf_flags & FC_DEAD) == 0
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2325 && !isdigit(*fp->uf_name)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2326 && vim_regexec(&regmatch, fp->uf_name, 0))
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2327 list_func_head(fp, FALSE);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2328 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2329 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2330 vim_regfree(regmatch.regprog);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2331 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2332 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2333 if (*p == '/')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2334 ++p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2335 eap->nextcmd = check_nextcmd(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2336 return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2337 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2338
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2339 ga_init(&newargs);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2340 ga_init(&argtypes);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2341 ga_init(&default_args);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2342
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2343 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2344 * Get the function name. There are these situations:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2345 * func normal function name
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2346 * "name" == func, "fudi.fd_dict" == NULL
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2347 * dict.func new dictionary entry
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2348 * "name" == NULL, "fudi.fd_dict" set,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2349 * "fudi.fd_di" == NULL, "fudi.fd_newkey" == func
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2350 * dict.func existing dict entry with a Funcref
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2351 * "name" == func, "fudi.fd_dict" set,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2352 * "fudi.fd_di" set, "fudi.fd_newkey" == NULL
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2353 * dict.func existing dict entry that's not a Funcref
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2354 * "name" == NULL, "fudi.fd_dict" set,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2355 * "fudi.fd_di" set, "fudi.fd_newkey" == NULL
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2356 * s:func script-local function name
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2357 * g:func global function name, same as "func"
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2358 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2359 p = eap->arg;
13004
41e46caf1030 patch 8.0.1378: autoload script sources itself when defining function
Christian Brabandt <cb@256bit.org>
parents: 13002
diff changeset
2360 name = trans_function_name(&p, eap->skip, TFN_NO_AUTOLOAD, &fudi, NULL);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2361 paren = (vim_strchr(p, '(') != NULL);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2362 if (name == NULL && (fudi.fd_dict == NULL || !paren) && !eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2363 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2364 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2365 * Return on an invalid expression in braces, unless the expression
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2366 * evaluation has been cancelled due to an aborting error, an
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2367 * interrupt, or an exception.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2368 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2369 if (!aborting())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2370 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2371 if (!eap->skip && fudi.fd_newkey != NULL)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
2372 semsg(_(e_dictkey), fudi.fd_newkey);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2373 vim_free(fudi.fd_newkey);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2374 return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2375 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2376 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2377 eap->skip = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2378 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2379
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2380 // An error in a function call during evaluation of an expression in magic
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2381 // braces should not cause the function not to be defined.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2382 saved_did_emsg = did_emsg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2383 did_emsg = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2384
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2385 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2386 * ":function func" with only function name: list function.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2387 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2388 if (!paren)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2389 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2390 if (!ends_excmd(*skipwhite(p)))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2391 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
2392 emsg(_(e_trailing));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2393 goto ret_free;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2394 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2395 eap->nextcmd = check_nextcmd(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2396 if (eap->nextcmd != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2397 *p = NUL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2398 if (!eap->skip && !got_int)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2399 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2400 fp = find_func(name, NULL);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2401 if (fp != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2402 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2403 list_func_head(fp, TRUE);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2404 for (j = 0; j < fp->uf_lines.ga_len && !got_int; ++j)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2405 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2406 if (FUNCLINE(fp, j) == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2407 continue;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2408 msg_putchar('\n');
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2409 msg_outnum((long)(j + 1));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2410 if (j < 9)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2411 msg_putchar(' ');
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2412 if (j < 99)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2413 msg_putchar(' ');
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2414 msg_prt_line(FUNCLINE(fp, j), FALSE);
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2415 out_flush(); // show a line at a time
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2416 ui_breakcheck();
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2417 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2418 if (!got_int)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2419 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2420 msg_putchar('\n');
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2421 if (fp->uf_dfunc_idx >= 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2422 msg_puts(" enddef");
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2423 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2424 msg_puts(" endfunction");
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2425 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2426 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2427 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2428 emsg_funcname(N_("E123: Undefined function: %s"), name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2429 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2430 goto ret_free;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2431 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2432
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2433 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2434 * ":function name(arg1, arg2)" Define function.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2435 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2436 p = skipwhite(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2437 if (*p != '(')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2438 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2439 if (!eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2440 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
2441 semsg(_("E124: Missing '(': %s"), eap->arg);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2442 goto ret_free;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2443 }
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2444 // attempt to continue by skipping some text
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2445 if (vim_strchr(p, '(') != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2446 p = vim_strchr(p, '(');
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2447 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2448 p = skipwhite(p + 1);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2449
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2450 ga_init2(&newlines, (int)sizeof(char_u *), 3);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2451
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2452 if (!eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2453 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2454 // Check the name of the function. Unless it's a dictionary function
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2455 // (that we are overwriting).
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2456 if (name != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2457 arg = name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2458 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2459 arg = fudi.fd_newkey;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2460 if (arg != NULL && (fudi.fd_di == NULL
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2461 || (fudi.fd_di->di_tv.v_type != VAR_FUNC
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2462 && fudi.fd_di->di_tv.v_type != VAR_PARTIAL)))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2463 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2464 if (*arg == K_SPECIAL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2465 j = 3;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2466 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2467 j = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2468 while (arg[j] != NUL && (j == 0 ? eval_isnamec1(arg[j])
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2469 : eval_isnamec(arg[j])))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2470 ++j;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2471 if (arg[j] != NUL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2472 emsg_funcname((char *)e_invarg2, arg);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2473 }
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2474 // Disallow using the g: dict.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2475 if (fudi.fd_dict != NULL && fudi.fd_dict->dv_scope == VAR_DEF_SCOPE)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
2476 emsg(_("E862: Cannot use g: here"));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2477 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2478
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2479 if (get_function_args(&p, ')', &newargs,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2480 eap->cmdidx == CMD_def ? &argtypes : NULL,
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2481 &varargs, &default_args, eap->skip) == FAIL)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2482 goto errret_2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2483
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2484 if (eap->cmdidx == CMD_def)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2485 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2486 // find the return type: :def Func(): type
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2487 if (*p == ':')
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2488 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2489 ret_type = skipwhite(p + 1);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2490 p = skip_type(ret_type);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2491 if (p > ret_type)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2492 p = skipwhite(p);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2493 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2494 semsg(_("E1056: expected a type: %s"), ret_type);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2495 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2496 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2497 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2498 // find extra arguments "range", "dict", "abort" and "closure"
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2499 for (;;)
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
2500 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2501 p = skipwhite(p);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2502 if (STRNCMP(p, "range", 5) == 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2503 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2504 flags |= FC_RANGE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2505 p += 5;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2506 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2507 else if (STRNCMP(p, "dict", 4) == 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2508 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2509 flags |= FC_DICT;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2510 p += 4;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2511 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2512 else if (STRNCMP(p, "abort", 5) == 0)
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
2513 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2514 flags |= FC_ABORT;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2515 p += 5;
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
2516 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2517 else if (STRNCMP(p, "closure", 7) == 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2518 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2519 flags |= FC_CLOSURE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2520 p += 7;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2521 if (current_funccal == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2522 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2523 emsg_funcname(N_("E932: Closure function should not be at top level: %s"),
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2524 name == NULL ? (char_u *)"" : name);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2525 goto erret;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2526 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2527 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2528 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2529 break;
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
2530 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2531
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2532 // When there is a line break use what follows for the function body.
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2533 // Makes 'exe "func Test()\n...\nendfunc"' work.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2534 if (*p == '\n')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2535 line_arg = p + 1;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2536 else if (*p != NUL && *p != '"' && !eap->skip && !did_emsg)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
2537 emsg(_(e_trailing));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2538
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2539 /*
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2540 * Read the body of the function, until "}", ":endfunction" or ":enddef" is
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2541 * found.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2542 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2543 if (KeyTyped)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2544 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2545 // Check if the function already exists, don't let the user type the
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2546 // whole function before telling him it doesn't work! For a script we
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2547 // need to skip the body to be able to find what follows.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2548 if (!eap->skip && !eap->forceit)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2549 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2550 if (fudi.fd_dict != NULL && fudi.fd_newkey == NULL)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
2551 emsg(_(e_funcdict));
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2552 else if (name != NULL && find_func(name, NULL) != NULL)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2553 emsg_funcname(e_funcexts, name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2554 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2555
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2556 if (!eap->skip && did_emsg)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2557 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2558
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2559 msg_putchar('\n'); // don't overwrite the function name
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2560 cmdline_row = msg_row;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2561 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2562
17251
984eef966002 patch 8.1.1625: script line numbers are not exactly right
Bram Moolenaar <Bram@vim.org>
parents: 17178
diff changeset
2563 // Save the starting line number.
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
2564 sourcing_lnum_top = SOURCING_LNUM;
17251
984eef966002 patch 8.1.1625: script line numbers are not exactly right
Bram Moolenaar <Bram@vim.org>
parents: 17178
diff changeset
2565
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2566 indent = 2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2567 nesting = 0;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2568 nesting_def[nesting] = (eap->cmdidx == CMD_def);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2569 for (;;)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2570 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2571 if (KeyTyped)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2572 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2573 msg_scroll = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2574 saved_wait_return = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2575 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2576 need_wait_return = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2577
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2578 if (line_arg != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2579 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2580 // Use eap->arg, split up in parts by line breaks.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2581 theline = line_arg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2582 p = vim_strchr(theline, '\n');
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2583 if (p == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2584 line_arg += STRLEN(line_arg);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2585 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2586 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2587 *p = NUL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2588 line_arg = p + 1;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2589 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2590 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2591 else
11569
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2592 {
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2593 vim_free(line_to_free);
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2594 if (eap->getline == NULL)
17178
40c4cb095d53 patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents: 17168
diff changeset
2595 theline = getcmdline(':', 0L, indent, do_concat);
11569
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2596 else
17178
40c4cb095d53 patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents: 17168
diff changeset
2597 theline = eap->getline(':', eap->cookie, indent, do_concat);
11569
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2598 line_to_free = theline;
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2599 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2600 if (KeyTyped)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2601 lines_left = Rows - 1;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2602 if (theline == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2603 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2604 if (eap->cmdidx == CMD_def)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2605 emsg(_("E1057: Missing :enddef"));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2606 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2607 emsg(_("E126: Missing :endfunction"));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2608 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2609 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2610
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
2611 // Detect line continuation: SOURCING_LNUM increased more than one.
17251
984eef966002 patch 8.1.1625: script line numbers are not exactly right
Bram Moolenaar <Bram@vim.org>
parents: 17178
diff changeset
2612 sourcing_lnum_off = get_sourced_lnum(eap->getline, eap->cookie);
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
2613 if (SOURCING_LNUM < sourcing_lnum_off)
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
2614 sourcing_lnum_off -= SOURCING_LNUM;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2615 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2616 sourcing_lnum_off = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2617
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2618 if (skip_until != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2619 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2620 // Don't check for ":endfunc"/":enddef" between
17462
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2621 // * ":append" and "."
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2622 // * ":python <<EOF" and "EOF"
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2623 // * ":let {var-name} =<< [trim] {marker}" and "{marker}"
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2624 if (heredoc_trimmed == NULL
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2625 || (is_heredoc && skipwhite(theline) == theline)
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2626 || STRNCMP(theline, heredoc_trimmed,
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2627 STRLEN(heredoc_trimmed)) == 0)
16708
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2628 {
17462
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2629 if (heredoc_trimmed == NULL)
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2630 p = theline;
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2631 else if (is_heredoc)
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2632 p = skipwhite(theline) == theline
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2633 ? theline : theline + STRLEN(heredoc_trimmed);
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2634 else
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2635 p = theline + STRLEN(heredoc_trimmed);
16708
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2636 if (STRCMP(p, skip_until) == 0)
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2637 {
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2638 VIM_CLEAR(skip_until);
17462
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2639 VIM_CLEAR(heredoc_trimmed);
17178
40c4cb095d53 patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents: 17168
diff changeset
2640 do_concat = TRUE;
17462
9088fafff9b3 patch 8.1.1729: heredoc with trim not properly handled in function
Bram Moolenaar <Bram@vim.org>
parents: 17381
diff changeset
2641 is_heredoc = FALSE;
16708
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2642 }
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2643 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2644 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2645 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2646 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2647 // skip ':' and blanks
11129
f4ea50924c6d patch 8.0.0452: some macros are in lower case
Christian Brabandt <cb@256bit.org>
parents: 10815
diff changeset
2648 for (p = theline; VIM_ISWHITE(*p) || *p == ':'; ++p)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2649 ;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2650
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2651 // Check for "endfunction" or "enddef".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2652 if (checkforcmd(&p, nesting_def[nesting]
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2653 ? "enddef" : "endfunction", 4) && nesting-- == 0)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2654 {
11569
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2655 char_u *nextcmd = NULL;
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2656
11543
57c452316da1 patch 8.0.0654: no warning for text after :endfunction
Christian Brabandt <cb@256bit.org>
parents: 11325
diff changeset
2657 if (*p == '|')
11569
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2658 nextcmd = p + 1;
11543
57c452316da1 patch 8.0.0654: no warning for text after :endfunction
Christian Brabandt <cb@256bit.org>
parents: 11325
diff changeset
2659 else if (line_arg != NULL && *skipwhite(line_arg) != NUL)
11569
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2660 nextcmd = line_arg;
11543
57c452316da1 patch 8.0.0654: no warning for text after :endfunction
Christian Brabandt <cb@256bit.org>
parents: 11325
diff changeset
2661 else if (*p != NUL && *p != '"' && p_verbose > 0)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2662 give_warning2(eap->cmdidx == CMD_def
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2663 ? (char_u *)_("W1001: Text found after :enddef: %s")
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2664 : (char_u *)_("W22: Text found after :endfunction: %s"),
11561
7ad79766365a patch 8.0.0663: unexpected error message only when 'verbose' is set
Christian Brabandt <cb@256bit.org>
parents: 11545
diff changeset
2665 p, TRUE);
11569
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2666 if (nextcmd != NULL)
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2667 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2668 // Another command follows. If the line came from "eap" we
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2669 // can simply point into it, otherwise we need to change
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2670 // "eap->cmdlinep".
11569
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2671 eap->nextcmd = nextcmd;
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2672 if (line_to_free != NULL)
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2673 {
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2674 vim_free(*eap->cmdlinep);
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2675 *eap->cmdlinep = line_to_free;
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2676 line_to_free = NULL;
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2677 }
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2678 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2679 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2680 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2681
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2682 // Increase indent inside "if", "while", "for" and "try", decrease
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2683 // at "end".
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2684 if (indent > 2 && (*p == '}' || STRNCMP(p, "end", 3) == 0))
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2685 indent -= 2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2686 else if (STRNCMP(p, "if", 2) == 0
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2687 || STRNCMP(p, "wh", 2) == 0
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2688 || STRNCMP(p, "for", 3) == 0
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2689 || STRNCMP(p, "try", 3) == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2690 indent += 2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2691
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2692 // Check for defining a function inside this function.
19183
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
2693 // Only recognize "def" inside "def", not inside "function",
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
2694 // For backwards compatibility, see Test_function_python().
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2695 c = *p;
19183
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
2696 if (checkforcmd(&p, "function", 2)
1168c53d1b49 patch 8.2.0150: cannot define python function when using :execute
Bram Moolenaar <Bram@vim.org>
parents: 19181
diff changeset
2697 || (eap->cmdidx == CMD_def && checkforcmd(&p, "def", 3)))
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2698 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2699 if (*p == '!')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2700 p = skipwhite(p + 1);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2701 p += eval_fname_script(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2702 vim_free(trans_function_name(&p, TRUE, 0, NULL, NULL));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2703 if (*skipwhite(p) == '(')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2704 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2705 if (nesting == MAX_FUNC_NESTING - 1)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2706 emsg(_("E1058: function nesting too deep"));
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2707 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2708 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2709 ++nesting;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2710 nesting_def[nesting] = (c == 'd');
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2711 indent += 2;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2712 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2713 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2714 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2715
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19225
diff changeset
2716 // Check for ":append", ":change", ":insert". Not for :def.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2717 p = skip_range(p, NULL);
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19225
diff changeset
2718 if (eap->cmdidx != CMD_def
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19225
diff changeset
2719 && ((p[0] == 'a' && (!ASCII_ISALPHA(p[1]) || p[1] == 'p'))
10573
3f777388b6ad patch 8.0.0176: cannot use :change inside a function definition
Christian Brabandt <cb@256bit.org>
parents: 10359
diff changeset
2720 || (p[0] == 'c'
3f777388b6ad patch 8.0.0176: cannot use :change inside a function definition
Christian Brabandt <cb@256bit.org>
parents: 10359
diff changeset
2721 && (!ASCII_ISALPHA(p[1]) || (p[1] == 'h'
3f777388b6ad patch 8.0.0176: cannot use :change inside a function definition
Christian Brabandt <cb@256bit.org>
parents: 10359
diff changeset
2722 && (!ASCII_ISALPHA(p[2]) || (p[2] == 'a'
3f777388b6ad patch 8.0.0176: cannot use :change inside a function definition
Christian Brabandt <cb@256bit.org>
parents: 10359
diff changeset
2723 && (STRNCMP(&p[3], "nge", 3) != 0
3f777388b6ad patch 8.0.0176: cannot use :change inside a function definition
Christian Brabandt <cb@256bit.org>
parents: 10359
diff changeset
2724 || !ASCII_ISALPHA(p[6])))))))
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2725 || (p[0] == 'i'
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2726 && (!ASCII_ISALPHA(p[1]) || (p[1] == 'n'
19253
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19225
diff changeset
2727 && (!ASCII_ISALPHA(p[2])
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19225
diff changeset
2728 || (p[2] == 's'
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19225
diff changeset
2729 && (!ASCII_ISALPHA(p[3])
a8d2d3c8f0b3 patch 8.2.0185: Vim9 script: cannot use "if has()" to skip lines
Bram Moolenaar <Bram@vim.org>
parents: 19225
diff changeset
2730 || p[3] == 'e'))))))))
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2731 skip_until = vim_strsave((char_u *)".");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2732
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2733 // Check for ":python <<EOF", ":tcl <<EOF", etc.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2734 arg = skipwhite(skiptowhite(p));
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2735 if (arg[0] == '<' && arg[1] =='<'
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2736 && ((p[0] == 'p' && p[1] == 'y'
10722
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents: 10573
diff changeset
2737 && (!ASCII_ISALNUM(p[2]) || p[2] == 't'
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents: 10573
diff changeset
2738 || ((p[2] == '3' || p[2] == 'x')
7598ce51bf2a patch 8.0.0251: not easy to select Python 2 or 3
Christian Brabandt <cb@256bit.org>
parents: 10573
diff changeset
2739 && !ASCII_ISALPHA(p[3]))))
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2740 || (p[0] == 'p' && p[1] == 'e'
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2741 && (!ASCII_ISALPHA(p[2]) || p[2] == 'r'))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2742 || (p[0] == 't' && p[1] == 'c'
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2743 && (!ASCII_ISALPHA(p[2]) || p[2] == 'l'))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2744 || (p[0] == 'l' && p[1] == 'u' && p[2] == 'a'
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2745 && !ASCII_ISALPHA(p[3]))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2746 || (p[0] == 'r' && p[1] == 'u' && p[2] == 'b'
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2747 && (!ASCII_ISALPHA(p[3]) || p[3] == 'y'))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2748 || (p[0] == 'm' && p[1] == 'z'
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2749 && (!ASCII_ISALPHA(p[2]) || p[2] == 's'))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2750 ))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2751 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2752 // ":python <<" continues until a dot, like ":append"
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2753 p = skipwhite(arg + 2);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2754 if (*p == NUL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2755 skip_until = vim_strsave((char_u *)".");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2756 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2757 skip_until = vim_strsave(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2758 }
16708
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2759
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2760 // Check for ":let v =<< [trim] EOF"
18536
c0cd979000f9 patch 8.1.2262: unpack assignment in function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 18265
diff changeset
2761 // and ":let [a, b] =<< [trim] EOF"
16708
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2762 arg = skipwhite(skiptowhite(p));
18536
c0cd979000f9 patch 8.1.2262: unpack assignment in function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 18265
diff changeset
2763 if (*arg == '[')
c0cd979000f9 patch 8.1.2262: unpack assignment in function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 18265
diff changeset
2764 arg = vim_strchr(arg, ']');
c0cd979000f9 patch 8.1.2262: unpack assignment in function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 18265
diff changeset
2765 if (arg != NULL)
16708
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2766 {
18536
c0cd979000f9 patch 8.1.2262: unpack assignment in function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 18265
diff changeset
2767 arg = skipwhite(skiptowhite(arg));
c0cd979000f9 patch 8.1.2262: unpack assignment in function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 18265
diff changeset
2768 if ( arg[0] == '=' && arg[1] == '<' && arg[2] =='<'
c0cd979000f9 patch 8.1.2262: unpack assignment in function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 18265
diff changeset
2769 && ((p[0] == 'l'
c0cd979000f9 patch 8.1.2262: unpack assignment in function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 18265
diff changeset
2770 && p[1] == 'e'
c0cd979000f9 patch 8.1.2262: unpack assignment in function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 18265
diff changeset
2771 && (!ASCII_ISALNUM(p[2])
c0cd979000f9 patch 8.1.2262: unpack assignment in function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 18265
diff changeset
2772 || (p[2] == 't' && !ASCII_ISALNUM(p[3]))))))
16708
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2773 {
18536
c0cd979000f9 patch 8.1.2262: unpack assignment in function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 18265
diff changeset
2774 p = skipwhite(arg + 3);
c0cd979000f9 patch 8.1.2262: unpack assignment in function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 18265
diff changeset
2775 if (STRNCMP(p, "trim", 4) == 0)
c0cd979000f9 patch 8.1.2262: unpack assignment in function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 18265
diff changeset
2776 {
c0cd979000f9 patch 8.1.2262: unpack assignment in function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 18265
diff changeset
2777 // Ignore leading white space.
c0cd979000f9 patch 8.1.2262: unpack assignment in function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 18265
diff changeset
2778 p = skipwhite(p + 4);
c0cd979000f9 patch 8.1.2262: unpack assignment in function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 18265
diff changeset
2779 heredoc_trimmed = vim_strnsave(theline,
16708
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2780 (int)(skipwhite(theline) - theline));
18536
c0cd979000f9 patch 8.1.2262: unpack assignment in function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 18265
diff changeset
2781 }
c0cd979000f9 patch 8.1.2262: unpack assignment in function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 18265
diff changeset
2782 skip_until = vim_strnsave(p, (int)(skiptowhite(p) - p));
c0cd979000f9 patch 8.1.2262: unpack assignment in function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 18265
diff changeset
2783 do_concat = FALSE;
c0cd979000f9 patch 8.1.2262: unpack assignment in function not recognized
Bram Moolenaar <Bram@vim.org>
parents: 18265
diff changeset
2784 is_heredoc = TRUE;
16708
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2785 }
98393772bddd patch 8.1.1356: some text in heredoc assignment ends the text
Bram Moolenaar <Bram@vim.org>
parents: 16634
diff changeset
2786 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2787 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2788
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2789 // Add the line to the function.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2790 if (ga_grow(&newlines, 1 + sourcing_lnum_off) == FAIL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2791 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2792
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2793 // Copy the line to newly allocated memory. get_one_sourceline()
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2794 // allocates 250 bytes per line, this saves 80% on average. The cost
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2795 // is an extra alloc/free.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2796 p = vim_strsave(theline);
11569
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2797 if (p == NULL)
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2798 goto erret;
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
2799 ((char_u **)(newlines.ga_data))[newlines.ga_len++] = p;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2800
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2801 // Add NULL lines for continuation lines, so that the line count is
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2802 // equal to the index in the growarray.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2803 while (sourcing_lnum_off-- > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2804 ((char_u **)(newlines.ga_data))[newlines.ga_len++] = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2805
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2806 // Check for end of eap->arg.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2807 if (line_arg != NULL && *line_arg == NUL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2808 line_arg = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2809 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2810
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2811 // Don't define the function when skipping commands or when an error was
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2812 // detected.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2813 if (eap->skip || did_emsg)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2814 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2815
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2816 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2817 * If there are no errors, add the function
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2818 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2819 if (fudi.fd_dict == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2820 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2821 hashtab_T *ht;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2822
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2823 v = find_var(name, &ht, FALSE);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2824 if (v != NULL && v->di_tv.v_type == VAR_FUNC)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2825 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2826 emsg_funcname(N_("E707: Function name conflicts with variable: %s"),
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2827 name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2828 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2829 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2830
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2831 fp = find_func_even_dead(name, NULL);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2832 if (fp != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2833 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2834 int dead = fp->uf_flags & FC_DEAD;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2835
15008
67e3103d6e18 patch 8.1.0515: reloading a script gives errors for existing functions
Bram Moolenaar <Bram@vim.org>
parents: 15000
diff changeset
2836 // Function can be replaced with "function!" and when sourcing the
67e3103d6e18 patch 8.1.0515: reloading a script gives errors for existing functions
Bram Moolenaar <Bram@vim.org>
parents: 15000
diff changeset
2837 // same script again, but only once.
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2838 if (!dead && !eap->forceit
15008
67e3103d6e18 patch 8.1.0515: reloading a script gives errors for existing functions
Bram Moolenaar <Bram@vim.org>
parents: 15000
diff changeset
2839 && (fp->uf_script_ctx.sc_sid != current_sctx.sc_sid
67e3103d6e18 patch 8.1.0515: reloading a script gives errors for existing functions
Bram Moolenaar <Bram@vim.org>
parents: 15000
diff changeset
2840 || fp->uf_script_ctx.sc_seq == current_sctx.sc_seq))
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2841 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2842 emsg_funcname(e_funcexts, name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2843 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2844 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2845 if (fp->uf_calls > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2846 {
15008
67e3103d6e18 patch 8.1.0515: reloading a script gives errors for existing functions
Bram Moolenaar <Bram@vim.org>
parents: 15000
diff changeset
2847 emsg_funcname(
67e3103d6e18 patch 8.1.0515: reloading a script gives errors for existing functions
Bram Moolenaar <Bram@vim.org>
parents: 15000
diff changeset
2848 N_("E127: Cannot redefine function %s: It is in use"),
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2849 name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2850 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2851 }
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2852 if (fp->uf_refcount > 1)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2853 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2854 // This function is referenced somewhere, don't redefine it but
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2855 // create a new one.
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2856 --fp->uf_refcount;
9733
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
2857 fp->uf_flags |= FC_REMOVED;
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2858 fp = NULL;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2859 overwrite = TRUE;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2860 }
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2861 else
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2862 {
19035
b920ae62c7b1 patch 8.2.0078: expanding <sfile> works differently the second time
Bram Moolenaar <Bram@vim.org>
parents: 19013
diff changeset
2863 char_u *exp_name = fp->uf_name_exp;
b920ae62c7b1 patch 8.2.0078: expanding <sfile> works differently the second time
Bram Moolenaar <Bram@vim.org>
parents: 19013
diff changeset
2864
b920ae62c7b1 patch 8.2.0078: expanding <sfile> works differently the second time
Bram Moolenaar <Bram@vim.org>
parents: 19013
diff changeset
2865 // redefine existing function, keep the expanded name
13244
ac42c4b11dbc patch 8.0.1496: clearing a pointer takes two lines
Christian Brabandt <cb@256bit.org>
parents: 13096
diff changeset
2866 VIM_CLEAR(name);
19035
b920ae62c7b1 patch 8.2.0078: expanding <sfile> works differently the second time
Bram Moolenaar <Bram@vim.org>
parents: 19013
diff changeset
2867 fp->uf_name_exp = NULL;
14430
2fba714294b9 patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents: 14323
diff changeset
2868 func_clear_items(fp);
19035
b920ae62c7b1 patch 8.2.0078: expanding <sfile> works differently the second time
Bram Moolenaar <Bram@vim.org>
parents: 19013
diff changeset
2869 fp->uf_name_exp = exp_name;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2870 fp->uf_flags &= ~FC_DEAD;
14430
2fba714294b9 patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents: 14323
diff changeset
2871 #ifdef FEAT_PROFILE
2fba714294b9 patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents: 14323
diff changeset
2872 fp->uf_profiling = FALSE;
2fba714294b9 patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents: 14323
diff changeset
2873 fp->uf_prof_initialized = FALSE;
2fba714294b9 patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents: 14323
diff changeset
2874 #endif
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2875 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2876 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2877 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2878 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2879 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2880 char numbuf[20];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2881
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2882 fp = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2883 if (fudi.fd_newkey == NULL && !eap->forceit)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2884 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
2885 emsg(_(e_funcdict));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2886 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2887 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2888 if (fudi.fd_di == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2889 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2890 // Can't add a function to a locked dictionary
15780
5b6c3c7feba8 patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
2891 if (var_check_lock(fudi.fd_dict->dv_lock, eap->arg, FALSE))
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2892 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2893 }
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2894 // Can't change an existing function if it is locked
15780
5b6c3c7feba8 patch 8.1.0897: can modify a:000 when using a reference
Bram Moolenaar <Bram@vim.org>
parents: 15762
diff changeset
2895 else if (var_check_lock(fudi.fd_di->di_tv.v_lock, eap->arg, FALSE))
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2896 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2897
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2898 // Give the function a sequential number. Can only be used with a
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2899 // Funcref!
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2900 vim_free(name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2901 sprintf(numbuf, "%d", ++func_nr);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2902 name = vim_strsave((char_u *)numbuf);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2903 if (name == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2904 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2905 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2906
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2907 if (fp == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2908 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2909 if (fudi.fd_dict == NULL && vim_strchr(name, AUTOLOAD_CHAR) != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2910 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2911 int slen, plen;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2912 char_u *scriptname;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2913
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2914 // Check that the autoload name matches the script name.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2915 j = FAIL;
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
2916 if (SOURCING_NAME != NULL)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2917 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2918 scriptname = autoload_name(name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2919 if (scriptname != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2920 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2921 p = vim_strchr(scriptname, '/');
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2922 plen = (int)STRLEN(p);
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
2923 slen = (int)STRLEN(SOURCING_NAME);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2924 if (slen > plen && fnamecmp(p,
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
2925 SOURCING_NAME + slen - plen) == 0)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2926 j = OK;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2927 vim_free(scriptname);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2928 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2929 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2930 if (j == FAIL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2931 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
2932 semsg(_("E746: Function name does not match script file name: %s"), name);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2933 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2934 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2935 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2936
17659
121bdff812b4 patch 8.1.1827: allocating more memory than needed for extended structs
Bram Moolenaar <Bram@vim.org>
parents: 17646
diff changeset
2937 fp = alloc_clear(offsetof(ufunc_T, uf_name) + STRLEN(name) + 1);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2938 if (fp == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2939 goto erret;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2940 fp->uf_dfunc_idx = -1;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2941
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2942 if (fudi.fd_dict != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2943 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2944 if (fudi.fd_di == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2945 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2946 // add new dict entry
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2947 fudi.fd_di = dictitem_alloc(fudi.fd_newkey);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2948 if (fudi.fd_di == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2949 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2950 vim_free(fp);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2951 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2952 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2953 if (dict_add(fudi.fd_dict, fudi.fd_di) == FAIL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2954 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2955 vim_free(fudi.fd_di);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2956 vim_free(fp);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2957 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2958 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2959 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2960 else
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2961 // overwrite existing dict entry
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2962 clear_tv(&fudi.fd_di->di_tv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2963 fudi.fd_di->di_tv.v_type = VAR_FUNC;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2964 fudi.fd_di->di_tv.vval.v_string = vim_strsave(name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2965
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2966 // behave like "dict" was used
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2967 flags |= FC_DICT;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2968 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2969
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
2970 // insert the new function in the function list
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
2971 set_ufunc_name(fp, name);
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2972 if (overwrite)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2973 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2974 hi = hash_find(&func_hashtab, name);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2975 hi->hi_key = UF2HIKEY(fp);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2976 }
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2977 else if (hash_add(&func_hashtab, UF2HIKEY(fp)) == FAIL)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2978 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2979 vim_free(fp);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2980 goto erret;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2981 }
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
2982 fp->uf_refcount = 1;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2983 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2984 fp->uf_args = newargs;
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
2985 fp->uf_def_args = default_args;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2986 fp->uf_ret_type = &t_any;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2987
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2988 if (eap->cmdidx == CMD_def)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2989 {
19297
84703c85a583 patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
2990 int lnum_save = SOURCING_LNUM;
84703c85a583 patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
2991
84703c85a583 patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
2992 // error messages are for the first function line
84703c85a583 patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
2993 SOURCING_LNUM = sourcing_lnum_top;
84703c85a583 patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
2994
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2995 // parse the argument types
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2996 ga_init2(&fp->uf_type_list, sizeof(type_T), 5);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2997
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2998 if (argtypes.ga_len > 0)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
2999 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3000 // When "varargs" is set the last name/type goes into uf_va_name
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3001 // and uf_va_type.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3002 int len = argtypes.ga_len - (varargs ? 1 : 0);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3003
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3004 fp->uf_arg_types = ALLOC_CLEAR_MULT(type_T *, len);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3005 if (fp->uf_arg_types != NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3006 {
19297
84703c85a583 patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
3007 int i;
84703c85a583 patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
3008 type_T *type;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3009
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3010 for (i = 0; i < len; ++ i)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3011 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3012 p = ((char_u **)argtypes.ga_data)[i];
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3013 if (p == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3014 // todo: get type from default value
19297
84703c85a583 patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
3015 type = &t_any;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3016 else
19297
84703c85a583 patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
3017 type = parse_type(&p, &fp->uf_type_list);
84703c85a583 patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
3018 if (type == NULL)
84703c85a583 patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
3019 {
84703c85a583 patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
3020 SOURCING_LNUM = lnum_save;
84703c85a583 patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
3021 goto errret_2;
84703c85a583 patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
3022 }
84703c85a583 patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
3023 fp->uf_arg_types[i] = type;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3024 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3025 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3026 if (varargs)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3027 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3028 // Move the last argument "...name: type" to uf_va_name and
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3029 // uf_va_type.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3030 fp->uf_va_name = ((char_u **)fp->uf_args.ga_data)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3031 [fp->uf_args.ga_len - 1];
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3032 --fp->uf_args.ga_len;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3033 p = ((char_u **)argtypes.ga_data)[len];
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3034 if (p == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3035 // todo: get type from default value
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3036 fp->uf_va_type = &t_any;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3037 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3038 fp->uf_va_type = parse_type(&p, &fp->uf_type_list);
19297
84703c85a583 patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
3039 if (fp->uf_va_type == NULL)
84703c85a583 patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
3040 {
84703c85a583 patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
3041 SOURCING_LNUM = lnum_save;
84703c85a583 patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
3042 goto errret_2;
84703c85a583 patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents: 19285
diff changeset
3043 }
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3044 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3045 varargs = FALSE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3046 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3047
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3048 // parse the return type, if any
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3049 if (ret_type == NULL)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3050 fp->uf_ret_type = &t_void;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3051 else
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3052 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3053 p = ret_type;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3054 fp->uf_ret_type = parse_type(&p, &fp->uf_type_list);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3055 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3056 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3057
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3058 fp->uf_lines = newlines;
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3059 if ((flags & FC_CLOSURE) != 0)
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3060 {
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
3061 if (register_closure(fp) == FAIL)
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3062 goto erret;
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3063 }
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3064 else
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3065 fp->uf_scoped = NULL;
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
3066
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3067 #ifdef FEAT_PROFILE
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3068 if (prof_def_func())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3069 func_do_profile(fp);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3070 #endif
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3071 fp->uf_varargs = varargs;
14323
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
3072 if (sandbox)
9df95cf9ea7e patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents: 14303
diff changeset
3073 flags |= FC_SANDBOX;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3074 fp->uf_flags = flags;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3075 fp->uf_calls = 0;
19443
6b1a59e71f85 patch 8.2.0279: Vim9: no test for deleted :def function
Bram Moolenaar <Bram@vim.org>
parents: 19421
diff changeset
3076 fp->uf_cleared = FALSE;
14700
0a3b9ecf7cb8 patch 8.1.0362: cannot get the script line number when executing a function
Christian Brabandt <cb@256bit.org>
parents: 14430
diff changeset
3077 fp->uf_script_ctx = current_sctx;
17251
984eef966002 patch 8.1.1625: script line numbers are not exactly right
Bram Moolenaar <Bram@vim.org>
parents: 17178
diff changeset
3078 fp->uf_script_ctx.sc_lnum += sourcing_lnum_top;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3079 if (is_export)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3080 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3081 fp->uf_flags |= FC_EXPORT;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3082 // let ex_export() know the export worked.
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3083 is_export = FALSE;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3084 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3085
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3086 // ":def Func()" needs to be compiled
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3087 if (eap->cmdidx == CMD_def)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3088 compile_def_function(fp, FALSE);
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3089
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3090 goto ret_free;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3091
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3092 erret:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3093 ga_clear_strings(&newargs);
16615
1a911bd57f11 patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents: 16606
diff changeset
3094 ga_clear_strings(&default_args);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3095 errret_2:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3096 ga_clear_strings(&newlines);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3097 ret_free:
19685
d64f403289db patch 8.2.0399: various memory leaks
Bram Moolenaar <Bram@vim.org>
parents: 19579
diff changeset
3098 ga_clear_strings(&argtypes);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3099 vim_free(skip_until);
11569
7003f241b6c7 patch 8.0.0667: memory access error when command follows :endfunc
Christian Brabandt <cb@256bit.org>
parents: 11561
diff changeset
3100 vim_free(line_to_free);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3101 vim_free(fudi.fd_newkey);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3102 vim_free(name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3103 did_emsg |= saved_did_emsg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3104 need_wait_return |= saved_wait_return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3105 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3106
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3107 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3108 * Return 5 if "p" starts with "<SID>" or "<SNR>" (ignoring case).
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3109 * Return 2 if "p" starts with "s:".
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3110 * Return 0 otherwise.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3111 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3112 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3113 eval_fname_script(char_u *p)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3114 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3115 // Use MB_STRICMP() because in Turkish comparing the "I" may not work with
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3116 // the standard library function.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3117 if (p[0] == '<' && (MB_STRNICMP(p + 1, "SID>", 4) == 0
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3118 || MB_STRNICMP(p + 1, "SNR>", 4) == 0))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3119 return 5;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3120 if (p[0] == 's' && p[1] == ':')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3121 return 2;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3122 return 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3123 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3124
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3125 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3126 translated_function_exists(char_u *name)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3127 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3128 if (builtin_function(name, -1))
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
3129 return has_internal_func(name);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3130 return find_func(name, NULL) != NULL;
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3131 }
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3132
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3133 /*
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3134 * Return TRUE when "ufunc" has old-style "..." varargs
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3135 * or named varargs "...name: type".
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3136 */
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3137 int
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3138 has_varargs(ufunc_T *ufunc)
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3139 {
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3140 return ufunc->uf_varargs || ufunc->uf_va_name != NULL;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3141 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3142
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3143 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3144 * Return TRUE if a function "name" exists.
9717
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
3145 * If "no_defef" is TRUE, do not dereference a Funcref.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3146 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3147 int
9717
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
3148 function_exists(char_u *name, int no_deref)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3149 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3150 char_u *nm = name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3151 char_u *p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3152 int n = FALSE;
9717
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
3153 int flag;
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
3154
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
3155 flag = TFN_INT | TFN_QUIET | TFN_NO_AUTOLOAD;
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
3156 if (no_deref)
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
3157 flag |= TFN_NO_DEREF;
6226de5f8137 commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents: 9688
diff changeset
3158 p = trans_function_name(&nm, FALSE, flag, NULL, NULL);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3159 nm = skipwhite(nm);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3160
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3161 // Only accept "funcname", "funcname ", "funcname (..." and
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3162 // "funcname(...", not "funcname!...".
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3163 if (p != NULL && (*nm == NUL || *nm == '('))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3164 n = translated_function_exists(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3165 vim_free(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3166 return n;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3167 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3168
15555
d89c5b339c2a patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
3169 #if defined(FEAT_PYTHON) || defined(FEAT_PYTHON3) || defined(PROTO)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3170 char_u *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3171 get_expanded_name(char_u *name, int check)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3172 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3173 char_u *nm = name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3174 char_u *p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3175
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3176 p = trans_function_name(&nm, FALSE, TFN_INT|TFN_QUIET, NULL, NULL);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3177
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3178 if (p != NULL && *nm == NUL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3179 if (!check || translated_function_exists(p))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3180 return p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3181
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3182 vim_free(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3183 return NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3184 }
15555
d89c5b339c2a patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents: 15543
diff changeset
3185 #endif
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3186
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3187 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3188 * Function given to ExpandGeneric() to obtain the list of user defined
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3189 * function names.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3190 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3191 char_u *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3192 get_user_func_name(expand_T *xp, int idx)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3193 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3194 static long_u done;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3195 static hashitem_T *hi;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3196 ufunc_T *fp;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3197
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3198 if (idx == 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3199 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3200 done = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3201 hi = func_hashtab.ht_array;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3202 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3203 if (done < func_hashtab.ht_used)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3204 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3205 if (done++ > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3206 ++hi;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3207 while (HASHITEM_EMPTY(hi))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3208 ++hi;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3209 fp = HI2UF(hi);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3210
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3211 // don't show dead, dict and lambda functions
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3212 if ((fp->uf_flags & FC_DEAD) || (fp->uf_flags & FC_DICT)
9638
af0d98d8836e commit https://github.com/vim/vim/commit/b49edc11a1872fa99befa9a4a8ea6c8537868038
Christian Brabandt <cb@256bit.org>
parents: 9626
diff changeset
3213 || STRNCMP(fp->uf_name, "<lambda>", 8) == 0)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3214 return (char_u *)"";
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3215
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3216 if (STRLEN(fp->uf_name) + 4 >= IOSIZE)
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3217 return fp->uf_name; // prevents overflow
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3218
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3219 cat_func_name(IObuff, fp);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3220 if (xp->xp_context != EXPAND_USER_FUNC)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3221 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3222 STRCAT(IObuff, "(");
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3223 if (!has_varargs(fp) && fp->uf_args.ga_len == 0)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3224 STRCAT(IObuff, ")");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3225 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3226 return IObuff;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3227 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3228 return NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3229 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3230
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3231 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3232 * ":delfunction {name}"
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3233 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3234 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3235 ex_delfunction(exarg_T *eap)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3236 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3237 ufunc_T *fp = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3238 char_u *p;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3239 char_u *name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3240 funcdict_T fudi;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3241
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3242 p = eap->arg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3243 name = trans_function_name(&p, eap->skip, 0, &fudi, NULL);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3244 vim_free(fudi.fd_newkey);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3245 if (name == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3246 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3247 if (fudi.fd_dict != NULL && !eap->skip)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
3248 emsg(_(e_funcref));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3249 return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3250 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3251 if (!ends_excmd(*skipwhite(p)))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3252 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3253 vim_free(name);
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
3254 emsg(_(e_trailing));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3255 return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3256 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3257 eap->nextcmd = check_nextcmd(p);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3258 if (eap->nextcmd != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3259 *p = NUL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3260
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3261 if (!eap->skip)
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3262 fp = find_func(name, NULL);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3263 vim_free(name);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3264
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3265 if (!eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3266 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3267 if (fp == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3268 {
11545
1780e6fecb30 patch 8.0.0655: not easy to make sure a function does not exist
Christian Brabandt <cb@256bit.org>
parents: 11543
diff changeset
3269 if (!eap->forceit)
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
3270 semsg(_(e_nofunc), eap->arg);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3271 return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3272 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3273 if (fp->uf_calls > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3274 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
3275 semsg(_("E131: Cannot delete function %s: It is in use"), eap->arg);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3276 return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3277 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3278
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3279 if (fudi.fd_dict != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3280 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3281 // Delete the dict item that refers to the function, it will
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3282 // invoke func_unref() and possibly delete the function.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3283 dictitem_remove(fudi.fd_dict, fudi.fd_di);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3284 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3285 else
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3286 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3287 // A normal function (not a numbered function or lambda) has a
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3288 // refcount of 1 for the entry in the hashtable. When deleting
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3289 // it and the refcount is more than one, it should be kept.
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3290 // A numbered function and lambda should be kept if the refcount is
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3291 // one or more.
9733
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
3292 if (fp->uf_refcount > (func_name_refcount(fp->uf_name) ? 0 : 1))
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3293 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3294 // Function is still referenced somewhere. Don't free it but
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3295 // do remove it from the hashtable.
9733
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
3296 if (func_remove(fp))
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
3297 fp->uf_refcount--;
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3298 fp->uf_flags |= FC_DELETED;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3299 }
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3300 else
10815
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
3301 func_clear_free(fp, FALSE);
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3302 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3303 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3304 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3305
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3306 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3307 * Unreference a Function: decrement the reference count and free it when it
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3308 * becomes zero.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3309 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3310 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3311 func_unref(char_u *name)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3312 {
9655
f1920505bc16 commit https://github.com/vim/vim/commit/97baee80f0906ee2f651ee1215ec033e84f866ad
Christian Brabandt <cb@256bit.org>
parents: 9638
diff changeset
3313 ufunc_T *fp = NULL;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3314
9733
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
3315 if (name == NULL || !func_name_refcount(name))
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3316 return;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3317 fp = find_func(name, NULL);
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3318 if (fp == NULL && isdigit(*name))
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3319 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3320 #ifdef EXITFREE
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3321 if (!entered_free_all_mem)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3322 #endif
10359
66f1b5bf3fa6 commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
3323 internal_error("func_unref()");
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3324 }
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3325 if (fp != NULL && --fp->uf_refcount <= 0)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3326 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3327 // Only delete it when it's not being used. Otherwise it's done
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3328 // when "uf_calls" becomes zero.
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3329 if (fp->uf_calls == 0)
10815
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
3330 func_clear_free(fp, FALSE);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3331 }
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3332 }
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3333
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3334 /*
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3335 * Unreference a Function: decrement the reference count and free it when it
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3336 * becomes zero.
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3337 */
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3338 void
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3339 func_ptr_unref(ufunc_T *fp)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3340 {
9655
f1920505bc16 commit https://github.com/vim/vim/commit/97baee80f0906ee2f651ee1215ec033e84f866ad
Christian Brabandt <cb@256bit.org>
parents: 9638
diff changeset
3341 if (fp != NULL && --fp->uf_refcount <= 0)
f1920505bc16 commit https://github.com/vim/vim/commit/97baee80f0906ee2f651ee1215ec033e84f866ad
Christian Brabandt <cb@256bit.org>
parents: 9638
diff changeset
3342 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3343 // Only delete it when it's not being used. Otherwise it's done
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3344 // when "uf_calls" becomes zero.
9655
f1920505bc16 commit https://github.com/vim/vim/commit/97baee80f0906ee2f651ee1215ec033e84f866ad
Christian Brabandt <cb@256bit.org>
parents: 9638
diff changeset
3345 if (fp->uf_calls == 0)
10815
f883a1224396 patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents: 10795
diff changeset
3346 func_clear_free(fp, FALSE);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3347 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3348 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3349
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3350 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3351 * Count a reference to a Function.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3352 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3353 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3354 func_ref(char_u *name)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3355 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3356 ufunc_T *fp;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3357
9733
59565cdd7261 commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents: 9731
diff changeset
3358 if (name == NULL || !func_name_refcount(name))
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3359 return;
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3360 fp = find_func(name, NULL);
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3361 if (fp != NULL)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3362 ++fp->uf_refcount;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3363 else if (isdigit(*name))
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3364 // Only give an error for a numbered function.
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3365 // Fail silently, when named or lambda function isn't found.
10359
66f1b5bf3fa6 commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents: 10042
diff changeset
3366 internal_error("func_ref()");
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3367 }
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3368
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3369 /*
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3370 * Count a reference to a Function.
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3371 */
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3372 void
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3373 func_ptr_ref(ufunc_T *fp)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3374 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3375 if (fp != NULL)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3376 ++fp->uf_refcount;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3377 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3378
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3379 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3380 * Return TRUE if items in "fc" do not have "copyID". That means they are not
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3381 * referenced from anywhere that is in use.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3382 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3383 static int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3384 can_free_funccal(funccall_T *fc, int copyID)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3385 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3386 return (fc->l_varlist.lv_copyID != copyID
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3387 && fc->l_vars.dv_copyID != copyID
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3388 && fc->l_avars.dv_copyID != copyID
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
3389 && fc->fc_copyID != copyID);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3390 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3391
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3392 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3393 * ":return [expr]"
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3394 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3395 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3396 ex_return(exarg_T *eap)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3397 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3398 char_u *arg = eap->arg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3399 typval_T rettv;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3400 int returning = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3401
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3402 if (current_funccal == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3403 {
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
3404 emsg(_("E133: :return not inside a function"));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3405 return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3406 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3407
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3408 if (eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3409 ++emsg_skip;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3410
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3411 eap->nextcmd = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3412 if ((*arg != NUL && *arg != '|' && *arg != '\n')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3413 && eval0(arg, &rettv, &eap->nextcmd, !eap->skip) != FAIL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3414 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3415 if (!eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3416 returning = do_return(eap, FALSE, TRUE, &rettv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3417 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3418 clear_tv(&rettv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3419 }
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3420 // It's safer to return also on error.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3421 else if (!eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3422 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3423 // In return statement, cause_abort should be force_abort.
13096
30f9a62f5f51 patch 8.0.1423: error in return not caught by try/catch
Christian Brabandt <cb@256bit.org>
parents: 13004
diff changeset
3424 update_force_abort();
30f9a62f5f51 patch 8.0.1423: error in return not caught by try/catch
Christian Brabandt <cb@256bit.org>
parents: 13004
diff changeset
3425
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3426 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3427 * Return unless the expression evaluation has been cancelled due to an
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3428 * aborting error, an interrupt, or an exception.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3429 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3430 if (!aborting())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3431 returning = do_return(eap, FALSE, TRUE, NULL);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3432 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3433
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3434 // When skipping or the return gets pending, advance to the next command
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3435 // in this line (!returning). Otherwise, ignore the rest of the line.
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3436 // Following lines will be ignored by get_func_line().
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3437 if (returning)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3438 eap->nextcmd = NULL;
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3439 else if (eap->nextcmd == NULL) // no argument
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3440 eap->nextcmd = check_nextcmd(arg);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3441
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3442 if (eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3443 --emsg_skip;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3444 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3445
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3446 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3447 * ":1,25call func(arg1, arg2)" function call.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3448 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3449 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3450 ex_call(exarg_T *eap)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3451 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3452 char_u *arg = eap->arg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3453 char_u *startarg;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3454 char_u *name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3455 char_u *tofree;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3456 int len;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3457 typval_T rettv;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3458 linenr_T lnum;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3459 int doesrange;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3460 int failed = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3461 funcdict_T fudi;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3462 partial_T *partial = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3463
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3464 if (eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3465 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3466 // trans_function_name() doesn't work well when skipping, use eval0()
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3467 // instead to skip to any following command, e.g. for:
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3468 // :if 0 | call dict.foo().bar() | endif
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3469 ++emsg_skip;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3470 if (eval0(eap->arg, &rettv, &eap->nextcmd, FALSE) != FAIL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3471 clear_tv(&rettv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3472 --emsg_skip;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3473 return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3474 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3475
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3476 tofree = trans_function_name(&arg, eap->skip, TFN_INT, &fudi, &partial);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3477 if (fudi.fd_newkey != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3478 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3479 // Still need to give an error message for missing key.
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
3480 semsg(_(e_dictkey), fudi.fd_newkey);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3481 vim_free(fudi.fd_newkey);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3482 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3483 if (tofree == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3484 return;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3485
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3486 // Increase refcount on dictionary, it could get deleted when evaluating
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3487 // the arguments.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3488 if (fudi.fd_dict != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3489 ++fudi.fd_dict->dv_refcount;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3490
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3491 // If it is the name of a variable of type VAR_FUNC or VAR_PARTIAL use its
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3492 // contents. For VAR_PARTIAL get its partial, unless we already have one
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3493 // from trans_function_name().
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3494 len = (int)STRLEN(tofree);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3495 name = deref_func_name(tofree, &len,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3496 partial != NULL ? NULL : &partial, FALSE);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3497
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3498 // Skip white space to allow ":call func ()". Not good, but required for
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3499 // backward compatibility.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3500 startarg = skipwhite(arg);
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3501 rettv.v_type = VAR_UNKNOWN; // clear_tv() uses this
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3502
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3503 if (*startarg != '(')
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3504 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3505 semsg(_(e_missing_paren), eap->arg);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3506 goto end;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3507 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3508
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3509 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3510 * When skipping, evaluate the function once, to find the end of the
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3511 * arguments.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3512 * When the function takes a range, this is discovered after the first
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3513 * call, and the loop is broken.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3514 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3515 if (eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3516 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3517 ++emsg_skip;
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3518 lnum = eap->line2; // do it once, also with an invalid range
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3519 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3520 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3521 lnum = eap->line1;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3522 for ( ; lnum <= eap->line2; ++lnum)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3523 {
17606
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
3524 funcexe_T funcexe;
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
3525
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3526 if (!eap->skip && eap->addr_count > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3527 {
15000
32787e326de2 patch 8.1.0511: ml_get error when calling a function with a range
Bram Moolenaar <Bram@vim.org>
parents: 14968
diff changeset
3528 if (lnum > curbuf->b_ml.ml_line_count)
32787e326de2 patch 8.1.0511: ml_get error when calling a function with a range
Bram Moolenaar <Bram@vim.org>
parents: 14968
diff changeset
3529 {
32787e326de2 patch 8.1.0511: ml_get error when calling a function with a range
Bram Moolenaar <Bram@vim.org>
parents: 14968
diff changeset
3530 // If the function deleted lines or switched to another buffer
32787e326de2 patch 8.1.0511: ml_get error when calling a function with a range
Bram Moolenaar <Bram@vim.org>
parents: 14968
diff changeset
3531 // the line number may become invalid.
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
3532 emsg(_(e_invrange));
15000
32787e326de2 patch 8.1.0511: ml_get error when calling a function with a range
Bram Moolenaar <Bram@vim.org>
parents: 14968
diff changeset
3533 break;
32787e326de2 patch 8.1.0511: ml_get error when calling a function with a range
Bram Moolenaar <Bram@vim.org>
parents: 14968
diff changeset
3534 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3535 curwin->w_cursor.lnum = lnum;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3536 curwin->w_cursor.col = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3537 curwin->w_cursor.coladd = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3538 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3539 arg = startarg;
17606
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
3540
17612
e259d11e2900 patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents: 17606
diff changeset
3541 vim_memset(&funcexe, 0, sizeof(funcexe));
17606
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
3542 funcexe.firstline = eap->line1;
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
3543 funcexe.lastline = eap->line2;
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
3544 funcexe.doesrange = &doesrange;
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
3545 funcexe.evaluate = !eap->skip;
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
3546 funcexe.partial = partial;
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
3547 funcexe.selfdict = fudi.fd_dict;
ff097edaae89 patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents: 17462
diff changeset
3548 if (get_func_tv(name, -1, &rettv, &arg, &funcexe) == FAIL)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3549 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3550 failed = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3551 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3552 }
13262
69278c25429d patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
3553 if (has_watchexpr())
69278c25429d patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents: 13244
diff changeset
3554 dbg_check_breakpoint(eap);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3555
17763
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17732
diff changeset
3556 // Handle a function returning a Funcref, Dictionary or List.
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17732
diff changeset
3557 if (handle_subscript(&arg, &rettv, !eap->skip, TRUE,
117c7795a979 patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents: 17732
diff changeset
3558 name, &name) == FAIL)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3559 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3560 failed = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3561 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3562 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3563
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3564 clear_tv(&rettv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3565 if (doesrange || eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3566 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3567
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3568 // Stop when immediately aborting on error, or when an interrupt
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3569 // occurred or an exception was thrown but not caught.
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3570 // get_func_tv() returned OK, so that the check for trailing
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3571 // characters below is executed.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3572 if (aborting())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3573 break;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3574 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3575 if (eap->skip)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3576 --emsg_skip;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3577
19419
c6c9d91d8290 patch 8.2.0267: no check for a following cmd when calling a function fails
Bram Moolenaar <Bram@vim.org>
parents: 19330
diff changeset
3578 // When inside :try we need to check for following "| catch".
c6c9d91d8290 patch 8.2.0267: no check for a following cmd when calling a function fails
Bram Moolenaar <Bram@vim.org>
parents: 19330
diff changeset
3579 if (!failed || eap->cstack->cs_trylevel > 0)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3580 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3581 // Check for trailing illegal characters and a following command.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3582 if (!ends_excmd(*arg))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3583 {
19421
208644ebdff8 patch 8.2.0268: trycatch test fails
Bram Moolenaar <Bram@vim.org>
parents: 19419
diff changeset
3584 if (!failed)
208644ebdff8 patch 8.2.0268: trycatch test fails
Bram Moolenaar <Bram@vim.org>
parents: 19419
diff changeset
3585 {
208644ebdff8 patch 8.2.0268: trycatch test fails
Bram Moolenaar <Bram@vim.org>
parents: 19419
diff changeset
3586 emsg_severe = TRUE;
208644ebdff8 patch 8.2.0268: trycatch test fails
Bram Moolenaar <Bram@vim.org>
parents: 19419
diff changeset
3587 emsg(_(e_trailing));
208644ebdff8 patch 8.2.0268: trycatch test fails
Bram Moolenaar <Bram@vim.org>
parents: 19419
diff changeset
3588 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3589 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3590 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3591 eap->nextcmd = check_nextcmd(arg);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3592 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3593
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3594 end:
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3595 dict_unref(fudi.fd_dict);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3596 vim_free(tofree);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3597 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3598
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3599 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3600 * Return from a function. Possibly makes the return pending. Also called
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3601 * for a pending return at the ":endtry" or after returning from an extra
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3602 * do_cmdline(). "reanimate" is used in the latter case. "is_cmd" is set
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3603 * when called due to a ":return" command. "rettv" may point to a typval_T
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3604 * with the return rettv. Returns TRUE when the return can be carried out,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3605 * FALSE when the return gets pending.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3606 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3607 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3608 do_return(
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3609 exarg_T *eap,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3610 int reanimate,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3611 int is_cmd,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3612 void *rettv)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3613 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3614 int idx;
18904
2bdc2e1f6e1f patch 8.2.0013: not using a typedef for condstack
Bram Moolenaar <Bram@vim.org>
parents: 18816
diff changeset
3615 cstack_T *cstack = eap->cstack;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3616
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3617 if (reanimate)
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3618 // Undo the return.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3619 current_funccal->returned = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3620
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3621 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3622 * Cleanup (and inactivate) conditionals, but stop when a try conditional
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3623 * not in its finally clause (which then is to be executed next) is found.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3624 * In this case, make the ":return" pending for execution at the ":endtry".
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3625 * Otherwise, return normally.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3626 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3627 idx = cleanup_conditionals(eap->cstack, 0, TRUE);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3628 if (idx >= 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3629 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3630 cstack->cs_pending[idx] = CSTP_RETURN;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3631
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3632 if (!is_cmd && !reanimate)
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3633 // A pending return again gets pending. "rettv" points to an
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3634 // allocated variable with the rettv of the original ":return"'s
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3635 // argument if present or is NULL else.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3636 cstack->cs_rettv[idx] = rettv;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3637 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3638 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3639 // When undoing a return in order to make it pending, get the stored
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3640 // return rettv.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3641 if (reanimate)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3642 rettv = current_funccal->rettv;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3643
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3644 if (rettv != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3645 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3646 // Store the value of the pending return.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3647 if ((cstack->cs_rettv[idx] = alloc_tv()) != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3648 *(typval_T *)cstack->cs_rettv[idx] = *(typval_T *)rettv;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3649 else
15470
55ccc2d353bd patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents: 15138
diff changeset
3650 emsg(_(e_outofmem));
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3651 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3652 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3653 cstack->cs_rettv[idx] = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3654
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3655 if (reanimate)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3656 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3657 // The pending return value could be overwritten by a ":return"
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3658 // without argument in a finally clause; reset the default
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3659 // return value.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3660 current_funccal->rettv->v_type = VAR_NUMBER;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3661 current_funccal->rettv->vval.v_number = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3662 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3663 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3664 report_make_pending(CSTP_RETURN, rettv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3665 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3666 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3667 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3668 current_funccal->returned = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3669
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3670 // If the return is carried out now, store the return value. For
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3671 // a return immediately after reanimation, the value is already
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3672 // there.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3673 if (!reanimate && rettv != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3674 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3675 clear_tv(current_funccal->rettv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3676 *current_funccal->rettv = *(typval_T *)rettv;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3677 if (!is_cmd)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3678 vim_free(rettv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3679 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3680 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3681
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3682 return idx < 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3683 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3684
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3685 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3686 * Free the variable with a pending return value.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3687 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3688 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3689 discard_pending_return(void *rettv)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3690 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3691 free_tv((typval_T *)rettv);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3692 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3693
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3694 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3695 * Generate a return command for producing the value of "rettv". The result
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3696 * is an allocated string. Used by report_pending() for verbose messages.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3697 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3698 char_u *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3699 get_return_cmd(void *rettv)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3700 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3701 char_u *s = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3702 char_u *tofree = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3703 char_u numbuf[NUMBUFLEN];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3704
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3705 if (rettv != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3706 s = echo_string((typval_T *)rettv, &tofree, numbuf, 0);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3707 if (s == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3708 s = (char_u *)"";
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3709
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3710 STRCPY(IObuff, ":return ");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3711 STRNCPY(IObuff + 8, s, IOSIZE - 8);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3712 if (STRLEN(s) + 8 >= IOSIZE)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3713 STRCPY(IObuff + IOSIZE - 4, "...");
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3714 vim_free(tofree);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3715 return vim_strsave(IObuff);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3716 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3717
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3718 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3719 * Get next function line.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3720 * Called by do_cmdline() to get the next line.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3721 * Returns allocated string, or NULL for end of function.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3722 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3723 char_u *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3724 get_func_line(
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3725 int c UNUSED,
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3726 void *cookie,
17178
40c4cb095d53 patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents: 17168
diff changeset
3727 int indent UNUSED,
40c4cb095d53 patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents: 17168
diff changeset
3728 int do_concat UNUSED)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3729 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3730 funccall_T *fcp = (funccall_T *)cookie;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3731 ufunc_T *fp = fcp->func;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3732 char_u *retval;
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3733 garray_T *gap; // growarray with function lines
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3734
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3735 // If breakpoints have been added/deleted need to check for it.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3736 if (fcp->dbg_tick != debug_tick)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3737 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3738 fcp->breakpoint = dbg_find_breakpoint(FALSE, fp->uf_name,
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
3739 SOURCING_LNUM);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3740 fcp->dbg_tick = debug_tick;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3741 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3742 #ifdef FEAT_PROFILE
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3743 if (do_profiling == PROF_YES)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3744 func_line_end(cookie);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3745 #endif
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3746
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3747 gap = &fp->uf_lines;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3748 if (((fp->uf_flags & FC_ABORT) && did_emsg && !aborted_in_try())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3749 || fcp->returned)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3750 retval = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3751 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3752 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3753 // Skip NULL lines (continuation lines).
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3754 while (fcp->linenr < gap->ga_len
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3755 && ((char_u **)(gap->ga_data))[fcp->linenr] == NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3756 ++fcp->linenr;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3757 if (fcp->linenr >= gap->ga_len)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3758 retval = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3759 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3760 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3761 retval = vim_strsave(((char_u **)(gap->ga_data))[fcp->linenr++]);
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
3762 SOURCING_LNUM = fcp->linenr;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3763 #ifdef FEAT_PROFILE
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3764 if (do_profiling == PROF_YES)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3765 func_line_start(cookie);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3766 #endif
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3767 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3768 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3769
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3770 // Did we encounter a breakpoint?
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
3771 if (fcp->breakpoint != 0 && fcp->breakpoint <= SOURCING_LNUM)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3772 {
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
3773 dbg_breakpoint(fp->uf_name, SOURCING_LNUM);
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3774 // Find next breakpoint.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3775 fcp->breakpoint = dbg_find_breakpoint(FALSE, fp->uf_name,
18991
847cc7932c42 patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents: 18962
diff changeset
3776 SOURCING_LNUM);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3777 fcp->dbg_tick = debug_tick;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3778 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3779
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3780 return retval;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3781 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3782
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3783 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3784 * Return TRUE if the currently active function should be ended, because a
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3785 * return was encountered or an error occurred. Used inside a ":while".
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3786 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3787 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3788 func_has_ended(void *cookie)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3789 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3790 funccall_T *fcp = (funccall_T *)cookie;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3791
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3792 // Ignore the "abort" flag if the abortion behavior has been changed due to
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3793 // an error inside a try conditional.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3794 return (((fcp->func->uf_flags & FC_ABORT) && did_emsg && !aborted_in_try())
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3795 || fcp->returned);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3796 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3797
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3798 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3799 * return TRUE if cookie indicates a function which "abort"s on errors.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3800 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3801 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3802 func_has_abort(
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3803 void *cookie)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3804 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3805 return ((funccall_T *)cookie)->func->uf_flags & FC_ABORT;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3806 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3807
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3808
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3809 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3810 * Turn "dict.Func" into a partial for "Func" bound to "dict".
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3811 * Don't do this when "Func" is already a partial that was bound
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3812 * explicitly (pt_auto is FALSE).
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3813 * Changes "rettv" in-place.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3814 * Returns the updated "selfdict_in".
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3815 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3816 dict_T *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3817 make_partial(dict_T *selfdict_in, typval_T *rettv)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3818 {
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3819 char_u *fname;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3820 char_u *tofree = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3821 ufunc_T *fp;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3822 char_u fname_buf[FLEN_FIXED + 1];
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3823 int error;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3824 dict_T *selfdict = selfdict_in;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3825
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3826 if (rettv->v_type == VAR_PARTIAL && rettv->vval.v_partial->pt_func != NULL)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3827 fp = rettv->vval.v_partial->pt_func;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3828 else
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3829 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3830 fname = rettv->v_type == VAR_FUNC ? rettv->vval.v_string
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3831 : rettv->vval.v_partial->pt_name;
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3832 // Translate "s:func" to the stored function name.
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3833 fname = fname_trans_sid(fname, fname_buf, &tofree, &error);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
3834 fp = find_func(fname, NULL);
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3835 vim_free(tofree);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3836 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3837
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3838 if (fp != NULL && (fp->uf_flags & FC_DICT))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3839 {
16825
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
3840 partial_T *pt = ALLOC_CLEAR_ONE(partial_T);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3841
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3842 if (pt != NULL)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3843 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3844 pt->pt_refcount = 1;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3845 pt->pt_dict = selfdict;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3846 pt->pt_auto = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3847 selfdict = NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3848 if (rettv->v_type == VAR_FUNC)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3849 {
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3850 // Just a function: Take over the function name and use
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3851 // selfdict.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3852 pt->pt_name = rettv->vval.v_string;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3853 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3854 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3855 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3856 partial_T *ret_pt = rettv->vval.v_partial;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3857 int i;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3858
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3859 // Partial: copy the function name, use selfdict and copy
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3860 // args. Can't take over name or args, the partial might
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3861 // be referenced elsewhere.
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3862 if (ret_pt->pt_name != NULL)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3863 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3864 pt->pt_name = vim_strsave(ret_pt->pt_name);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3865 func_ref(pt->pt_name);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3866 }
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3867 else
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3868 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3869 pt->pt_func = ret_pt->pt_func;
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3870 func_ptr_ref(pt->pt_func);
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
3871 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3872 if (ret_pt->pt_argc > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3873 {
16825
ce04ebdf26b8 patch 8.1.1414: alloc() returning "char_u *" causes a lot of type casts
Bram Moolenaar <Bram@vim.org>
parents: 16768
diff changeset
3874 pt->pt_argv = ALLOC_MULT(typval_T, ret_pt->pt_argc);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3875 if (pt->pt_argv == NULL)
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3876 // out of memory: drop the arguments
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3877 pt->pt_argc = 0;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3878 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3879 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3880 pt->pt_argc = ret_pt->pt_argc;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3881 for (i = 0; i < pt->pt_argc; i++)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3882 copy_tv(&ret_pt->pt_argv[i], &pt->pt_argv[i]);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3883 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3884 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3885 partial_unref(ret_pt);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3886 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3887 rettv->v_type = VAR_PARTIAL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3888 rettv->vval.v_partial = pt;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3889 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3890 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3891 return selfdict;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3892 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3893
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3894 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3895 * Return the name of the executed function.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3896 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3897 char_u *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3898 func_name(void *cookie)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3899 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3900 return ((funccall_T *)cookie)->func->uf_name;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3901 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3902
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3903 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3904 * Return the address holding the next breakpoint line for a funccall cookie.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3905 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3906 linenr_T *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3907 func_breakpoint(void *cookie)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3908 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3909 return &((funccall_T *)cookie)->breakpoint;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3910 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3911
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3912 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3913 * Return the address holding the debug tick for a funccall cookie.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3914 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3915 int *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3916 func_dbg_tick(void *cookie)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3917 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3918 return &((funccall_T *)cookie)->dbg_tick;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3919 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3920
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3921 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3922 * Return the nesting level for a funccall cookie.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3923 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3924 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3925 func_level(void *cookie)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3926 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3927 return ((funccall_T *)cookie)->level;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3928 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3929
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3930 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3931 * Return TRUE when a function was ended by a ":return" command.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3932 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3933 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3934 current_func_returned(void)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3935 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3936 return current_funccal->returned;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3937 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3938
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3939 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3940 free_unref_funccal(int copyID, int testing)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3941 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3942 int did_free = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3943 int did_free_funccal = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3944 funccall_T *fc, **pfc;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3945
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3946 for (pfc = &previous_funccal; *pfc != NULL; )
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3947 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3948 if (can_free_funccal(*pfc, copyID))
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3949 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3950 fc = *pfc;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3951 *pfc = fc->caller;
16003
879829e44091 patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents: 15820
diff changeset
3952 free_funccal_contents(fc);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3953 did_free = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3954 did_free_funccal = TRUE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3955 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3956 else
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3957 pfc = &(*pfc)->caller;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3958 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3959 if (did_free_funccal)
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3960 // When a funccal was freed some more items might be garbage
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3961 // collected, so run again.
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3962 (void)garbage_collect(testing);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3963
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3964 return did_free;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3965 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3966
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3967 /*
9951
d990a4394c9d commit https://github.com/vim/vim/commit/ba2099034f92a2814494f37bddb0c57d034401b4
Christian Brabandt <cb@256bit.org>
parents: 9844
diff changeset
3968 * Get function call environment based on backtrace debug level
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3969 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3970 static funccall_T *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3971 get_funccal(void)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3972 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3973 int i;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3974 funccall_T *funccal;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3975 funccall_T *temp_funccal;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3976
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3977 funccal = current_funccal;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3978 if (debug_backtrace_level > 0)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3979 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3980 for (i = 0; i < debug_backtrace_level; i++)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3981 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3982 temp_funccal = funccal->caller;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3983 if (temp_funccal)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3984 funccal = temp_funccal;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3985 else
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
3986 // backtrace level overflow. reset to max
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3987 debug_backtrace_level = i;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3988 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3989 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3990 return funccal;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3991 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3992
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3993 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3994 * Return the hashtable used for local variables in the current funccal.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3995 * Return NULL if there is no current funccal.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3996 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3997 hashtab_T *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3998 get_funccal_local_ht()
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3999 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
4000 if (current_funccal == NULL || current_funccal->l_vars.dv_refcount == 0)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4001 return NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4002 return &get_funccal()->l_vars.dv_hashtab;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4003 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4004
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4005 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4006 * Return the l: scope variable.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4007 * Return NULL if there is no current funccal.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4008 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4009 dictitem_T *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4010 get_funccal_local_var()
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4011 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
4012 if (current_funccal == NULL || current_funccal->l_vars.dv_refcount == 0)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4013 return NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4014 return &get_funccal()->l_vars_var;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4015 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4016
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4017 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4018 * Return the hashtable used for argument in the current funccal.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4019 * Return NULL if there is no current funccal.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4020 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4021 hashtab_T *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4022 get_funccal_args_ht()
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4023 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
4024 if (current_funccal == NULL || current_funccal->l_vars.dv_refcount == 0)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4025 return NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4026 return &get_funccal()->l_avars.dv_hashtab;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4027 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4028
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4029 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4030 * Return the a: scope variable.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4031 * Return NULL if there is no current funccal.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4032 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4033 dictitem_T *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4034 get_funccal_args_var()
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4035 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
4036 if (current_funccal == NULL || current_funccal->l_vars.dv_refcount == 0)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4037 return NULL;
10795
8afee415119d patch 8.0.0287: debug mode: cannot access function arguments
Christian Brabandt <cb@256bit.org>
parents: 10722
diff changeset
4038 return &get_funccal()->l_avars_var;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4039 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4040
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4041 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4042 * List function variables, if there is a function.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4043 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4044 void
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4045 list_func_vars(int *first)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4046 {
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
4047 if (current_funccal != NULL && current_funccal->l_vars.dv_refcount > 0)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4048 list_hashtable_vars(&current_funccal->l_vars.dv_hashtab,
15543
dd725a8ab112 patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents: 15470
diff changeset
4049 "l:", FALSE, first);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4050 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4051
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4052 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4053 * If "ht" is the hashtable for local variables in the current funccal, return
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4054 * the dict that contains it.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4055 * Otherwise return NULL.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4056 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4057 dict_T *
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4058 get_current_funccal_dict(hashtab_T *ht)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4059 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4060 if (current_funccal != NULL
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4061 && ht == &current_funccal->l_vars.dv_hashtab)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4062 return &current_funccal->l_vars;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4063 return NULL;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4064 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4065
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4066 /*
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
4067 * Search hashitem in parent scope.
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
4068 */
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
4069 hashitem_T *
9731
f85d94eee05b commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
4070 find_hi_in_scoped_ht(char_u *name, hashtab_T **pht)
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
4071 {
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
4072 funccall_T *old_current_funccal = current_funccal;
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
4073 hashtab_T *ht;
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
4074 hashitem_T *hi = NULL;
9731
f85d94eee05b commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
4075 char_u *varname;
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
4076
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
4077 if (current_funccal == NULL || current_funccal->func->uf_scoped == NULL)
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
4078 return NULL;
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
4079
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
4080 // Search in parent scope which is possible to reference from lambda
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
4081 current_funccal = current_funccal->func->uf_scoped;
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
4082 while (current_funccal != NULL)
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
4083 {
9731
f85d94eee05b commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
4084 ht = find_var_ht(name, &varname);
f85d94eee05b commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
4085 if (ht != NULL && *varname != NUL)
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
4086 {
9731
f85d94eee05b commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
4087 hi = hash_find(ht, varname);
9721
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
4088 if (!HASHITEM_EMPTY(hi))
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
4089 {
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
4090 *pht = ht;
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
4091 break;
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
4092 }
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
4093 }
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
4094 if (current_funccal == current_funccal->func->uf_scoped)
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
4095 break;
79862f44c647 commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents: 9717
diff changeset
4096 current_funccal = current_funccal->func->uf_scoped;
9688
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
4097 }
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
4098 current_funccal = old_current_funccal;
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
4099
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
4100 return hi;
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
4101 }
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
4102
2ea935bdd1a1 commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents: 9686
diff changeset
4103 /*
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4104 * Search variable in parent scope.
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4105 */
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4106 dictitem_T *
9731
f85d94eee05b commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
4107 find_var_in_scoped_ht(char_u *name, int no_autoload)
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4108 {
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4109 dictitem_T *v = NULL;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4110 funccall_T *old_current_funccal = current_funccal;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4111 hashtab_T *ht;
9731
f85d94eee05b commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
4112 char_u *varname;
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4113
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4114 if (current_funccal == NULL || current_funccal->func->uf_scoped == NULL)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4115 return NULL;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4116
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
4117 // Search in parent scope which is possible to reference from lambda
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4118 current_funccal = current_funccal->func->uf_scoped;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4119 while (current_funccal)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4120 {
9731
f85d94eee05b commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
4121 ht = find_var_ht(name, &varname);
f85d94eee05b commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
4122 if (ht != NULL && *varname != NUL)
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4123 {
9731
f85d94eee05b commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents: 9727
diff changeset
4124 v = find_var_in_ht(ht, *name, varname, no_autoload);
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4125 if (v != NULL)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4126 break;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4127 }
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4128 if (current_funccal == current_funccal->func->uf_scoped)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4129 break;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4130 current_funccal = current_funccal->func->uf_scoped;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4131 }
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4132 current_funccal = old_current_funccal;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4133
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4134 return v;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4135 }
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4136
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4137 /*
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4138 * Set "copyID + 1" in previous_funccal and callers.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4139 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4140 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4141 set_ref_in_previous_funccal(int copyID)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4142 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4143 int abort = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4144 funccall_T *fc;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4145
17127
d244a9be99db patch 8.1.1563: crash when using closures
Bram Moolenaar <Bram@vim.org>
parents: 16969
diff changeset
4146 for (fc = previous_funccal; !abort && fc != NULL; fc = fc->caller)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4147 {
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4148 fc->fc_copyID = copyID + 1;
17127
d244a9be99db patch 8.1.1563: crash when using closures
Bram Moolenaar <Bram@vim.org>
parents: 16969
diff changeset
4149 abort = abort
d244a9be99db patch 8.1.1563: crash when using closures
Bram Moolenaar <Bram@vim.org>
parents: 16969
diff changeset
4150 || set_ref_in_ht(&fc->l_vars.dv_hashtab, copyID + 1, NULL)
d244a9be99db patch 8.1.1563: crash when using closures
Bram Moolenaar <Bram@vim.org>
parents: 16969
diff changeset
4151 || set_ref_in_ht(&fc->l_avars.dv_hashtab, copyID + 1, NULL)
17168
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4152 || set_ref_in_list_items(&fc->l_varlist, copyID + 1, NULL);
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4153 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4154 return abort;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4155 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4156
9735
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4157 static int
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4158 set_ref_in_funccal(funccall_T *fc, int copyID)
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4159 {
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4160 int abort = FALSE;
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4161
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4162 if (fc->fc_copyID != copyID)
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4163 {
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4164 fc->fc_copyID = copyID;
17127
d244a9be99db patch 8.1.1563: crash when using closures
Bram Moolenaar <Bram@vim.org>
parents: 16969
diff changeset
4165 abort = abort
d244a9be99db patch 8.1.1563: crash when using closures
Bram Moolenaar <Bram@vim.org>
parents: 16969
diff changeset
4166 || set_ref_in_ht(&fc->l_vars.dv_hashtab, copyID, NULL)
d244a9be99db patch 8.1.1563: crash when using closures
Bram Moolenaar <Bram@vim.org>
parents: 16969
diff changeset
4167 || set_ref_in_ht(&fc->l_avars.dv_hashtab, copyID, NULL)
17168
1d30eb64a7a2 patch 8.1.1583: set_ref_in_list() only sets ref in items
Bram Moolenaar <Bram@vim.org>
parents: 17151
diff changeset
4168 || set_ref_in_list_items(&fc->l_varlist, copyID, NULL)
17127
d244a9be99db patch 8.1.1563: crash when using closures
Bram Moolenaar <Bram@vim.org>
parents: 16969
diff changeset
4169 || set_ref_in_func(NULL, fc->func, copyID);
9735
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4170 }
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4171 return abort;
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4172 }
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4173
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4174 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4175 * Set "copyID" in all local vars and arguments in the call stack.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4176 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4177 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4178 set_ref_in_call_stack(int copyID)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4179 {
16969
8c794a694d66 patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents: 16872
diff changeset
4180 int abort = FALSE;
8c794a694d66 patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents: 16872
diff changeset
4181 funccall_T *fc;
8c794a694d66 patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents: 16872
diff changeset
4182 funccal_entry_T *entry;
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4183
17151
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 17127
diff changeset
4184 for (fc = current_funccal; !abort && fc != NULL; fc = fc->caller)
9735
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4185 abort = abort || set_ref_in_funccal(fc, copyID);
16969
8c794a694d66 patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents: 16872
diff changeset
4186
8c794a694d66 patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents: 16872
diff changeset
4187 // Also go through the funccal_stack.
17151
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 17127
diff changeset
4188 for (entry = funccal_stack; !abort && entry != NULL; entry = entry->next)
ebe9aab81898 patch 8.1.1575: callbacks may be garbage collected
Bram Moolenaar <Bram@vim.org>
parents: 17127
diff changeset
4189 for (fc = entry->top_funccal; !abort && fc != NULL; fc = fc->caller)
16969
8c794a694d66 patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents: 16872
diff changeset
4190 abort = abort || set_ref_in_funccal(fc, copyID);
8c794a694d66 patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents: 16872
diff changeset
4191
9735
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4192 return abort;
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4193 }
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4194
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4195 /*
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4196 * Set "copyID" in all functions available by name.
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4197 */
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4198 int
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4199 set_ref_in_functions(int copyID)
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4200 {
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4201 int todo;
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4202 hashitem_T *hi = NULL;
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4203 int abort = FALSE;
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4204 ufunc_T *fp;
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4205
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4206 todo = (int)func_hashtab.ht_used;
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4207 for (hi = func_hashtab.ht_array; todo > 0 && !got_int; ++hi)
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4208 {
9735
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4209 if (!HASHITEM_EMPTY(hi))
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4210 {
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4211 --todo;
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4212 fp = HI2UF(hi);
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4213 if (!func_name_refcount(fp->uf_name))
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4214 abort = abort || set_ref_in_func(NULL, fp, copyID);
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4215 }
9562
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4216 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4217 return abort;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4218 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4219
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4220 /*
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4221 * Set "copyID" in all function arguments.
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4222 */
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4223 int
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4224 set_ref_in_func_args(int copyID)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4225 {
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4226 int i;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4227 int abort = FALSE;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4228
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4229 for (i = 0; i < funcargs.ga_len; ++i)
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4230 abort = abort || set_ref_in_item(((typval_T **)funcargs.ga_data)[i],
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4231 copyID, NULL, NULL);
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4232 return abort;
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4233 }
86af4a48c00a commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4234
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4235 /*
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4236 * Mark all lists and dicts referenced through function "name" with "copyID".
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4237 * Returns TRUE if setting references failed somehow.
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4238 */
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4239 int
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
4240 set_ref_in_func(char_u *name, ufunc_T *fp_in, int copyID)
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4241 {
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
4242 ufunc_T *fp = fp_in;
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4243 funccall_T *fc;
19013
dd9ab0674eec patch 8.2.0067: ERROR_UNKNOWN clashes on some systems
Bram Moolenaar <Bram@vim.org>
parents: 18991
diff changeset
4244 int error = FCERR_NONE;
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4245 char_u fname_buf[FLEN_FIXED + 1];
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4246 char_u *tofree = NULL;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4247 char_u *fname;
9735
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4248 int abort = FALSE;
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4249
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
4250 if (name == NULL && fp_in == NULL)
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4251 return FALSE;
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4252
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
4253 if (fp_in == NULL)
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
4254 {
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
4255 fname = fname_trans_sid(name, fname_buf, &tofree, &error);
19181
94eda51ba9ba patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents: 19075
diff changeset
4256 fp = find_func(fname, NULL);
9723
80ac9cf77c9b commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents: 9721
diff changeset
4257 }
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4258 if (fp != NULL)
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4259 {
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4260 for (fc = fp->uf_scoped; fc != NULL; fc = fc->func->uf_scoped)
9735
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4261 abort = abort || set_ref_in_funccal(fc, copyID);
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4262 }
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4263 vim_free(tofree);
9735
8037eb704e93 commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents: 9733
diff changeset
4264 return abort;
9686
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4265 }
8c2553beff0f commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents: 9655
diff changeset
4266
18816
15539899a112 patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents: 18576
diff changeset
4267 #endif // FEAT_EVAL