Mercurial > vim
annotate src/userfunc.c @ 28571:9b622722bad0
Added tag v8.2.4809 for changeset 35e24d9de8588b4f449738ac4c726ae60e5a2556
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 23 Apr 2022 12:00:07 +0200 |
parents | c6aadb2c4cd7 |
children | 30862b2f7431 |
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) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
17 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
18 * 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
|
19 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
20 static hashtab_T func_hashtab; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
21 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
22 // Used by get_func_tv() |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
23 static garray_T funcargs = GA_EMPTY; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
24 |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
25 // 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
|
26 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
|
27 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
28 // 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
|
29 // 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
|
30 static funccall_T *previous_funccal = NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
31 |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
32 static void funccal_unref(funccall_T *fc, ufunc_T *fp, int force); |
24244
827fcf174f15
patch 8.2.2663: Vim9: leaking memory when inline function has an error
Bram Moolenaar <Bram@vim.org>
parents:
24208
diff
changeset
|
33 static void func_clear(ufunc_T *fp, int force); |
827fcf174f15
patch 8.2.2663: Vim9: leaking memory when inline function has an error
Bram Moolenaar <Bram@vim.org>
parents:
24208
diff
changeset
|
34 static int func_free(ufunc_T *fp, int force); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
35 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
36 void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
37 func_init() |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
38 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
39 hash_init(&func_hashtab); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
40 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
41 |
27018
268f6a3511df
patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents:
27002
diff
changeset
|
42 #if defined(FEAT_PROFILE) || defined(PROTO) |
9597
3ca0fd9709b1
commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents:
9593
diff
changeset
|
43 /* |
17381
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
44 * Return the function hash table |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
45 */ |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
46 hashtab_T * |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
47 func_tbl_get(void) |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
48 { |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
49 return &func_hashtab; |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
50 } |
27018
268f6a3511df
patch 8.2.4038: various code not used when features are disabled
Bram Moolenaar <Bram@vim.org>
parents:
27002
diff
changeset
|
51 #endif |
17381
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
52 |
8f44c630c366
patch 8.1.1689: profiling code is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17370
diff
changeset
|
53 /* |
20029
8fb1cf4c44d5
patch 8.2.0570: Vim9: no error when omitting type from argument
Bram Moolenaar <Bram@vim.org>
parents:
20023
diff
changeset
|
54 * Get one function argument. |
24410
25db91a3281b
patch 8.2.2745: Vim9: missing part of the argument change
Bram Moolenaar <Bram@vim.org>
parents:
24400
diff
changeset
|
55 * If "argtypes" is not NULL also get the type: "arg: type" (:def function). |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
56 * If "types_optional" is TRUE a missing type is OK, use "any". |
24033
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
24004
diff
changeset
|
57 * If "evalarg" is not NULL use it to check for an already declared name. |
27611
e311a80f8cbe
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Bram Moolenaar <Bram@vim.org>
parents:
27595
diff
changeset
|
58 * If "eap" is not NULL use it to check for an already declared name. |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
59 * 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
|
60 * 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
|
61 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
62 static char_u * |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
63 one_function_arg( |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
64 char_u *arg, |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
65 garray_T *newargs, |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
66 garray_T *argtypes, |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
67 int types_optional, |
24033
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
24004
diff
changeset
|
68 evalarg_T *evalarg, |
27611
e311a80f8cbe
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Bram Moolenaar <Bram@vim.org>
parents:
27595
diff
changeset
|
69 exarg_T *eap, |
24400
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
70 int is_vararg, |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
71 int skip) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
72 { |
20029
8fb1cf4c44d5
patch 8.2.0570: Vim9: no error when omitting type from argument
Bram Moolenaar <Bram@vim.org>
parents:
20023
diff
changeset
|
73 char_u *p = arg; |
8fb1cf4c44d5
patch 8.2.0570: Vim9: no error when omitting type from argument
Bram Moolenaar <Bram@vim.org>
parents:
20023
diff
changeset
|
74 char_u *arg_copy = NULL; |
24410
25db91a3281b
patch 8.2.2745: Vim9: missing part of the argument change
Bram Moolenaar <Bram@vim.org>
parents:
24400
diff
changeset
|
75 int is_underscore = FALSE; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
76 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
77 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
|
78 ++p; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
79 if (arg == p || isdigit(*arg) |
22339
56f674e7518c
patch 8.2.1718: Vim9: :def function disallows "firstline" for no good reason
Bram Moolenaar <Bram@vim.org>
parents:
22326
diff
changeset
|
80 || (argtypes == NULL |
56f674e7518c
patch 8.2.1718: Vim9: :def function disallows "firstline" for no good reason
Bram Moolenaar <Bram@vim.org>
parents:
22326
diff
changeset
|
81 && ((p - arg == 9 && STRNCMP(arg, "firstline", 9) == 0) |
56f674e7518c
patch 8.2.1718: Vim9: :def function disallows "firstline" for no good reason
Bram Moolenaar <Bram@vim.org>
parents:
22326
diff
changeset
|
82 || (p - arg == 8 && STRNCMP(arg, "lastline", 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
|
83 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
84 if (!skip) |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
85 semsg(_(e_illegal_argument_str), arg); |
19181
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 } |
23996
c192411b27e8
patch 8.2.2540: Vim9: no error for using script var name for argument
Bram Moolenaar <Bram@vim.org>
parents:
23988
diff
changeset
|
88 |
24033
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
24004
diff
changeset
|
89 // Vim9 script: cannot use script var name for argument. In function: also |
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
24004
diff
changeset
|
90 // check local vars and arguments. |
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
24004
diff
changeset
|
91 if (!skip && argtypes != NULL && check_defined(arg, p - arg, |
27611
e311a80f8cbe
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Bram Moolenaar <Bram@vim.org>
parents:
27595
diff
changeset
|
92 evalarg == NULL ? NULL : evalarg->eval_cctx, |
e311a80f8cbe
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Bram Moolenaar <Bram@vim.org>
parents:
27595
diff
changeset
|
93 eap == NULL ? NULL : eap->cstack, TRUE) == FAIL) |
23996
c192411b27e8
patch 8.2.2540: Vim9: no error for using script var name for argument
Bram Moolenaar <Bram@vim.org>
parents:
23988
diff
changeset
|
94 return arg; |
c192411b27e8
patch 8.2.2540: Vim9: no error for using script var name for argument
Bram Moolenaar <Bram@vim.org>
parents:
23988
diff
changeset
|
95 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
96 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
|
97 return arg; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
98 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
|
99 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
100 int c; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
101 int i; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
102 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
103 c = *p; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
104 *p = NUL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
105 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
|
106 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
|
107 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
108 *p = c; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
109 return arg; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
110 } |
24410
25db91a3281b
patch 8.2.2745: Vim9: missing part of the argument change
Bram Moolenaar <Bram@vim.org>
parents:
24400
diff
changeset
|
111 is_underscore = arg_copy[0] == '_' && arg_copy[1] == NUL; |
24412
0e0943dfdbf9
patch 8.2.2746: check for duplicate arguments does not work
Bram Moolenaar <Bram@vim.org>
parents:
24410
diff
changeset
|
112 if (argtypes == NULL || !is_underscore) |
24410
25db91a3281b
patch 8.2.2745: Vim9: missing part of the argument change
Bram Moolenaar <Bram@vim.org>
parents:
24400
diff
changeset
|
113 // Check for duplicate argument name. |
25db91a3281b
patch 8.2.2745: Vim9: missing part of the argument change
Bram Moolenaar <Bram@vim.org>
parents:
24400
diff
changeset
|
114 for (i = 0; i < newargs->ga_len; ++i) |
25db91a3281b
patch 8.2.2745: Vim9: missing part of the argument change
Bram Moolenaar <Bram@vim.org>
parents:
24400
diff
changeset
|
115 if (STRCMP(((char_u **)(newargs->ga_data))[i], arg_copy) == 0) |
25db91a3281b
patch 8.2.2745: Vim9: missing part of the argument change
Bram Moolenaar <Bram@vim.org>
parents:
24400
diff
changeset
|
116 { |
26962
85866e069c24
patch 8.2.4010: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26958
diff
changeset
|
117 semsg(_(e_duplicate_argument_name_str), arg_copy); |
24410
25db91a3281b
patch 8.2.2745: Vim9: missing part of the argument change
Bram Moolenaar <Bram@vim.org>
parents:
24400
diff
changeset
|
118 vim_free(arg_copy); |
25db91a3281b
patch 8.2.2745: Vim9: missing part of the argument change
Bram Moolenaar <Bram@vim.org>
parents:
24400
diff
changeset
|
119 return arg; |
25db91a3281b
patch 8.2.2745: Vim9: missing part of the argument change
Bram Moolenaar <Bram@vim.org>
parents:
24400
diff
changeset
|
120 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
121 ((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
|
122 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
|
123 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
124 *p = c; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
125 } |
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 // get any type from "arg: type" |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
128 if (argtypes != NULL && (skip || ga_grow(argtypes, 1) == OK)) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
129 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
130 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
|
131 |
20029
8fb1cf4c44d5
patch 8.2.0570: Vim9: no error when omitting type from argument
Bram Moolenaar <Bram@vim.org>
parents:
20023
diff
changeset
|
132 if (VIM_ISWHITE(*p) && *skipwhite(p) == ':') |
8fb1cf4c44d5
patch 8.2.0570: Vim9: no error when omitting type from argument
Bram Moolenaar <Bram@vim.org>
parents:
20023
diff
changeset
|
133 { |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21791
diff
changeset
|
134 semsg(_(e_no_white_space_allowed_before_colon_str), |
20029
8fb1cf4c44d5
patch 8.2.0570: Vim9: no error when omitting type from argument
Bram Moolenaar <Bram@vim.org>
parents:
20023
diff
changeset
|
135 arg_copy == NULL ? arg : arg_copy); |
8fb1cf4c44d5
patch 8.2.0570: Vim9: no error when omitting type from argument
Bram Moolenaar <Bram@vim.org>
parents:
20023
diff
changeset
|
136 p = skipwhite(p); |
8fb1cf4c44d5
patch 8.2.0570: Vim9: no error when omitting type from argument
Bram Moolenaar <Bram@vim.org>
parents:
20023
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 if (*p == ':') |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
139 { |
20142
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20138
diff
changeset
|
140 ++p; |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
141 if (!skip && !VIM_ISWHITE(*p)) |
20142
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20138
diff
changeset
|
142 { |
23877
85cf06ddb2a8
patch 8.2.2480: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents:
23829
diff
changeset
|
143 semsg(_(e_white_space_required_after_str_str), ":", p - 1); |
20142
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20138
diff
changeset
|
144 return arg; |
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20138
diff
changeset
|
145 } |
fe8d0a4344df
patch 8.2.0626: Vim9: wrong syntax of function in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20138
diff
changeset
|
146 type = skipwhite(p); |
21500
574517d682cf
patch 8.2.1300: Vim9: optional argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents:
21479
diff
changeset
|
147 p = skip_type(type, TRUE); |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
148 if (!skip) |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
149 type = vim_strnsave(type, p - type); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
150 } |
24410
25db91a3281b
patch 8.2.2745: Vim9: missing part of the argument change
Bram Moolenaar <Bram@vim.org>
parents:
24400
diff
changeset
|
151 else if (*skipwhite(p) != '=' && !types_optional && !is_underscore) |
20029
8fb1cf4c44d5
patch 8.2.0570: Vim9: no error when omitting type from argument
Bram Moolenaar <Bram@vim.org>
parents:
20023
diff
changeset
|
152 { |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21791
diff
changeset
|
153 semsg(_(e_missing_argument_type_for_str), |
20029
8fb1cf4c44d5
patch 8.2.0570: Vim9: no error when omitting type from argument
Bram Moolenaar <Bram@vim.org>
parents:
20023
diff
changeset
|
154 arg_copy == NULL ? arg : arg_copy); |
8fb1cf4c44d5
patch 8.2.0570: Vim9: no error when omitting type from argument
Bram Moolenaar <Bram@vim.org>
parents:
20023
diff
changeset
|
155 return arg; |
8fb1cf4c44d5
patch 8.2.0570: Vim9: no error when omitting type from argument
Bram Moolenaar <Bram@vim.org>
parents:
20023
diff
changeset
|
156 } |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
157 if (!skip) |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
158 { |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
159 if (type == NULL && types_optional) |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
160 // lambda arguments default to "any" type |
24400
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
161 type = vim_strsave((char_u *) |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
162 (is_vararg ? "list<any>" : "any")); |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
163 ((char_u **)argtypes->ga_data)[argtypes->ga_len++] = type; |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
164 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
165 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
166 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
167 return p; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
168 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
169 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
170 /* |
26792
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
171 * Handle line continuation in function arguments or body. |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
172 * Get a next line, store it in "eap" if appropriate and put the line in |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
173 * "lines_to_free" to free the line later. |
26792
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
174 */ |
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
175 static char_u * |
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
176 get_function_line( |
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
177 exarg_T *eap, |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
178 garray_T *lines_to_free, |
26800
e0ec45216f05
patch 8.2.3928: heredoc test fails
Bram Moolenaar <Bram@vim.org>
parents:
26798
diff
changeset
|
179 int indent, |
e0ec45216f05
patch 8.2.3928: heredoc test fails
Bram Moolenaar <Bram@vim.org>
parents:
26798
diff
changeset
|
180 getline_opt_T getline_options) |
26792
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
181 { |
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
182 char_u *theline; |
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
183 |
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
184 if (eap->getline == NULL) |
26804
34f1b7d6974a
patch 8.2.3930: getcmdline() argument has a misleading type
Bram Moolenaar <Bram@vim.org>
parents:
26800
diff
changeset
|
185 theline = getcmdline(':', 0L, indent, 0); |
26792
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
186 else |
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
187 theline = eap->getline(':', eap->cookie, indent, getline_options); |
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
188 if (theline != NULL) |
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
189 { |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
190 if (lines_to_free->ga_len > 0 |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
191 && *eap->cmdlinep == ((char_u **)lines_to_free->ga_data) |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
192 [lines_to_free->ga_len - 1]) |
26792
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
193 *eap->cmdlinep = theline; |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
194 ga_add_string(lines_to_free, theline); |
26792
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
195 } |
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
196 |
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
197 return theline; |
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
198 } |
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
199 |
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
200 /* |
9597
3ca0fd9709b1
commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents:
9593
diff
changeset
|
201 * Get function arguments. |
23511
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
202 * "argp" should point to just after the "(", possibly to white space. |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
203 * "argp" is advanced just after "endchar". |
9597
3ca0fd9709b1
commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents:
9593
diff
changeset
|
204 */ |
23511
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
205 static int |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
206 get_function_args( |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
207 char_u **argp, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
208 char_u endchar, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
209 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
|
210 garray_T *argtypes, // NULL unless using :def |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
211 int types_optional, // types optional if "argtypes" is not NULL |
24033
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
24004
diff
changeset
|
212 evalarg_T *evalarg, // context or NULL |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
213 int *varargs, |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
214 garray_T *default_args, |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
215 int skip, |
27611
e311a80f8cbe
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Bram Moolenaar <Bram@vim.org>
parents:
27595
diff
changeset
|
216 exarg_T *eap, // can be NULL |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
217 garray_T *lines_to_free) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
218 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
219 int mustend = FALSE; |
23511
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
220 char_u *arg; |
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
221 char_u *p; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
222 int c; |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
223 int any_default = FALSE; |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
224 char_u *expr; |
23511
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
225 char_u *whitep = *argp; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
226 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
227 if (newargs != NULL) |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
228 ga_init2(newargs, 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
|
229 if (argtypes != NULL) |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
230 ga_init2(argtypes, sizeof(char_u *), 3); |
25044
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
231 if (!skip && default_args != NULL) |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
232 ga_init2(default_args, sizeof(char_u *), 3); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
233 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
234 if (varargs != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
235 *varargs = FALSE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
236 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
237 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
238 * Isolate the arguments: "arg1, arg2, ...)" |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
239 */ |
23511
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
240 arg = skipwhite(*argp); |
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
241 p = arg; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
242 while (*p != endchar) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
243 { |
20023
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20015
diff
changeset
|
244 while (eap != NULL && eap->getline != NULL |
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20015
diff
changeset
|
245 && (*p == NUL || (VIM_ISWHITE(*whitep) && *p == '#'))) |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
246 { |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
247 // End of the line, get the next one. |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
248 char_u *theline = get_function_line(eap, lines_to_free, 0, |
26800
e0ec45216f05
patch 8.2.3928: heredoc test fails
Bram Moolenaar <Bram@vim.org>
parents:
26798
diff
changeset
|
249 GETLINE_CONCAT_CONT); |
26792
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
250 |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
251 if (theline == NULL) |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
252 break; |
20023
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20015
diff
changeset
|
253 whitep = (char_u *)" "; |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
254 p = skipwhite(theline); |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
255 } |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
256 |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
257 if (mustend && *p != endchar) |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
258 { |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
259 if (!skip) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26857
diff
changeset
|
260 semsg(_(e_invalid_argument_str), *argp); |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
261 goto err_ret; |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
262 } |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
263 if (*p == endchar) |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
264 break; |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
265 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
266 if (p[0] == '.' && p[1] == '.' && p[2] == '.') |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
267 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
268 if (varargs != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
269 *varargs = TRUE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
270 p += 3; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
271 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
|
272 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
273 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
|
274 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
275 // ...name: list<type> |
22349
b66a2e046c2e
patch 8.2.1723: Vim9: Variable argument name cannot start with underscore
Bram Moolenaar <Bram@vim.org>
parents:
22339
diff
changeset
|
276 if (!eval_isnamec1(*p)) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
277 { |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
278 if (!skip) |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
279 emsg(_(e_missing_name_after_dots)); |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
280 goto err_ret; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
281 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
282 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
283 arg = p; |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
284 p = one_function_arg(p, newargs, argtypes, types_optional, |
27611
e311a80f8cbe
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Bram Moolenaar <Bram@vim.org>
parents:
27595
diff
changeset
|
285 evalarg, eap, TRUE, skip); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
286 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
|
287 break; |
23879
9ddf1a537fc2
patch 8.2.2481: Vim9: confusing error when variable arguments have default
Bram Moolenaar <Bram@vim.org>
parents:
23877
diff
changeset
|
288 if (*skipwhite(p) == '=') |
9ddf1a537fc2
patch 8.2.2481: Vim9: confusing error when variable arguments have default
Bram Moolenaar <Bram@vim.org>
parents:
23877
diff
changeset
|
289 { |
9ddf1a537fc2
patch 8.2.2481: Vim9: confusing error when variable arguments have default
Bram Moolenaar <Bram@vim.org>
parents:
23877
diff
changeset
|
290 emsg(_(e_cannot_use_default_for_variable_arguments)); |
9ddf1a537fc2
patch 8.2.2481: Vim9: confusing error when variable arguments have default
Bram Moolenaar <Bram@vim.org>
parents:
23877
diff
changeset
|
291 break; |
9ddf1a537fc2
patch 8.2.2481: Vim9: confusing error when variable arguments have default
Bram Moolenaar <Bram@vim.org>
parents:
23877
diff
changeset
|
292 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
293 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
294 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
295 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
296 { |
25042
3f39b6b73019
patch 8.2.3058: Vim9: cannot use ternary operator in parenthesis
Bram Moolenaar <Bram@vim.org>
parents:
25038
diff
changeset
|
297 char_u *np; |
3f39b6b73019
patch 8.2.3058: Vim9: cannot use ternary operator in parenthesis
Bram Moolenaar <Bram@vim.org>
parents:
25038
diff
changeset
|
298 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
299 arg = p; |
24033
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
24004
diff
changeset
|
300 p = one_function_arg(p, newargs, argtypes, types_optional, |
27611
e311a80f8cbe
patch 8.2.4332: Vim9: incomplete test for existing script variable in block
Bram Moolenaar <Bram@vim.org>
parents:
27595
diff
changeset
|
301 evalarg, eap, FALSE, skip); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
302 if (p == arg) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
303 break; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
304 |
25042
3f39b6b73019
patch 8.2.3058: Vim9: cannot use ternary operator in parenthesis
Bram Moolenaar <Bram@vim.org>
parents:
25038
diff
changeset
|
305 // Recognize " = expr" but not " == expr". A lambda can have |
25046
2f702d19013a
patch 8.2.3060: Vim9: cannot use ternary operator in parenthesis
Bram Moolenaar <Bram@vim.org>
parents:
25044
diff
changeset
|
306 // "(a = expr" but "(a == expr" and "(a =~ expr" are not a lambda. |
25042
3f39b6b73019
patch 8.2.3058: Vim9: cannot use ternary operator in parenthesis
Bram Moolenaar <Bram@vim.org>
parents:
25038
diff
changeset
|
307 np = skipwhite(p); |
25046
2f702d19013a
patch 8.2.3060: Vim9: cannot use ternary operator in parenthesis
Bram Moolenaar <Bram@vim.org>
parents:
25044
diff
changeset
|
308 if (*np == '=' && np[1] != '=' && np[1] != '~' |
2f702d19013a
patch 8.2.3060: Vim9: cannot use ternary operator in parenthesis
Bram Moolenaar <Bram@vim.org>
parents:
25044
diff
changeset
|
309 && default_args != NULL) |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
310 { |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
311 typval_T rettv; |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
312 |
19328
e99e6d794597
patch 8.2.0222: Vim9: optional function arguments don't work yet
Bram Moolenaar <Bram@vim.org>
parents:
19297
diff
changeset
|
313 // 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
|
314 any_default = TRUE; |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
315 p = skipwhite(p) + 1; |
20023
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20015
diff
changeset
|
316 whitep = p; |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
317 p = skipwhite(p); |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
318 expr = p; |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
319 if (eval1(&p, &rettv, NULL) != FAIL) |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
320 { |
25044
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
321 if (!skip) |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
322 { |
25044
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
323 if (ga_grow(default_args, 1) == FAIL) |
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
324 goto err_ret; |
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
325 |
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
326 // trim trailing whitespace |
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
327 while (p > expr && VIM_ISWHITE(p[-1])) |
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
328 p--; |
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
329 c = *p; |
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
330 *p = NUL; |
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
331 expr = vim_strsave(expr); |
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
332 if (expr == NULL) |
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
333 { |
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
334 *p = c; |
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
335 goto err_ret; |
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
336 } |
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
337 ((char_u **)(default_args->ga_data)) |
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
338 [default_args->ga_len] = expr; |
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
339 default_args->ga_len++; |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
340 *p = c; |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
341 } |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
342 } |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
343 else |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
344 mustend = TRUE; |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
345 } |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
346 else if (any_default) |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
347 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
348 emsg(_(e_non_default_argument_follows_default_argument)); |
21263
71bd2f9adb61
patch 8.2.1182: Vim9: no check for whitespace after comma in lambda
Bram Moolenaar <Bram@vim.org>
parents:
21222
diff
changeset
|
349 goto err_ret; |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
350 } |
24371
2b4883926a24
patch 8.2.2726: confusing error message with white space before comma
Bram Moolenaar <Bram@vim.org>
parents:
24272
diff
changeset
|
351 |
2b4883926a24
patch 8.2.2726: confusing error message with white space before comma
Bram Moolenaar <Bram@vim.org>
parents:
24272
diff
changeset
|
352 if (VIM_ISWHITE(*p) && *skipwhite(p) == ',') |
2b4883926a24
patch 8.2.2726: confusing error message with white space before comma
Bram Moolenaar <Bram@vim.org>
parents:
24272
diff
changeset
|
353 { |
2b4883926a24
patch 8.2.2726: confusing error message with white space before comma
Bram Moolenaar <Bram@vim.org>
parents:
24272
diff
changeset
|
354 // Be tolerant when skipping |
2b4883926a24
patch 8.2.2726: confusing error message with white space before comma
Bram Moolenaar <Bram@vim.org>
parents:
24272
diff
changeset
|
355 if (!skip) |
2b4883926a24
patch 8.2.2726: confusing error message with white space before comma
Bram Moolenaar <Bram@vim.org>
parents:
24272
diff
changeset
|
356 { |
2b4883926a24
patch 8.2.2726: confusing error message with white space before comma
Bram Moolenaar <Bram@vim.org>
parents:
24272
diff
changeset
|
357 semsg(_(e_no_white_space_allowed_before_str_str), ",", p); |
2b4883926a24
patch 8.2.2726: confusing error message with white space before comma
Bram Moolenaar <Bram@vim.org>
parents:
24272
diff
changeset
|
358 goto err_ret; |
2b4883926a24
patch 8.2.2726: confusing error message with white space before comma
Bram Moolenaar <Bram@vim.org>
parents:
24272
diff
changeset
|
359 } |
2b4883926a24
patch 8.2.2726: confusing error message with white space before comma
Bram Moolenaar <Bram@vim.org>
parents:
24272
diff
changeset
|
360 p = skipwhite(p); |
2b4883926a24
patch 8.2.2726: confusing error message with white space before comma
Bram Moolenaar <Bram@vim.org>
parents:
24272
diff
changeset
|
361 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
362 if (*p == ',') |
21263
71bd2f9adb61
patch 8.2.1182: Vim9: no check for whitespace after comma in lambda
Bram Moolenaar <Bram@vim.org>
parents:
21222
diff
changeset
|
363 { |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
364 ++p; |
21263
71bd2f9adb61
patch 8.2.1182: Vim9: no check for whitespace after comma in lambda
Bram Moolenaar <Bram@vim.org>
parents:
21222
diff
changeset
|
365 // Don't give this error when skipping, it makes the "->" not |
71bd2f9adb61
patch 8.2.1182: Vim9: no check for whitespace after comma in lambda
Bram Moolenaar <Bram@vim.org>
parents:
21222
diff
changeset
|
366 // found in "{k,v -> x}" and give a confusing error. |
24069
324408c61b20
patch 8.2.2576: Vim9: defining a :func function checks for white space
Bram Moolenaar <Bram@vim.org>
parents:
24033
diff
changeset
|
367 // Allow missing space after comma in legacy functions. |
324408c61b20
patch 8.2.2576: Vim9: defining a :func function checks for white space
Bram Moolenaar <Bram@vim.org>
parents:
24033
diff
changeset
|
368 if (!skip && argtypes != NULL |
21263
71bd2f9adb61
patch 8.2.1182: Vim9: no check for whitespace after comma in lambda
Bram Moolenaar <Bram@vim.org>
parents:
21222
diff
changeset
|
369 && !IS_WHITE_OR_NUL(*p) && *p != endchar) |
71bd2f9adb61
patch 8.2.1182: Vim9: no check for whitespace after comma in lambda
Bram Moolenaar <Bram@vim.org>
parents:
21222
diff
changeset
|
370 { |
23877
85cf06ddb2a8
patch 8.2.2480: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents:
23829
diff
changeset
|
371 semsg(_(e_white_space_required_after_str_str), ",", p - 1); |
21263
71bd2f9adb61
patch 8.2.1182: Vim9: no check for whitespace after comma in lambda
Bram Moolenaar <Bram@vim.org>
parents:
21222
diff
changeset
|
372 goto err_ret; |
71bd2f9adb61
patch 8.2.1182: Vim9: no check for whitespace after comma in lambda
Bram Moolenaar <Bram@vim.org>
parents:
21222
diff
changeset
|
373 } |
71bd2f9adb61
patch 8.2.1182: Vim9: no check for whitespace after comma in lambda
Bram Moolenaar <Bram@vim.org>
parents:
21222
diff
changeset
|
374 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
375 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
376 mustend = TRUE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
377 } |
20023
c85d4e173cc9
patch 8.2.0567: Vim9: cannot put comments halfway expressions
Bram Moolenaar <Bram@vim.org>
parents:
20015
diff
changeset
|
378 whitep = p; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
379 p = skipwhite(p); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
380 } |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
381 |
9597
3ca0fd9709b1
commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents:
9593
diff
changeset
|
382 if (*p != endchar) |
3ca0fd9709b1
commit https://github.com/vim/vim/commit/4f0383bc3fe5af0229fb66b53fe94329af783eff
Christian Brabandt <cb@256bit.org>
parents:
9593
diff
changeset
|
383 goto err_ret; |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
384 ++p; // skip "endchar" |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
385 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
386 *argp = p; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
387 return OK; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
388 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
389 err_ret: |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
390 if (newargs != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
391 ga_clear_strings(newargs); |
25044
a9a21631c090
patch 8.2.3059: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
25042
diff
changeset
|
392 if (!skip && default_args != NULL) |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
393 ga_clear_strings(default_args); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
394 return FAIL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
395 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
396 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
397 /* |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
398 * Parse the argument types, filling "fp->uf_arg_types". |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
399 * Return OK or FAIL. |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
400 */ |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
401 static int |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
402 parse_argument_types(ufunc_T *fp, garray_T *argtypes, int varargs) |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
403 { |
24400
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
404 int len = 0; |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
405 |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
406 ga_init2(&fp->uf_type_list, sizeof(type_T *), 10); |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
407 if (argtypes->ga_len > 0) |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
408 { |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
409 // When "varargs" is set the last name/type goes into uf_va_name |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
410 // and uf_va_type. |
24400
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
411 len = argtypes->ga_len - (varargs ? 1 : 0); |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
412 |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
413 if (len > 0) |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
414 fp->uf_arg_types = ALLOC_CLEAR_MULT(type_T *, len); |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
415 if (fp->uf_arg_types != NULL) |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
416 { |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
417 int i; |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
418 type_T *type; |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
419 |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
420 for (i = 0; i < len; ++ i) |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
421 { |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
422 char_u *p = ((char_u **)argtypes->ga_data)[i]; |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
423 |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
424 if (p == NULL) |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
425 // will get the type from the default value |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
426 type = &t_unknown; |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
427 else |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
428 type = parse_type(&p, &fp->uf_type_list, TRUE); |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
429 if (type == NULL) |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
430 return FAIL; |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
431 fp->uf_arg_types[i] = type; |
28123
e5fcd1256ee3
patch 8.2.4586: Vim9: no error for using lower case name for "func" argument
Bram Moolenaar <Bram@vim.org>
parents:
28047
diff
changeset
|
432 if (i < fp->uf_args.ga_len |
e5fcd1256ee3
patch 8.2.4586: Vim9: no error for using lower case name for "func" argument
Bram Moolenaar <Bram@vim.org>
parents:
28047
diff
changeset
|
433 && (type->tt_type == VAR_FUNC |
e5fcd1256ee3
patch 8.2.4586: Vim9: no error for using lower case name for "func" argument
Bram Moolenaar <Bram@vim.org>
parents:
28047
diff
changeset
|
434 || type->tt_type == VAR_PARTIAL) |
e5fcd1256ee3
patch 8.2.4586: Vim9: no error for using lower case name for "func" argument
Bram Moolenaar <Bram@vim.org>
parents:
28047
diff
changeset
|
435 && var_wrong_func_name( |
e5fcd1256ee3
patch 8.2.4586: Vim9: no error for using lower case name for "func" argument
Bram Moolenaar <Bram@vim.org>
parents:
28047
diff
changeset
|
436 ((char_u **)fp->uf_args.ga_data)[i], TRUE)) |
e5fcd1256ee3
patch 8.2.4586: Vim9: no error for using lower case name for "func" argument
Bram Moolenaar <Bram@vim.org>
parents:
28047
diff
changeset
|
437 return FAIL; |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
438 } |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
439 } |
24400
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
440 } |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
441 |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
442 if (varargs) |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
443 { |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
444 char_u *p; |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
445 |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
446 // Move the last argument "...name: type" to uf_va_name and |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
447 // uf_va_type. |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
448 fp->uf_va_name = ((char_u **)fp->uf_args.ga_data) |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
449 [fp->uf_args.ga_len - 1]; |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
450 --fp->uf_args.ga_len; |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
451 p = ((char_u **)argtypes->ga_data)[len]; |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
452 if (p == NULL) |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
453 // TODO: get type from default value |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
454 fp->uf_va_type = &t_list_any; |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
455 else |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
456 { |
24400
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
457 fp->uf_va_type = parse_type(&p, &fp->uf_type_list, TRUE); |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
458 if (fp->uf_va_type != NULL && fp->uf_va_type->tt_type != VAR_LIST) |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
459 { |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
460 semsg(_(e_variable_arguments_type_must_be_list_str), |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
461 ((char_u **)argtypes->ga_data)[len]); |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
462 return FAIL; |
24400
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
463 } |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
464 } |
24400
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
465 if (fp->uf_va_type == NULL) |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
466 return FAIL; |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
467 } |
24400
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
468 |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
469 return OK; |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
470 } |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
471 |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
472 static int |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
473 parse_return_type(ufunc_T *fp, char_u *ret_type) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
474 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
475 if (ret_type == NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
476 fp->uf_ret_type = &t_void; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
477 else |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
478 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
479 char_u *p = ret_type; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
480 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
481 fp->uf_ret_type = parse_type(&p, &fp->uf_type_list, TRUE); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
482 if (fp->uf_ret_type == NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
483 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
484 fp->uf_ret_type = &t_void; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
485 return FAIL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
486 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
487 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
488 return OK; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
489 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
490 |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
491 /* |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
492 * 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
|
493 */ |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
494 static int |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
495 register_closure(ufunc_T *fp) |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
496 { |
9733
59565cdd7261
commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents:
9731
diff
changeset
|
497 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
|
498 // no change |
9733
59565cdd7261
commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents:
9731
diff
changeset
|
499 return OK; |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
500 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
|
501 fp->uf_scoped = current_funccal; |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
502 current_funccal->fc_refcount++; |
9733
59565cdd7261
commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents:
9731
diff
changeset
|
503 |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
504 if (ga_grow(¤t_funccal->fc_funcs, 1) == FAIL) |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
505 return FAIL; |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
506 ((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
|
507 [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
|
508 return OK; |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
509 } |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
510 |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
511 static void |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
512 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
|
513 { |
23829
950875545045
patch 8.2.2456: Coverity warning for strcpy() into fixed size array
Bram Moolenaar <Bram@vim.org>
parents:
23808
diff
changeset
|
514 // Add a type cast to avoid a warning for an overflow, the uf_name[] array |
950875545045
patch 8.2.2456: Coverity warning for strcpy() into fixed size array
Bram Moolenaar <Bram@vim.org>
parents:
23808
diff
changeset
|
515 // actually extends beyond the struct. |
950875545045
patch 8.2.2456: Coverity warning for strcpy() into fixed size array
Bram Moolenaar <Bram@vim.org>
parents:
23808
diff
changeset
|
516 STRCPY((void *)fp->uf_name, name); |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
517 |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
518 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
|
519 { |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
520 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
|
521 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
|
522 { |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
523 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
|
524 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
|
525 } |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
526 } |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
527 } |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
528 |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
529 /* |
28263
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
530 * If "name" starts with K_SPECIAL and "buf[bufsize]" is big enough |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
531 * return "buf" filled with a readable function name. |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
532 * Otherwise just return "name", thus the return value can always be used. |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
533 * "name" and "buf" may be equal. |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
534 */ |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
535 char_u * |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
536 make_ufunc_name_readable(char_u *name, char_u *buf, size_t bufsize) |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
537 { |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
538 size_t len; |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
539 |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
540 if (name[0] != K_SPECIAL) |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
541 return name; |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
542 len = STRLEN(name); |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
543 if (len + 3 > bufsize) |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
544 return name; |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
545 |
28267
39a833e69bf3
patch 8.2.4659: invalid memory access when using printable function name
Bram Moolenaar <Bram@vim.org>
parents:
28263
diff
changeset
|
546 mch_memmove(buf + 5, name + 3, len - 2); // Include trailing NUL |
28263
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
547 mch_memmove(buf, "<SNR>", 5); |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
548 return buf; |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
549 } |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
550 |
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
551 /* |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
552 * Get a name for a lambda. Returned in static memory. |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
553 */ |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
554 char_u * |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
555 get_lambda_name(void) |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
556 { |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
557 static char_u name[30]; |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
558 static int lambda_no = 0; |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
559 |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
560 sprintf((char*)name, "<lambda>%d", ++lambda_no); |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
561 return name; |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
562 } |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
563 |
21006
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
564 #if defined(FEAT_LUA) || defined(PROTO) |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
565 /* |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
566 * Registers a native C callback which can be called from Vim script. |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
567 * Returns the name of the Vim script function. |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
568 */ |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
569 char_u * |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
570 register_cfunc(cfunc_T cb, cfunc_free_T cb_free, void *state) |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
571 { |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
572 char_u *name = get_lambda_name(); |
21066
48cfc37fe4fc
patch 8.2.1084: Lua: registering function has useless code
Bram Moolenaar <Bram@vim.org>
parents:
21058
diff
changeset
|
573 ufunc_T *fp; |
21006
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
574 |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
575 fp = alloc_clear(offsetof(ufunc_T, uf_name) + STRLEN(name) + 1); |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
576 if (fp == NULL) |
21066
48cfc37fe4fc
patch 8.2.1084: Lua: registering function has useless code
Bram Moolenaar <Bram@vim.org>
parents:
21058
diff
changeset
|
577 return NULL; |
21006
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
578 |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
579 fp->uf_def_status = UF_NOT_COMPILED; |
21006
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
580 fp->uf_refcount = 1; |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
581 fp->uf_varargs = TRUE; |
26323
3841da4eac23
patch 8.2.3692: Vim9: cannot use :func inside a :def function
Bram Moolenaar <Bram@vim.org>
parents:
26205
diff
changeset
|
582 fp->uf_flags = FC_CFUNC | FC_LAMBDA; |
21006
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
583 fp->uf_calls = 0; |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
584 fp->uf_script_ctx = current_sctx; |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
585 fp->uf_cb = cb; |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
586 fp->uf_cb_free = cb_free; |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
587 fp->uf_cb_state = state; |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
588 |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
589 set_ufunc_name(fp, name); |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
590 hash_add(&func_hashtab, UF2HIKEY(fp)); |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
591 |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
592 return name; |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
593 } |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
594 #endif |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
595 |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
596 /* |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
597 * Skip over "->" or "=>" after the arguments of a lambda. |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
598 * If ": type" is found make "ret_type" point to "type". |
23338
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
599 * If "white_error" is not NULL check for correct use of white space and set |
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
600 * "white_error" to TRUE if there is an error. |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
601 * Return NULL if no valid arrow found. |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
602 */ |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
603 static char_u * |
23338
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
604 skip_arrow( |
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
605 char_u *start, |
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
606 int equal_arrow, |
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
607 char_u **ret_type, |
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
608 int *white_error) |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
609 { |
23338
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
610 char_u *s = start; |
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
611 char_u *bef = start - 2; // "start" points to > of -> |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
612 |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
613 if (equal_arrow) |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
614 { |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
615 if (*s == ':') |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
616 { |
23338
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
617 if (white_error != NULL && !VIM_ISWHITE(s[1])) |
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
618 { |
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
619 *white_error = TRUE; |
23877
85cf06ddb2a8
patch 8.2.2480: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents:
23829
diff
changeset
|
620 semsg(_(e_white_space_required_after_str_str), ":", s); |
23338
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
621 return NULL; |
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
622 } |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
623 s = skipwhite(s + 1); |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
624 *ret_type = s; |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
625 s = skip_type(s, TRUE); |
23808
baf9069f64ca
patch 8.2.2445: Vim9: no proper error for lambda missing return type
Bram Moolenaar <Bram@vim.org>
parents:
23727
diff
changeset
|
626 if (s == *ret_type) |
baf9069f64ca
patch 8.2.2445: Vim9: no proper error for lambda missing return type
Bram Moolenaar <Bram@vim.org>
parents:
23727
diff
changeset
|
627 { |
baf9069f64ca
patch 8.2.2445: Vim9: no proper error for lambda missing return type
Bram Moolenaar <Bram@vim.org>
parents:
23727
diff
changeset
|
628 emsg(_(e_missing_return_type)); |
baf9069f64ca
patch 8.2.2445: Vim9: no proper error for lambda missing return type
Bram Moolenaar <Bram@vim.org>
parents:
23727
diff
changeset
|
629 return NULL; |
baf9069f64ca
patch 8.2.2445: Vim9: no proper error for lambda missing return type
Bram Moolenaar <Bram@vim.org>
parents:
23727
diff
changeset
|
630 } |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
631 } |
23338
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
632 bef = s; |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
633 s = skipwhite(s); |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
634 if (*s != '=') |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
635 return NULL; |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
636 ++s; |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
637 } |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
638 if (*s != '>') |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
639 return NULL; |
23338
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
640 if (white_error != NULL && ((!VIM_ISWHITE(*bef) && *bef != '{') |
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
641 || !IS_WHITE_OR_NUL(s[1]))) |
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
642 { |
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
643 *white_error = TRUE; |
23446
b1dbbc81a011
patch 8.2.2266: Vim9: it can be hard to see where white space is missing
Bram Moolenaar <Bram@vim.org>
parents:
23444
diff
changeset
|
644 semsg(_(e_white_space_required_before_and_after_str_at_str), |
b1dbbc81a011
patch 8.2.2266: Vim9: it can be hard to see where white space is missing
Bram Moolenaar <Bram@vim.org>
parents:
23444
diff
changeset
|
645 equal_arrow ? "=>" : "->", bef); |
23338
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
646 return NULL; |
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
647 } |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
648 return skipwhite(s + 1); |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
649 } |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
650 |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
651 /* |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
652 * Check if "*cmd" points to a function command and if so advance "*cmd" and |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
653 * return TRUE. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
654 * Otherwise return FALSE; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
655 * Do not consider "function(" to be a command. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
656 */ |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
657 static int |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
658 is_function_cmd(char_u **cmd) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
659 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
660 char_u *p = *cmd; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
661 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
662 if (checkforcmd(&p, "function", 2)) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
663 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
664 if (*p == '(') |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
665 return FALSE; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
666 *cmd = p; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
667 return TRUE; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
668 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
669 return FALSE; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
670 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
671 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
672 /* |
25358
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
673 * Called when defining a function: The context may be needed for script |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
674 * variables declared in a block that is visible now but not when the function |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
675 * is compiled or called later. |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
676 */ |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
677 static void |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
678 function_using_block_scopes(ufunc_T *fp, cstack_T *cstack) |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
679 { |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
680 if (cstack != NULL && cstack->cs_idx >= 0) |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
681 { |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
682 int count = cstack->cs_idx + 1; |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
683 int i; |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
684 |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
685 fp->uf_block_ids = ALLOC_MULT(int, count); |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
686 if (fp->uf_block_ids != NULL) |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
687 { |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
688 mch_memmove(fp->uf_block_ids, cstack->cs_block_id, |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
689 sizeof(int) * count); |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
690 fp->uf_block_depth = count; |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
691 } |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
692 |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
693 // Set flag in each block to indicate a function was defined. This |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
694 // is used to keep the variable when leaving the block, see |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
695 // hide_script_var(). |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
696 for (i = 0; i <= cstack->cs_idx; ++i) |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
697 cstack->cs_flags[i] |= CSF_FUNC_DEF; |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
698 } |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
699 } |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
700 |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
701 /* |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
702 * Read the body of a function, put every line in "newlines". |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
703 * This stops at "}", "endfunction" or "enddef". |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
704 * "newlines" must already have been initialized. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
705 * "eap->cmdidx" is CMD_function, CMD_def or CMD_block; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
706 */ |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
707 static int |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
708 get_function_body( |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
709 exarg_T *eap, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
710 garray_T *newlines, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
711 char_u *line_arg_in, |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
712 garray_T *lines_to_free) |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
713 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
714 linenr_T sourcing_lnum_top = SOURCING_LNUM; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
715 linenr_T sourcing_lnum_off; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
716 int saved_wait_return = need_wait_return; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
717 char_u *line_arg = line_arg_in; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
718 int vim9_function = eap->cmdidx == CMD_def |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
719 || eap->cmdidx == CMD_block; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
720 #define MAX_FUNC_NESTING 50 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
721 char nesting_def[MAX_FUNC_NESTING]; |
25265
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
722 char nesting_inline[MAX_FUNC_NESTING]; |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
723 int nesting = 0; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
724 getline_opt_T getline_options; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
725 int indent = 2; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
726 char_u *skip_until = NULL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
727 int ret = FAIL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
728 int is_heredoc = FALSE; |
24826
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
729 int heredoc_concat_len = 0; |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
730 garray_T heredoc_ga; |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
731 char_u *heredoc_trimmed = NULL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
732 |
24826
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
733 ga_init2(&heredoc_ga, 1, 500); |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
734 |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
735 // Detect having skipped over comment lines to find the return |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
736 // type. Add NULL lines to keep the line count correct. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
737 sourcing_lnum_off = get_sourced_lnum(eap->getline, eap->cookie); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
738 if (SOURCING_LNUM < sourcing_lnum_off) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
739 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
740 sourcing_lnum_off -= SOURCING_LNUM; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
741 if (ga_grow(newlines, sourcing_lnum_off) == FAIL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
742 goto theend; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
743 while (sourcing_lnum_off-- > 0) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
744 ((char_u **)(newlines->ga_data))[newlines->ga_len++] = NULL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
745 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
746 |
25265
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
747 nesting_def[0] = vim9_function; |
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
748 nesting_inline[0] = eap->cmdidx == CMD_block; |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
749 getline_options = vim9_function |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
750 ? GETLINE_CONCAT_CONTBAR : GETLINE_CONCAT_CONT; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
751 for (;;) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
752 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
753 char_u *theline; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
754 char_u *p; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
755 char_u *arg; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
756 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
757 if (KeyTyped) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
758 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
759 msg_scroll = TRUE; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
760 saved_wait_return = FALSE; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
761 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
762 need_wait_return = FALSE; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
763 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
764 if (line_arg != NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
765 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
766 // Use eap->arg, split up in parts by line breaks. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
767 theline = line_arg; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
768 p = vim_strchr(theline, '\n'); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
769 if (p == NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
770 line_arg += STRLEN(line_arg); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
771 else |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
772 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
773 *p = NUL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
774 line_arg = p + 1; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
775 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
776 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
777 else |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
778 { |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
779 theline = get_function_line(eap, lines_to_free, indent, |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
780 getline_options); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
781 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
782 if (KeyTyped) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
783 lines_left = Rows - 1; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
784 if (theline == NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
785 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
786 // Use the start of the function for the line number. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
787 SOURCING_LNUM = sourcing_lnum_top; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
788 if (skip_until != NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
789 semsg(_(e_missing_heredoc_end_marker_str), skip_until); |
25265
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
790 else if (nesting_inline[nesting]) |
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
791 emsg(_(e_missing_end_block)); |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
792 else if (eap->cmdidx == CMD_def) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
793 emsg(_(e_missing_enddef)); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
794 else |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
795 emsg(_(e_missing_endfunction)); |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
796 goto theend; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
797 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
798 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
799 // Detect line continuation: SOURCING_LNUM increased more than one. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
800 sourcing_lnum_off = get_sourced_lnum(eap->getline, eap->cookie); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
801 if (SOURCING_LNUM < sourcing_lnum_off) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
802 sourcing_lnum_off -= SOURCING_LNUM; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
803 else |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
804 sourcing_lnum_off = 0; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
805 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
806 if (skip_until != NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
807 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
808 // Don't check for ":endfunc"/":enddef" between |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
809 // * ":append" and "." |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
810 // * ":python <<EOF" and "EOF" |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
811 // * ":let {var-name} =<< [trim] {marker}" and "{marker}" |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
812 if (heredoc_trimmed == NULL |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
813 || (is_heredoc && skipwhite(theline) == theline) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
814 || STRNCMP(theline, heredoc_trimmed, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
815 STRLEN(heredoc_trimmed)) == 0) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
816 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
817 if (heredoc_trimmed == NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
818 p = theline; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
819 else if (is_heredoc) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
820 p = skipwhite(theline) == theline |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
821 ? theline : theline + STRLEN(heredoc_trimmed); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
822 else |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
823 p = theline + STRLEN(heredoc_trimmed); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
824 if (STRCMP(p, skip_until) == 0) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
825 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
826 VIM_CLEAR(skip_until); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
827 VIM_CLEAR(heredoc_trimmed); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
828 getline_options = vim9_function |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
829 ? GETLINE_CONCAT_CONTBAR : GETLINE_CONCAT_CONT; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
830 is_heredoc = FALSE; |
24826
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
831 |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
832 if (heredoc_concat_len > 0) |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
833 { |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
834 // Replace the starting line with all the concatenated |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
835 // lines. |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
836 ga_concat(&heredoc_ga, theline); |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
837 vim_free(((char_u **)(newlines->ga_data))[ |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
838 heredoc_concat_len - 1]); |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
839 ((char_u **)(newlines->ga_data))[ |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
840 heredoc_concat_len - 1] = heredoc_ga.ga_data; |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
841 ga_init(&heredoc_ga); |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
842 heredoc_concat_len = 0; |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
843 theline += STRLEN(theline); // skip the "EOF" |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
844 } |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
845 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
846 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
847 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
848 else |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
849 { |
25265
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
850 int c; |
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
851 char_u *end; |
27978
442ca2007bec
patch 8.2.4514: Vim9: some flow commands can be shortened
Bram Moolenaar <Bram@vim.org>
parents:
27893
diff
changeset
|
852 char_u *cmd; |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
853 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
854 // skip ':' and blanks |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
855 for (p = theline; VIM_ISWHITE(*p) || *p == ':'; ++p) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
856 ; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
857 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
858 // Check for "endfunction", "enddef" or "}". |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
859 // When a ":" follows it must be a dict key; "enddef: value," |
27978
442ca2007bec
patch 8.2.4514: Vim9: some flow commands can be shortened
Bram Moolenaar <Bram@vim.org>
parents:
27893
diff
changeset
|
860 cmd = p; |
25265
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
861 if (nesting_inline[nesting] |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
862 ? *p == '}' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
863 : (checkforcmd(&p, nesting_def[nesting] |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
864 ? "enddef" : "endfunction", 4) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
865 && *p != ':')) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
866 { |
27978
442ca2007bec
patch 8.2.4514: Vim9: some flow commands can be shortened
Bram Moolenaar <Bram@vim.org>
parents:
27893
diff
changeset
|
867 if (!nesting_inline[nesting] && nesting_def[nesting] |
442ca2007bec
patch 8.2.4514: Vim9: some flow commands can be shortened
Bram Moolenaar <Bram@vim.org>
parents:
27893
diff
changeset
|
868 && p < cmd + 6) |
442ca2007bec
patch 8.2.4514: Vim9: some flow commands can be shortened
Bram Moolenaar <Bram@vim.org>
parents:
27893
diff
changeset
|
869 semsg(_(e_command_cannot_be_shortened_str), "enddef"); |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
870 if (nesting-- == 0) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
871 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
872 char_u *nextcmd = NULL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
873 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
874 if (*p == '|' || *p == '}') |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
875 nextcmd = p + 1; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
876 else if (line_arg != NULL && *skipwhite(line_arg) != NUL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
877 nextcmd = line_arg; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
878 else if (*p != NUL && *p != (vim9_function ? '#' : '"') |
24208
7a21b2581dce
patch 8.2.2645: using inline function is not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
24202
diff
changeset
|
879 && (vim9_function || p_verbose > 0)) |
7a21b2581dce
patch 8.2.2645: using inline function is not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
24202
diff
changeset
|
880 { |
25632
c204815f3058
patch 8.2.3352: Vim9: error for nested :enddef has wrong line number
Bram Moolenaar <Bram@vim.org>
parents:
25561
diff
changeset
|
881 SOURCING_LNUM = sourcing_lnum_top |
c204815f3058
patch 8.2.3352: Vim9: error for nested :enddef has wrong line number
Bram Moolenaar <Bram@vim.org>
parents:
25561
diff
changeset
|
882 + newlines->ga_len + 1; |
24208
7a21b2581dce
patch 8.2.2645: using inline function is not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
24202
diff
changeset
|
883 if (eap->cmdidx == CMD_def) |
26792
30d8377ea1b1
patch 8.2.3924: Vim9: no error if something follows :enddef
Bram Moolenaar <Bram@vim.org>
parents:
26790
diff
changeset
|
884 semsg(_(e_text_found_after_str_str), "enddef", p); |
24208
7a21b2581dce
patch 8.2.2645: using inline function is not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
24202
diff
changeset
|
885 else |
7a21b2581dce
patch 8.2.2645: using inline function is not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
24202
diff
changeset
|
886 give_warning2((char_u *) |
7a21b2581dce
patch 8.2.2645: using inline function is not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
24202
diff
changeset
|
887 _("W22: Text found after :endfunction: %s"), |
7a21b2581dce
patch 8.2.2645: using inline function is not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
24202
diff
changeset
|
888 p, TRUE); |
7a21b2581dce
patch 8.2.2645: using inline function is not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
24202
diff
changeset
|
889 } |
7a21b2581dce
patch 8.2.2645: using inline function is not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
24202
diff
changeset
|
890 if (nextcmd != NULL && *skipwhite(nextcmd) != NUL) |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
891 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
892 // Another command follows. If the line came from "eap" |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
893 // we can simply point into it, otherwise we need to |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
894 // change "eap->cmdlinep" to point to the last fetched |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
895 // line. |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
896 eap->nextcmd = nextcmd; |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
897 if (lines_to_free->ga_len > 0 |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
898 && *eap->cmdlinep != |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
899 ((char_u **)lines_to_free->ga_data) |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
900 [lines_to_free->ga_len - 1]) |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
901 { |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
902 // *cmdlinep will be freed later, thus remove the |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
903 // line from lines_to_free. |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
904 vim_free(*eap->cmdlinep); |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
905 *eap->cmdlinep = ((char_u **)lines_to_free->ga_data) |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
906 [lines_to_free->ga_len - 1]; |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
907 --lines_to_free->ga_len; |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
908 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
909 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
910 break; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
911 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
912 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
913 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
914 // Check for mismatched "endfunc" or "enddef". |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
915 // We don't check for "def" inside "func" thus we also can't check |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
916 // for "enddef". |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
917 // We continue to find the end of the function, although we might |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
918 // not find it. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
919 else if (nesting_def[nesting]) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
920 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
921 if (checkforcmd(&p, "endfunction", 4) && *p != ':') |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
922 emsg(_(e_mismatched_endfunction)); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
923 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
924 else if (eap->cmdidx == CMD_def && checkforcmd(&p, "enddef", 4)) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
925 emsg(_(e_mismatched_enddef)); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
926 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
927 // Increase indent inside "if", "while", "for" and "try", decrease |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
928 // at "end". |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
929 if (indent > 2 && (*p == '}' || STRNCMP(p, "end", 3) == 0)) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
930 indent -= 2; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
931 else if (STRNCMP(p, "if", 2) == 0 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
932 || STRNCMP(p, "wh", 2) == 0 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
933 || STRNCMP(p, "for", 3) == 0 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
934 || STRNCMP(p, "try", 3) == 0) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
935 indent += 2; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
936 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
937 // Check for defining a function inside this function. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
938 // Only recognize "def" inside "def", not inside "function", |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
939 // For backwards compatibility, see Test_function_python(). |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
940 c = *p; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
941 if (is_function_cmd(&p) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
942 || (eap->cmdidx == CMD_def && checkforcmd(&p, "def", 3))) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
943 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
944 if (*p == '!') |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
945 p = skipwhite(p + 1); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
946 p += eval_fname_script(p); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
947 vim_free(trans_function_name(&p, NULL, TRUE, 0, NULL, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
948 NULL, NULL)); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
949 if (*skipwhite(p) == '(') |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
950 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
951 if (nesting == MAX_FUNC_NESTING - 1) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
952 emsg(_(e_function_nesting_too_deep)); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
953 else |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
954 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
955 ++nesting; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
956 nesting_def[nesting] = (c == 'd'); |
25265
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
957 nesting_inline[nesting] = FALSE; |
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
958 indent += 2; |
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
959 } |
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
960 } |
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
961 } |
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
962 |
25296
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
963 if (nesting_def[nesting] ? *p != '#' : *p != '"') |
25265
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
964 { |
25296
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
965 // Not a comment line: check for nested inline function. |
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
966 end = p + STRLEN(p) - 1; |
25265
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
967 while (end > p && VIM_ISWHITE(*end)) |
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
968 --end; |
25473
9a4cb96c9550
patch 8.2.3273: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
25469
diff
changeset
|
969 if (end > p + 1 && *end == '{' && VIM_ISWHITE(end[-1])) |
25265
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
970 { |
25469
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25409
diff
changeset
|
971 int is_block; |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25409
diff
changeset
|
972 |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25409
diff
changeset
|
973 // check for trailing "=> {": start of an inline function |
25296
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
974 --end; |
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
975 while (end > p && VIM_ISWHITE(*end)) |
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
976 --end; |
25469
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25409
diff
changeset
|
977 is_block = end > p + 2 && end[-1] == '=' && end[0] == '>'; |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25409
diff
changeset
|
978 if (!is_block) |
25265
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
979 { |
25469
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25409
diff
changeset
|
980 char_u *s = p; |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25409
diff
changeset
|
981 |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25409
diff
changeset
|
982 // check for line starting with "au" for :autocmd or |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25409
diff
changeset
|
983 // "com" for :command, these can use a {} block |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25409
diff
changeset
|
984 is_block = checkforcmd_noparen(&s, "autocmd", 2) |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25409
diff
changeset
|
985 || checkforcmd_noparen(&s, "command", 3); |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25409
diff
changeset
|
986 } |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25409
diff
changeset
|
987 |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25409
diff
changeset
|
988 if (is_block) |
dcd45fe7fe2e
patch 8.2.3271: Vim9: cannot use :command or :au with block in :def function
Bram Moolenaar <Bram@vim.org>
parents:
25409
diff
changeset
|
989 { |
25296
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
990 if (nesting == MAX_FUNC_NESTING - 1) |
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
991 emsg(_(e_function_nesting_too_deep)); |
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
992 else |
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
993 { |
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
994 ++nesting; |
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
995 nesting_def[nesting] = TRUE; |
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
996 nesting_inline[nesting] = TRUE; |
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
997 indent += 2; |
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
998 } |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
999 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1000 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1001 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1002 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1003 // Check for ":append", ":change", ":insert". Not for :def. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1004 p = skip_range(p, FALSE, NULL); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1005 if (!vim9_function |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1006 && ((p[0] == 'a' && (!ASCII_ISALPHA(p[1]) || p[1] == 'p')) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1007 || (p[0] == 'c' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1008 && (!ASCII_ISALPHA(p[1]) || (p[1] == 'h' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1009 && (!ASCII_ISALPHA(p[2]) || (p[2] == 'a' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1010 && (STRNCMP(&p[3], "nge", 3) != 0 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1011 || !ASCII_ISALPHA(p[6]))))))) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1012 || (p[0] == 'i' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1013 && (!ASCII_ISALPHA(p[1]) || (p[1] == 'n' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1014 && (!ASCII_ISALPHA(p[2]) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1015 || (p[2] == 's' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1016 && (!ASCII_ISALPHA(p[3]) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1017 || p[3] == 'e')))))))) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1018 skip_until = vim_strsave((char_u *)"."); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1019 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1020 // Check for ":python <<EOF", ":tcl <<EOF", etc. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1021 arg = skipwhite(skiptowhite(p)); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1022 if (arg[0] == '<' && arg[1] =='<' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1023 && ((p[0] == 'p' && p[1] == 'y' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1024 && (!ASCII_ISALNUM(p[2]) || p[2] == 't' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1025 || ((p[2] == '3' || p[2] == 'x') |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1026 && !ASCII_ISALPHA(p[3])))) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1027 || (p[0] == 'p' && p[1] == 'e' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1028 && (!ASCII_ISALPHA(p[2]) || p[2] == 'r')) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1029 || (p[0] == 't' && p[1] == 'c' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1030 && (!ASCII_ISALPHA(p[2]) || p[2] == 'l')) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1031 || (p[0] == 'l' && p[1] == 'u' && p[2] == 'a' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1032 && !ASCII_ISALPHA(p[3])) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1033 || (p[0] == 'r' && p[1] == 'u' && p[2] == 'b' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1034 && (!ASCII_ISALPHA(p[3]) || p[3] == 'y')) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1035 || (p[0] == 'm' && p[1] == 'z' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1036 && (!ASCII_ISALPHA(p[2]) || p[2] == 's')) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1037 )) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1038 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1039 // ":python <<" continues until a dot, like ":append" |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1040 p = skipwhite(arg + 2); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1041 if (STRNCMP(p, "trim", 4) == 0) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1042 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1043 // Ignore leading white space. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1044 p = skipwhite(p + 4); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1045 heredoc_trimmed = vim_strnsave(theline, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1046 skipwhite(theline) - theline); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1047 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1048 if (*p == NUL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1049 skip_until = vim_strsave((char_u *)"."); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1050 else |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1051 skip_until = vim_strnsave(p, skiptowhite(p) - p); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1052 getline_options = GETLINE_NONE; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1053 is_heredoc = TRUE; |
24826
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1054 if (eap->cmdidx == CMD_def) |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1055 heredoc_concat_len = newlines->ga_len + 1; |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1056 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1057 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1058 // Check for ":cmd v =<< [trim] EOF" |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1059 // and ":cmd [a, b] =<< [trim] EOF" |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1060 // and "lines =<< [trim] EOF" for Vim9 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1061 // Where "cmd" can be "let", "var", "final" or "const". |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1062 arg = skipwhite(skiptowhite(p)); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1063 if (*arg == '[') |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1064 arg = vim_strchr(arg, ']'); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1065 if (arg != NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1066 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1067 int found = (eap->cmdidx == CMD_def && arg[0] == '=' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1068 && arg[1] == '<' && arg[2] =='<'); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1069 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1070 if (!found) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1071 // skip over the argument after "cmd" |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1072 arg = skipwhite(skiptowhite(arg)); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1073 if (found || (arg[0] == '=' && arg[1] == '<' && arg[2] =='<' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1074 && (checkforcmd(&p, "let", 2) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1075 || checkforcmd(&p, "var", 3) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1076 || checkforcmd(&p, "final", 5) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1077 || checkforcmd(&p, "const", 5)))) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1078 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1079 p = skipwhite(arg + 3); |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28382
diff
changeset
|
1080 while (TRUE) |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1081 { |
28491
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28382
diff
changeset
|
1082 if (STRNCMP(p, "trim", 4) == 0) |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28382
diff
changeset
|
1083 { |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28382
diff
changeset
|
1084 // Ignore leading white space. |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28382
diff
changeset
|
1085 p = skipwhite(p + 4); |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28382
diff
changeset
|
1086 heredoc_trimmed = vim_strnsave(theline, |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28382
diff
changeset
|
1087 skipwhite(theline) - theline); |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28382
diff
changeset
|
1088 continue; |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28382
diff
changeset
|
1089 } |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28382
diff
changeset
|
1090 if (STRNCMP(p, "eval", 4) == 0) |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28382
diff
changeset
|
1091 { |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28382
diff
changeset
|
1092 // Ignore leading white space. |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28382
diff
changeset
|
1093 p = skipwhite(p + 4); |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28382
diff
changeset
|
1094 continue; |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28382
diff
changeset
|
1095 } |
769599ee9f06
patch 8.2.4770: cannot easily mix expression and heredoc
Bram Moolenaar <Bram@vim.org>
parents:
28382
diff
changeset
|
1096 break; |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1097 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1098 skip_until = vim_strnsave(p, skiptowhite(p) - p); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1099 getline_options = GETLINE_NONE; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1100 is_heredoc = TRUE; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1101 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1102 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1103 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1104 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1105 // Add the line to the function. |
28382
f24d4826e6bf
patch 8.2.4716: memory allocation failure not tested when defining a function
Bram Moolenaar <Bram@vim.org>
parents:
28313
diff
changeset
|
1106 if (ga_grow_id(newlines, 1 + sourcing_lnum_off, aid_get_func) == FAIL) |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1107 goto theend; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1108 |
24826
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1109 if (heredoc_concat_len > 0) |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1110 { |
26771
fc859aea8cec
patch 8.2.3914: various spelling mistakes in comments
Bram Moolenaar <Bram@vim.org>
parents:
26757
diff
changeset
|
1111 // For a :def function "python << EOF" concatenates all the lines, |
24826
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1112 // to be used for the instruction later. |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1113 ga_concat(&heredoc_ga, theline); |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1114 ga_concat(&heredoc_ga, (char_u *)"\n"); |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1115 p = vim_strsave((char_u *)""); |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1116 } |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1117 else |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1118 { |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1119 // Copy the line to newly allocated memory. get_one_sourceline() |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1120 // allocates 250 bytes per line, this saves 80% on average. The |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1121 // cost is an extra alloc/free. |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1122 p = vim_strsave(theline); |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1123 } |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1124 if (p == NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1125 goto theend; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1126 ((char_u **)(newlines->ga_data))[newlines->ga_len++] = p; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1127 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1128 // Add NULL lines for continuation lines, so that the line count is |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1129 // equal to the index in the growarray. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1130 while (sourcing_lnum_off-- > 0) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1131 ((char_u **)(newlines->ga_data))[newlines->ga_len++] = NULL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1132 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1133 // Check for end of eap->arg. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1134 if (line_arg != NULL && *line_arg == NUL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1135 line_arg = NULL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1136 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1137 |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1138 // Return OK when no error was detected. |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1139 if (!did_emsg) |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1140 ret = OK; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1141 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1142 theend: |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1143 vim_free(skip_until); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1144 vim_free(heredoc_trimmed); |
24826
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1145 vim_free(heredoc_ga.ga_data); |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1146 need_wait_return |= saved_wait_return; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1147 return ret; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1148 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1149 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1150 /* |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1151 * Handle the body of a lambda. *arg points to the "{", process statements |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1152 * until the matching "}". |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1153 * When not evaluating "newargs" is NULL. |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1154 * When successful "rettv" is set to a funcref. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1155 */ |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1156 static int |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1157 lambda_function_body( |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1158 char_u **arg, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1159 typval_T *rettv, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1160 evalarg_T *evalarg, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1161 garray_T *newargs, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1162 garray_T *argtypes, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1163 int varargs, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1164 garray_T *default_args, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1165 char_u *ret_type) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1166 { |
24422
41cf1155ab90
patch 8.2.2751: Coverity warns for using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
24412
diff
changeset
|
1167 int evaluate = (evalarg->eval_flags & EVAL_EVALUATE); |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1168 garray_T *gap = &evalarg->eval_ga; |
24655
3876d9629ebd
patch 8.2.2866: Vim9: memory leak when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24653
diff
changeset
|
1169 garray_T *freegap = &evalarg->eval_freega; |
24244
827fcf174f15
patch 8.2.2663: Vim9: leaking memory when inline function has an error
Bram Moolenaar <Bram@vim.org>
parents:
24208
diff
changeset
|
1170 ufunc_T *ufunc = NULL; |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1171 exarg_T eap; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1172 garray_T newlines; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1173 char_u *cmdline = NULL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1174 int ret = FAIL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1175 partial_T *pt; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1176 char_u *name; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1177 int lnum_save = -1; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1178 linenr_T sourcing_lnum_top = SOURCING_LNUM; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1179 |
24202
c50c5464e6dc
patch 8.2.2642: Vim9: no clear error for wrong inline function
Bram Moolenaar <Bram@vim.org>
parents:
24190
diff
changeset
|
1180 if (!ends_excmd2(*arg, skipwhite(*arg + 1))) |
c50c5464e6dc
patch 8.2.2642: Vim9: no clear error for wrong inline function
Bram Moolenaar <Bram@vim.org>
parents:
24190
diff
changeset
|
1181 { |
26883
7f150a4936f2
patch 8.2.3970: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
1182 semsg(_(e_trailing_characters_str), *arg + 1); |
24202
c50c5464e6dc
patch 8.2.2642: Vim9: no clear error for wrong inline function
Bram Moolenaar <Bram@vim.org>
parents:
24190
diff
changeset
|
1183 return FAIL; |
c50c5464e6dc
patch 8.2.2642: Vim9: no clear error for wrong inline function
Bram Moolenaar <Bram@vim.org>
parents:
24190
diff
changeset
|
1184 } |
c50c5464e6dc
patch 8.2.2642: Vim9: no clear error for wrong inline function
Bram Moolenaar <Bram@vim.org>
parents:
24190
diff
changeset
|
1185 |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1186 CLEAR_FIELD(eap); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1187 eap.cmdidx = CMD_block; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1188 eap.forceit = FALSE; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1189 eap.cmdlinep = &cmdline; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1190 eap.skip = !evaluate; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1191 if (evalarg->eval_cctx != NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1192 fill_exarg_from_cctx(&eap, evalarg->eval_cctx); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1193 else |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1194 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1195 eap.getline = evalarg->eval_getline; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1196 eap.cookie = evalarg->eval_cookie; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1197 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1198 |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
1199 ga_init2(&newlines, sizeof(char_u *), 10); |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
1200 if (get_function_body(&eap, &newlines, NULL, |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
1201 &evalarg->eval_tofree_ga) == FAIL) |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1202 goto erret; |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1203 |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1204 // When inside a lambda must add the function lines to evalarg.eval_ga. |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1205 evalarg->eval_break_count += newlines.ga_len; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1206 if (gap->ga_itemsize > 0) |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1207 { |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1208 int idx; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1209 char_u *last; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1210 size_t plen; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1211 char_u *pnl; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1212 |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1213 for (idx = 0; idx < newlines.ga_len; ++idx) |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1214 { |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1215 char_u *p = skipwhite(((char_u **)newlines.ga_data)[idx]); |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1216 |
24655
3876d9629ebd
patch 8.2.2866: Vim9: memory leak when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24653
diff
changeset
|
1217 if (ga_grow(gap, 1) == FAIL || ga_grow(freegap, 1) == FAIL) |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1218 goto erret; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1219 |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1220 // Going to concatenate the lines after parsing. For an empty or |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1221 // comment line use an empty string. |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1222 // Insert NL characters at the start of each line, the string will |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1223 // be split again later in .get_lambda_tv(). |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1224 if (*p == NUL || vim9_comment_start(p)) |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1225 p = (char_u *)""; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1226 plen = STRLEN(p); |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1227 pnl = vim_strnsave((char_u *)"\n", plen + 1); |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1228 if (pnl != NULL) |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1229 mch_memmove(pnl + 1, p, plen + 1); |
24655
3876d9629ebd
patch 8.2.2866: Vim9: memory leak when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24653
diff
changeset
|
1230 ((char_u **)gap->ga_data)[gap->ga_len++] = pnl; |
3876d9629ebd
patch 8.2.2866: Vim9: memory leak when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24653
diff
changeset
|
1231 ((char_u **)freegap->ga_data)[freegap->ga_len++] = pnl; |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1232 } |
24655
3876d9629ebd
patch 8.2.2866: Vim9: memory leak when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24653
diff
changeset
|
1233 if (ga_grow(gap, 1) == FAIL || ga_grow(freegap, 1) == FAIL) |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1234 goto erret; |
26747
a8a4e1e7b111
patch 8.2.3902: Vim9: double free with nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
1235 if (eap.nextcmd != NULL) |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1236 // more is following after the "}", which was skipped |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1237 last = cmdline; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1238 else |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1239 // nothing is following the "}" |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1240 last = (char_u *)"}"; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1241 plen = STRLEN(last); |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1242 pnl = vim_strnsave((char_u *)"\n", plen + 1); |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1243 if (pnl != NULL) |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1244 mch_memmove(pnl + 1, last, plen + 1); |
24655
3876d9629ebd
patch 8.2.2866: Vim9: memory leak when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24653
diff
changeset
|
1245 ((char_u **)gap->ga_data)[gap->ga_len++] = pnl; |
3876d9629ebd
patch 8.2.2866: Vim9: memory leak when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24653
diff
changeset
|
1246 ((char_u **)freegap->ga_data)[freegap->ga_len++] = pnl; |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1247 } |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1248 |
26747
a8a4e1e7b111
patch 8.2.3902: Vim9: double free with nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
1249 if (eap.nextcmd != NULL) |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1250 { |
26053
e861c5aaedd8
patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents:
26046
diff
changeset
|
1251 garray_T *tfgap = &evalarg->eval_tofree_ga; |
e861c5aaedd8
patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents:
26046
diff
changeset
|
1252 |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1253 // Something comes after the "}". |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1254 *arg = eap.nextcmd; |
24190
5f3a2d31c48d
patch 8.2.2636: memory leak when compiling inline function
Bram Moolenaar <Bram@vim.org>
parents:
24188
diff
changeset
|
1255 |
5f3a2d31c48d
patch 8.2.2636: memory leak when compiling inline function
Bram Moolenaar <Bram@vim.org>
parents:
24188
diff
changeset
|
1256 // "arg" points into cmdline, need to keep the line and free it later. |
26053
e861c5aaedd8
patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents:
26046
diff
changeset
|
1257 if (ga_grow(tfgap, 1) == OK) |
e861c5aaedd8
patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents:
26046
diff
changeset
|
1258 { |
e861c5aaedd8
patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents:
26046
diff
changeset
|
1259 ((char_u **)(tfgap->ga_data))[tfgap->ga_len++] = cmdline; |
e861c5aaedd8
patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents:
26046
diff
changeset
|
1260 evalarg->eval_using_cmdline = TRUE; |
e861c5aaedd8
patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents:
26046
diff
changeset
|
1261 } |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1262 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1263 else |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1264 *arg = (char_u *)""; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1265 |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1266 if (!evaluate) |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1267 { |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1268 ret = OK; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1269 goto erret; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1270 } |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1271 |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1272 name = get_lambda_name(); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1273 ufunc = alloc_clear(offsetof(ufunc_T, uf_name) + STRLEN(name) + 1); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1274 if (ufunc == NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1275 goto erret; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1276 set_ufunc_name(ufunc, name); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1277 if (hash_add(&func_hashtab, UF2HIKEY(ufunc)) == FAIL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1278 goto erret; |
26323
3841da4eac23
patch 8.2.3692: Vim9: cannot use :func inside a :def function
Bram Moolenaar <Bram@vim.org>
parents:
26205
diff
changeset
|
1279 ufunc->uf_flags = FC_LAMBDA; |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1280 ufunc->uf_refcount = 1; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1281 ufunc->uf_args = *newargs; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1282 newargs->ga_data = NULL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1283 ufunc->uf_def_args = *default_args; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1284 default_args->ga_data = NULL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1285 ufunc->uf_func_type = &t_func_any; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1286 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1287 // error messages are for the first function line |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1288 lnum_save = SOURCING_LNUM; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1289 SOURCING_LNUM = sourcing_lnum_top; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1290 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1291 // parse argument types |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1292 if (parse_argument_types(ufunc, argtypes, varargs) == FAIL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1293 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1294 SOURCING_LNUM = lnum_save; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1295 goto erret; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1296 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1297 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1298 // parse the return type, if any |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1299 if (parse_return_type(ufunc, ret_type) == FAIL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1300 goto erret; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1301 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1302 pt = ALLOC_CLEAR_ONE(partial_T); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1303 if (pt == NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1304 goto erret; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1305 pt->pt_func = ufunc; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1306 pt->pt_refcount = 1; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1307 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1308 ufunc->uf_lines = newlines; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1309 newlines.ga_data = NULL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1310 if (sandbox) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1311 ufunc->uf_flags |= FC_SANDBOX; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1312 if (!ASCII_ISUPPER(*ufunc->uf_name)) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1313 ufunc->uf_flags |= FC_VIM9; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1314 ufunc->uf_script_ctx = current_sctx; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1315 ufunc->uf_script_ctx_version = current_sctx.sc_version; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1316 ufunc->uf_script_ctx.sc_lnum += sourcing_lnum_top; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1317 set_function_type(ufunc); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1318 |
25358
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
1319 function_using_block_scopes(ufunc, evalarg->eval_cstack); |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
1320 |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1321 rettv->vval.v_partial = pt; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1322 rettv->v_type = VAR_PARTIAL; |
24244
827fcf174f15
patch 8.2.2663: Vim9: leaking memory when inline function has an error
Bram Moolenaar <Bram@vim.org>
parents:
24208
diff
changeset
|
1323 ufunc = NULL; |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1324 ret = OK; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1325 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1326 erret: |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1327 if (lnum_save >= 0) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1328 SOURCING_LNUM = lnum_save; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1329 ga_clear_strings(&newlines); |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1330 if (newargs != NULL) |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1331 ga_clear_strings(newargs); |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1332 ga_clear_strings(default_args); |
24244
827fcf174f15
patch 8.2.2663: Vim9: leaking memory when inline function has an error
Bram Moolenaar <Bram@vim.org>
parents:
24208
diff
changeset
|
1333 if (ufunc != NULL) |
827fcf174f15
patch 8.2.2663: Vim9: leaking memory when inline function has an error
Bram Moolenaar <Bram@vim.org>
parents:
24208
diff
changeset
|
1334 { |
827fcf174f15
patch 8.2.2663: Vim9: leaking memory when inline function has an error
Bram Moolenaar <Bram@vim.org>
parents:
24208
diff
changeset
|
1335 func_clear(ufunc, TRUE); |
827fcf174f15
patch 8.2.2663: Vim9: leaking memory when inline function has an error
Bram Moolenaar <Bram@vim.org>
parents:
24208
diff
changeset
|
1336 func_free(ufunc, TRUE); |
827fcf174f15
patch 8.2.2663: Vim9: leaking memory when inline function has an error
Bram Moolenaar <Bram@vim.org>
parents:
24208
diff
changeset
|
1337 } |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1338 return ret; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1339 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1340 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1341 /* |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1342 * Parse a lambda expression and get a Funcref from "*arg" into "rettv". |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1343 * "arg" points to the { in "{arg -> expr}" or the ( in "(arg) => expr" |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
1344 * When "types_optional" is TRUE optionally take argument types. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1345 * 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
|
1346 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1347 int |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
1348 get_lambda_tv( |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
1349 char_u **arg, |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
1350 typval_T *rettv, |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
1351 int types_optional, |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
1352 evalarg_T *evalarg) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1353 { |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21032
diff
changeset
|
1354 int evaluate = evalarg != NULL |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21032
diff
changeset
|
1355 && (evalarg->eval_flags & EVAL_EVALUATE); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1356 garray_T newargs; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1357 garray_T newlines; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1358 garray_T *pnewargs; |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
1359 garray_T argtypes; |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1360 garray_T default_args; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1361 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
|
1362 partial_T *pt = NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1363 int varargs; |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1364 char_u *ret_type = NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1365 int ret; |
21220
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21218
diff
changeset
|
1366 char_u *s; |
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21218
diff
changeset
|
1367 char_u *start, *end; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1368 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
|
1369 int eval_lavars = FALSE; |
23644
03acf9c49f07
patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents:
23630
diff
changeset
|
1370 char_u *tofree1 = NULL; |
03acf9c49f07
patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents:
23630
diff
changeset
|
1371 char_u *tofree2 = NULL; |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1372 int equal_arrow = **arg == '('; |
23338
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
1373 int white_error = FALSE; |
23808
baf9069f64ca
patch 8.2.2445: Vim9: no proper error for lambda missing return type
Bram Moolenaar <Bram@vim.org>
parents:
23727
diff
changeset
|
1374 int called_emsg_start = called_emsg; |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
1375 int vim9script = in_vim9script(); |
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
1376 |
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
1377 if (equal_arrow && !vim9script) |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1378 return NOTDONE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1379 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1380 ga_init(&newargs); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1381 ga_init(&newlines); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1382 |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1383 // First, check if this is really a lambda expression. "->" or "=>" must |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1384 // be found after the arguments. |
23511
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
1385 s = *arg + 1; |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1386 ret = get_function_args(&s, equal_arrow ? ')' : '-', NULL, |
24033
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
24004
diff
changeset
|
1387 types_optional ? &argtypes : NULL, types_optional, evalarg, |
25038
efdb9608cc11
patch 8.2.3056: Vim9: using default value in lambda gives confusing error
Bram Moolenaar <Bram@vim.org>
parents:
24988
diff
changeset
|
1388 NULL, &default_args, TRUE, NULL, NULL); |
23338
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
1389 if (ret == FAIL || skip_arrow(s, equal_arrow, &ret_type, NULL) == NULL) |
23320
1d11e3adbe52
patch 8.2.2205: Vim9: memory leak when parsing lambda fails
Bram Moolenaar <Bram@vim.org>
parents:
23318
diff
changeset
|
1390 { |
1d11e3adbe52
patch 8.2.2205: Vim9: memory leak when parsing lambda fails
Bram Moolenaar <Bram@vim.org>
parents:
23318
diff
changeset
|
1391 if (types_optional) |
1d11e3adbe52
patch 8.2.2205: Vim9: memory leak when parsing lambda fails
Bram Moolenaar <Bram@vim.org>
parents:
23318
diff
changeset
|
1392 ga_clear_strings(&argtypes); |
23808
baf9069f64ca
patch 8.2.2445: Vim9: no proper error for lambda missing return type
Bram Moolenaar <Bram@vim.org>
parents:
23727
diff
changeset
|
1393 return called_emsg == called_emsg_start ? NOTDONE : FAIL; |
23320
1d11e3adbe52
patch 8.2.2205: Vim9: memory leak when parsing lambda fails
Bram Moolenaar <Bram@vim.org>
parents:
23318
diff
changeset
|
1394 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1395 |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1396 // Parse the arguments for real. |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1397 if (evaluate) |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1398 pnewargs = &newargs; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1399 else |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1400 pnewargs = NULL; |
23511
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
1401 *arg += 1; |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1402 ret = get_function_args(arg, equal_arrow ? ')' : '-', pnewargs, |
24033
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
24004
diff
changeset
|
1403 types_optional ? &argtypes : NULL, types_optional, evalarg, |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1404 &varargs, &default_args, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1405 FALSE, NULL, NULL); |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1406 if (ret == FAIL |
23338
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
1407 || (s = skip_arrow(*arg, equal_arrow, &ret_type, |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
1408 equal_arrow || vim9script ? &white_error : NULL)) == NULL) |
23320
1d11e3adbe52
patch 8.2.2205: Vim9: memory leak when parsing lambda fails
Bram Moolenaar <Bram@vim.org>
parents:
23318
diff
changeset
|
1409 { |
1d11e3adbe52
patch 8.2.2205: Vim9: memory leak when parsing lambda fails
Bram Moolenaar <Bram@vim.org>
parents:
23318
diff
changeset
|
1410 if (types_optional) |
1d11e3adbe52
patch 8.2.2205: Vim9: memory leak when parsing lambda fails
Bram Moolenaar <Bram@vim.org>
parents:
23318
diff
changeset
|
1411 ga_clear_strings(&argtypes); |
23354
611e19cd237d
patch 8.2.2220: Vim9: memory leak when parsing nested parenthesis
Bram Moolenaar <Bram@vim.org>
parents:
23340
diff
changeset
|
1412 ga_clear_strings(&newargs); |
23338
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
1413 return white_error ? FAIL : NOTDONE; |
23320
1d11e3adbe52
patch 8.2.2205: Vim9: memory leak when parsing lambda fails
Bram Moolenaar <Bram@vim.org>
parents:
23318
diff
changeset
|
1414 } |
23338
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
1415 *arg = s; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1416 |
23644
03acf9c49f07
patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents:
23630
diff
changeset
|
1417 // Skipping over linebreaks may make "ret_type" invalid, make a copy. |
03acf9c49f07
patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents:
23630
diff
changeset
|
1418 if (ret_type != NULL) |
03acf9c49f07
patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents:
23630
diff
changeset
|
1419 { |
03acf9c49f07
patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents:
23630
diff
changeset
|
1420 ret_type = vim_strsave(ret_type); |
03acf9c49f07
patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents:
23630
diff
changeset
|
1421 tofree2 = ret_type; |
03acf9c49f07
patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents:
23630
diff
changeset
|
1422 } |
03acf9c49f07
patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents:
23630
diff
changeset
|
1423 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1424 // 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
|
1425 if (evaluate) |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1426 eval_lavars_used = &eval_lavars; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1427 |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1428 *arg = skipwhite_and_linebreak(*arg, evalarg); |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1429 |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1430 // Recognize "{" as the start of a function body. |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1431 if (equal_arrow && **arg == '{') |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1432 { |
24422
41cf1155ab90
patch 8.2.2751: Coverity warns for using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
24412
diff
changeset
|
1433 if (evalarg == NULL) |
41cf1155ab90
patch 8.2.2751: Coverity warns for using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
24412
diff
changeset
|
1434 // cannot happen? |
41cf1155ab90
patch 8.2.2751: Coverity warns for using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
24412
diff
changeset
|
1435 goto theend; |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1436 if (lambda_function_body(arg, rettv, evalarg, pnewargs, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1437 types_optional ? &argtypes : NULL, varargs, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1438 &default_args, ret_type) == FAIL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1439 goto errret; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1440 goto theend; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1441 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1442 if (default_args.ga_len > 0) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1443 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1444 emsg(_(e_cannot_use_default_values_in_lambda)); |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1445 goto errret; |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1446 } |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1447 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1448 // Get the start and the end of the expression. |
21220
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21218
diff
changeset
|
1449 start = *arg; |
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21218
diff
changeset
|
1450 ret = skip_expr_concatenate(arg, &start, &end, evalarg); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1451 if (ret == FAIL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1452 goto errret; |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21032
diff
changeset
|
1453 if (evalarg != NULL) |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21032
diff
changeset
|
1454 { |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21032
diff
changeset
|
1455 // avoid that the expression gets freed when another line break follows |
23644
03acf9c49f07
patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents:
23630
diff
changeset
|
1456 tofree1 = evalarg->eval_tofree; |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21032
diff
changeset
|
1457 evalarg->eval_tofree = NULL; |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21032
diff
changeset
|
1458 } |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21032
diff
changeset
|
1459 |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1460 if (!equal_arrow) |
19826
293a22b677a8
patch 8.2.0469: Vim9: no error for missing ] after list
Bram Moolenaar <Bram@vim.org>
parents:
19685
diff
changeset
|
1461 { |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1462 *arg = skipwhite_and_linebreak(*arg, evalarg); |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1463 if (**arg != '}') |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1464 { |
26915
3631d2deb36c
patch 8.2.3986: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26897
diff
changeset
|
1465 semsg(_(e_expected_right_curly_str), *arg); |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1466 goto errret; |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1467 } |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1468 ++*arg; |
19826
293a22b677a8
patch 8.2.0469: Vim9: no error for missing ] after list
Bram Moolenaar <Bram@vim.org>
parents:
19685
diff
changeset
|
1469 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1470 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1471 if (evaluate) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1472 { |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21032
diff
changeset
|
1473 int len; |
26323
3841da4eac23
patch 8.2.3692: Vim9: cannot use :func inside a :def function
Bram Moolenaar <Bram@vim.org>
parents:
26205
diff
changeset
|
1474 int flags = FC_LAMBDA; |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
1475 char_u *p; |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1476 char_u *line_end; |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
1477 char_u *name = get_lambda_name(); |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1478 |
17659
121bdff812b4
patch 8.1.1827: allocating more memory than needed for extended structs
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
1479 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
|
1480 if (fp == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1481 goto errret; |
20943
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
1482 fp->uf_def_status = UF_NOT_COMPILED; |
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
|
1483 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
|
1484 if (pt == NULL) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
1485 goto errret; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1486 |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
1487 ga_init2(&newlines, sizeof(char_u *), 1); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1488 if (ga_grow(&newlines, 1) == FAIL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1489 goto errret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1490 |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1491 // If there are line breaks, we need to split up the string. |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1492 line_end = vim_strchr(start, '\n'); |
25396
8ecd3575bc8c
patch 8.2.3235: cannot use lambda in {} block in user command
Bram Moolenaar <Bram@vim.org>
parents:
25358
diff
changeset
|
1493 if (line_end == NULL || line_end > end) |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1494 line_end = end; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1495 |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1496 // Add "return " before the expression (or the first line). |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1497 len = 7 + (int)(line_end - start) + 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
|
1498 p = alloc(len); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1499 if (p == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1500 goto errret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1501 ((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
|
1502 STRCPY(p, "return "); |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1503 vim_strncpy(p + 7, start, line_end - start); |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1504 |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1505 if (line_end != end) |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1506 { |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1507 // Add more lines, split by line breaks. Thus is used when a |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1508 // lambda with { cmds } is encountered. |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1509 while (*line_end == '\n') |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1510 { |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1511 if (ga_grow(&newlines, 1) == FAIL) |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1512 goto errret; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1513 start = line_end + 1; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1514 line_end = vim_strchr(start, '\n'); |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1515 if (line_end == NULL) |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1516 line_end = end; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1517 ((char_u **)(newlines.ga_data))[newlines.ga_len++] = |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1518 vim_strnsave(start, line_end - start); |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1519 } |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1520 } |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1521 |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
1522 if (strstr((char *)p + 7, "a:") == NULL) |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
1523 // No a: variables are used for sure. |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
1524 flags |= FC_NOARGS; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1525 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1526 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
|
1527 set_ufunc_name(fp, name); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1528 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
|
1529 ga_init(&fp->uf_def_args); |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1530 if (types_optional) |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1531 { |
24400
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
1532 if (parse_argument_types(fp, &argtypes, |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
1533 vim9script && varargs) == FAIL) |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1534 goto errret; |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1535 if (ret_type != NULL) |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1536 { |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1537 fp->uf_ret_type = parse_type(&ret_type, |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1538 &fp->uf_type_list, TRUE); |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1539 if (fp->uf_ret_type == NULL) |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1540 goto errret; |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1541 } |
23420
42294d4d4f6e
patch 8.2.2253: Vim9: expr test fails
Bram Moolenaar <Bram@vim.org>
parents:
23398
diff
changeset
|
1542 else |
24890
0cba2be8cbd7
patch 8.2.2983: Vim9: an inline function requires specifying the return type
Bram Moolenaar <Bram@vim.org>
parents:
24826
diff
changeset
|
1543 fp->uf_ret_type = &t_unknown; |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1544 } |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
1545 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1546 fp->uf_lines = newlines; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1547 if (current_funccal != NULL && eval_lavars) |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1548 { |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
1549 flags |= FC_CLOSURE; |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
1550 if (register_closure(fp) == FAIL) |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1551 goto errret; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1552 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1553 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1554 #ifdef FEAT_PROFILE |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1555 if (prof_def_func()) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1556 func_do_profile(fp); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1557 #endif |
14323
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1558 if (sandbox) |
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1559 flags |= FC_SANDBOX; |
24398
bed5ec739304
patch 8.2.2739: Vim9: a lambda accepts too many arguments at the script level
Bram Moolenaar <Bram@vim.org>
parents:
24371
diff
changeset
|
1560 // In legacy script a lambda can be called with more args than |
24400
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
1561 // uf_args.ga_len. In Vim9 script "...name" has to be used. |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
1562 fp->uf_varargs = !vim9script || varargs; |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
1563 fp->uf_flags = flags; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1564 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
|
1565 fp->uf_script_ctx = current_sctx; |
26203
a968027f8a2c
patch 8.2.3633: Vim9: line number of lambda is off by one
Bram Moolenaar <Bram@vim.org>
parents:
26053
diff
changeset
|
1566 fp->uf_script_ctx.sc_lnum += SOURCING_LNUM - newlines.ga_len + 1; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1567 |
25358
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
1568 function_using_block_scopes(fp, evalarg->eval_cstack); |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
1569 |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
1570 pt->pt_func = fp; |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
1571 pt->pt_refcount = 1; |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
1572 rettv->vval.v_partial = pt; |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
1573 rettv->v_type = VAR_PARTIAL; |
24033
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
24004
diff
changeset
|
1574 |
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
24004
diff
changeset
|
1575 hash_add(&func_hashtab, UF2HIKEY(fp)); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1576 } |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1577 |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1578 theend: |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1579 eval_lavars_used = old_eval_lavars; |
21222
a4d00a2dadd6
patch 8.2.1162: crash when using a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21220
diff
changeset
|
1580 if (evalarg != NULL && evalarg->eval_tofree == NULL) |
23644
03acf9c49f07
patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents:
23630
diff
changeset
|
1581 evalarg->eval_tofree = tofree1; |
21220
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21218
diff
changeset
|
1582 else |
23644
03acf9c49f07
patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents:
23630
diff
changeset
|
1583 vim_free(tofree1); |
03acf9c49f07
patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents:
23630
diff
changeset
|
1584 vim_free(tofree2); |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
1585 if (types_optional) |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
1586 ga_clear_strings(&argtypes); |
25358
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
1587 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1588 return OK; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1589 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1590 errret: |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1591 ga_clear_strings(&newargs); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1592 ga_clear_strings(&newlines); |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1593 ga_clear_strings(&default_args); |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
1594 if (types_optional) |
24687
0668fe755d2b
patch 8.2.2882: Vim9: memory leak when lambda has an error
Bram Moolenaar <Bram@vim.org>
parents:
24655
diff
changeset
|
1595 { |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
1596 ga_clear_strings(&argtypes); |
24687
0668fe755d2b
patch 8.2.2882: Vim9: memory leak when lambda has an error
Bram Moolenaar <Bram@vim.org>
parents:
24655
diff
changeset
|
1597 if (fp != NULL) |
0668fe755d2b
patch 8.2.2882: Vim9: memory leak when lambda has an error
Bram Moolenaar <Bram@vim.org>
parents:
24655
diff
changeset
|
1598 vim_free(fp->uf_arg_types); |
0668fe755d2b
patch 8.2.2882: Vim9: memory leak when lambda has an error
Bram Moolenaar <Bram@vim.org>
parents:
24655
diff
changeset
|
1599 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1600 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
|
1601 vim_free(pt); |
21222
a4d00a2dadd6
patch 8.2.1162: crash when using a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21220
diff
changeset
|
1602 if (evalarg != NULL && evalarg->eval_tofree == NULL) |
23644
03acf9c49f07
patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents:
23630
diff
changeset
|
1603 evalarg->eval_tofree = tofree1; |
21220
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21218
diff
changeset
|
1604 else |
23644
03acf9c49f07
patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents:
23630
diff
changeset
|
1605 vim_free(tofree1); |
03acf9c49f07
patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents:
23630
diff
changeset
|
1606 vim_free(tofree2); |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1607 eval_lavars_used = old_eval_lavars; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1608 return FAIL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1609 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1610 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1611 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1612 * 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
|
1613 * name it contains, otherwise return "name". |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1614 * 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
|
1615 * "partialp". |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1616 * If "type" is not NULL and a Vim9 script-local variable is found look up the |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1617 * type of the variable. |
27233
73232ed49cf2
patch 8.2.4145: confusing error when using name of import for a function
Bram Moolenaar <Bram@vim.org>
parents:
27189
diff
changeset
|
1618 * If "new_function" is TRUE the name is for a new function. |
26506
4a1d2abc2016
patch 8.2.3783: confusing error for using a variable as a function
Bram Moolenaar <Bram@vim.org>
parents:
26504
diff
changeset
|
1619 * If "found_var" is not NULL and a variable was found set it to TRUE. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1620 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1621 char_u * |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1622 deref_func_name( |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1623 char_u *name, |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1624 int *lenp, |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1625 partial_T **partialp, |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1626 type_T **type, |
26506
4a1d2abc2016
patch 8.2.3783: confusing error for using a variable as a function
Bram Moolenaar <Bram@vim.org>
parents:
26504
diff
changeset
|
1627 int no_autoload, |
27233
73232ed49cf2
patch 8.2.4145: confusing error when using name of import for a function
Bram Moolenaar <Bram@vim.org>
parents:
27189
diff
changeset
|
1628 int new_function, |
26506
4a1d2abc2016
patch 8.2.3783: confusing error for using a variable as a function
Bram Moolenaar <Bram@vim.org>
parents:
26504
diff
changeset
|
1629 int *found_var) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1630 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1631 dictitem_T *v; |
26046
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1632 typval_T *tv = NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1633 int cc; |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1634 char_u *s = NULL; |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1635 hashtab_T *ht; |
26046
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1636 int did_type = FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1637 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1638 if (partialp != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1639 *partialp = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1640 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1641 cc = name[*lenp]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1642 name[*lenp] = NUL; |
24826
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1643 |
27002
cf5b5e95f62b
patch 8.2.4030: a script local funcref is not found from a mapping
Bram Moolenaar <Bram@vim.org>
parents:
26990
diff
changeset
|
1644 v = find_var_also_in_script(name, &ht, no_autoload); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1645 name[*lenp] = cc; |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1646 if (v != NULL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1647 { |
26046
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1648 tv = &v->di_tv; |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1649 } |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1650 else if (in_vim9script() || STRNCMP(name, "s:", 2) == 0) |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1651 { |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1652 imported_T *import; |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1653 char_u *p = name; |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1654 int len = *lenp; |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1655 |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1656 if (STRNCMP(name, "s:", 2) == 0) |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1657 { |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1658 p = name + 2; |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1659 len -= 2; |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1660 } |
27698
3813036f19cb
patch 8.2.4375: ctx_imports is not used
Bram Moolenaar <Bram@vim.org>
parents:
27682
diff
changeset
|
1661 import = find_imported(p, len, FALSE); |
26046
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1662 |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
1663 // imported function from another script |
26046
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1664 if (import != NULL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1665 { |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
1666 name[len] = NUL; |
27233
73232ed49cf2
patch 8.2.4145: confusing error when using name of import for a function
Bram Moolenaar <Bram@vim.org>
parents:
27189
diff
changeset
|
1667 if (new_function) |
73232ed49cf2
patch 8.2.4145: confusing error when using name of import for a function
Bram Moolenaar <Bram@vim.org>
parents:
27189
diff
changeset
|
1668 semsg(_(e_redefining_imported_item_str), name); |
73232ed49cf2
patch 8.2.4145: confusing error when using name of import for a function
Bram Moolenaar <Bram@vim.org>
parents:
27189
diff
changeset
|
1669 else |
73232ed49cf2
patch 8.2.4145: confusing error when using name of import for a function
Bram Moolenaar <Bram@vim.org>
parents:
27189
diff
changeset
|
1670 semsg(_(e_cannot_use_str_itself_it_is_imported), name); |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
1671 name[len] = cc; |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
1672 *lenp = 0; |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
1673 return (char_u *)""; // just in case |
26046
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1674 } |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1675 } |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1676 |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1677 if (tv != NULL) |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1678 { |
26506
4a1d2abc2016
patch 8.2.3783: confusing error for using a variable as a function
Bram Moolenaar <Bram@vim.org>
parents:
26504
diff
changeset
|
1679 if (found_var != NULL) |
4a1d2abc2016
patch 8.2.3783: confusing error for using a variable as a function
Bram Moolenaar <Bram@vim.org>
parents:
26504
diff
changeset
|
1680 *found_var = TRUE; |
26046
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1681 if (tv->v_type == VAR_FUNC) |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1682 { |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1683 if (tv->vval.v_string == NULL) |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1684 { |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1685 *lenp = 0; |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1686 return (char_u *)""; // just in case |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1687 } |
26046
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1688 s = tv->vval.v_string; |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1689 *lenp = (int)STRLEN(s); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1690 } |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1691 |
26046
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1692 if (tv->v_type == VAR_PARTIAL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1693 { |
26046
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1694 partial_T *pt = tv->vval.v_partial; |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1695 |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1696 if (pt == NULL) |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1697 { |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1698 *lenp = 0; |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1699 return (char_u *)""; // just in case |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1700 } |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1701 if (partialp != NULL) |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1702 *partialp = pt; |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1703 s = partial_name(pt); |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1704 *lenp = (int)STRLEN(s); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1705 } |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1706 |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1707 if (s != NULL) |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1708 { |
26046
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1709 if (!did_type && type != NULL && ht == get_script_local_ht()) |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1710 { |
28313
b418e073b42f
patch 8.2.4682: Vim9: can use :unlockvar for const variable
Bram Moolenaar <Bram@vim.org>
parents:
28267
diff
changeset
|
1711 svar_T *sv = find_typval_in_script(tv, 0, TRUE); |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1712 |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1713 if (sv != NULL) |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1714 *type = sv->sv_type; |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1715 } |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1716 return s; |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1717 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1718 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1719 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1720 return name; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1721 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1722 |
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 * 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
|
1725 * "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
|
1726 */ |
18576
e9675870c480
patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents:
18572
diff
changeset
|
1727 void |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1728 emsg_funcname(char *ermsg, char_u *name) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1729 { |
27088
3956e3bb47ec
patch 8.2.4073: Coverity warns for using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
27076
diff
changeset
|
1730 char_u *p = name; |
3956e3bb47ec
patch 8.2.4073: Coverity warns for using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
27076
diff
changeset
|
1731 |
3956e3bb47ec
patch 8.2.4073: Coverity warns for using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
27076
diff
changeset
|
1732 if (name[0] == K_SPECIAL && name[1] != NUL && name[2] != NUL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1733 p = concat_str((char_u *)"<SNR>", name + 3); |
15470
55ccc2d353bd
patch 8.1.0743: giving error messages is not flexible
Bram Moolenaar <Bram@vim.org>
parents:
15138
diff
changeset
|
1734 semsg(_(ermsg), p); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1735 if (p != name) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1736 vim_free(p); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1737 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1738 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1739 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1740 * 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
|
1741 * Return OK or FAIL. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1742 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1743 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1744 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
|
1745 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
|
1746 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
|
1747 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
|
1748 char_u **arg, // argument, pointing to the '(' |
21118
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21066
diff
changeset
|
1749 evalarg_T *evalarg, // for line continuation |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17462
diff
changeset
|
1750 funcexe_T *funcexe) // various values |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1751 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1752 char_u *argp; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1753 int ret = OK; |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1754 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
|
1755 int argcount = 0; // number of arguments found |
21909
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21883
diff
changeset
|
1756 int vim9script = in_vim9script(); |
27053
58cfcd3ed15b
patch 8.2.4055: Vim9: line break in expression causes v:errmsg to be fillec
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
1757 int evaluate = evalarg == NULL |
58cfcd3ed15b
patch 8.2.4055: Vim9: line break in expression causes v:errmsg to be fillec
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
1758 ? FALSE : (evalarg->eval_flags & EVAL_EVALUATE); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1759 |
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 * Get the arguments. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1762 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1763 argp = *arg; |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
1764 while (argcount < MAX_FUNC_ARGS - (funcexe->fe_partial == NULL ? 0 |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
1765 : funcexe->fe_partial->pt_argc)) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1766 { |
21118
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21066
diff
changeset
|
1767 // skip the '(' or ',' and possibly line breaks |
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21066
diff
changeset
|
1768 argp = skipwhite_and_linebreak(argp + 1, evalarg); |
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21066
diff
changeset
|
1769 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1770 if (*argp == ')' || *argp == ',' || *argp == NUL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1771 break; |
21118
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21066
diff
changeset
|
1772 if (eval1(&argp, &argvars[argcount], evalarg) == FAIL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1773 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1774 ret = FAIL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1775 break; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1776 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1777 ++argcount; |
21552
cbc570e66d11
patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents:
21528
diff
changeset
|
1778 // The comma should come right after the argument, but this wasn't |
cbc570e66d11
patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents:
21528
diff
changeset
|
1779 // checked previously, thus only enforce it in Vim9 script. |
21909
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21883
diff
changeset
|
1780 if (vim9script) |
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21883
diff
changeset
|
1781 { |
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21883
diff
changeset
|
1782 if (*argp != ',' && *skipwhite(argp) == ',') |
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21883
diff
changeset
|
1783 { |
27053
58cfcd3ed15b
patch 8.2.4055: Vim9: line break in expression causes v:errmsg to be fillec
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
1784 if (evaluate) |
58cfcd3ed15b
patch 8.2.4055: Vim9: line break in expression causes v:errmsg to be fillec
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
1785 semsg(_(e_no_white_space_allowed_before_str_str), |
58cfcd3ed15b
patch 8.2.4055: Vim9: line break in expression causes v:errmsg to be fillec
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
1786 ",", argp); |
21909
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21883
diff
changeset
|
1787 ret = FAIL; |
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21883
diff
changeset
|
1788 break; |
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21883
diff
changeset
|
1789 } |
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21883
diff
changeset
|
1790 } |
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21883
diff
changeset
|
1791 else |
21552
cbc570e66d11
patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents:
21528
diff
changeset
|
1792 argp = skipwhite(argp); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1793 if (*argp != ',') |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1794 break; |
21909
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21883
diff
changeset
|
1795 if (vim9script && !IS_WHITE_OR_NUL(argp[1])) |
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21883
diff
changeset
|
1796 { |
27053
58cfcd3ed15b
patch 8.2.4055: Vim9: line break in expression causes v:errmsg to be fillec
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
1797 if (evaluate) |
58cfcd3ed15b
patch 8.2.4055: Vim9: line break in expression causes v:errmsg to be fillec
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
1798 semsg(_(e_white_space_required_after_str_str), ",", argp); |
21909
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21883
diff
changeset
|
1799 ret = FAIL; |
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21883
diff
changeset
|
1800 break; |
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21883
diff
changeset
|
1801 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1802 } |
21118
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21066
diff
changeset
|
1803 argp = skipwhite_and_linebreak(argp, evalarg); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1804 if (*argp == ')') |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1805 ++argp; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1806 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1807 ret = FAIL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1808 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1809 if (ret == OK) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1810 { |
25400
5c7192180b89
patch 8.2.3237: when a builtin function gives an error processing continues
Bram Moolenaar <Bram@vim.org>
parents:
25396
diff
changeset
|
1811 int i = 0; |
5c7192180b89
patch 8.2.3237: when a builtin function gives an error processing continues
Bram Moolenaar <Bram@vim.org>
parents:
25396
diff
changeset
|
1812 int did_emsg_before = did_emsg; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1813 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1814 if (get_vim_var_nr(VV_TESTING)) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1815 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1816 // 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
|
1817 // 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
|
1818 if (funcargs.ga_itemsize == 0) |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
1819 ga_init2(&funcargs, sizeof(typval_T *), 50); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1820 for (i = 0; i < argcount; ++i) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1821 if (ga_grow(&funcargs, 1) == OK) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1822 ((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
|
1823 &argvars[i]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1824 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1825 |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17462
diff
changeset
|
1826 ret = call_func(name, len, rettv, argcount, argvars, funcexe); |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
1827 if (vim9script && did_emsg > did_emsg_before) |
25409
e3f1086429d8
patch 8.2.3241: Vim9: memory leak when function reports an error
Bram Moolenaar <Bram@vim.org>
parents:
25400
diff
changeset
|
1828 { |
25400
5c7192180b89
patch 8.2.3237: when a builtin function gives an error processing continues
Bram Moolenaar <Bram@vim.org>
parents:
25396
diff
changeset
|
1829 // An error in a builtin function does not return FAIL, but we do |
5c7192180b89
patch 8.2.3237: when a builtin function gives an error processing continues
Bram Moolenaar <Bram@vim.org>
parents:
25396
diff
changeset
|
1830 // want to abort further processing if an error was given. |
5c7192180b89
patch 8.2.3237: when a builtin function gives an error processing continues
Bram Moolenaar <Bram@vim.org>
parents:
25396
diff
changeset
|
1831 ret = FAIL; |
25409
e3f1086429d8
patch 8.2.3241: Vim9: memory leak when function reports an error
Bram Moolenaar <Bram@vim.org>
parents:
25400
diff
changeset
|
1832 clear_tv(rettv); |
e3f1086429d8
patch 8.2.3241: Vim9: memory leak when function reports an error
Bram Moolenaar <Bram@vim.org>
parents:
25400
diff
changeset
|
1833 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1834 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1835 funcargs.ga_len -= i; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1836 } |
27053
58cfcd3ed15b
patch 8.2.4055: Vim9: line break in expression causes v:errmsg to be fillec
Bram Moolenaar <Bram@vim.org>
parents:
27049
diff
changeset
|
1837 else if (!aborting() && evaluate) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1838 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1839 if (argcount == MAX_FUNC_ARGS) |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
1840 emsg_funcname(e_too_many_arguments_for_function_str_2, name); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1841 else |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
1842 emsg_funcname(e_invalid_arguments_for_function_str, name); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1843 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1844 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1845 while (--argcount >= 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1846 clear_tv(&argvars[argcount]); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1847 |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
1848 if (vim9script) |
21737
a849c984b485
patch 8.2.1418: Vim9: invalid error for missing white space
Bram Moolenaar <Bram@vim.org>
parents:
21699
diff
changeset
|
1849 *arg = argp; |
a849c984b485
patch 8.2.1418: Vim9: invalid error for missing white space
Bram Moolenaar <Bram@vim.org>
parents:
21699
diff
changeset
|
1850 else |
a849c984b485
patch 8.2.1418: Vim9: invalid error for missing white space
Bram Moolenaar <Bram@vim.org>
parents:
21699
diff
changeset
|
1851 *arg = skipwhite(argp); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1852 return ret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1853 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1854 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1855 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1856 * 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
|
1857 * 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
|
1858 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1859 static int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1860 eval_fname_sid(char_u *p) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1861 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1862 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
|
1863 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1864 |
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 * 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
|
1867 * 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
|
1868 * 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
|
1869 * (slow). |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1870 */ |
19330
9c8b803fe598
patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents:
19328
diff
changeset
|
1871 char_u * |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1872 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
|
1873 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1874 int llen; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1875 char_u *fname; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1876 int i; |
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 llen = eval_fname_script(name); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1879 if (llen > 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1880 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1881 fname_buf[0] = K_SPECIAL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1882 fname_buf[1] = KS_EXTRA; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1883 fname_buf[2] = (int)KE_SNR; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1884 i = 3; |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1885 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
|
1886 { |
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
|
1887 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
|
1888 *error = FCERR_SCRIPT; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1889 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1890 { |
16378
3d6b282e2d6e
patch 8.1.1194: typos and small problems in source files
Bram Moolenaar <Bram@vim.org>
parents:
16003
diff
changeset
|
1891 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
|
1892 (long)current_sctx.sc_sid); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1893 i = (int)STRLEN(fname_buf); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1894 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1895 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1896 if (i + STRLEN(name + llen) < FLEN_FIXED) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1897 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1898 STRCPY(fname_buf + i, name + llen); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1899 fname = fname_buf; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1900 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1901 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1902 { |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16708
diff
changeset
|
1903 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
|
1904 if (fname == NULL) |
19013
dd9ab0674eec
patch 8.2.0067: ERROR_UNKNOWN clashes on some systems
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
1905 *error = FCERR_OTHER; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1906 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1907 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1908 *tofree = fname; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1909 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
|
1910 STRCPY(fname + i, name + llen); |
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 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1913 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1914 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1915 fname = name; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1916 return fname; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1917 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1918 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1919 /* |
28249
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1920 * Concatenate the script ID and function name into "<SNR>99_name". |
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1921 * "buffer" must have size MAX_FUNC_NAME_LEN. |
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1922 */ |
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1923 void |
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1924 func_name_with_sid(char_u *name, int sid, char_u *buffer) |
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1925 { |
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1926 // A script-local function is stored as "<SNR>99_name". |
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1927 buffer[0] = K_SPECIAL; |
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1928 buffer[1] = KS_EXTRA; |
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1929 buffer[2] = (int)KE_SNR; |
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1930 vim_snprintf((char *)buffer + 3, MAX_FUNC_NAME_LEN - 3, "%ld_%s", |
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1931 (long)sid, name); |
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1932 } |
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1933 |
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1934 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1935 * 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
|
1936 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1937 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
|
1938 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
|
1939 { |
27068
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1940 hashitem_T *hi; |
28249
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1941 char_u buffer[MAX_FUNC_NAME_LEN]; |
27068
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1942 |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1943 if (!SCRIPT_ID_VALID(sid)) |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1944 return NULL; // not in a script |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1945 |
28249
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1946 func_name_with_sid(name, sid, buffer); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1947 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
|
1948 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
|
1949 return HI2UF(hi); |
27068
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1950 return NULL; |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1951 } |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1952 |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1953 /* |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1954 * Find a function "name" in script "sid" prefixing the autoload prefix. |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1955 */ |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1956 static ufunc_T * |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1957 find_func_with_prefix(char_u *name, int sid) |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1958 { |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1959 hashitem_T *hi; |
28249
4b322951ebac
patch 8.2.4650: "import autoload" only works with using 'runtimepath'
Bram Moolenaar <Bram@vim.org>
parents:
28123
diff
changeset
|
1960 char_u buffer[MAX_FUNC_NAME_LEN]; |
27068
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1961 scriptitem_T *si; |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1962 |
27464
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
1963 if (vim_strchr(name, AUTOLOAD_CHAR) != NULL) |
27068
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1964 return NULL; // already has the prefix |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1965 if (!SCRIPT_ID_VALID(sid)) |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1966 return NULL; // not in a script |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1967 si = SCRIPT_ITEM(sid); |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1968 if (si->sn_autoload_prefix != NULL) |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1969 { |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1970 size_t len = STRLEN(si->sn_autoload_prefix) + STRLEN(name) + 1; |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1971 char_u *auto_name; |
27267
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
1972 char_u *namep; |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
1973 |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
1974 // skip a "<SNR>99_" prefix |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
1975 namep = untrans_function_name(name); |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
1976 if (namep == NULL) |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
1977 namep = name; |
27068
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1978 |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1979 // An exported function in an autoload script is stored as |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1980 // "dir#path#name". |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1981 if (len < sizeof(buffer)) |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1982 auto_name = buffer; |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1983 else |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1984 auto_name = alloc(len); |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1985 if (auto_name != NULL) |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1986 { |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1987 vim_snprintf((char *)auto_name, len, "%s%s", |
27267
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
1988 si->sn_autoload_prefix, namep); |
27068
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1989 hi = hash_find(&func_hashtab, auto_name); |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1990 if (auto_name != buffer) |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1991 vim_free(auto_name); |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1992 if (!HASHITEM_EMPTY(hi)) |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1993 return HI2UF(hi); |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1994 } |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1995 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1996 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1997 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1998 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1999 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2000 /* |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2001 * Find a function by name, return pointer to it in ufuncs. |
27348
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
2002 * When "flags" has FFED_IS_GLOBAL don't find script-local or imported |
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
2003 * functions. |
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
2004 * When "flags" has "FFED_NO_GLOBAL" don't find global functions. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2005 * Return NULL for unknown function. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2006 */ |
21564
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
2007 ufunc_T * |
27348
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
2008 find_func_even_dead(char_u *name, int flags) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2009 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2010 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
|
2011 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
|
2012 |
27348
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
2013 if ((flags & FFED_IS_GLOBAL) == 0) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2014 { |
27807
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2015 // Find script-local function before global one. |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2016 if (in_vim9script() && eval_isnamec1(*name) |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2017 && (name[1] != ':' || *name == 's')) |
20816
9faab49c880f
patch 8.2.0960: cannot use :import in legacy Vim script
Bram Moolenaar <Bram@vim.org>
parents:
20709
diff
changeset
|
2018 { |
26530
2fbd05a873e3
patch 8.2.3794: Vim9: cannot find script-local func using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
26506
diff
changeset
|
2019 func = find_func_with_sid(name[0] == 's' && name[1] == ':' |
2fbd05a873e3
patch 8.2.3794: Vim9: cannot find script-local func using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
26506
diff
changeset
|
2020 ? name + 2 : name, current_sctx.sc_sid); |
20816
9faab49c880f
patch 8.2.0960: cannot use :import in legacy Vim script
Bram Moolenaar <Bram@vim.org>
parents:
20709
diff
changeset
|
2021 if (func != NULL) |
9faab49c880f
patch 8.2.0960: cannot use :import in legacy Vim script
Bram Moolenaar <Bram@vim.org>
parents:
20709
diff
changeset
|
2022 return func; |
9faab49c880f
patch 8.2.0960: cannot use :import in legacy Vim script
Bram Moolenaar <Bram@vim.org>
parents:
20709
diff
changeset
|
2023 } |
27807
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2024 if (in_vim9script() && STRNCMP(name, "<SNR>", 5) == 0) |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2025 { |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2026 char_u *p = name + 5; |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2027 long sid; |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2028 |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2029 // printable "<SNR>123_Name" form |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2030 sid = getdigits(&p); |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2031 if (*p == '_') |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2032 { |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2033 func = find_func_with_sid(p + 1, (int)sid); |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2034 if (func != NULL) |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2035 return func; |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2036 } |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
2037 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2038 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2039 |
27348
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
2040 if ((flags & FFED_NO_GLOBAL) == 0) |
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
2041 { |
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
2042 hi = hash_find(&func_hashtab, |
20079
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
2043 STRNCMP(name, "g:", 2) == 0 ? name + 2 : name); |
27348
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
2044 if (!HASHITEM_EMPTY(hi)) |
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
2045 return HI2UF(hi); |
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
2046 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2047 |
27068
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
2048 // Find autoload function if this is an autoload script. |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
2049 return find_func_with_prefix(name[0] == 's' && name[1] == ':' |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
2050 ? name + 2 : name, 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
|
2051 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2052 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2053 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2054 * 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
|
2055 * "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
|
2056 * 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
|
2057 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2058 ufunc_T * |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27092
diff
changeset
|
2059 find_func(char_u *name, int is_global) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2060 { |
27348
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
2061 ufunc_T *fp = find_func_even_dead(name, is_global ? FFED_IS_GLOBAL : 0); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2062 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2063 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
|
2064 return fp; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2065 return NULL; |
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 /* |
22236
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22188
diff
changeset
|
2069 * Return TRUE if "ufunc" is a global function. |
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22188
diff
changeset
|
2070 */ |
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22188
diff
changeset
|
2071 int |
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22188
diff
changeset
|
2072 func_is_global(ufunc_T *ufunc) |
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22188
diff
changeset
|
2073 { |
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22188
diff
changeset
|
2074 return ufunc->uf_name[0] != K_SPECIAL; |
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22188
diff
changeset
|
2075 } |
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22188
diff
changeset
|
2076 |
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22188
diff
changeset
|
2077 /* |
27464
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
2078 * Return TRUE if "ufunc" must be called with a g: prefix in Vim9 script. |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
2079 */ |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
2080 int |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
2081 func_requires_g_prefix(ufunc_T *ufunc) |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
2082 { |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
2083 return ufunc->uf_name[0] != K_SPECIAL |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
2084 && (ufunc->uf_flags & FC_LAMBDA) == 0 |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
2085 && vim_strchr(ufunc->uf_name, AUTOLOAD_CHAR) == NULL; |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
2086 } |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
2087 |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
2088 /* |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2089 * 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
|
2090 * "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
|
2091 * Takes care of script-local function names. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2092 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2093 static void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2094 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
|
2095 { |
22236
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22188
diff
changeset
|
2096 if (!func_is_global(fp)) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2097 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2098 STRCPY(buf, "<SNR>"); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2099 STRCAT(buf, fp->uf_name + 3); |
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 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2102 STRCPY(buf, fp->uf_name); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2103 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2104 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2105 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2106 * 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
|
2107 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2108 static void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2109 add_nr_var( |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2110 dict_T *dp, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2111 dictitem_T *v, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2112 char *name, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2113 varnumber_T nr) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2114 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2115 STRCPY(v->di_key, name); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2116 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
|
2117 hash_add(&dp->dv_hashtab, DI2HIKEY(v)); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2118 v->di_tv.v_type = VAR_NUMBER; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2119 v->di_tv.v_lock = VAR_FIXED; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2120 v->di_tv.vval.v_number = nr; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2121 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2122 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2123 /* |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2124 * Free "fc". |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2125 */ |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2126 static void |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2127 free_funccal(funccall_T *fc) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2128 { |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2129 int i; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
2130 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
2131 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
|
2132 { |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2133 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
|
2134 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2135 // 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
|
2136 // 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
|
2137 // 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
|
2138 // 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
|
2139 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
|
2140 fp->uf_scoped = NULL; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
2141 } |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
2142 ga_clear(&fc->fc_funcs); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2143 |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
2144 func_ptr_unref(fc->func); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2145 vim_free(fc); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2146 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2147 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2148 /* |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2149 * 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
|
2150 * 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
|
2151 * 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
|
2152 */ |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2153 static void |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2154 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
|
2155 { |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2156 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
|
2157 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2158 // 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
|
2159 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
|
2160 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2161 // 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
|
2162 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
|
2163 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2164 // Free the a:000 variables. |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19886
diff
changeset
|
2165 FOR_ALL_LIST_ITEMS(&fc->l_varlist, li) |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2166 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
|
2167 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2168 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
|
2169 } |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2170 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2171 /* |
11299
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2172 * 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
|
2173 * 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
|
2174 */ |
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2175 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
|
2176 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
|
2177 { |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2178 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
|
2179 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
|
2180 |
11299
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2181 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
|
2182 |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2183 // 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
|
2184 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
|
2185 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
|
2186 else |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2187 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
|
2188 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2189 // 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
|
2190 // 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
|
2191 // in it. |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2192 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
|
2193 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
|
2194 else |
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2195 { |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2196 int todo; |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2197 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
|
2198 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
|
2199 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2200 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
|
2201 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2202 // 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
|
2203 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
|
2204 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
|
2205 { |
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2206 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
|
2207 { |
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2208 --todo; |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2209 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
|
2210 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
|
2211 } |
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2212 } |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2213 } |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2214 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2215 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
|
2216 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
|
2217 else |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2218 { |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2219 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
|
2220 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2221 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
|
2222 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2223 // Make a copy of the a:000 items, since we didn't do that above. |
19888
435726a03481
patch 8.2.0500: using the same loop in many places
Bram Moolenaar <Bram@vim.org>
parents:
19886
diff
changeset
|
2224 FOR_ALL_LIST_ITEMS(&fc->l_varlist, li) |
11299
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2225 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
|
2226 } |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2227 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2228 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
|
2229 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
|
2230 else |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2231 { |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2232 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
|
2233 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2234 // "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
|
2235 // 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
|
2236 // 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
|
2237 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
|
2238 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
|
2239 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2240 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
|
2241 // 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
|
2242 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
|
2243 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
|
2244 { |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2245 // 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
|
2246 // 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
|
2247 // 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
|
2248 // 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
|
2249 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
|
2250 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
|
2251 } |
11299
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2252 } |
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2253 } |
22324
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2254 |
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2255 /* |
26566
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
2256 * Return TRUE if "name" is a numbered function, ignoring a "g:" prefix. |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
2257 */ |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
2258 static int |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
2259 numbered_function(char_u *name) |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
2260 { |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
2261 return isdigit(*name) |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
2262 || (name[0] == 'g' && name[1] == ':' && isdigit(name[2])); |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
2263 } |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
2264 |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
2265 /* |
22324
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2266 * There are two kinds of function names: |
28047
b10fa9b17c85
patch 8.2.4548: script-local function is deleted when used in a funcref
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
2267 * 1. ordinary names, function defined with :function or :def; |
b10fa9b17c85
patch 8.2.4548: script-local function is deleted when used in a funcref
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
2268 * can start with "<SNR>123_" literally or with K_SPECIAL. |
b10fa9b17c85
patch 8.2.4548: script-local function is deleted when used in a funcref
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
2269 * 2. Numbered functions and lambdas: "<lambda>123" |
22324
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2270 * For the first we only count the name stored in func_hashtab as a reference, |
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2271 * using function() does not count as a reference, because the function is |
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2272 * looked up by name. |
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2273 */ |
22326
fb69b43d73f3
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents:
22324
diff
changeset
|
2274 int |
22324
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2275 func_name_refcount(char_u *name) |
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2276 { |
28047
b10fa9b17c85
patch 8.2.4548: script-local function is deleted when used in a funcref
Bram Moolenaar <Bram@vim.org>
parents:
28008
diff
changeset
|
2277 return numbered_function(name) || (name[0] == '<' && name[1] == 'l'); |
22324
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2278 } |
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2279 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2280 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2281 * 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
|
2282 * 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
|
2283 * 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
|
2284 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2285 static void |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2286 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
|
2287 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2288 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
|
2289 int i; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2290 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2291 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
|
2292 return; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2293 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2294 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
|
2295 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
|
2296 && 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
|
2297 && 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
|
2298 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
|
2299 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2300 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
|
2301 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2302 *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
|
2303 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
|
2304 return; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2305 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2306 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2307 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
|
2308 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
|
2309 ((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
|
2310 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2311 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2312 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2313 * 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
|
2314 * 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
|
2315 * 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
|
2316 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2317 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2318 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
|
2319 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2320 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
|
2321 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2322 // 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
|
2323 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
|
2324 return FALSE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2325 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2326 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
|
2327 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
|
2328 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2329 // 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
|
2330 // function, so we can find the index when defining the function again. |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2331 // Do remove it when it's a copy. |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2332 if (fp->uf_def_status == UF_COMPILED && (fp->uf_flags & FC_COPY) == 0) |
24146
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
2333 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2334 fp->uf_flags |= FC_DEAD; |
24146
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
2335 return FALSE; |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
2336 } |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
2337 hash_remove(&func_hashtab, hi); |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
2338 fp->uf_flags |= FC_DELETED; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2339 return TRUE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2340 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2341 return FALSE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2342 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2343 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2344 static void |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2345 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
|
2346 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2347 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
|
2348 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
|
2349 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
|
2350 VIM_CLEAR(fp->uf_arg_types); |
22596
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22496
diff
changeset
|
2351 VIM_CLEAR(fp->uf_block_ids); |
19685
d64f403289db
patch 8.2.0399: various memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19579
diff
changeset
|
2352 VIM_CLEAR(fp->uf_va_name); |
21218
1f4d0375f947
patch 8.2.1160: Vim9: memory leak in allocated types
Bram Moolenaar <Bram@vim.org>
parents:
21118
diff
changeset
|
2353 clear_type_list(&fp->uf_type_list); |
23699
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
2354 |
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
2355 // Increment the refcount of this function to avoid it being freed |
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
2356 // recursively when the partial is freed. |
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
2357 fp->uf_refcount += 3; |
23249
43532077b5ff
patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents:
23237
diff
changeset
|
2358 partial_unref(fp->uf_partial); |
43532077b5ff
patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents:
23237
diff
changeset
|
2359 fp->uf_partial = NULL; |
23699
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
2360 fp->uf_refcount -= 3; |
21006
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
2361 |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
2362 #ifdef FEAT_LUA |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
2363 if (fp->uf_cb_free != NULL) |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
2364 { |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
2365 fp->uf_cb_free(fp->uf_cb_state); |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
2366 fp->uf_cb_free = NULL; |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
2367 } |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
2368 |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
2369 fp->uf_cb_state = NULL; |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
2370 fp->uf_cb = NULL; |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
2371 #endif |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2372 #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
|
2373 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
|
2374 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
|
2375 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
|
2376 #endif |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2377 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2378 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2379 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2380 * 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
|
2381 * 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
|
2382 * 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
|
2383 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2384 static void |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2385 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
|
2386 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2387 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
|
2388 return; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2389 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
|
2390 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2391 // 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
|
2392 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
|
2393 funccal_unref(fp->uf_scoped, fp, force); |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2394 unlink_def_function(fp); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2395 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2396 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2397 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2398 * 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
|
2399 * what a function contains, call func_clear() first. |
20257
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20255
diff
changeset
|
2400 * When "force" is TRUE we are exiting. |
22326
fb69b43d73f3
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents:
22324
diff
changeset
|
2401 * Returns OK when the function was actually freed. |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2402 */ |
22326
fb69b43d73f3
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents:
22324
diff
changeset
|
2403 static int |
20257
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20255
diff
changeset
|
2404 func_free(ufunc_T *fp, int force) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2405 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2406 // 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
|
2407 // 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
|
2408 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
|
2409 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
|
2410 |
20257
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20255
diff
changeset
|
2411 if ((fp->uf_flags & FC_DEAD) == 0 || force) |
21791
d504fcd3d2c0
patch 8.2.1445: Vim9: function expanded name is cleared when sourcing again
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
2412 { |
22324
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2413 if (fp->uf_dfunc_idx > 0) |
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2414 unlink_def_function(fp); |
21791
d504fcd3d2c0
patch 8.2.1445: Vim9: function expanded name is cleared when sourcing again
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
2415 VIM_CLEAR(fp->uf_name_exp); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2416 vim_free(fp); |
22326
fb69b43d73f3
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents:
22324
diff
changeset
|
2417 return OK; |
21791
d504fcd3d2c0
patch 8.2.1445: Vim9: function expanded name is cleared when sourcing again
Bram Moolenaar <Bram@vim.org>
parents:
21789
diff
changeset
|
2418 } |
22326
fb69b43d73f3
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents:
22324
diff
changeset
|
2419 return FAIL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2420 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2421 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2422 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2423 * 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
|
2424 * 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
|
2425 */ |
26445
568f93dcdc62
patch 8.2.3753: Vim9: function unreferenced while called is never deleted
Bram Moolenaar <Bram@vim.org>
parents:
26439
diff
changeset
|
2426 void |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2427 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
|
2428 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2429 func_clear(fp, force); |
22324
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2430 if (force || fp->uf_dfunc_idx == 0 || func_name_refcount(fp->uf_name) |
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2431 || (fp->uf_flags & FC_COPY)) |
20943
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2432 func_free(fp, force); |
21479
90d859a402cc
patch 8.2.1290: Vim9: cannot replace a global function
Bram Moolenaar <Bram@vim.org>
parents:
21461
diff
changeset
|
2433 else |
90d859a402cc
patch 8.2.1290: Vim9: cannot replace a global function
Bram Moolenaar <Bram@vim.org>
parents:
21461
diff
changeset
|
2434 fp->uf_flags |= FC_DEAD; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2435 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2436 |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2437 /* |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2438 * Copy already defined function "lambda" to a new function with name "global". |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2439 * This is for when a compiled function defines a global function. |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2440 */ |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2441 int |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2442 copy_func(char_u *lambda, char_u *global, ectx_T *ectx) |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2443 { |
27348
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
2444 ufunc_T *ufunc = find_func_even_dead(lambda, FFED_IS_GLOBAL); |
23249
43532077b5ff
patch 8.2.2170: Vim9: a global function defined in a :def function fails
Bram Moolenaar <Bram@vim.org>
parents:
23237
diff
changeset
|
2445 ufunc_T *fp = NULL; |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2446 |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2447 if (ufunc == NULL) |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2448 { |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21791
diff
changeset
|
2449 semsg(_(e_lambda_function_not_found_str), lambda); |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2450 return FAIL; |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2451 } |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2452 |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27092
diff
changeset
|
2453 fp = find_func(global, TRUE); |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2454 if (fp != NULL) |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2455 { |
23699
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
2456 // TODO: handle ! to overwrite |
26857
2aeea8611342
patch 8.2.3957: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26833
diff
changeset
|
2457 semsg(_(e_function_str_already_exists_add_bang_to_replace), global); |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2458 return FAIL; |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2459 } |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2460 |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2461 fp = alloc_clear(offsetof(ufunc_T, uf_name) + STRLEN(global) + 1); |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2462 if (fp == NULL) |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2463 return FAIL; |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2464 |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2465 fp->uf_varargs = ufunc->uf_varargs; |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2466 fp->uf_flags = (ufunc->uf_flags & ~FC_VIM9) | FC_COPY; |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2467 fp->uf_def_status = ufunc->uf_def_status; |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2468 fp->uf_dfunc_idx = ufunc->uf_dfunc_idx; |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2469 if (ga_copy_strings(&ufunc->uf_args, &fp->uf_args) == FAIL |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2470 || ga_copy_strings(&ufunc->uf_def_args, &fp->uf_def_args) |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2471 == FAIL |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2472 || ga_copy_strings(&ufunc->uf_lines, &fp->uf_lines) == FAIL) |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2473 goto failed; |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2474 |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2475 fp->uf_name_exp = ufunc->uf_name_exp == NULL ? NULL |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2476 : vim_strsave(ufunc->uf_name_exp); |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2477 if (ufunc->uf_arg_types != NULL) |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2478 { |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2479 fp->uf_arg_types = ALLOC_MULT(type_T *, fp->uf_args.ga_len); |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2480 if (fp->uf_arg_types == NULL) |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2481 goto failed; |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2482 mch_memmove(fp->uf_arg_types, ufunc->uf_arg_types, |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2483 sizeof(type_T *) * fp->uf_args.ga_len); |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2484 } |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2485 if (ufunc->uf_va_name != NULL) |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2486 { |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2487 fp->uf_va_name = vim_strsave(ufunc->uf_va_name); |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2488 if (fp->uf_va_name == NULL) |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2489 goto failed; |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2490 } |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2491 fp->uf_ret_type = ufunc->uf_ret_type; |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2492 |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2493 fp->uf_refcount = 1; |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2494 STRCPY(fp->uf_name, global); |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2495 hash_add(&func_hashtab, UF2HIKEY(fp)); |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2496 |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2497 // the referenced dfunc_T is now used one more time |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2498 link_def_function(fp); |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2499 |
23699
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
2500 // Create a partial to store the context of the function where it was |
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
2501 // instantiated. Only needs to be done once. Do this on the original |
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
2502 // function, "dfunc->df_ufunc" will point to it. |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2503 if ((ufunc->uf_flags & FC_CLOSURE) && ufunc->uf_partial == NULL) |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2504 { |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2505 partial_T *pt = ALLOC_CLEAR_ONE(partial_T); |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2506 |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2507 if (pt == NULL) |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2508 goto failed; |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2509 if (fill_partial_and_closure(pt, ufunc, ectx) == FAIL) |
23699
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
2510 { |
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
2511 vim_free(pt); |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2512 goto failed; |
23699
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
2513 } |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2514 ufunc->uf_partial = pt; |
23699
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
2515 --pt->pt_refcount; // not actually referenced here |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2516 } |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2517 |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2518 return OK; |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2519 |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2520 failed: |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2521 func_clear_free(fp, TRUE); |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2522 return FAIL; |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2523 } |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2524 |
22908
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2525 static int funcdepth = 0; |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2526 |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2527 /* |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2528 * Increment the function call depth count. |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2529 * Return FAIL when going over 'maxfuncdepth'. |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2530 * Otherwise return OK, must call funcdepth_decrement() later! |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2531 */ |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2532 int |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2533 funcdepth_increment(void) |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2534 { |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2535 if (funcdepth >= p_mfd) |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2536 { |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
2537 emsg(_(e_function_call_depth_is_higher_than_macfuncdepth)); |
22908
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2538 return FAIL; |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2539 } |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2540 ++funcdepth; |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2541 return OK; |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2542 } |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2543 |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2544 void |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2545 funcdepth_decrement(void) |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2546 { |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2547 --funcdepth; |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2548 } |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2549 |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2550 /* |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2551 * Get the current function call depth. |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2552 */ |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2553 int |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2554 funcdepth_get(void) |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2555 { |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2556 return funcdepth; |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2557 } |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2558 |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2559 /* |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2560 * Restore the function call depth. This is for cases where there is no |
23229
b545334ae654
patch 8.2.2160: various typos
Bram Moolenaar <Bram@vim.org>
parents:
23193
diff
changeset
|
2561 * guarantee funcdepth_decrement() can be called exactly the same number of |
22908
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2562 * times as funcdepth_increment(). |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2563 */ |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2564 void |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2565 funcdepth_restore(int depth) |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2566 { |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2567 funcdepth = depth; |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2568 } |
11299
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2569 |
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2570 /* |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2571 * Call a user function. |
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 static void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2574 call_user_func( |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2575 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
|
2576 int argcount, // nr of args |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2577 typval_T *argvars, // arguments |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2578 typval_T *rettv, // return value |
20433
5950284a517f
patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents:
20397
diff
changeset
|
2579 funcexe_T *funcexe, // context |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2580 dict_T *selfdict) // Dictionary for "self" |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2581 { |
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
|
2582 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
|
2583 int using_sandbox = FALSE; |
27678
1646525507aa
patch 8.2.4365: sticky command modifiers are too sticky
Bram Moolenaar <Bram@vim.org>
parents:
27669
diff
changeset
|
2584 int save_sticky_cmdmod_flags = sticky_cmdmod_flags; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2585 funccall_T *fc; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2586 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
|
2587 int default_arg_err = FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2588 dictitem_T *v; |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2589 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
|
2590 int i; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2591 int ai; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2592 int islambda = FALSE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2593 char_u numbuf[NUMBUFLEN]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2594 char_u *name; |
24448
faac16c365b6
patch 8.2.2764: memory leak when default function argument is allocated
Bram Moolenaar <Bram@vim.org>
parents:
24436
diff
changeset
|
2595 typval_T *tv_to_free[MAX_FUNC_ARGS]; |
faac16c365b6
patch 8.2.2764: memory leak when default function argument is allocated
Bram Moolenaar <Bram@vim.org>
parents:
24436
diff
changeset
|
2596 int tv_to_free_len = 0; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2597 #ifdef FEAT_PROFILE |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23699
diff
changeset
|
2598 profinfo_T profile_info; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2599 #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
|
2600 ESTACK_CHECK_DECLARATION |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2601 |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23699
diff
changeset
|
2602 #ifdef FEAT_PROFILE |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23699
diff
changeset
|
2603 CLEAR_FIELD(profile_info); |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23699
diff
changeset
|
2604 #endif |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23699
diff
changeset
|
2605 |
22908
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2606 // If depth of calling is getting too high, don't execute the function. |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2607 if (funcdepth_increment() == FAIL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2608 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2609 rettv->v_type = VAR_NUMBER; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2610 rettv->vval.v_number = -1; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2611 return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2612 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2613 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2614 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
|
2615 |
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
|
2616 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
|
2617 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
|
2618 return; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2619 fc->caller = current_funccal; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2620 current_funccal = fc; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2621 fc->func = fp; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2622 fc->rettv = rettv; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2623 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
|
2624 // 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
|
2625 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
|
2626 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
|
2627 // Set up fields for closure. |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
2628 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
|
2629 func_ptr_ref(fp); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2630 |
20943
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
2631 if (fp->uf_def_status != UF_NOT_COMPILED) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2632 { |
23976
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2633 #ifdef FEAT_PROFILE |
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2634 ufunc_T *caller = fc->caller == NULL ? NULL : fc->caller->func; |
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2635 #endif |
20538
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20532
diff
changeset
|
2636 // Execute the function, possibly compiling it first. |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23699
diff
changeset
|
2637 #ifdef FEAT_PROFILE |
23976
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2638 if (do_profiling == PROF_YES) |
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2639 profile_may_start_func(&profile_info, fp, caller); |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23699
diff
changeset
|
2640 #endif |
27678
1646525507aa
patch 8.2.4365: sticky command modifiers are too sticky
Bram Moolenaar <Bram@vim.org>
parents:
27669
diff
changeset
|
2641 sticky_cmdmod_flags = 0; |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
2642 call_def_function(fp, argcount, argvars, funcexe->fe_partial, rettv); |
22908
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2643 funcdepth_decrement(); |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23699
diff
changeset
|
2644 #ifdef FEAT_PROFILE |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23699
diff
changeset
|
2645 if (do_profiling == PROF_YES && (fp->uf_profiling |
23976
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2646 || (caller != NULL && caller->uf_profiling))) |
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2647 profile_may_end_func(&profile_info, fp, caller); |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23699
diff
changeset
|
2648 #endif |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2649 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
|
2650 free_funccal(fc); |
27678
1646525507aa
patch 8.2.4365: sticky command modifiers are too sticky
Bram Moolenaar <Bram@vim.org>
parents:
27669
diff
changeset
|
2651 sticky_cmdmod_flags = save_sticky_cmdmod_flags; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2652 return; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2653 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2654 |
26323
3841da4eac23
patch 8.2.3692: Vim9: cannot use :func inside a :def function
Bram Moolenaar <Bram@vim.org>
parents:
26205
diff
changeset
|
2655 islambda = fp->uf_flags & FC_LAMBDA; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2656 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2657 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2658 * 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
|
2659 * 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
|
2660 * 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
|
2661 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2662 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2663 * Init l: variables. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2664 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2665 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
|
2666 if (selfdict != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2667 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2668 // 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
|
2669 // 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
|
2670 v = &fc->fixvar[fixvar_idx++].var; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2671 name = v->di_key; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2672 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
|
2673 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
|
2674 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
|
2675 v->di_tv.v_type = VAR_DICT; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2676 v->di_tv.v_lock = 0; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2677 v->di_tv.vval.v_dict = selfdict; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2678 ++selfdict->dv_refcount; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2679 } |
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 /* |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2682 * Init a: variables, unless none found (in lambda). |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2683 * 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
|
2684 * 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
|
2685 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2686 init_var_dict(&fc->l_avars, &fc->l_avars_var, VAR_SCOPE); |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2687 if ((fp->uf_flags & FC_NOARGS) == 0) |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2688 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
|
2689 (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
|
2690 ? 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
|
2691 fc->l_avars.dv_lock = VAR_FIXED; |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2692 if ((fp->uf_flags & FC_NOARGS) == 0) |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2693 { |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2694 // Use "name" to avoid a warning from some compiler that checks the |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2695 // destination size. |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2696 v = &fc->fixvar[fixvar_idx++].var; |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2697 name = v->di_key; |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2698 STRCPY(name, "000"); |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2699 v->di_flags = DI_FLAGS_RO | DI_FLAGS_FIX; |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2700 hash_add(&fc->l_avars.dv_hashtab, DI2HIKEY(v)); |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2701 v->di_tv.v_type = VAR_LIST; |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2702 v->di_tv.v_lock = VAR_FIXED; |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2703 v->di_tv.vval.v_list = &fc->l_varlist; |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2704 } |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
2705 CLEAR_FIELD(fc->l_varlist); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2706 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
|
2707 fc->l_varlist.lv_lock = VAR_FIXED; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2708 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2709 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2710 * 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
|
2711 * Set a:name to named arguments. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2712 * Set a:N to the "..." arguments. |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2713 * Skipped when no a: variables used (in lambda). |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2714 */ |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2715 if ((fp->uf_flags & FC_NOARGS) == 0) |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2716 { |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2717 add_nr_var(&fc->l_avars, &fc->fixvar[fixvar_idx++].var, "firstline", |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
2718 (varnumber_T)funcexe->fe_firstline); |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2719 add_nr_var(&fc->l_avars, &fc->fixvar[fixvar_idx++].var, "lastline", |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
2720 (varnumber_T)funcexe->fe_lastline); |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2721 } |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2722 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
|
2723 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2724 int addlocal = FALSE; |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2725 typval_T def_rettv; |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2726 int isdefault = FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2727 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2728 ai = i - fp->uf_args.ga_len; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2729 if (ai < 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2730 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2731 // named argument a:name |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2732 name = FUNCARG(fp, i); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2733 if (islambda) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2734 addlocal = TRUE; |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2735 |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2736 // 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
|
2737 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
|
2738 && (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
|
2739 && 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
|
2740 if (isdefault) |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2741 { |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2742 char_u *default_expr = NULL; |
24448
faac16c365b6
patch 8.2.2764: memory leak when default function argument is allocated
Bram Moolenaar <Bram@vim.org>
parents:
24436
diff
changeset
|
2743 |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2744 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
|
2745 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
|
2746 |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2747 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
|
2748 [ai + fp->uf_def_args.ga_len]; |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
2749 if (eval1(&default_expr, &def_rettv, &EVALARG_EVALUATE) == FAIL) |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2750 { |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2751 default_arg_err = 1; |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2752 break; |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2753 } |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2754 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2755 } |
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 { |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2758 if ((fp->uf_flags & FC_NOARGS) != 0) |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2759 // Bail out if no a: arguments used (in lambda). |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2760 break; |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2761 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2762 // "..." argument a:1, a:2, etc. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2763 sprintf((char *)numbuf, "%d", ai + 1); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2764 name = numbuf; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2765 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2766 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
|
2767 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2768 v = &fc->fixvar[fixvar_idx++].var; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2769 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
|
2770 STRCPY(v->di_key, name); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2771 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2772 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2773 { |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2774 v = dictitem_alloc(name); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2775 if (v == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2776 break; |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2777 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
|
2778 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2779 |
17127
d244a9be99db
patch 8.1.1563: crash when using closures
Bram Moolenaar <Bram@vim.org>
parents:
16969
diff
changeset
|
2780 // 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
|
2781 // "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
|
2782 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
|
2783 v->di_tv.v_lock = VAR_FIXED; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2784 |
24448
faac16c365b6
patch 8.2.2764: memory leak when default function argument is allocated
Bram Moolenaar <Bram@vim.org>
parents:
24436
diff
changeset
|
2785 if (isdefault) |
faac16c365b6
patch 8.2.2764: memory leak when default function argument is allocated
Bram Moolenaar <Bram@vim.org>
parents:
24436
diff
changeset
|
2786 // Need to free this later, no matter where it's stored. |
faac16c365b6
patch 8.2.2764: memory leak when default function argument is allocated
Bram Moolenaar <Bram@vim.org>
parents:
24436
diff
changeset
|
2787 tv_to_free[tv_to_free_len++] = &v->di_tv; |
faac16c365b6
patch 8.2.2764: memory leak when default function argument is allocated
Bram Moolenaar <Bram@vim.org>
parents:
24436
diff
changeset
|
2788 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2789 if (addlocal) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2790 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2791 // 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
|
2792 // 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
|
2793 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
|
2794 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
|
2795 } |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
2796 else |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
2797 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
|
2798 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2799 if (ai >= 0 && ai < MAX_FUNC_ARGS) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2800 { |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2801 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
|
2802 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2803 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
|
2804 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
|
2805 list_append(&fc->l_varlist, li); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2806 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2807 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2808 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2809 // 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
|
2810 ++RedrawingDisabled; |
14323
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
2811 |
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
2812 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
|
2813 { |
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
2814 using_sandbox = TRUE; |
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
2815 ++sandbox; |
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
2816 } |
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
2817 |
20538
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20532
diff
changeset
|
2818 estack_push_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
|
2819 ESTACK_CHECK_SETUP |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2820 if (p_verbose >= 12) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2821 { |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2822 ++no_wait_return; |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2823 verbose_enter_scroll(); |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2824 |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2825 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
|
2826 if (p_verbose >= 14) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2827 { |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2828 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
|
2829 char_u numbuf2[NUMBUFLEN]; |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2830 char_u *tofree; |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2831 char_u *s; |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2832 |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2833 msg_puts("("); |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2834 for (i = 0; i < argcount; ++i) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2835 { |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2836 if (i > 0) |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2837 msg_puts(", "); |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2838 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
|
2839 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
|
2840 else |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2841 { |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2842 // 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
|
2843 ++emsg_off; |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2844 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
|
2845 --emsg_off; |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2846 if (s != NULL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2847 { |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2848 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
|
2849 { |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2850 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
|
2851 s = buf; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2852 } |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2853 msg_puts((char *)s); |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2854 vim_free(tofree); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2855 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2856 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2857 } |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2858 msg_puts(")"); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2859 } |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2860 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
|
2861 |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2862 verbose_leave_scroll(); |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2863 --no_wait_return; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2864 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2865 #ifdef FEAT_PROFILE |
23976
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2866 if (do_profiling == PROF_YES) |
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2867 profile_may_start_func(&profile_info, fp, |
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2868 fc->caller == NULL ? NULL : fc->caller->func); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2869 #endif |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2870 |
27678
1646525507aa
patch 8.2.4365: sticky command modifiers are too sticky
Bram Moolenaar <Bram@vim.org>
parents:
27669
diff
changeset
|
2871 // "legacy" does not apply to commands in the function |
1646525507aa
patch 8.2.4365: sticky command modifiers are too sticky
Bram Moolenaar <Bram@vim.org>
parents:
27669
diff
changeset
|
2872 sticky_cmdmod_flags = 0; |
1646525507aa
patch 8.2.4365: sticky command modifiers are too sticky
Bram Moolenaar <Bram@vim.org>
parents:
27669
diff
changeset
|
2873 |
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
|
2874 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
|
2875 current_sctx = fp->uf_script_ctx; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2876 save_did_emsg = did_emsg; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2877 did_emsg = FALSE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2878 |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2879 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
|
2880 did_emsg = TRUE; |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2881 else if (islambda) |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2882 { |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2883 char_u *p = *(char_u **)fp->uf_lines.ga_data + 7; |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2884 |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2885 // A Lambda always has the command "return {expr}". It is much faster |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2886 // to evaluate {expr} directly. |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2887 ++ex_nesting_level; |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
2888 (void)eval1(&p, rettv, &EVALARG_EVALUATE); |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2889 --ex_nesting_level; |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2890 } |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2891 else |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2892 // 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
|
2893 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
|
2894 DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2895 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2896 --RedrawingDisabled; |
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 // 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
|
2899 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
|
2900 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2901 clear_tv(rettv); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2902 rettv->v_type = VAR_NUMBER; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2903 rettv->vval.v_number = -1; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2904 } |
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 #ifdef FEAT_PROFILE |
23976
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2907 if (do_profiling == PROF_YES) |
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2908 { |
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2909 ufunc_T *caller = fc->caller == NULL ? NULL : fc->caller->func; |
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2910 |
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2911 if (fp->uf_profiling || (caller != NULL && caller->uf_profiling)) |
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2912 profile_may_end_func(&profile_info, fp, caller); |
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2913 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2914 #endif |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2915 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2916 // 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
|
2917 if (p_verbose >= 12) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2918 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2919 ++no_wait_return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2920 verbose_enter_scroll(); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2921 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2922 if (aborting()) |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2923 smsg(_("%s aborted"), SOURCING_NAME); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2924 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
|
2925 smsg(_("%s returning #%ld"), SOURCING_NAME, |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2926 (long)fc->rettv->vval.v_number); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2927 else |
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 char_u buf[MSG_BUF_LEN]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2930 char_u numbuf2[NUMBUFLEN]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2931 char_u *tofree; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2932 char_u *s; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2933 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2934 // 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
|
2935 // 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
|
2936 // 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
|
2937 ++emsg_off; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2938 s = tv2string(fc->rettv, &tofree, numbuf2, 0); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2939 --emsg_off; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2940 if (s != NULL) |
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 (vim_strsize(s) > MSG_BUF_CLEN) |
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 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
|
2945 s = buf; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2946 } |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2947 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
|
2948 vim_free(tofree); |
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 } |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2951 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
|
2952 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2953 verbose_leave_scroll(); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2954 --no_wait_return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2955 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2956 |
19075
af1eca322b9e
patch 8.2.0098: exe stack length can be wrong without being detected
Bram Moolenaar <Bram@vim.org>
parents:
19035
diff
changeset
|
2957 ESTACK_CHECK_NOW |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2958 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
|
2959 current_sctx = save_current_sctx; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2960 #ifdef FEAT_PROFILE |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2961 if (do_profiling == PROF_YES) |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23699
diff
changeset
|
2962 script_prof_restore(&profile_info.pi_wait_start); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2963 #endif |
14323
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
2964 if (using_sandbox) |
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
2965 --sandbox; |
27678
1646525507aa
patch 8.2.4365: sticky command modifiers are too sticky
Bram Moolenaar <Bram@vim.org>
parents:
27669
diff
changeset
|
2966 sticky_cmdmod_flags = save_sticky_cmdmod_flags; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2967 |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2968 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
|
2969 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2970 ++no_wait_return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2971 verbose_enter_scroll(); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2972 |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2973 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
|
2974 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
|
2975 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2976 verbose_leave_scroll(); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2977 --no_wait_return; |
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 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2980 did_emsg |= save_did_emsg; |
22908
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2981 funcdepth_decrement(); |
24448
faac16c365b6
patch 8.2.2764: memory leak when default function argument is allocated
Bram Moolenaar <Bram@vim.org>
parents:
24436
diff
changeset
|
2982 for (i = 0; i < tv_to_free_len; ++i) |
faac16c365b6
patch 8.2.2764: memory leak when default function argument is allocated
Bram Moolenaar <Bram@vim.org>
parents:
24436
diff
changeset
|
2983 clear_tv(tv_to_free[i]); |
11299
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2984 cleanup_function_call(fc); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2985 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2986 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2987 /* |
23252
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
2988 * Check the argument count for user function "fp". |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
2989 * Return FCERR_UNKNOWN if OK, FCERR_TOOFEW or FCERR_TOOMANY otherwise. |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
2990 */ |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
2991 int |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
2992 check_user_func_argcount(ufunc_T *fp, int argcount) |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
2993 { |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
2994 int regular_args = fp->uf_args.ga_len; |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
2995 |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
2996 if (argcount < regular_args - fp->uf_def_args.ga_len) |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
2997 return FCERR_TOOFEW; |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
2998 else if (!has_varargs(fp) && argcount > regular_args) |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
2999 return FCERR_TOOMANY; |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
3000 return FCERR_UNKNOWN; |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
3001 } |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
3002 |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
3003 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3004 * 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
|
3005 */ |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3006 int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3007 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
|
3008 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
|
3009 int argcount, |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3010 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
|
3011 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
|
3012 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
|
3013 dict_T *selfdict) |
14430
2fba714294b9
patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents:
14323
diff
changeset
|
3014 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3015 int error; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3016 |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3017 if (fp->uf_flags & FC_RANGE && funcexe->fe_doesrange != NULL) |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3018 *funcexe->fe_doesrange = TRUE; |
23252
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
3019 error = check_user_func_argcount(fp, argcount); |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
3020 if (error != FCERR_UNKNOWN) |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
3021 return error; |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
3022 if ((fp->uf_flags & FC_DICT) && selfdict == NULL) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3023 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
|
3024 else |
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 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
|
3027 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
|
3028 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3029 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3030 * 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
|
3031 * 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
|
3032 * redo buffer. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3033 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3034 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
|
3035 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
|
3036 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3037 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
|
3038 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
|
3039 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3040 ++fp->uf_calls; |
20433
5950284a517f
patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents:
20397
diff
changeset
|
3041 call_user_func(fp, argcount, argvars, rettv, funcexe, |
5950284a517f
patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents:
20397
diff
changeset
|
3042 (fp->uf_flags & FC_DICT) ? selfdict : NULL); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3043 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
|
3044 // 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
|
3045 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
|
3046 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
|
3047 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
|
3048 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
|
3049 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
|
3050 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3051 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
|
3052 } |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3053 |
14927
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3054 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
|
3055 |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3056 /* |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3057 * 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
|
3058 * 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
|
3059 */ |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3060 void |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3061 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
|
3062 { |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3063 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
|
3064 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
|
3065 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
|
3066 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
|
3067 } |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3068 |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3069 void |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3070 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
|
3071 { |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3072 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
|
3073 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
|
3074 else |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3075 { |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3076 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
|
3077 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
|
3078 } |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3079 } |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3080 |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17251
diff
changeset
|
3081 funccall_T * |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17251
diff
changeset
|
3082 get_current_funccal(void) |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17251
diff
changeset
|
3083 { |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17251
diff
changeset
|
3084 return current_funccal; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17251
diff
changeset
|
3085 } |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17251
diff
changeset
|
3086 |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3087 /* |
27669
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
3088 * Return TRUE when currently at the script level: |
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
3089 * - not in a function |
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
3090 * - not executing an autocommand |
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
3091 * Note that when an autocommand sources a script the result is FALSE; |
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
3092 */ |
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
3093 int |
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
3094 at_script_level(void) |
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
3095 { |
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
3096 return current_funccal == NULL && autocmd_match == NULL; |
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
3097 } |
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
3098 |
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
3099 /* |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3100 * Mark all functions of script "sid" as deleted. |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3101 */ |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3102 void |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3103 delete_script_functions(int sid) |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3104 { |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3105 hashitem_T *hi; |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3106 ufunc_T *fp; |
21564
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3107 long_u todo = 1; |
20193
cf13b26be258
patch 8.2.0652: compiler warning for char conversion
Bram Moolenaar <Bram@vim.org>
parents:
20189
diff
changeset
|
3108 char_u buf[30]; |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3109 size_t len; |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3110 |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3111 buf[0] = K_SPECIAL; |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3112 buf[1] = KS_EXTRA; |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3113 buf[2] = (int)KE_SNR; |
20193
cf13b26be258
patch 8.2.0652: compiler warning for char conversion
Bram Moolenaar <Bram@vim.org>
parents:
20189
diff
changeset
|
3114 sprintf((char *)buf + 3, "%d_", sid); |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3115 len = STRLEN(buf); |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3116 |
21564
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3117 while (todo > 0) |
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3118 { |
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3119 todo = func_hashtab.ht_used; |
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3120 for (hi = func_hashtab.ht_array; todo > 0; ++hi) |
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3121 if (!HASHITEM_EMPTY(hi)) |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3122 { |
21564
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3123 fp = HI2UF(hi); |
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3124 if (STRNCMP(fp->uf_name, buf, len) == 0) |
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3125 { |
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3126 int changed = func_hashtab.ht_changed; |
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3127 |
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3128 fp->uf_flags |= FC_DEAD; |
24146
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3129 |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3130 if (fp->uf_calls > 0) |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3131 { |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3132 // Function is executing, don't free it but do remove |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3133 // it from the hashtable. |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3134 if (func_remove(fp)) |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3135 fp->uf_refcount--; |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3136 } |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3137 else |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3138 { |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3139 func_clear(fp, TRUE); |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3140 // When clearing a function another function can be |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3141 // cleared as a side effect. When that happens start |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3142 // over. |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3143 if (changed != func_hashtab.ht_changed) |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3144 break; |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3145 } |
21564
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3146 } |
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3147 --todo; |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3148 } |
21564
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3149 } |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3150 } |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3151 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3152 #if defined(EXITFREE) || defined(PROTO) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3153 void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3154 free_all_functions(void) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3155 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3156 hashitem_T *hi; |
9844
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3157 ufunc_T *fp; |
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3158 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
|
3159 long_u todo = 1; |
21319
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21313
diff
changeset
|
3160 int changed; |
10815
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3161 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3162 // 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
|
3163 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
|
3164 { |
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
3165 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
|
3166 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
|
3167 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
|
3168 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
|
3169 } |
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
3170 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3171 // 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
|
3172 // 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
|
3173 // 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
|
3174 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
|
3175 { |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3176 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
|
3177 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
|
3178 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
|
3179 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3180 // 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
|
3181 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
|
3182 fp->uf_flags &= ~FC_DEAD; |
20943
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
3183 fp->uf_def_status = UF_NOT_COMPILED; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3184 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3185 // 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
|
3186 // 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
|
3187 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
|
3188 ++skipped; |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3189 else |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3190 { |
21319
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21313
diff
changeset
|
3191 changed = func_hashtab.ht_changed; |
10815
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3192 func_clear(fp, TRUE); |
21319
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21313
diff
changeset
|
3193 if (changed != func_hashtab.ht_changed) |
10815
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3194 { |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3195 skipped = 0; |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3196 break; |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3197 } |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3198 } |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3199 --todo; |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3200 } |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3201 } |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3202 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3203 // 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
|
3204 // 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
|
3205 skipped = 0; |
9844
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3206 while (func_hashtab.ht_used > skipped) |
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3207 { |
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3208 todo = func_hashtab.ht_used; |
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3209 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
|
3210 if (!HASHITEM_EMPTY(hi)) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3211 { |
9844
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3212 --todo; |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3213 // 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
|
3214 // 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
|
3215 fp = HI2UF(hi); |
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3216 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
|
3217 ++skipped; |
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3218 else |
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3219 { |
22326
fb69b43d73f3
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents:
22324
diff
changeset
|
3220 if (func_free(fp, FALSE) == OK) |
fb69b43d73f3
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents:
22324
diff
changeset
|
3221 { |
fb69b43d73f3
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents:
22324
diff
changeset
|
3222 skipped = 0; |
fb69b43d73f3
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents:
22324
diff
changeset
|
3223 break; |
fb69b43d73f3
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents:
22324
diff
changeset
|
3224 } |
fb69b43d73f3
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents:
22324
diff
changeset
|
3225 // did not actually free it |
fb69b43d73f3
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents:
22324
diff
changeset
|
3226 ++skipped; |
9844
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3227 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3228 } |
9844
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3229 } |
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3230 if (skipped == 0) |
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3231 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
|
3232 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3233 free_def_functions(); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3234 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3235 #endif |
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 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3238 * Return TRUE if "name" looks like a builtin function name: starts with a |
27189
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3239 * lower case letter, doesn't contain AUTOLOAD_CHAR or ':', no "." after the |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3240 * name. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3241 * "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
|
3242 */ |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3243 int |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3244 builtin_function(char_u *name, int len) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3245 { |
27189
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3246 int i; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3247 |
20079
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3248 if (!ASCII_ISLOWER(name[0]) || name[1] == ':') |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3249 return FALSE; |
27189
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3250 for (i = 0; name[i] != NUL && (len < 0 || i < len); ++i) |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3251 { |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3252 if (name[i] == AUTOLOAD_CHAR) |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3253 return FALSE; |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3254 if (!eval_isnamec(name[i])) |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3255 { |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3256 // "name.something" is not a builtin function |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3257 if (name[i] == '.') |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3258 return FALSE; |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3259 break; |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3260 } |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3261 } |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3262 return TRUE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3263 } |
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 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3266 func_call( |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3267 char_u *name, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3268 typval_T *args, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3269 partial_T *partial, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3270 dict_T *selfdict, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3271 typval_T *rettv) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3272 { |
19201
e7b4fff348dd
patch 8.2.0159: non-materialized range() list causes problems
Bram Moolenaar <Bram@vim.org>
parents:
19183
diff
changeset
|
3273 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
|
3274 listitem_T *item; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3275 typval_T argv[MAX_FUNC_ARGS + 1]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3276 int argc = 0; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3277 int r = 0; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3278 |
20392
4c317d8c1051
patch 8.2.0751: Vim9: performance can be improved
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
3279 CHECK_LIST_MATERIALIZE(l); |
19934
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
3280 FOR_ALL_LIST_ITEMS(l, item) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3281 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3282 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
|
3283 { |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
3284 emsg(_(e_too_many_arguments)); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3285 break; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3286 } |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3287 // 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
|
3288 // 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
|
3289 copy_tv(&item->li_tv, &argv[argc++]); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3290 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3291 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3292 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
|
3293 { |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17462
diff
changeset
|
3294 funcexe_T funcexe; |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17462
diff
changeset
|
3295 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
3296 CLEAR_FIELD(funcexe); |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3297 funcexe.fe_firstline = curwin->w_cursor.lnum; |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3298 funcexe.fe_lastline = curwin->w_cursor.lnum; |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3299 funcexe.fe_evaluate = TRUE; |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3300 funcexe.fe_partial = partial; |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3301 funcexe.fe_selfdict = selfdict; |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17462
diff
changeset
|
3302 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
|
3303 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3304 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3305 // Free the arguments. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3306 while (argc > 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3307 clear_tv(&argv[--argc]); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3308 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3309 return r; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3310 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3311 |
18104
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3312 static int callback_depth = 0; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3313 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3314 int |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3315 get_callback_depth(void) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3316 { |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3317 return callback_depth; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3318 } |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3319 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3320 /* |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3321 * Invoke call_func() with a callback. |
26452
65b4109a4297
patch 8.2.3756: might crash when callback is not valid
Bram Moolenaar <Bram@vim.org>
parents:
26445
diff
changeset
|
3322 * Returns FAIL if the callback could not be called. |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3323 */ |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3324 int |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3325 call_callback( |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3326 callback_T *callback, |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3327 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
|
3328 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
|
3329 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
|
3330 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
|
3331 // PLUS ONE elements! |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3332 { |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17462
diff
changeset
|
3333 funcexe_T funcexe; |
18104
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3334 int ret; |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17462
diff
changeset
|
3335 |
26452
65b4109a4297
patch 8.2.3756: might crash when callback is not valid
Bram Moolenaar <Bram@vim.org>
parents:
26445
diff
changeset
|
3336 if (callback->cb_name == NULL || *callback->cb_name == NUL) |
65b4109a4297
patch 8.2.3756: might crash when callback is not valid
Bram Moolenaar <Bram@vim.org>
parents:
26445
diff
changeset
|
3337 return FAIL; |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
3338 CLEAR_FIELD(funcexe); |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3339 funcexe.fe_evaluate = TRUE; |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3340 funcexe.fe_partial = callback->cb_partial; |
18104
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3341 ++callback_depth; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3342 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
|
3343 --callback_depth; |
26538
dfa658800f21
patch 8.2.3798: a :def callback function postpones an error message
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3344 |
dfa658800f21
patch 8.2.3798: a :def callback function postpones an error message
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3345 // When a :def function was called that uses :try an error would be turned |
dfa658800f21
patch 8.2.3798: a :def callback function postpones an error message
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3346 // into an exception. Need to give the error here. |
26540
682ff45f289f
patch 8.2.3799: edit test hangs or fails
Bram Moolenaar <Bram@vim.org>
parents:
26538
diff
changeset
|
3347 if (need_rethrow && current_exception != NULL && trylevel == 0) |
26538
dfa658800f21
patch 8.2.3798: a :def callback function postpones an error message
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3348 { |
dfa658800f21
patch 8.2.3798: a :def callback function postpones an error message
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3349 need_rethrow = FALSE; |
dfa658800f21
patch 8.2.3798: a :def callback function postpones an error message
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3350 handle_did_throw(); |
dfa658800f21
patch 8.2.3798: a :def callback function postpones an error message
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3351 } |
dfa658800f21
patch 8.2.3798: a :def callback function postpones an error message
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3352 |
18104
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3353 return ret; |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3354 } |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3355 |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3356 /* |
26388
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3357 * call the 'callback' function and return the result as a number. |
26452
65b4109a4297
patch 8.2.3756: might crash when callback is not valid
Bram Moolenaar <Bram@vim.org>
parents:
26445
diff
changeset
|
3358 * Returns -2 when calling the function fails. Uses argv[0] to argv[argc - 1] |
26388
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3359 * for the function arguments. argv[argc] should have type VAR_UNKNOWN. |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3360 */ |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3361 varnumber_T |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3362 call_callback_retnr( |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3363 callback_T *callback, |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3364 int argcount, // number of "argvars" |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3365 typval_T *argvars) // vars for arguments, must have "argcount" |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3366 // PLUS ONE elements! |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3367 { |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3368 typval_T rettv; |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3369 varnumber_T retval; |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3370 |
27285
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27279
diff
changeset
|
3371 if (call_callback(callback, -1, &rettv, argcount, argvars) == FAIL) |
26452
65b4109a4297
patch 8.2.3756: might crash when callback is not valid
Bram Moolenaar <Bram@vim.org>
parents:
26445
diff
changeset
|
3372 return -2; |
26388
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3373 |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3374 retval = tv_get_number_chk(&rettv, NULL); |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3375 clear_tv(&rettv); |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3376 return retval; |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3377 } |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3378 |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3379 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3380 * 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
|
3381 * 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
|
3382 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3383 void |
26506
4a1d2abc2016
patch 8.2.3783: confusing error for using a variable as a function
Bram Moolenaar <Bram@vim.org>
parents:
26504
diff
changeset
|
3384 user_func_error(int error, char_u *name, funcexe_T *funcexe) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3385 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3386 switch (error) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3387 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3388 case FCERR_UNKNOWN: |
26506
4a1d2abc2016
patch 8.2.3783: confusing error for using a variable as a function
Bram Moolenaar <Bram@vim.org>
parents:
26504
diff
changeset
|
3389 if (funcexe->fe_found_var) |
28263
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
3390 emsg_funcname(e_not_callable_type_str, name); |
26506
4a1d2abc2016
patch 8.2.3783: confusing error for using a variable as a function
Bram Moolenaar <Bram@vim.org>
parents:
26504
diff
changeset
|
3391 else |
26602
fac6673086df
patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26574
diff
changeset
|
3392 emsg_funcname(e_unknown_function_str, name); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3393 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3394 case FCERR_NOTMETHOD: |
28263
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
3395 emsg_funcname(e_cannot_use_function_as_method_str, name); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3396 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3397 case FCERR_DELETED: |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
3398 emsg_funcname(e_function_was_deleted_str, name); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3399 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3400 case FCERR_TOOMANY: |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
3401 emsg_funcname(e_too_many_arguments_for_function_str, name); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3402 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3403 case FCERR_TOOFEW: |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
3404 emsg_funcname(e_not_enough_arguments_for_function_str, name); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3405 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3406 case FCERR_SCRIPT: |
28263
c446812efd60
patch 8.2.4657: errors for functions are sometimes hard to read
Bram Moolenaar <Bram@vim.org>
parents:
28249
diff
changeset
|
3407 emsg_funcname(e_using_sid_not_in_script_context_str, name); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3408 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3409 case FCERR_DICT: |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
3410 emsg_funcname(e_calling_dict_function_without_dictionary_str, |
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
3411 name); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3412 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3413 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3414 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3415 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3416 /* |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3417 * 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
|
3418 * |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3419 * 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
|
3420 * 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
|
3421 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3422 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3423 call_func( |
16634
a1ba0bd74e7d
patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents:
16615
diff
changeset
|
3424 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
|
3425 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
|
3426 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
|
3427 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
|
3428 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
|
3429 // 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
|
3430 funcexe_T *funcexe) // more arguments |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3431 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3432 int ret = FAIL; |
19013
dd9ab0674eec
patch 8.2.0067: ERROR_UNKNOWN clashes on some systems
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
3433 int error = FCERR_NONE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3434 int i; |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3435 ufunc_T *fp = NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3436 char_u fname_buf[FLEN_FIXED + 1]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3437 char_u *tofree = NULL; |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3438 char_u *fname = NULL; |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3439 char_u *name = NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3440 int argcount = argcount_in; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3441 typval_T *argvars = argvars_in; |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3442 dict_T *selfdict = funcexe->fe_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
|
3443 typval_T argv[MAX_FUNC_ARGS + 1]; // used when "partial" or |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3444 // "funcexe->fe_basetv" is not NULL |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3445 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
|
3446 int argv_base = 0; |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3447 partial_T *partial = funcexe->fe_partial; |
25137
34f18d4081af
patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents:
25104
diff
changeset
|
3448 type_T check_type; |
26833
434eaef2ac62
patch 8.2.3945: Vim9: partial variable argument types are wrong
Bram Moolenaar <Bram@vim.org>
parents:
26804
diff
changeset
|
3449 type_T *check_type_args[MAX_FUNC_ARGS]; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3450 |
17883
6249953b0609
patch 8.1.1938: may crash when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3451 // 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
|
3452 // 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
|
3453 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
|
3454 |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3455 if (partial != NULL) |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3456 fp = partial->pt_func; |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3457 if (fp == NULL) |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3458 { |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3459 // Make a copy of the name, if it comes from a funcref variable it |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3460 // could be changed or deleted in the called function. |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3461 name = len > 0 ? vim_strnsave(funcname, len) : vim_strsave(funcname); |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3462 if (name == NULL) |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3463 return ret; |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3464 |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3465 fname = fname_trans_sid(name, fname_buf, &tofree, &error); |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3466 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3467 |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3468 if (funcexe->fe_doesrange != NULL) |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3469 *funcexe->fe_doesrange = FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3470 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3471 if (partial != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3472 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3473 // 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
|
3474 // 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
|
3475 // 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
|
3476 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
|
3477 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
|
3478 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
|
3479 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3480 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
|
3481 { |
e9675870c480
patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents:
18572
diff
changeset
|
3482 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
|
3483 { |
19013
dd9ab0674eec
patch 8.2.0067: ERROR_UNKNOWN clashes on some systems
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
3484 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
|
3485 goto theend; |
e9675870c480
patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents:
18572
diff
changeset
|
3486 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3487 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
|
3488 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3489 for (i = 0; i < argcount_in; ++i) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3490 argv[i + argv_clear] = argvars_in[i]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3491 argvars = argv; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3492 argcount = partial->pt_argc + argcount_in; |
25137
34f18d4081af
patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents:
25104
diff
changeset
|
3493 |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3494 if (funcexe->fe_check_type != NULL |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3495 && funcexe->fe_check_type->tt_argcount != -1) |
25137
34f18d4081af
patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents:
25104
diff
changeset
|
3496 { |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3497 // Now funcexe->fe_check_type is missing the added arguments, |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3498 // make a copy of the type with the correction. |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3499 check_type = *funcexe->fe_check_type; |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3500 funcexe->fe_check_type = &check_type; |
26833
434eaef2ac62
patch 8.2.3945: Vim9: partial variable argument types are wrong
Bram Moolenaar <Bram@vim.org>
parents:
26804
diff
changeset
|
3501 check_type.tt_args = check_type_args; |
434eaef2ac62
patch 8.2.3945: Vim9: partial variable argument types are wrong
Bram Moolenaar <Bram@vim.org>
parents:
26804
diff
changeset
|
3502 CLEAR_FIELD(check_type_args); |
434eaef2ac62
patch 8.2.3945: Vim9: partial variable argument types are wrong
Bram Moolenaar <Bram@vim.org>
parents:
26804
diff
changeset
|
3503 for (i = 0; i < check_type.tt_argcount; ++i) |
434eaef2ac62
patch 8.2.3945: Vim9: partial variable argument types are wrong
Bram Moolenaar <Bram@vim.org>
parents:
26804
diff
changeset
|
3504 check_type_args[i + partial->pt_argc] = |
434eaef2ac62
patch 8.2.3945: Vim9: partial variable argument types are wrong
Bram Moolenaar <Bram@vim.org>
parents:
26804
diff
changeset
|
3505 check_type.tt_args[i]; |
25137
34f18d4081af
patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents:
25104
diff
changeset
|
3506 check_type.tt_argcount += partial->pt_argc; |
34f18d4081af
patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents:
25104
diff
changeset
|
3507 check_type.tt_min_argcount += partial->pt_argc; |
34f18d4081af
patch 8.2.3105: Vim9: type of partial is wrong when it has arguments
Bram Moolenaar <Bram@vim.org>
parents:
25104
diff
changeset
|
3508 } |
9562
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 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3511 |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3512 if (error == FCERR_NONE && funcexe->fe_check_type != NULL |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3513 && funcexe->fe_evaluate) |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
3514 { |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
3515 // Check that the argument types are OK for the types of the funcref. |
27171
374c7d5a096a
patch 8.2.4114: Vim9: type checking for a funcref does not work for method
Bram Moolenaar <Bram@vim.org>
parents:
27114
diff
changeset
|
3516 if (check_argument_types(funcexe->fe_check_type, |
374c7d5a096a
patch 8.2.4114: Vim9: type checking for a funcref does not work for method
Bram Moolenaar <Bram@vim.org>
parents:
27114
diff
changeset
|
3517 argvars, argcount, funcexe->fe_basetv, |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
3518 (name != NULL) ? name : funcname) == FAIL) |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
3519 error = FCERR_OTHER; |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
3520 } |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
3521 |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3522 if (error == FCERR_NONE && funcexe->fe_evaluate) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3523 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3524 char_u *rfname = fname; |
21586
5470c36ed7e6
patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents:
21566
diff
changeset
|
3525 int is_global = FALSE; |
5470c36ed7e6
patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents:
21566
diff
changeset
|
3526 |
5470c36ed7e6
patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents:
21566
diff
changeset
|
3527 // Skip "g:" before a function name. |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3528 if (fp == NULL && fname[0] == 'g' && fname[1] == ':') |
21586
5470c36ed7e6
patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents:
21566
diff
changeset
|
3529 { |
5470c36ed7e6
patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents:
21566
diff
changeset
|
3530 is_global = TRUE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3531 rfname = fname + 2; |
21586
5470c36ed7e6
patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents:
21566
diff
changeset
|
3532 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3533 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3534 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
|
3535 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
|
3536 error = FCERR_UNKNOWN; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3537 |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3538 if (fp != NULL || !builtin_function(rfname, -1)) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3539 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3540 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3541 * User defined function. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3542 */ |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3543 if (fp == NULL) |
27464
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3544 { |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27092
diff
changeset
|
3545 fp = find_func(rfname, is_global); |
27464
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3546 if (fp != NULL && !is_global && in_vim9script() |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3547 && func_requires_g_prefix(fp)) |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3548 // In Vim9 script g: is required to find a global |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3549 // non-autoload function. |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3550 fp = NULL; |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3551 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3552 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3553 // 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
|
3554 if (fp == NULL |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3555 && apply_autocmds(EVENT_FUNCUNDEFINED, |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3556 rfname, rfname, TRUE, NULL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3557 && !aborting()) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3558 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3559 // executed an autocommand, search for the function again |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27092
diff
changeset
|
3560 fp = find_func(rfname, is_global); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3561 } |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3562 // Try loading a package. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3563 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
|
3564 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3565 // loaded a package, search for the function again |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27092
diff
changeset
|
3566 fp = find_func(rfname, is_global); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3567 } |
20079
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3568 if (fp == NULL) |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3569 { |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3570 char_u *p = untrans_function_name(rfname); |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3571 |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3572 // If using Vim9 script try not local to the script. |
21747
7e1316c6d0eb
patch 8.2.1423: Vim9: find global function when looking for script-local
Bram Moolenaar <Bram@vim.org>
parents:
21737
diff
changeset
|
3573 // Don't do this if the name starts with "s:". |
7e1316c6d0eb
patch 8.2.1423: Vim9: find global function when looking for script-local
Bram Moolenaar <Bram@vim.org>
parents:
21737
diff
changeset
|
3574 if (p != NULL && (funcname[0] != 's' || funcname[1] != ':')) |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27092
diff
changeset
|
3575 fp = find_func(p, is_global); |
20079
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3576 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3577 |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
3578 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
|
3579 error = FCERR_DELETED; |
21006
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
3580 #ifdef FEAT_LUA |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
3581 else if (fp != NULL && (fp->uf_flags & FC_CFUNC)) |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
3582 { |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
3583 cfunc_T cb = fp->uf_cb; |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
3584 |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
3585 error = (*cb)(argcount, argvars, rettv, fp->uf_cb_state); |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
3586 } |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
3587 #endif |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
3588 else if (fp != NULL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3589 { |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3590 if (funcexe->fe_argv_func != NULL) |
18572
23fef64352a1
patch 8.1.2280: crash when passing partial to substitute()
Bram Moolenaar <Bram@vim.org>
parents:
18536
diff
changeset
|
3591 // postponed filling in the arguments, do it now |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3592 argcount = funcexe->fe_argv_func(argcount, argvars, |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3593 argv_clear, fp->uf_args.ga_len); |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3594 |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3595 if (funcexe->fe_basetv != NULL) |
17638
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
3596 { |
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
3597 // 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
|
3598 mch_memmove(&argv[1], argvars, sizeof(typval_T) * argcount); |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3599 argv[0] = *funcexe->fe_basetv; |
17638
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
3600 argcount++; |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3601 argvars = argv; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3602 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
|
3603 } |
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
3604 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3605 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
|
3606 funcexe, selfdict); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3607 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3608 } |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3609 else if (funcexe->fe_basetv != NULL) |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3610 { |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3611 /* |
17638
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
3612 * 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
|
3613 * 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
|
3614 */ |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3615 error = call_internal_method(fname, argcount, argvars, rettv, |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3616 funcexe->fe_basetv); |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3617 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3618 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3619 { |
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 * 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
|
3622 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3623 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
|
3624 } |
21586
5470c36ed7e6
patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents:
21566
diff
changeset
|
3625 |
9562
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 * 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
|
3628 * 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
|
3629 * 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
|
3630 * 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
|
3631 * 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
|
3632 * 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
|
3633 * 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
|
3634 * 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
|
3635 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3636 update_force_abort(); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3637 } |
19013
dd9ab0674eec
patch 8.2.0067: ERROR_UNKNOWN clashes on some systems
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
3638 if (error == FCERR_NONE) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3639 ret = OK; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3640 |
18576
e9675870c480
patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents:
18572
diff
changeset
|
3641 theend: |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3642 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3643 * 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
|
3644 * 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
|
3645 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3646 if (!aborting()) |
26506
4a1d2abc2016
patch 8.2.3783: confusing error for using a variable as a function
Bram Moolenaar <Bram@vim.org>
parents:
26504
diff
changeset
|
3647 user_func_error(error, (name != NULL) ? name : funcname, funcexe); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3648 |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3649 // 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
|
3650 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
|
3651 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
|
3652 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3653 vim_free(tofree); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3654 vim_free(name); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3655 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3656 return ret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3657 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3658 |
21401
aa7675a4a0cd
patch 8.2.1251: Vim9: warning for pointer usage, test failure undetected
Bram Moolenaar <Bram@vim.org>
parents:
21319
diff
changeset
|
3659 char_u * |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3660 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
|
3661 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3662 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
|
3663 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3664 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3665 /* |
19579
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3666 * 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
|
3667 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3668 static void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3669 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
|
3670 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3671 int j; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3672 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3673 msg_start(); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3674 if (indent) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3675 msg_puts(" "); |
20943
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
3676 if (fp->uf_def_status != UF_NOT_COMPILED) |
19579
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3677 msg_puts("def "); |
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3678 else |
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3679 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
|
3680 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
|
3681 msg_putchar('('); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3682 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
|
3683 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3684 if (j) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3685 msg_puts(", "); |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3686 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
|
3687 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
|
3688 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3689 char *tofree; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3690 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3691 msg_puts(": "); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3692 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
|
3693 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
|
3694 } |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
3695 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
|
3696 { |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
3697 msg_puts(" = "); |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
3698 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
|
3699 [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
|
3700 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3701 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3702 if (fp->uf_varargs) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3703 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3704 if (j) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3705 msg_puts(", "); |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3706 msg_puts("..."); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3707 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3708 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
|
3709 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3710 if (j) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3711 msg_puts(", "); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3712 msg_puts("..."); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3713 msg_puts((char *)fp->uf_va_name); |
24400
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
3714 if (fp->uf_va_type != NULL) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3715 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3716 char *tofree; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3717 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3718 msg_puts(": "); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3719 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
|
3720 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
|
3721 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3722 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3723 msg_putchar(')'); |
19579
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3724 |
20943
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
3725 if (fp->uf_def_status != UF_NOT_COMPILED) |
19579
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3726 { |
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3727 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
|
3728 { |
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3729 char *tofree; |
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3730 |
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3731 msg_puts(": "); |
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3732 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
|
3733 vim_free(tofree); |
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3734 } |
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3735 } |
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3736 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
|
3737 msg_puts(" abort"); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3738 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
|
3739 msg_puts(" range"); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3740 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
|
3741 msg_puts(" dict"); |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
3742 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
|
3743 msg_puts(" closure"); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3744 msg_clr_eos(); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3745 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
|
3746 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
|
3747 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3748 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3749 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3750 * 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
|
3751 * 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
|
3752 * Returns the function name in allocated memory, or NULL for failure. |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3753 * Set "*is_global" to TRUE when the function must be global, unless |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3754 * "is_global" is NULL. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3755 * flags: |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3756 * TFN_INT: internal function name OK |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3757 * TFN_QUIET: be quiet |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3758 * 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
|
3759 * 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
|
3760 * 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
|
3761 */ |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
3762 char_u * |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3763 trans_function_name( |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3764 char_u **pp, |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3765 int *is_global, |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3766 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
|
3767 int flags, |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3768 funcdict_T *fdp, // return: info about dictionary used |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
3769 partial_T **partial, // return: partial of a FuncRef |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
3770 type_T **type) // return: type of funcref if not NULL |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3771 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3772 char_u *name = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3773 char_u *start; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3774 char_u *end; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3775 int lead; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3776 char_u sid_buf[20]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3777 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
|
3778 int extra = 0; |
27464
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3779 int prefix_g = FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3780 lval_T lv; |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
3781 int vim9script = in_vim9script(); |
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
3782 int vim9_local; |
9562
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 if (fdp != NULL) |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
3785 CLEAR_POINTER(fdp); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3786 start = *pp; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3787 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3788 // 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
|
3789 // command). |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3790 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
|
3791 && (*pp)[2] == (int)KE_SNR) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3792 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3793 *pp += 3; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3794 len = get_id_len(pp) + 3; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3795 return vim_strnsave(start, len); |
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 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3798 // 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
|
3799 // 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
|
3800 lead = eval_fname_script(start); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3801 if (lead > 2) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3802 start += lead; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3803 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3804 // 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
|
3805 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
|
3806 lead > 2 ? 0 : FNE_CHECK_START); |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
3807 if (end == start || (vim9script && end != NULL |
27279
6e1b0c4ab668
patch 8.2.4168: disallowing empty function name breaks existing plugins
Bram Moolenaar <Bram@vim.org>
parents:
27271
diff
changeset
|
3808 && end[-1] == AUTOLOAD_CHAR && *end == '(')) |
9562
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 if (!skip) |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
3811 emsg(_(e_function_name_required)); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3812 goto theend; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3813 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3814 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
|
3815 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3816 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3817 * 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
|
3818 * 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
|
3819 * interrupt, or an exception. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3820 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3821 if (!aborting()) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3822 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3823 if (end != NULL) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26857
diff
changeset
|
3824 semsg(_(e_invalid_argument_str), start); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3825 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3826 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3827 *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
|
3828 goto theend; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3829 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3830 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3831 if (lv.ll_tv != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3832 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3833 if (fdp != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3834 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3835 fdp->fd_dict = lv.ll_dict; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3836 fdp->fd_newkey = lv.ll_newkey; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3837 lv.ll_newkey = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3838 fdp->fd_di = lv.ll_di; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3839 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3840 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
|
3841 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3842 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
|
3843 *pp = end; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3844 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3845 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
|
3846 && lv.ll_tv->vval.v_partial != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3847 { |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
3848 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
|
3849 *pp = end; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3850 if (partial != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3851 *partial = lv.ll_tv->vval.v_partial; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3852 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3853 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3854 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3855 if (!skip && !(flags & TFN_QUIET) && (fdp == NULL |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3856 || lv.ll_dict == NULL || fdp->fd_newkey == NULL)) |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
3857 emsg(_(e_funcref_required)); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3858 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3859 *pp = end; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3860 name = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3861 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3862 goto theend; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3863 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3864 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3865 if (lv.ll_name == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3866 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3867 // 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
|
3868 *pp = end; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3869 goto theend; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3870 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3871 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3872 // 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
|
3873 if (lv.ll_exp_name != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3874 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3875 len = (int)STRLEN(lv.ll_exp_name); |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
3876 name = deref_func_name(lv.ll_exp_name, &len, partial, type, |
27233
73232ed49cf2
patch 8.2.4145: confusing error when using name of import for a function
Bram Moolenaar <Bram@vim.org>
parents:
27189
diff
changeset
|
3877 flags & TFN_NO_AUTOLOAD, flags & TFN_NEW_FUNC, NULL); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3878 if (name == lv.ll_exp_name) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3879 name = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3880 } |
27076
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3881 else if (lv.ll_sid > 0) |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3882 { |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3883 scriptitem_T *si = SCRIPT_ITEM(lv.ll_sid); |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3884 int cc = *lv.ll_name_end; |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3885 |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3886 // function in another script. Prefix <SNR>99_ or the autoload prefix. |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3887 *lv.ll_name_end = NUL; |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3888 if (si->sn_autoload_prefix != NULL) |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3889 { |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3890 name = concat_str(si->sn_autoload_prefix, lv.ll_name); |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3891 } |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3892 else |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3893 { |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3894 sid_buf[0] = K_SPECIAL; |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3895 sid_buf[1] = KS_EXTRA; |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3896 sid_buf[2] = (int)KE_SNR; |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3897 vim_snprintf((char *)sid_buf + 3, sizeof(sid_buf) - 3, |
27457
4c16acb2525f
patch 8.2.4257: Vim9: finding global function without g: prefix inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
27348
diff
changeset
|
3898 "%ld_", (long)lv.ll_sid); |
27076
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3899 name = concat_str(sid_buf, lv.ll_name); |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3900 } |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3901 *lv.ll_name_end = cc; |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3902 *pp = end; |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3903 goto theend; |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3904 } |
9717
6226de5f8137
commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents:
9688
diff
changeset
|
3905 else if (!(flags & TFN_NO_DEREF)) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3906 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3907 len = (int)(end - *pp); |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
3908 name = deref_func_name(*pp, &len, partial, type, |
27233
73232ed49cf2
patch 8.2.4145: confusing error when using name of import for a function
Bram Moolenaar <Bram@vim.org>
parents:
27189
diff
changeset
|
3909 flags & TFN_NO_AUTOLOAD, flags & TFN_NEW_FUNC, NULL); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3910 if (name == *pp) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3911 name = NULL; |
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 if (name != NULL) |
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 name = vim_strsave(name); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3916 *pp = end; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3917 if (STRNCMP(name, "<SNR>", 5) == 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3918 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3919 // Change "<SNR>" to the byte sequence. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3920 name[0] = K_SPECIAL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3921 name[1] = KS_EXTRA; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3922 name[2] = (int)KE_SNR; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3923 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
|
3924 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3925 goto theend; |
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 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3928 if (lv.ll_exp_name != NULL) |
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 len = (int)STRLEN(lv.ll_exp_name); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3931 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
|
3932 && STRNCMP(lv.ll_name, "s:", 2) == 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3933 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3934 // 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
|
3935 // leading "s:" then remove it. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3936 lv.ll_name += 2; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3937 len -= 2; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3938 lead = 2; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3939 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3940 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3941 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3942 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3943 // skip over "s:" and "g:" |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3944 if (lead == 2 || (lv.ll_name[0] == 'g' && lv.ll_name[1] == ':')) |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3945 { |
27464
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3946 if (lv.ll_name[0] == 'g') |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3947 { |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3948 if (is_global != NULL) |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3949 { |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3950 *is_global = TRUE; |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3951 } |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3952 else |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3953 { |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3954 // dropping "g:" without setting "is_global" won't work in |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3955 // Vim9script, put it back later |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3956 prefix_g = TRUE; |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3957 extra = 2; |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3958 } |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3959 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3960 lv.ll_name += 2; |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3961 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3962 len = (int)(end - lv.ll_name); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3963 } |
22496
454b78ca8247
patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents:
22415
diff
changeset
|
3964 if (len <= 0) |
454b78ca8247
patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents:
22415
diff
changeset
|
3965 { |
454b78ca8247
patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents:
22415
diff
changeset
|
3966 if (!skip) |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
3967 emsg(_(e_function_name_required)); |
22496
454b78ca8247
patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents:
22415
diff
changeset
|
3968 goto theend; |
454b78ca8247
patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents:
22415
diff
changeset
|
3969 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3970 |
23237
033b2a97d59b
patch 8.2.2164: Vim9: autoload function doesn't work in uppercased script
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
3971 // In Vim9 script a user function is script-local by default, unless it |
033b2a97d59b
patch 8.2.2164: Vim9: autoload function doesn't work in uppercased script
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
3972 // starts with a lower case character: dict.func(). |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
3973 vim9_local = ASCII_ISUPPER(*start) && vim9script; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3974 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3975 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3976 * Copy the function name to allocated memory. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3977 * 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
|
3978 * Accept <SNR>123_name() outside a script. |
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 if (skip) |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3981 lead = 0; // do nothing |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
3982 else if (lead > 0 || vim9_local) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3983 { |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
3984 if (!vim9_local) |
27595
d504745607bc
patch 8.2.4324: Vim9: script-local function name can start with "_"
Bram Moolenaar <Bram@vim.org>
parents:
27563
diff
changeset
|
3985 { |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
3986 if (vim9script && lead == 2 && !ASCII_ISUPPER(*lv.ll_name)) |
27595
d504745607bc
patch 8.2.4324: Vim9: script-local function name can start with "_"
Bram Moolenaar <Bram@vim.org>
parents:
27563
diff
changeset
|
3987 { |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
3988 semsg(_(vim9script |
27595
d504745607bc
patch 8.2.4324: Vim9: script-local function name can start with "_"
Bram Moolenaar <Bram@vim.org>
parents:
27563
diff
changeset
|
3989 ? e_function_name_must_start_with_capital_str |
d504745607bc
patch 8.2.4324: Vim9: script-local function name can start with "_"
Bram Moolenaar <Bram@vim.org>
parents:
27563
diff
changeset
|
3990 : e_function_name_must_start_with_capital_or_s_str), |
d504745607bc
patch 8.2.4324: Vim9: script-local function name can start with "_"
Bram Moolenaar <Bram@vim.org>
parents:
27563
diff
changeset
|
3991 start); |
d504745607bc
patch 8.2.4324: Vim9: script-local function name can start with "_"
Bram Moolenaar <Bram@vim.org>
parents:
27563
diff
changeset
|
3992 goto theend; |
d504745607bc
patch 8.2.4324: Vim9: script-local function name can start with "_"
Bram Moolenaar <Bram@vim.org>
parents:
27563
diff
changeset
|
3993 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3994 lead = 3; |
27595
d504745607bc
patch 8.2.4324: Vim9: script-local function name can start with "_"
Bram Moolenaar <Bram@vim.org>
parents:
27563
diff
changeset
|
3995 } |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
3996 if (vim9_local || (lv.ll_exp_name != NULL |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3997 && 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
|
3998 || eval_fname_sid(*pp)) |
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 // 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
|
4001 if (current_sctx.sc_sid <= 0) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4002 { |
26439
b18f3b0f317c
patch 8.2.3750: error messages are everywhere
Bram Moolenaar <Bram@vim.org>
parents:
26388
diff
changeset
|
4003 emsg(_(e_using_sid_not_in_script_context)); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4004 goto theend; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4005 } |
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
|
4006 sprintf((char *)sid_buf, "%ld_", (long)current_sctx.sc_sid); |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
4007 if (vim9_local) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4008 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
|
4009 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4010 lead += (int)STRLEN(sid_buf); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4011 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4012 } |
24988
494112d2aa93
patch 8.2.3031: no error if a function name starts with an underscore
Bram Moolenaar <Bram@vim.org>
parents:
24895
diff
changeset
|
4013 else if (!(flags & TFN_INT) && (builtin_function(lv.ll_name, len) |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
4014 || (vim9script && *lv.ll_name == '_'))) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4015 { |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
4016 semsg(_(vim9script ? e_function_name_must_start_with_capital_str |
27595
d504745607bc
patch 8.2.4324: Vim9: script-local function name can start with "_"
Bram Moolenaar <Bram@vim.org>
parents:
27563
diff
changeset
|
4017 : e_function_name_must_start_with_capital_or_s_str), |
d504745607bc
patch 8.2.4324: Vim9: script-local function name can start with "_"
Bram Moolenaar <Bram@vim.org>
parents:
27563
diff
changeset
|
4018 start); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4019 goto theend; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4020 } |
9717
6226de5f8137
commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents:
9688
diff
changeset
|
4021 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
|
4022 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4023 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
|
4024 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4025 if (cp != NULL && cp < end) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4026 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
4027 semsg(_(e_function_name_cannot_contain_colon_str), start); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4028 goto theend; |
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 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4031 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4032 name = alloc(len + lead + extra + 1); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4033 if (name != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4034 { |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
4035 if (!skip && (lead > 0 || vim9_local)) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4036 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4037 name[0] = K_SPECIAL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4038 name[1] = KS_EXTRA; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4039 name[2] = (int)KE_SNR; |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
4040 if (vim9_local || lead > 3) // If it's "<SID>" |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4041 STRCPY(name + 3, sid_buf); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4042 } |
27464
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
4043 else if (prefix_g) |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
4044 { |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
4045 name[0] = 'g'; |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
4046 name[1] = ':'; |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
4047 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4048 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
|
4049 name[lead + extra + len] = NUL; |
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 *pp = end; |
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 theend: |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4054 clear_lval(&lv); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4055 return name; |
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 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4058 /* |
20079
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4059 * Assuming "name" is the result of trans_function_name() and it was prefixed |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4060 * to use the script-local name, return the unmodified name (points into |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4061 * "name"). Otherwise return NULL. |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4062 * This can be used to first search for a script-local function and fall back |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4063 * to the global function if not found. |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4064 */ |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4065 char_u * |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4066 untrans_function_name(char_u *name) |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4067 { |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4068 char_u *p; |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4069 |
21279
8d1d11afd8c8
patch 8.2.1190: Vim9: checking for Vim9 syntax is spread out
Bram Moolenaar <Bram@vim.org>
parents:
21263
diff
changeset
|
4070 if (*name == K_SPECIAL && in_vim9script()) |
20079
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4071 { |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4072 p = vim_strchr(name, '_'); |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4073 if (p != NULL) |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4074 return p + 1; |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4075 } |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4076 return NULL; |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4077 } |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4078 |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4079 /* |
26721
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4080 * If the 'funcname' starts with "s:" or "<SID>", then expands it to the |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4081 * current script ID and returns the expanded function name. The caller should |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4082 * free the returned name. If not called from a script context or the function |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4083 * name doesn't start with these prefixes, then returns NULL. |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4084 * This doesn't check whether the script-local function exists or not. |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4085 */ |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4086 char_u * |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4087 get_scriptlocal_funcname(char_u *funcname) |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4088 { |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4089 char sid_buf[25]; |
27782
40ae50de0d27
patch 8.2.4417: using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
27780
diff
changeset
|
4090 int off; |
26721
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4091 char_u *newname; |
27780
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4092 char_u *p = funcname; |
26721
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4093 |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4094 if (funcname == NULL) |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4095 return NULL; |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4096 |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4097 if (STRNCMP(funcname, "s:", 2) != 0 |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4098 && STRNCMP(funcname, "<SID>", 5) != 0) |
27780
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4099 { |
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4100 ufunc_T *ufunc; |
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4101 |
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4102 // The function name does not have a script-local prefix. Try finding |
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4103 // it when in a Vim9 script and there is no "g:" prefix. |
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4104 if (!in_vim9script() || STRNCMP(funcname, "g:", 2) == 0) |
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4105 return NULL; |
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4106 ufunc = find_func(funcname, FALSE); |
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4107 if (ufunc == NULL || func_is_global(ufunc) |
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4108 || (p = vim_strchr(ufunc->uf_name, '_')) == NULL) |
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4109 return NULL; |
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4110 ++p; |
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4111 off = 0; |
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4112 } |
27782
40ae50de0d27
patch 8.2.4417: using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
27780
diff
changeset
|
4113 else |
40ae50de0d27
patch 8.2.4417: using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
27780
diff
changeset
|
4114 off = *funcname == 's' ? 2 : 5; |
26721
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4115 |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4116 if (!SCRIPT_ID_VALID(current_sctx.sc_sid)) |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4117 { |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4118 emsg(_(e_using_sid_not_in_script_context)); |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4119 return NULL; |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4120 } |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4121 // Expand s: prefix into <SNR>nr_<name> |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4122 vim_snprintf(sid_buf, sizeof(sid_buf), "<SNR>%ld_", |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4123 (long)current_sctx.sc_sid); |
27780
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4124 newname = alloc(STRLEN(sid_buf) + STRLEN(p + off) + 1); |
26721
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4125 if (newname == NULL) |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4126 return NULL; |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4127 STRCPY(newname, sid_buf); |
27780
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4128 STRCAT(newname, p + off); |
26721
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4129 |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4130 return newname; |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4131 } |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4132 |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4133 /* |
27807
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4134 * Return script-local "fname" with the 3-byte sequence replaced by |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4135 * printable <SNR> in allocated memory. |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4136 */ |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4137 char_u * |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4138 alloc_printable_func_name(char_u *fname) |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4139 { |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4140 char_u *n = alloc(STRLEN(fname + 3) + 6); |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4141 |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4142 if (n != NULL) |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4143 { |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4144 STRCPY(n, "<SNR>"); |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4145 STRCPY(n + 5, fname + 3); |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4146 } |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4147 return n; |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4148 } |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4149 |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4150 /* |
26348
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4151 * Call trans_function_name(), except that a lambda is returned as-is. |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4152 * Returns the name in allocated memory. |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4153 */ |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4154 char_u * |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4155 save_function_name( |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4156 char_u **name, |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4157 int *is_global, |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4158 int skip, |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4159 int flags, |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4160 funcdict_T *fudi) |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4161 { |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4162 char_u *p = *name; |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4163 char_u *saved; |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4164 |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4165 if (STRNCMP(p, "<lambda>", 8) == 0) |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4166 { |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4167 p += 8; |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4168 (void)getdigits(&p); |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4169 saved = vim_strnsave(*name, p - *name); |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4170 if (fudi != NULL) |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4171 CLEAR_POINTER(fudi); |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4172 } |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4173 else |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4174 saved = trans_function_name(&p, is_global, skip, |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4175 flags, fudi, NULL, NULL); |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4176 *name = p; |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4177 return saved; |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4178 } |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4179 |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4180 /* |
20709
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4181 * List functions. When "regmatch" is NULL all of then. |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4182 * Otherwise functions matching "regmatch". |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4183 */ |
22973
4c97c0747017
patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents:
22908
diff
changeset
|
4184 void |
20709
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4185 list_functions(regmatch_T *regmatch) |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4186 { |
21319
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21313
diff
changeset
|
4187 int changed = func_hashtab.ht_changed; |
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21313
diff
changeset
|
4188 long_u todo = func_hashtab.ht_used; |
20709
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4189 hashitem_T *hi; |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4190 |
21319
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21313
diff
changeset
|
4191 for (hi = func_hashtab.ht_array; todo > 0 && !got_int; ++hi) |
20709
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4192 { |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4193 if (!HASHITEM_EMPTY(hi)) |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4194 { |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4195 ufunc_T *fp = HI2UF(hi); |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4196 |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4197 --todo; |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4198 if ((fp->uf_flags & FC_DEAD) == 0 |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4199 && (regmatch == NULL |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4200 ? !message_filtered(fp->uf_name) |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4201 && !func_name_refcount(fp->uf_name) |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4202 : !isdigit(*fp->uf_name) |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4203 && vim_regexec(regmatch, fp->uf_name, 0))) |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4204 { |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4205 list_func_head(fp, FALSE); |
21319
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21313
diff
changeset
|
4206 if (changed != func_hashtab.ht_changed) |
20709
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4207 { |
26915
3631d2deb36c
patch 8.2.3986: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26897
diff
changeset
|
4208 emsg(_(e_function_list_was_modified)); |
20709
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4209 return; |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4210 } |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4211 } |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4212 } |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4213 } |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4214 } |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4215 |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4216 /* |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4217 * ":function" also supporting nested ":def". |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
4218 * When "name_arg" is not NULL this is a nested function, using "name_arg" for |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
4219 * the function name. |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
4220 * "lines_to_free" is a list of strings to be freed later. |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4221 * Returns a pointer to the function or NULL if no function defined. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4222 */ |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4223 ufunc_T * |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
4224 define_function(exarg_T *eap, char_u *name_arg, garray_T *lines_to_free) |
9562
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 j; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4227 int c; |
27476
4f1cf9579e4e
patch 8.2.4266: compiler warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
27472
diff
changeset
|
4228 int saved_did_emsg = FALSE; |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4229 char_u *name = name_arg; |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
4230 int is_global = FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4231 char_u *p; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4232 char_u *arg; |
23511
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
4233 char_u *whitep; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4234 char_u *line_arg = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4235 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
|
4236 garray_T argtypes; |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
4237 garray_T default_args; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4238 garray_T newlines; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4239 int varargs = FALSE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4240 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
|
4241 char_u *ret_type = NULL; |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4242 ufunc_T *fp = NULL; |
26566
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4243 int fp_allocated = FALSE; |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4244 int free_fp = FALSE; |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
4245 int overwrite = FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4246 dictitem_T *v; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4247 funcdict_T fudi; |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4248 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
|
4249 int paren; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4250 hashitem_T *hi; |
17251
984eef966002
patch 8.1.1625: script line numbers are not exactly right
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
4251 linenr_T sourcing_lnum_top; |
21435
8ec9e2b54ce7
patch 8.2.1268: Vim9: no error for using double quote comment
Bram Moolenaar <Bram@vim.org>
parents:
21401
diff
changeset
|
4252 int vim9script = in_vim9script(); |
21598
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21586
diff
changeset
|
4253 imported_T *import = NULL; |
21435
8ec9e2b54ce7
patch 8.2.1268: Vim9: no error for using double quote comment
Bram Moolenaar <Bram@vim.org>
parents:
21401
diff
changeset
|
4254 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4255 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4256 * ":function" without argument: list functions. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4257 */ |
20138
d0a9766167ab
patch 8.2.0624: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20081
diff
changeset
|
4258 if (ends_excmd2(eap->cmd, eap->arg)) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4259 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4260 if (!eap->skip) |
20709
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4261 list_functions(NULL); |
25521
2063b858cad9
patch 8.2.3297: cannot use all commands inside a {} block
Bram Moolenaar <Bram@vim.org>
parents:
25473
diff
changeset
|
4262 set_nextcmd(eap, eap->arg); |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4263 return NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4264 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4265 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4266 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4267 * ":function /pat": list functions matching pattern. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4268 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4269 if (*eap->arg == '/') |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4270 { |
19892
5feb426d2ea1
patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
4271 p = skip_regexp(eap->arg + 1, '/', TRUE); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4272 if (!eap->skip) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4273 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4274 regmatch_T regmatch; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4275 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4276 c = *p; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4277 *p = NUL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4278 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
|
4279 *p = c; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4280 if (regmatch.regprog != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4281 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4282 regmatch.rm_ic = p_ic; |
20709
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4283 list_functions(®match); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4284 vim_regfree(regmatch.regprog); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4285 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4286 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4287 if (*p == '/') |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4288 ++p; |
25521
2063b858cad9
patch 8.2.3297: cannot use all commands inside a {} block
Bram Moolenaar <Bram@vim.org>
parents:
25473
diff
changeset
|
4289 set_nextcmd(eap, p); |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4290 return NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4291 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4292 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4293 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
|
4294 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
|
4295 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
|
4296 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4297 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4298 * 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
|
4299 * func normal function name |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4300 * "name" == func, "fudi.fd_dict" == NULL |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4301 * dict.func new dictionary entry |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4302 * "name" == NULL, "fudi.fd_dict" set, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4303 * "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
|
4304 * 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
|
4305 * "name" == func, "fudi.fd_dict" set, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4306 * "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
|
4307 * 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
|
4308 * "name" == NULL, "fudi.fd_dict" set, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4309 * "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
|
4310 * s:func script-local function name |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4311 * 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
|
4312 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4313 p = eap->arg; |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4314 if (name_arg != NULL) |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4315 { |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4316 // nested function, argument is (args). |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4317 paren = TRUE; |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4318 CLEAR_FIELD(fudi); |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4319 } |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4320 else |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4321 { |
27869
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4322 if (vim9script) |
27669
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
4323 { |
27869
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4324 if (p[0] == 's' && p[1] == ':') |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4325 { |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4326 semsg(_(e_cannot_use_s_colon_in_vim9_script_str), p); |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4327 return NULL; |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4328 } |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4329 p = to_name_end(p, TRUE); |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4330 if (*skipwhite(p) == '.' && vim_strchr(p, '(') != NULL) |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4331 { |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4332 semsg(_(e_cannot_define_dict_func_in_vim9_script_str), |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4333 eap->arg); |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4334 return NULL; |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4335 } |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4336 p = eap->arg; |
27669
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
4337 } |
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
4338 |
26348
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4339 name = save_function_name(&p, &is_global, eap->skip, |
27233
73232ed49cf2
patch 8.2.4145: confusing error when using name of import for a function
Bram Moolenaar <Bram@vim.org>
parents:
27189
diff
changeset
|
4340 TFN_NO_AUTOLOAD | TFN_NEW_FUNC, &fudi); |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4341 paren = (vim_strchr(p, '(') != NULL); |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4342 if (name == NULL && (fudi.fd_dict == NULL || !paren) && !eap->skip) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4343 { |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4344 /* |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4345 * Return on an invalid expression in braces, unless the expression |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4346 * evaluation has been cancelled due to an aborting error, an |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4347 * interrupt, or an exception. |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4348 */ |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4349 if (!aborting()) |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4350 { |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4351 if (!eap->skip && fudi.fd_newkey != NULL) |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
4352 semsg(_(e_key_not_present_in_dictionary), fudi.fd_newkey); |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4353 vim_free(fudi.fd_newkey); |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4354 return NULL; |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4355 } |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4356 else |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4357 eap->skip = TRUE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4358 } |
27043
15f40772e10a
patch 8.2.4050: Vim9: need to prefix every item in an autoload script
Bram Moolenaar <Bram@vim.org>
parents:
27028
diff
changeset
|
4359 |
27049
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
4360 // For "export def FuncName()" in an autoload script the function name |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
4361 // is stored with the legacy autoload name "dir#script#FuncName" so |
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
4362 // that it can also be found in legacy script. |
27092
6d063974af23
patch 8.2.4075: test failures
Bram Moolenaar <Bram@vim.org>
parents:
27088
diff
changeset
|
4363 if (is_export && name != NULL) |
27267
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4364 { |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4365 char_u *prefixed = may_prefix_autoload(name); |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4366 |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4367 if (prefixed != NULL && prefixed != name) |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4368 { |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4369 vim_free(name); |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4370 name = prefixed; |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4371 } |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4372 } |
27563
a54064e14114
patch 8.2.4308: Vim9: cannot list autoload function
Bram Moolenaar <Bram@vim.org>
parents:
27482
diff
changeset
|
4373 else if (paren && vim9script && name != NULL |
27482
14640c6fe1fe
patch 8.2.4269: Coverity warns for using a NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
27476
diff
changeset
|
4374 && vim_strchr(name, AUTOLOAD_CHAR) != NULL) |
27472
55613f0d59bc
patch 8.2.4264: Vim9: can use old style autoload function name
Bram Moolenaar <Bram@vim.org>
parents:
27464
diff
changeset
|
4375 { |
55613f0d59bc
patch 8.2.4264: Vim9: can use old style autoload function name
Bram Moolenaar <Bram@vim.org>
parents:
27464
diff
changeset
|
4376 emsg(_(e_cannot_use_name_with_hash_in_vim9_script_use_export_instead)); |
55613f0d59bc
patch 8.2.4264: Vim9: can use old style autoload function name
Bram Moolenaar <Bram@vim.org>
parents:
27464
diff
changeset
|
4377 goto ret_free; |
55613f0d59bc
patch 8.2.4264: Vim9: can use old style autoload function name
Bram Moolenaar <Bram@vim.org>
parents:
27464
diff
changeset
|
4378 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4379 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4380 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4381 // 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
|
4382 // 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
|
4383 saved_did_emsg = did_emsg; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4384 did_emsg = FALSE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4385 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4386 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4387 * ":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
|
4388 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4389 if (!paren) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4390 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4391 if (!ends_excmd(*skipwhite(p))) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4392 { |
26883
7f150a4936f2
patch 8.2.3970: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
4393 semsg(_(e_trailing_characters_str), p); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4394 goto ret_free; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4395 } |
25521
2063b858cad9
patch 8.2.3297: cannot use all commands inside a {} block
Bram Moolenaar <Bram@vim.org>
parents:
25473
diff
changeset
|
4396 set_nextcmd(eap, p); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4397 if (eap->nextcmd != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4398 *p = NUL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4399 if (!eap->skip && !got_int) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4400 { |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27092
diff
changeset
|
4401 fp = find_func(name, is_global); |
20079
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4402 if (fp == NULL && ASCII_ISUPPER(*eap->arg)) |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4403 { |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4404 char_u *up = untrans_function_name(name); |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4405 |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4406 // With Vim9 script the name was made script-local, if not |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4407 // found try again with the original name. |
20081
75589416d02d
patch 8.2.0596: crash in test49
Bram Moolenaar <Bram@vim.org>
parents:
20079
diff
changeset
|
4408 if (up != NULL) |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27092
diff
changeset
|
4409 fp = find_func(up, FALSE); |
20079
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4410 } |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4411 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4412 if (fp != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4413 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4414 list_func_head(fp, TRUE); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4415 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
|
4416 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4417 if (FUNCLINE(fp, j) == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4418 continue; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4419 msg_putchar('\n'); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4420 msg_outnum((long)(j + 1)); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4421 if (j < 9) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4422 msg_putchar(' '); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4423 if (j < 99) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4424 msg_putchar(' '); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4425 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
|
4426 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
|
4427 ui_breakcheck(); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4428 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4429 if (!got_int) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4430 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4431 msg_putchar('\n'); |
20943
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4432 if (fp->uf_def_status != UF_NOT_COMPILED) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4433 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
|
4434 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4435 msg_puts(" endfunction"); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4436 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4437 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4438 else |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
4439 emsg_funcname(e_undefined_function_str, eap->arg); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4440 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4441 goto ret_free; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4442 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4443 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4444 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4445 * ":function name(arg1, arg2)" Define function. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4446 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4447 p = skipwhite(p); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4448 if (*p != '(') |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4449 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4450 if (!eap->skip) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4451 { |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
4452 semsg(_(e_missing_paren_str), eap->arg); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4453 goto ret_free; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4454 } |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4455 // 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
|
4456 if (vim_strchr(p, '(') != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4457 p = vim_strchr(p, '('); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4458 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4459 |
23727
7d0959080545
patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents:
23717
diff
changeset
|
4460 if ((vim9script || eap->cmdidx == CMD_def) && VIM_ISWHITE(p[-1])) |
7d0959080545
patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents:
23717
diff
changeset
|
4461 { |
23888
d95403445b6b
patch 8.2.2486: Vim9: some errors for white space do not show context
Bram Moolenaar <Bram@vim.org>
parents:
23879
diff
changeset
|
4462 semsg(_(e_no_white_space_allowed_before_str_str), "(", p - 1); |
23727
7d0959080545
patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents:
23717
diff
changeset
|
4463 goto ret_free; |
7d0959080545
patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents:
23717
diff
changeset
|
4464 } |
7d0959080545
patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents:
23717
diff
changeset
|
4465 |
21479
90d859a402cc
patch 8.2.1290: Vim9: cannot replace a global function
Bram Moolenaar <Bram@vim.org>
parents:
21461
diff
changeset
|
4466 // In Vim9 script only global functions can be redefined. |
90d859a402cc
patch 8.2.1290: Vim9: cannot replace a global function
Bram Moolenaar <Bram@vim.org>
parents:
21461
diff
changeset
|
4467 if (vim9script && eap->forceit && !is_global) |
90d859a402cc
patch 8.2.1290: Vim9: cannot replace a global function
Bram Moolenaar <Bram@vim.org>
parents:
21461
diff
changeset
|
4468 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
4469 emsg(_(e_no_bang_allowed)); |
21479
90d859a402cc
patch 8.2.1290: Vim9: cannot replace a global function
Bram Moolenaar <Bram@vim.org>
parents:
21461
diff
changeset
|
4470 goto ret_free; |
90d859a402cc
patch 8.2.1290: Vim9: cannot replace a global function
Bram Moolenaar <Bram@vim.org>
parents:
21461
diff
changeset
|
4471 } |
90d859a402cc
patch 8.2.1290: Vim9: cannot replace a global function
Bram Moolenaar <Bram@vim.org>
parents:
21461
diff
changeset
|
4472 |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
4473 ga_init2(&newlines, sizeof(char_u *), 10); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4474 |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4475 if (!eap->skip && name_arg == NULL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4476 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4477 // 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
|
4478 // (that we are overwriting). |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4479 if (name != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4480 arg = name; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4481 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4482 arg = fudi.fd_newkey; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4483 if (arg != NULL && (fudi.fd_di == NULL |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4484 || (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
|
4485 && 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
|
4486 { |
26504
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4487 char_u *name_base = arg; |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4488 int i; |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4489 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4490 if (*arg == K_SPECIAL) |
26504
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4491 { |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4492 name_base = vim_strchr(arg, '_'); |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4493 if (name_base == NULL) |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4494 name_base = arg + 3; |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4495 else |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4496 ++name_base; |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4497 } |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4498 for (i = 0; name_base[i] != NUL && (i == 0 |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4499 ? eval_isnamec1(name_base[i]) |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4500 : eval_isnamec(name_base[i])); ++i) |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4501 ; |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4502 if (name_base[i] != NUL) |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
4503 emsg_funcname(e_invalid_argument_str, arg); |
26504
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4504 |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4505 // In Vim9 script a function cannot have the same name as a |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4506 // variable. |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4507 if (vim9script && *arg == K_SPECIAL |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
4508 && eval_variable(name_base, (int)STRLEN(name_base), 0, NULL, |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
4509 NULL, EVAL_VAR_NOAUTOLOAD + EVAL_VAR_IMPORT |
26504
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4510 + EVAL_VAR_NO_FUNC) == OK) |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4511 { |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4512 semsg(_(e_redefining_script_item_str), name_base); |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4513 goto ret_free; |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4514 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4515 } |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4516 // Disallow using the g: dict. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4517 if (fudi.fd_dict != NULL && fudi.fd_dict->dv_scope == VAR_DEF_SCOPE) |
26504
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4518 { |
26962
85866e069c24
patch 8.2.4010: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26958
diff
changeset
|
4519 emsg(_(e_cannot_use_g_here)); |
26504
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4520 goto ret_free; |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4521 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4522 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4523 |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4524 // This may get more lines and make the pointers into the first line |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4525 // invalid. |
23511
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
4526 ++p; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4527 if (get_function_args(&p, ')', &newargs, |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
4528 eap->cmdidx == CMD_def ? &argtypes : NULL, FALSE, |
24033
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
24004
diff
changeset
|
4529 NULL, &varargs, &default_args, eap->skip, |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
4530 eap, lines_to_free) == FAIL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4531 goto errret_2; |
23511
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
4532 whitep = p; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4533 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4534 if (eap->cmdidx == CMD_def) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4535 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4536 // find the return type: :def Func(): type |
25561
164cef0bc7ab
patch 8.2.3317: Vim9: No error for missing white space before return type
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
4537 if (*skipwhite(p) == ':') |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4538 { |
25561
164cef0bc7ab
patch 8.2.3317: Vim9: No error for missing white space before return type
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
4539 if (*p != ':') |
164cef0bc7ab
patch 8.2.3317: Vim9: No error for missing white space before return type
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
4540 { |
164cef0bc7ab
patch 8.2.3317: Vim9: No error for missing white space before return type
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
4541 semsg(_(e_no_white_space_allowed_before_colon_str), p); |
164cef0bc7ab
patch 8.2.3317: Vim9: No error for missing white space before return type
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
4542 p = skipwhite(p); |
164cef0bc7ab
patch 8.2.3317: Vim9: No error for missing white space before return type
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
4543 } |
164cef0bc7ab
patch 8.2.3317: Vim9: No error for missing white space before return type
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
4544 else if (!IS_WHITE_OR_NUL(p[1])) |
164cef0bc7ab
patch 8.2.3317: Vim9: No error for missing white space before return type
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
4545 semsg(_(e_white_space_required_after_str_str), ":", p); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4546 ret_type = skipwhite(p + 1); |
21500
574517d682cf
patch 8.2.1300: Vim9: optional argument type not parsed properly
Bram Moolenaar <Bram@vim.org>
parents:
21479
diff
changeset
|
4547 p = skip_type(ret_type, FALSE); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4548 if (p > ret_type) |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4549 { |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
4550 ret_type = vim_strnsave(ret_type, p - ret_type); |
23511
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
4551 whitep = p; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4552 p = skipwhite(p); |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4553 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4554 else |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4555 { |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21791
diff
changeset
|
4556 semsg(_(e_expected_type_str), ret_type); |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4557 ret_type = NULL; |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4558 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4559 } |
21435
8ec9e2b54ce7
patch 8.2.1268: Vim9: no error for using double quote comment
Bram Moolenaar <Bram@vim.org>
parents:
21401
diff
changeset
|
4560 p = skipwhite(p); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4561 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4562 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4563 // 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
|
4564 for (;;) |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
4565 { |
23511
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
4566 whitep = p; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4567 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
|
4568 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
|
4569 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4570 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
|
4571 p += 5; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4572 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4573 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
|
4574 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4575 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
|
4576 p += 4; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4577 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4578 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
|
4579 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4580 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
|
4581 p += 5; |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
4582 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4583 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
|
4584 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4585 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
|
4586 p += 7; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4587 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
|
4588 { |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
4589 emsg_funcname(e_closure_function_should_not_be_at_top_level, |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4590 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
|
4591 goto erret; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4592 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4593 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4594 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4595 break; |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
4596 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4597 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4598 // 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
|
4599 // 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
|
4600 if (*p == '\n') |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4601 line_arg = p + 1; |
21435
8ec9e2b54ce7
patch 8.2.1268: Vim9: no error for using double quote comment
Bram Moolenaar <Bram@vim.org>
parents:
21401
diff
changeset
|
4602 else if (*p != NUL |
21528
e0aa9b81f6a9
patch 8.2.1314: Vim9: rule for comment after :function is confusing
Bram Moolenaar <Bram@vim.org>
parents:
21500
diff
changeset
|
4603 && !(*p == '"' && (!vim9script || eap->cmdidx == CMD_function) |
e0aa9b81f6a9
patch 8.2.1314: Vim9: rule for comment after :function is confusing
Bram Moolenaar <Bram@vim.org>
parents:
21500
diff
changeset
|
4604 && eap->cmdidx != CMD_def) |
23511
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
4605 && !(VIM_ISWHITE(*whitep) && *p == '#' |
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
4606 && (vim9script || eap->cmdidx == CMD_def)) |
21435
8ec9e2b54ce7
patch 8.2.1268: Vim9: no error for using double quote comment
Bram Moolenaar <Bram@vim.org>
parents:
21401
diff
changeset
|
4607 && !eap->skip |
8ec9e2b54ce7
patch 8.2.1268: Vim9: no error for using double quote comment
Bram Moolenaar <Bram@vim.org>
parents:
21401
diff
changeset
|
4608 && !did_emsg) |
26883
7f150a4936f2
patch 8.2.3970: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
4609 semsg(_(e_trailing_characters_str), p); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4610 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4611 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4612 * 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
|
4613 * found. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4614 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4615 if (KeyTyped) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4616 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4617 // 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
|
4618 // 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
|
4619 // 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
|
4620 if (!eap->skip && !eap->forceit) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4621 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4622 if (fudi.fd_dict != NULL && fudi.fd_newkey == NULL) |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
4623 emsg(_(e_dictionary_entry_already_exists)); |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27092
diff
changeset
|
4624 else if (name != NULL && find_func(name, is_global) != NULL) |
26857
2aeea8611342
patch 8.2.3957: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26833
diff
changeset
|
4625 emsg_funcname(e_function_str_already_exists_add_bang_to_replace, name); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4626 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4627 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4628 if (!eap->skip && did_emsg) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4629 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4630 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4631 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
|
4632 cmdline_row = msg_row; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4633 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4634 |
17251
984eef966002
patch 8.1.1625: script line numbers are not exactly right
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
4635 // 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
|
4636 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
|
4637 |
24653
0ef7bb28f2c3
patch 8.2.2865: skipping over function body fails
Bram Moolenaar <Bram@vim.org>
parents:
24651
diff
changeset
|
4638 // Do not define the function when getting the body fails and when |
0ef7bb28f2c3
patch 8.2.2865: skipping over function body fails
Bram Moolenaar <Bram@vim.org>
parents:
24651
diff
changeset
|
4639 // skipping. |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
4640 if (get_function_body(eap, &newlines, line_arg, lines_to_free) == FAIL |
24653
0ef7bb28f2c3
patch 8.2.2865: skipping over function body fails
Bram Moolenaar <Bram@vim.org>
parents:
24651
diff
changeset
|
4641 || eap->skip) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4642 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4643 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4644 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4645 * 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
|
4646 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4647 if (fudi.fd_dict == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4648 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4649 hashtab_T *ht; |
27267
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4650 char_u *find_name = name; |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4651 int var_conflict = FALSE; |
27348
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
4652 int ffed_flags = is_global ? FFED_IS_GLOBAL : 0; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4653 |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
4654 v = find_var(name, &ht, TRUE); |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
4655 if (v != NULL && (vim9script || v->di_tv.v_type == VAR_FUNC)) |
27267
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4656 var_conflict = TRUE; |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4657 |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4658 if (SCRIPT_ID_VALID(current_sctx.sc_sid)) |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4659 { |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4660 scriptitem_T *si = SCRIPT_ITEM(current_sctx.sc_sid); |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4661 |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4662 if (si->sn_autoload_prefix != NULL) |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4663 { |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4664 if (is_export) |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4665 { |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4666 find_name = name + STRLEN(si->sn_autoload_prefix); |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4667 v = find_var(find_name, &ht, TRUE); |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4668 if (v != NULL) |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4669 var_conflict = TRUE; |
27348
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
4670 // Only check if the function already exists in the script, |
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
4671 // global functions can be shadowed. |
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
4672 ffed_flags |= FFED_NO_GLOBAL; |
27267
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4673 } |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4674 else |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4675 { |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4676 char_u *prefixed = may_prefix_autoload(name); |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4677 |
27893
8e630053c59c
patch 8.2.4472: Coverity warns for use of a freed function name
Bram Moolenaar <Bram@vim.org>
parents:
27869
diff
changeset
|
4678 if (prefixed != NULL && prefixed != name) |
27267
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4679 { |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4680 v = find_var(prefixed, &ht, TRUE); |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4681 if (v != NULL) |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4682 var_conflict = TRUE; |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4683 vim_free(prefixed); |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4684 } |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4685 } |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4686 } |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4687 } |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4688 if (var_conflict) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4689 { |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
4690 emsg_funcname(e_function_name_conflicts_with_variable_str, name); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4691 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4692 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4693 |
27348
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
4694 fp = find_func_even_dead(find_name, ffed_flags); |
21598
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21586
diff
changeset
|
4695 if (vim9script) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4696 { |
21598
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21586
diff
changeset
|
4697 char_u *uname = untrans_function_name(name); |
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21586
diff
changeset
|
4698 |
27698
3813036f19cb
patch 8.2.4375: ctx_imports is not used
Bram Moolenaar <Bram@vim.org>
parents:
27682
diff
changeset
|
4699 import = find_imported(uname == NULL ? name : uname, 0, FALSE); |
21598
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21586
diff
changeset
|
4700 } |
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21586
diff
changeset
|
4701 |
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21586
diff
changeset
|
4702 if (fp != NULL || import != NULL) |
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21586
diff
changeset
|
4703 { |
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21586
diff
changeset
|
4704 int dead = fp != NULL && (fp->uf_flags & FC_DEAD); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4705 |
15008
67e3103d6e18
patch 8.1.0515: reloading a script gives errors for existing functions
Bram Moolenaar <Bram@vim.org>
parents:
15000
diff
changeset
|
4706 // 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
|
4707 // same script again, but only once. |
21598
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21586
diff
changeset
|
4708 // A name that is used by an import can not be overruled. |
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21586
diff
changeset
|
4709 if (import != NULL |
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21586
diff
changeset
|
4710 || (!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
|
4711 && (fp->uf_script_ctx.sc_sid != current_sctx.sc_sid |
21598
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21586
diff
changeset
|
4712 || 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
|
4713 { |
26205
9e5e331828da
patch 8.2.3634: error for already defined function uses wrong line number
Bram Moolenaar <Bram@vim.org>
parents:
26203
diff
changeset
|
4714 SOURCING_LNUM = sourcing_lnum_top; |
21598
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21586
diff
changeset
|
4715 if (vim9script) |
21909
a211bca98bc3
patch 8.2.1504: Vim9: white space checks are only done for a :def function
Bram Moolenaar <Bram@vim.org>
parents:
21883
diff
changeset
|
4716 emsg_funcname(e_name_already_defined_str, name); |
21598
7b5b9558500a
patch 8.2.1349: Vim9: can define a function with the name of an import
Bram Moolenaar <Bram@vim.org>
parents:
21586
diff
changeset
|
4717 else |
26857
2aeea8611342
patch 8.2.3957: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26833
diff
changeset
|
4718 emsg_funcname(e_function_str_already_exists_add_bang_to_replace, name); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4719 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4720 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4721 if (fp->uf_calls > 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4722 { |
15008
67e3103d6e18
patch 8.1.0515: reloading a script gives errors for existing functions
Bram Moolenaar <Bram@vim.org>
parents:
15000
diff
changeset
|
4723 emsg_funcname( |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
4724 e_cannot_redefine_function_str_it_is_in_use, name); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4725 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4726 } |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
4727 if (fp->uf_refcount > 1) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
4728 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4729 // 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
|
4730 // create a new one. |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
4731 --fp->uf_refcount; |
9733
59565cdd7261
commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents:
9731
diff
changeset
|
4732 fp->uf_flags |= FC_REMOVED; |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
4733 fp = NULL; |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
4734 overwrite = TRUE; |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
4735 } |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
4736 else |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
4737 { |
19035
b920ae62c7b1
patch 8.2.0078: expanding <sfile> works differently the second time
Bram Moolenaar <Bram@vim.org>
parents:
19013
diff
changeset
|
4738 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
|
4739 |
b920ae62c7b1
patch 8.2.0078: expanding <sfile> works differently the second time
Bram Moolenaar <Bram@vim.org>
parents:
19013
diff
changeset
|
4740 // 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
|
4741 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
|
4742 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
|
4743 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
|
4744 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
|
4745 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
|
4746 #ifdef FEAT_PROFILE |
2fba714294b9
patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents:
14323
diff
changeset
|
4747 fp->uf_profiling = FALSE; |
2fba714294b9
patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents:
14323
diff
changeset
|
4748 fp->uf_prof_initialized = FALSE; |
2fba714294b9
patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents:
14323
diff
changeset
|
4749 #endif |
23360
eb7d8f39363c
patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents:
23354
diff
changeset
|
4750 fp->uf_def_status = UF_NOT_COMPILED; |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
4751 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4752 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4753 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4754 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4755 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4756 char numbuf[20]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4757 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4758 fp = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4759 if (fudi.fd_newkey == NULL && !eap->forceit) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4760 { |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
4761 emsg(_(e_dictionary_entry_already_exists)); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4762 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4763 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4764 if (fudi.fd_di == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4765 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4766 // Can't add a function to a locked dictionary |
22298
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22260
diff
changeset
|
4767 if (value_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
|
4768 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4769 } |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4770 // Can't change an existing function if it is locked |
22298
07e48ee8c3bb
patch 8.2.1698: cannot lock a variable in legacy Vim script like in Vim9
Bram Moolenaar <Bram@vim.org>
parents:
22260
diff
changeset
|
4771 else if (value_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
|
4772 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4773 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4774 // 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
|
4775 // Funcref! |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4776 vim_free(name); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4777 sprintf(numbuf, "%d", ++func_nr); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4778 name = vim_strsave((char_u *)numbuf); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4779 if (name == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4780 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4781 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4782 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4783 if (fp == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4784 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4785 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
|
4786 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4787 int slen, plen; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4788 char_u *scriptname; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4789 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4790 // 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
|
4791 j = FAIL; |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
4792 if (SOURCING_NAME != NULL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4793 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4794 scriptname = autoload_name(name); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4795 if (scriptname != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4796 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4797 p = vim_strchr(scriptname, '/'); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4798 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
|
4799 slen = (int)STRLEN(SOURCING_NAME); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4800 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
|
4801 SOURCING_NAME + slen - plen) == 0) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4802 j = OK; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4803 vim_free(scriptname); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4804 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4805 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4806 if (j == FAIL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4807 { |
24436
ccdd5e9a3763
patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name
Bram Moolenaar <Bram@vim.org>
parents:
24422
diff
changeset
|
4808 linenr_T save_lnum = SOURCING_LNUM; |
ccdd5e9a3763
patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name
Bram Moolenaar <Bram@vim.org>
parents:
24422
diff
changeset
|
4809 |
ccdd5e9a3763
patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name
Bram Moolenaar <Bram@vim.org>
parents:
24422
diff
changeset
|
4810 SOURCING_LNUM = sourcing_lnum_top; |
26958
d92e0d85923f
patch 8.2.4008: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26952
diff
changeset
|
4811 semsg(_(e_function_name_does_not_match_script_file_name_str), |
d92e0d85923f
patch 8.2.4008: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26952
diff
changeset
|
4812 name); |
24436
ccdd5e9a3763
patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name
Bram Moolenaar <Bram@vim.org>
parents:
24422
diff
changeset
|
4813 SOURCING_LNUM = save_lnum; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4814 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4815 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4816 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4817 |
17659
121bdff812b4
patch 8.1.1827: allocating more memory than needed for extended structs
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
4818 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
|
4819 if (fp == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4820 goto erret; |
26566
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4821 fp_allocated = TRUE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4822 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4823 if (fudi.fd_dict != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4824 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4825 if (fudi.fd_di == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4826 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4827 // add new dict entry |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4828 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
|
4829 if (fudi.fd_di == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4830 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4831 vim_free(fp); |
20542
dd3165956464
patch 8.2.0825: def_function() may return pointer that was freed
Bram Moolenaar <Bram@vim.org>
parents:
20538
diff
changeset
|
4832 fp = NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4833 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4834 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4835 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
|
4836 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4837 vim_free(fudi.fd_di); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4838 vim_free(fp); |
20542
dd3165956464
patch 8.2.0825: def_function() may return pointer that was freed
Bram Moolenaar <Bram@vim.org>
parents:
20538
diff
changeset
|
4839 fp = NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4840 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4841 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4842 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4843 else |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4844 // overwrite existing dict entry |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4845 clear_tv(&fudi.fd_di->di_tv); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4846 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
|
4847 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
|
4848 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4849 // behave like "dict" was used |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4850 flags |= FC_DICT; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4851 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4852 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4853 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
|
4854 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
|
4855 fp->uf_ret_type = &t_any; |
19912
d4fa9db88d16
patch 8.2.0512: Vim9: no optional arguments in func type
Bram Moolenaar <Bram@vim.org>
parents:
19900
diff
changeset
|
4856 fp->uf_func_type = &t_func_any; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4857 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4858 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
|
4859 { |
22643
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
4860 int lnum_save = SOURCING_LNUM; |
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
4861 cstack_T *cstack = eap->cstack; |
19297
84703c85a583
patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents:
19285
diff
changeset
|
4862 |
20943
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4863 fp->uf_def_status = UF_TO_BE_COMPILED; |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
4864 |
19297
84703c85a583
patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents:
19285
diff
changeset
|
4865 // 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
|
4866 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
|
4867 |
25358
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
4868 // The function may use script variables from the context. |
f03271631eb5
patch 8.2.3216: Vim9: crash when using variable in a loop at script level
Bram Moolenaar <Bram@vim.org>
parents:
25306
diff
changeset
|
4869 function_using_block_scopes(fp, cstack); |
22596
107eae953b87
patch 8.2.1846: Vim9: block variables are not found in compiled function
Bram Moolenaar <Bram@vim.org>
parents:
22496
diff
changeset
|
4870 |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
4871 if (parse_argument_types(fp, &argtypes, varargs) == FAIL) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4872 { |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
4873 SOURCING_LNUM = lnum_save; |
26566
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4874 free_fp = fp_allocated; |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4875 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
|
4876 } |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
4877 varargs = FALSE; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4878 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4879 // parse the return type, if any |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
4880 if (parse_return_type(fp, ret_type) == FAIL) |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4881 { |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
4882 SOURCING_LNUM = lnum_save; |
26566
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4883 free_fp = fp_allocated; |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
4884 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
|
4885 } |
20339
7587d892c00c
patch 8.2.0725: Vim9: cannot call a function declared later in Vim9 script
Bram Moolenaar <Bram@vim.org>
parents:
20279
diff
changeset
|
4886 SOURCING_LNUM = lnum_save; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4887 } |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
4888 else |
20943
1693ca876049
patch 8.2.1023: Vim9: redefining a function uses a new index every time
Bram Moolenaar <Bram@vim.org>
parents:
20830
diff
changeset
|
4889 fp->uf_def_status = UF_NOT_COMPILED; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4890 |
26566
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4891 if (fp_allocated) |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4892 { |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4893 // insert the new function in the function list |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4894 set_ufunc_name(fp, name); |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4895 if (overwrite) |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4896 { |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4897 hi = hash_find(&func_hashtab, name); |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4898 hi->hi_key = UF2HIKEY(fp); |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4899 } |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4900 else if (hash_add(&func_hashtab, UF2HIKEY(fp)) == FAIL) |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4901 { |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4902 free_fp = TRUE; |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4903 goto erret; |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4904 } |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4905 fp->uf_refcount = 1; |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4906 } |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4907 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4908 fp->uf_lines = newlines; |
26566
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4909 newlines.ga_data = NULL; |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
4910 if ((flags & FC_CLOSURE) != 0) |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
4911 { |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
4912 if (register_closure(fp) == FAIL) |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
4913 goto erret; |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
4914 } |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
4915 else |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
4916 fp->uf_scoped = NULL; |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
4917 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4918 #ifdef FEAT_PROFILE |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4919 if (prof_def_func()) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4920 func_do_profile(fp); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4921 #endif |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4922 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
|
4923 if (sandbox) |
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
4924 flags |= FC_SANDBOX; |
21435
8ec9e2b54ce7
patch 8.2.1268: Vim9: no error for using double quote comment
Bram Moolenaar <Bram@vim.org>
parents:
21401
diff
changeset
|
4925 if (vim9script && !ASCII_ISUPPER(*fp->uf_name)) |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
4926 flags |= FC_VIM9; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4927 fp->uf_flags = flags; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4928 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
|
4929 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
|
4930 fp->uf_script_ctx = current_sctx; |
21646
a640bc762196
patch 8.2.1373: Vim9: no error for assigning to non-existing script var
Bram Moolenaar <Bram@vim.org>
parents:
21598
diff
changeset
|
4931 fp->uf_script_ctx_version = current_sctx.sc_version; |
17251
984eef966002
patch 8.1.1625: script line numbers are not exactly right
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
4932 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
|
4933 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
|
4934 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4935 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
|
4936 // 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
|
4937 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
|
4938 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4939 |
20532
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
4940 if (eap->cmdidx == CMD_def) |
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
4941 set_function_type(fp); |
20945
0653b9b72091
patch 8.2.1024: Vim9: no error for using "let g:var = val"
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
4942 else if (fp->uf_script_ctx.sc_version == SCRIPT_VERSION_VIM9) |
0653b9b72091
patch 8.2.1024: Vim9: no error for using "let g:var = val"
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
4943 // :func does not use Vim9 script syntax, even in a Vim9 script file |
0653b9b72091
patch 8.2.1024: Vim9: no error for using "let g:var = val"
Bram Moolenaar <Bram@vim.org>
parents:
20943
diff
changeset
|
4944 fp->uf_script_ctx.sc_version = SCRIPT_VERSION_MAX; |
20532
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
4945 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4946 goto ret_free; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4947 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4948 erret: |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4949 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
|
4950 ga_clear_strings(&default_args); |
23925
e979bf909fd8
patch 8.2.2505: Vim9: crash after defining function with invalid return type
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
4951 if (fp != NULL) |
e979bf909fd8
patch 8.2.2505: Vim9: crash after defining function with invalid return type
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
4952 { |
e979bf909fd8
patch 8.2.2505: Vim9: crash after defining function with invalid return type
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
4953 ga_init(&fp->uf_args); |
e979bf909fd8
patch 8.2.2505: Vim9: crash after defining function with invalid return type
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
4954 ga_init(&fp->uf_def_args); |
e979bf909fd8
patch 8.2.2505: Vim9: crash after defining function with invalid return type
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
4955 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4956 errret_2: |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4957 ga_clear_strings(&newlines); |
23925
e979bf909fd8
patch 8.2.2505: Vim9: crash after defining function with invalid return type
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
4958 if (fp != NULL) |
e979bf909fd8
patch 8.2.2505: Vim9: crash after defining function with invalid return type
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
4959 VIM_CLEAR(fp->uf_arg_types); |
26566
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4960 if (free_fp) |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4961 { |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4962 vim_free(fp); |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4963 fp = NULL; |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4964 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4965 ret_free: |
19685
d64f403289db
patch 8.2.0399: various memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19579
diff
changeset
|
4966 ga_clear_strings(&argtypes); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4967 vim_free(fudi.fd_newkey); |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4968 if (name != name_arg) |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4969 vim_free(name); |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4970 vim_free(ret_type); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4971 did_emsg |= saved_did_emsg; |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4972 |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4973 return fp; |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4974 } |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4975 |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4976 /* |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4977 * ":function" |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4978 */ |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4979 void |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4980 ex_function(exarg_T *eap) |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4981 { |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
4982 garray_T lines_to_free; |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
4983 |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
4984 ga_init2(&lines_to_free, sizeof(char_u *), 50); |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
4985 (void)define_function(eap, NULL, &lines_to_free); |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
4986 ga_clear_strings(&lines_to_free); |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
4987 } |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
4988 |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
4989 /* |
22188
ec0a5ae32d5e
patch 8.2.1643: Vim9: :defcompile compiles dead functions
Bram Moolenaar <Bram@vim.org>
parents:
21983
diff
changeset
|
4990 * :defcompile - compile all :def functions in the current script that need to |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23699
diff
changeset
|
4991 * be compiled. Except dead functions. Doesn't do profiling. |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
4992 */ |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
4993 void |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
4994 ex_defcompile(exarg_T *eap UNUSED) |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
4995 { |
21313
e641f678bdb9
patch 8.2.1207: Vim9: crash in expr test when run in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
4996 long todo = (long)func_hashtab.ht_used; |
e641f678bdb9
patch 8.2.1207: Vim9: crash in expr test when run in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
4997 int changed = func_hashtab.ht_changed; |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
4998 hashitem_T *hi; |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
4999 ufunc_T *ufunc; |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
5000 |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
5001 for (hi = func_hashtab.ht_array; todo > 0 && !got_int; ++hi) |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
5002 { |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
5003 if (!HASHITEM_EMPTY(hi)) |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
5004 { |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
5005 --todo; |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
5006 ufunc = HI2UF(hi); |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
5007 if (ufunc->uf_script_ctx.sc_sid == current_sctx.sc_sid |
22188
ec0a5ae32d5e
patch 8.2.1643: Vim9: :defcompile compiles dead functions
Bram Moolenaar <Bram@vim.org>
parents:
21983
diff
changeset
|
5008 && ufunc->uf_def_status == UF_TO_BE_COMPILED |
ec0a5ae32d5e
patch 8.2.1643: Vim9: :defcompile compiles dead functions
Bram Moolenaar <Bram@vim.org>
parents:
21983
diff
changeset
|
5009 && (ufunc->uf_flags & FC_DEAD) == 0) |
20544
e8132bec4b0f
patch 8.2.0826: Vim9: crash in :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
20542
diff
changeset
|
5010 { |
24895
e61a2085c89b
patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents:
24890
diff
changeset
|
5011 (void)compile_def_function(ufunc, FALSE, CT_NONE, NULL); |
20544
e8132bec4b0f
patch 8.2.0826: Vim9: crash in :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
20542
diff
changeset
|
5012 |
21313
e641f678bdb9
patch 8.2.1207: Vim9: crash in expr test when run in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
5013 if (func_hashtab.ht_changed != changed) |
20544
e8132bec4b0f
patch 8.2.0826: Vim9: crash in :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
20542
diff
changeset
|
5014 { |
21313
e641f678bdb9
patch 8.2.1207: Vim9: crash in expr test when run in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
5015 // a function has been added or removed, need to start over |
e641f678bdb9
patch 8.2.1207: Vim9: crash in expr test when run in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
5016 todo = (long)func_hashtab.ht_used; |
e641f678bdb9
patch 8.2.1207: Vim9: crash in expr test when run in the GUI
Bram Moolenaar <Bram@vim.org>
parents:
21279
diff
changeset
|
5017 changed = func_hashtab.ht_changed; |
20544
e8132bec4b0f
patch 8.2.0826: Vim9: crash in :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
20542
diff
changeset
|
5018 hi = func_hashtab.ht_array; |
20546
1ea55bad1234
patch 8.2.0827: Vim9: crash in :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
20544
diff
changeset
|
5019 --hi; |
20544
e8132bec4b0f
patch 8.2.0826: Vim9: crash in :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
20542
diff
changeset
|
5020 } |
e8132bec4b0f
patch 8.2.0826: Vim9: crash in :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
20542
diff
changeset
|
5021 } |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
5022 } |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
5023 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5024 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5025 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5026 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5027 * 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
|
5028 * Return 2 if "p" starts with "s:". |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5029 * Return 0 otherwise. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5030 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5031 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5032 eval_fname_script(char_u *p) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5033 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5034 // 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
|
5035 // the standard library function. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5036 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
|
5037 || MB_STRNICMP(p + 1, "SNR>", 4) == 0)) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5038 return 5; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5039 if (p[0] == 's' && p[1] == ':') |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5040 return 2; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5041 return 0; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5042 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5043 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5044 int |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5045 translated_function_exists(char_u *name, int is_global) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5046 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5047 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
|
5048 return has_internal_func(name); |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27092
diff
changeset
|
5049 return find_func(name, is_global) != NULL; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5050 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5051 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5052 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5053 * 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
|
5054 * 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
|
5055 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5056 int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5057 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
|
5058 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5059 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
|
5060 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5061 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5062 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5063 * 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
|
5064 * 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
|
5065 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5066 int |
9717
6226de5f8137
commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents:
9688
diff
changeset
|
5067 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
|
5068 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5069 char_u *nm = name; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5070 char_u *p; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5071 int n = FALSE; |
9717
6226de5f8137
commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents:
9688
diff
changeset
|
5072 int flag; |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5073 int is_global = FALSE; |
9717
6226de5f8137
commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents:
9688
diff
changeset
|
5074 |
6226de5f8137
commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents:
9688
diff
changeset
|
5075 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
|
5076 if (no_deref) |
6226de5f8137
commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents:
9688
diff
changeset
|
5077 flag |= TFN_NO_DEREF; |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
5078 p = trans_function_name(&nm, &is_global, FALSE, flag, NULL, NULL, NULL); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5079 nm = skipwhite(nm); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5080 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5081 // 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
|
5082 // "funcname(...", not "funcname!...". |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5083 if (p != NULL && (*nm == NUL || *nm == '(')) |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5084 n = translated_function_exists(p, is_global); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5085 vim_free(p); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5086 return n; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5087 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5088 |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
5089 #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
|
5090 char_u * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5091 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
|
5092 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5093 char_u *nm = name; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5094 char_u *p; |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5095 int is_global = FALSE; |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5096 |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5097 p = trans_function_name(&nm, &is_global, FALSE, |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
5098 TFN_INT|TFN_QUIET, NULL, NULL, NULL); |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5099 |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5100 if (p != NULL && *nm == NUL |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5101 && (!check || translated_function_exists(p, is_global))) |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5102 return p; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5103 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5104 vim_free(p); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5105 return NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5106 } |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
5107 #endif |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5108 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5109 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5110 * 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
|
5111 * function names. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5112 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5113 char_u * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5114 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
|
5115 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5116 static long_u done; |
21319
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21313
diff
changeset
|
5117 static int changed; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5118 static hashitem_T *hi; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5119 ufunc_T *fp; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5120 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5121 if (idx == 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5122 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5123 done = 0; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5124 hi = func_hashtab.ht_array; |
21319
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21313
diff
changeset
|
5125 changed = func_hashtab.ht_changed; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5126 } |
21319
fb3dcd8ed14d
patch 8.2.1210: using ht_used when looping through a hashtab is less reliable
Bram Moolenaar <Bram@vim.org>
parents:
21313
diff
changeset
|
5127 if (changed == func_hashtab.ht_changed && done < func_hashtab.ht_used) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5128 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5129 if (done++ > 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5130 ++hi; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5131 while (HASHITEM_EMPTY(hi)) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5132 ++hi; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5133 fp = HI2UF(hi); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5134 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5135 // 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
|
5136 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
|
5137 || 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
|
5138 return (char_u *)""; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5139 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5140 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
|
5141 return fp->uf_name; // prevents overflow |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5142 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5143 cat_func_name(IObuff, fp); |
25694
ce91372ca07b
patch 8.2.3383: Vim9: completion for :disassemble adds parenthesis
Bram Moolenaar <Bram@vim.org>
parents:
25632
diff
changeset
|
5144 if (xp->xp_context != EXPAND_USER_FUNC |
ce91372ca07b
patch 8.2.3383: Vim9: completion for :disassemble adds parenthesis
Bram Moolenaar <Bram@vim.org>
parents:
25632
diff
changeset
|
5145 && xp->xp_context != EXPAND_DISASSEMBLE) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5146 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5147 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
|
5148 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
|
5149 STRCAT(IObuff, ")"); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5150 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5151 return IObuff; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5152 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5153 return NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5154 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5155 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5156 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5157 * ":delfunction {name}" |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5158 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5159 void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5160 ex_delfunction(exarg_T *eap) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5161 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5162 ufunc_T *fp = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5163 char_u *p; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5164 char_u *name; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5165 funcdict_T fudi; |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5166 int is_global = FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5167 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5168 p = eap->arg; |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
5169 name = trans_function_name(&p, &is_global, eap->skip, 0, &fudi, |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
5170 NULL, NULL); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5171 vim_free(fudi.fd_newkey); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5172 if (name == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5173 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5174 if (fudi.fd_dict != NULL && !eap->skip) |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
5175 emsg(_(e_funcref_required)); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5176 return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5177 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5178 if (!ends_excmd(*skipwhite(p))) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5179 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5180 vim_free(name); |
26883
7f150a4936f2
patch 8.2.3970: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
5181 semsg(_(e_trailing_characters_str), p); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5182 return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5183 } |
25521
2063b858cad9
patch 8.2.3297: cannot use all commands inside a {} block
Bram Moolenaar <Bram@vim.org>
parents:
25473
diff
changeset
|
5184 set_nextcmd(eap, p); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5185 if (eap->nextcmd != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5186 *p = NUL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5187 |
26566
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
5188 if (numbered_function(name) && fudi.fd_dict == NULL) |
25745
b916d59f259f
patch 8.2.3408: can delete a numbered function
Bram Moolenaar <Bram@vim.org>
parents:
25737
diff
changeset
|
5189 { |
b916d59f259f
patch 8.2.3408: can delete a numbered function
Bram Moolenaar <Bram@vim.org>
parents:
25737
diff
changeset
|
5190 if (!eap->skip) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26857
diff
changeset
|
5191 semsg(_(e_invalid_argument_str), eap->arg); |
25745
b916d59f259f
patch 8.2.3408: can delete a numbered function
Bram Moolenaar <Bram@vim.org>
parents:
25737
diff
changeset
|
5192 vim_free(name); |
b916d59f259f
patch 8.2.3408: can delete a numbered function
Bram Moolenaar <Bram@vim.org>
parents:
25737
diff
changeset
|
5193 return; |
b916d59f259f
patch 8.2.3408: can delete a numbered function
Bram Moolenaar <Bram@vim.org>
parents:
25737
diff
changeset
|
5194 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5195 if (!eap->skip) |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27092
diff
changeset
|
5196 fp = find_func(name, is_global); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5197 vim_free(name); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5198 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5199 if (!eap->skip) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5200 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5201 if (fp == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5202 { |
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
|
5203 if (!eap->forceit) |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
5204 semsg(_(e_unknown_function_str), eap->arg); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5205 return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5206 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5207 if (fp->uf_calls > 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5208 { |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
5209 semsg(_(e_cannot_delete_function_str_it_is_in_use), eap->arg); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5210 return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5211 } |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5212 if (fp->uf_flags & FC_VIM9) |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5213 { |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21791
diff
changeset
|
5214 semsg(_(e_cannot_delete_vim9_script_function_str), eap->arg); |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5215 return; |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5216 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5217 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5218 if (fudi.fd_dict != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5219 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5220 // 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
|
5221 // 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
|
5222 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
|
5223 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5224 else |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5225 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5226 // 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
|
5227 // 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
|
5228 // 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
|
5229 // 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
|
5230 // one or more. |
9733
59565cdd7261
commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents:
9731
diff
changeset
|
5231 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
|
5232 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5233 // 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
|
5234 // 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
|
5235 if (func_remove(fp)) |
59565cdd7261
commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents:
9731
diff
changeset
|
5236 fp->uf_refcount--; |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5237 } |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5238 else |
10815
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
5239 func_clear_free(fp, FALSE); |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5240 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5241 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5242 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5243 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5244 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5245 * 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
|
5246 * becomes zero. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5247 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5248 void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5249 func_unref(char_u *name) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5250 { |
9655
f1920505bc16
commit https://github.com/vim/vim/commit/97baee80f0906ee2f651ee1215ec033e84f866ad
Christian Brabandt <cb@256bit.org>
parents:
9638
diff
changeset
|
5251 ufunc_T *fp = NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5252 |
9733
59565cdd7261
commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents:
9731
diff
changeset
|
5253 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
|
5254 return; |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27092
diff
changeset
|
5255 fp = find_func(name, FALSE); |
26566
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
5256 if (fp == NULL && numbered_function(name)) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5257 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5258 #ifdef EXITFREE |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5259 if (!entered_free_all_mem) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5260 #endif |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5261 internal_error("func_unref()"); |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5262 } |
23699
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
5263 func_ptr_unref(fp); |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5264 } |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5265 |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5266 /* |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5267 * 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
|
5268 * becomes zero. |
23699
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
5269 * Also when it becomes one and uf_partial points to the function. |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5270 */ |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5271 void |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5272 func_ptr_unref(ufunc_T *fp) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5273 { |
23699
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
5274 if (fp != NULL && (--fp->uf_refcount <= 0 |
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
5275 || (fp->uf_refcount == 1 && fp->uf_partial != NULL |
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
5276 && fp->uf_partial->pt_refcount <= 1 |
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
5277 && fp->uf_partial->pt_func == fp))) |
9655
f1920505bc16
commit https://github.com/vim/vim/commit/97baee80f0906ee2f651ee1215ec033e84f866ad
Christian Brabandt <cb@256bit.org>
parents:
9638
diff
changeset
|
5278 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5279 // 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
|
5280 // when "uf_calls" becomes zero. |
9655
f1920505bc16
commit https://github.com/vim/vim/commit/97baee80f0906ee2f651ee1215ec033e84f866ad
Christian Brabandt <cb@256bit.org>
parents:
9638
diff
changeset
|
5281 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
|
5282 func_clear_free(fp, FALSE); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5283 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5284 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5285 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5286 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5287 * Count a reference to a Function. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5288 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5289 void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5290 func_ref(char_u *name) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5291 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5292 ufunc_T *fp; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5293 |
9733
59565cdd7261
commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents:
9731
diff
changeset
|
5294 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
|
5295 return; |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27092
diff
changeset
|
5296 fp = find_func(name, FALSE); |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5297 if (fp != NULL) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5298 ++fp->uf_refcount; |
26566
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
5299 else if (numbered_function(name)) |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5300 // 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
|
5301 // 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
|
5302 internal_error("func_ref()"); |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5303 } |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5304 |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5305 /* |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5306 * Count a reference to a Function. |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5307 */ |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5308 void |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5309 func_ptr_ref(ufunc_T *fp) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5310 { |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5311 if (fp != NULL) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5312 ++fp->uf_refcount; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5313 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5314 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5315 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5316 * 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
|
5317 * referenced from anywhere that is in use. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5318 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5319 static int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5320 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
|
5321 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5322 return (fc->l_varlist.lv_copyID != copyID |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5323 && 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
|
5324 && fc->l_avars.dv_copyID != copyID |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
5325 && fc->fc_copyID != copyID); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5326 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5327 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5328 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5329 * ":return [expr]" |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5330 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5331 void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5332 ex_return(exarg_T *eap) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5333 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5334 char_u *arg = eap->arg; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5335 typval_T rettv; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5336 int returning = FALSE; |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
5337 evalarg_T evalarg; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5338 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5339 if (current_funccal == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5340 { |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
5341 emsg(_(e_return_not_inside_function)); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5342 return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5343 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5344 |
26053
e861c5aaedd8
patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents:
26046
diff
changeset
|
5345 init_evalarg(&evalarg); |
20992
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
5346 evalarg.eval_flags = eap->skip ? 0 : EVAL_EVALUATE; |
7ee565134d4a
patch 8.2.1047: Vim9: script cannot use line continuation like :def function
Bram Moolenaar <Bram@vim.org>
parents:
20945
diff
changeset
|
5347 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5348 if (eap->skip) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5349 ++emsg_skip; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5350 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5351 eap->nextcmd = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5352 if ((*arg != NUL && *arg != '|' && *arg != '\n') |
20996
3af71cbcfdbe
patch 8.2.1049: Vim9: leaking memory when using continuation line
Bram Moolenaar <Bram@vim.org>
parents:
20992
diff
changeset
|
5353 && eval0(arg, &rettv, eap, &evalarg) != FAIL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5354 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5355 if (!eap->skip) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5356 returning = do_return(eap, FALSE, TRUE, &rettv); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5357 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5358 clear_tv(&rettv); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5359 } |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5360 // 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
|
5361 else if (!eap->skip) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5362 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5363 // 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
|
5364 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
|
5365 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5366 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5367 * 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
|
5368 * aborting error, an interrupt, or an exception. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5369 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5370 if (!aborting()) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5371 returning = do_return(eap, FALSE, TRUE, NULL); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5372 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5373 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5374 // 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
|
5375 // 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
|
5376 // 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
|
5377 if (returning) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5378 eap->nextcmd = NULL; |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5379 else if (eap->nextcmd == NULL) // no argument |
25521
2063b858cad9
patch 8.2.3297: cannot use all commands inside a {} block
Bram Moolenaar <Bram@vim.org>
parents:
25473
diff
changeset
|
5380 set_nextcmd(eap, arg); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5381 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5382 if (eap->skip) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5383 --emsg_skip; |
21058
111f877e63d9
patch 8.2.1080: Vim9: no line break allowed in a for loop
Bram Moolenaar <Bram@vim.org>
parents:
21046
diff
changeset
|
5384 clear_evalarg(&evalarg, eap); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5385 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5386 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5387 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5388 * ":1,25call func(arg1, arg2)" function call. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5389 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5390 void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5391 ex_call(exarg_T *eap) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5392 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5393 char_u *arg = eap->arg; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5394 char_u *startarg; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5395 char_u *name; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5396 char_u *tofree; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5397 int len; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5398 typval_T rettv; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5399 linenr_T lnum; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5400 int doesrange; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5401 int failed = FALSE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5402 funcdict_T fudi; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5403 partial_T *partial = NULL; |
21118
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21066
diff
changeset
|
5404 evalarg_T evalarg; |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
5405 type_T *type = NULL; |
26506
4a1d2abc2016
patch 8.2.3783: confusing error for using a variable as a function
Bram Moolenaar <Bram@vim.org>
parents:
26504
diff
changeset
|
5406 int found_var = FALSE; |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
5407 int vim9script = in_vim9script(); |
21118
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21066
diff
changeset
|
5408 |
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21066
diff
changeset
|
5409 fill_evalarg_from_eap(&evalarg, eap, eap->skip); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5410 if (eap->skip) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5411 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5412 // 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
|
5413 // 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
|
5414 // :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
|
5415 ++emsg_skip; |
21118
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21066
diff
changeset
|
5416 if (eval0(eap->arg, &rettv, eap, &evalarg) != FAIL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5417 clear_tv(&rettv); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5418 --emsg_skip; |
21118
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21066
diff
changeset
|
5419 clear_evalarg(&evalarg, eap); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5420 return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5421 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5422 |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
5423 tofree = trans_function_name(&arg, NULL, eap->skip, TFN_INT, |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
5424 &fudi, &partial, vim9script ? &type : NULL); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5425 if (fudi.fd_newkey != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5426 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5427 // Still need to give an error message for missing key. |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
5428 semsg(_(e_key_not_present_in_dictionary), fudi.fd_newkey); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5429 vim_free(fudi.fd_newkey); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5430 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5431 if (tofree == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5432 return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5433 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5434 // 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
|
5435 // the arguments. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5436 if (fudi.fd_dict != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5437 ++fudi.fd_dict->dv_refcount; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5438 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5439 // 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
|
5440 // 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
|
5441 // from trans_function_name(). |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5442 len = (int)STRLEN(tofree); |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
5443 name = deref_func_name(tofree, &len, partial != NULL ? NULL : &partial, |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
5444 vim9script && type == NULL ? &type : NULL, |
27233
73232ed49cf2
patch 8.2.4145: confusing error when using name of import for a function
Bram Moolenaar <Bram@vim.org>
parents:
27189
diff
changeset
|
5445 FALSE, FALSE, &found_var); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5446 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5447 // 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
|
5448 // backward compatibility. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5449 startarg = skipwhite(arg); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5450 if (*startarg != '(') |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5451 { |
26602
fac6673086df
patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26574
diff
changeset
|
5452 semsg(_(e_missing_parenthesis_str), eap->arg); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5453 goto end; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5454 } |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
5455 if (vim9script && startarg > arg) |
25737
d923be9d752d
patch 8.2.3404: Vim9: no error for white space before "("
Bram Moolenaar <Bram@vim.org>
parents:
25694
diff
changeset
|
5456 { |
d923be9d752d
patch 8.2.3404: Vim9: no error for white space before "("
Bram Moolenaar <Bram@vim.org>
parents:
25694
diff
changeset
|
5457 semsg(_(e_no_white_space_allowed_before_str_str), "(", eap->arg); |
d923be9d752d
patch 8.2.3404: Vim9: no error for white space before "("
Bram Moolenaar <Bram@vim.org>
parents:
25694
diff
changeset
|
5458 goto end; |
d923be9d752d
patch 8.2.3404: Vim9: no error for white space before "("
Bram Moolenaar <Bram@vim.org>
parents:
25694
diff
changeset
|
5459 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5460 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5461 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5462 * 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
|
5463 * arguments. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5464 * 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
|
5465 * call, and the loop is broken. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5466 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5467 if (eap->skip) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5468 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5469 ++emsg_skip; |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5470 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
|
5471 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5472 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5473 lnum = eap->line1; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5474 for ( ; lnum <= eap->line2; ++lnum) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5475 { |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17462
diff
changeset
|
5476 funcexe_T funcexe; |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17462
diff
changeset
|
5477 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5478 if (!eap->skip && eap->addr_count > 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5479 { |
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
|
5480 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
|
5481 { |
32787e326de2
patch 8.1.0511: ml_get error when calling a function with a range
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
5482 // 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
|
5483 // the line number may become invalid. |
25064
8f2262c72178
patch 8.2.3069: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
25046
diff
changeset
|
5484 emsg(_(e_invalid_range)); |
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
|
5485 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
|
5486 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5487 curwin->w_cursor.lnum = lnum; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5488 curwin->w_cursor.col = 0; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5489 curwin->w_cursor.coladd = 0; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5490 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5491 arg = startarg; |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17462
diff
changeset
|
5492 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
5493 CLEAR_FIELD(funcexe); |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
5494 funcexe.fe_firstline = eap->line1; |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
5495 funcexe.fe_lastline = eap->line2; |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
5496 funcexe.fe_doesrange = &doesrange; |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
5497 funcexe.fe_evaluate = !eap->skip; |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
5498 funcexe.fe_partial = partial; |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
5499 funcexe.fe_selfdict = fudi.fd_dict; |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
5500 funcexe.fe_check_type = type; |
26506
4a1d2abc2016
patch 8.2.3783: confusing error for using a variable as a function
Bram Moolenaar <Bram@vim.org>
parents:
26504
diff
changeset
|
5501 funcexe.fe_found_var = found_var; |
25737
d923be9d752d
patch 8.2.3404: Vim9: no error for white space before "("
Bram Moolenaar <Bram@vim.org>
parents:
25694
diff
changeset
|
5502 rettv.v_type = VAR_UNKNOWN; // clear_tv() uses this |
21118
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21066
diff
changeset
|
5503 if (get_func_tv(name, -1, &rettv, &arg, &evalarg, &funcexe) == FAIL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5504 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5505 failed = TRUE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5506 break; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5507 } |
13262
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5508 if (has_watchexpr()) |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5509 dbg_check_breakpoint(eap); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5510 |
17763
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17732
diff
changeset
|
5511 // Handle a function returning a Funcref, Dictionary or List. |
26990
4b8d836db103
patch 8.2.4024: confusing error message if imported name is used directly
Bram Moolenaar <Bram@vim.org>
parents:
26980
diff
changeset
|
5512 if (handle_subscript(&arg, NULL, &rettv, |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21032
diff
changeset
|
5513 eap->skip ? NULL : &EVALARG_EVALUATE, TRUE) == FAIL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5514 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5515 failed = TRUE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5516 break; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5517 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5518 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5519 clear_tv(&rettv); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5520 if (doesrange || eap->skip) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5521 break; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5522 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5523 // 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
|
5524 // 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
|
5525 // 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
|
5526 // characters below is executed. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5527 if (aborting()) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5528 break; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5529 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5530 if (eap->skip) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5531 --emsg_skip; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5532 |
25826
5040fae521f6
patch 8.2.3448: :endtry after function call that throws not found
Bram Moolenaar <Bram@vim.org>
parents:
25761
diff
changeset
|
5533 // When inside :try we need to check for following "| catch" or "| endtry". |
5040fae521f6
patch 8.2.3448: :endtry after function call that throws not found
Bram Moolenaar <Bram@vim.org>
parents:
25761
diff
changeset
|
5534 // Not when there was an error, but do check if an exception was thrown. |
5040fae521f6
patch 8.2.3448: :endtry after function call that throws not found
Bram Moolenaar <Bram@vim.org>
parents:
25761
diff
changeset
|
5535 if ((!aborting() || did_throw) |
5040fae521f6
patch 8.2.3448: :endtry after function call that throws not found
Bram Moolenaar <Bram@vim.org>
parents:
25761
diff
changeset
|
5536 && (!failed || eap->cstack->cs_trylevel > 0)) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5537 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5538 // Check for trailing illegal characters and a following command. |
21737
a849c984b485
patch 8.2.1418: Vim9: invalid error for missing white space
Bram Moolenaar <Bram@vim.org>
parents:
21699
diff
changeset
|
5539 arg = skipwhite(arg); |
20138
d0a9766167ab
patch 8.2.0624: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20081
diff
changeset
|
5540 if (!ends_excmd2(eap->arg, arg)) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5541 { |
25826
5040fae521f6
patch 8.2.3448: :endtry after function call that throws not found
Bram Moolenaar <Bram@vim.org>
parents:
25761
diff
changeset
|
5542 if (!failed && !aborting()) |
19421
208644ebdff8
patch 8.2.0268: trycatch test fails
Bram Moolenaar <Bram@vim.org>
parents:
19419
diff
changeset
|
5543 { |
208644ebdff8
patch 8.2.0268: trycatch test fails
Bram Moolenaar <Bram@vim.org>
parents:
19419
diff
changeset
|
5544 emsg_severe = TRUE; |
26883
7f150a4936f2
patch 8.2.3970: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
5545 semsg(_(e_trailing_characters_str), arg); |
19421
208644ebdff8
patch 8.2.0268: trycatch test fails
Bram Moolenaar <Bram@vim.org>
parents:
19419
diff
changeset
|
5546 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5547 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5548 else |
25521
2063b858cad9
patch 8.2.3297: cannot use all commands inside a {} block
Bram Moolenaar <Bram@vim.org>
parents:
25473
diff
changeset
|
5549 set_nextcmd(eap, arg); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5550 } |
28515
c6aadb2c4cd7
patch 8.2.4782: accessing freed memory
Bram Moolenaar <Bram@vim.org>
parents:
28491
diff
changeset
|
5551 // Must be after using "arg", it may point into memory cleared here. |
c6aadb2c4cd7
patch 8.2.4782: accessing freed memory
Bram Moolenaar <Bram@vim.org>
parents:
28491
diff
changeset
|
5552 clear_evalarg(&evalarg, eap); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5553 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5554 end: |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5555 dict_unref(fudi.fd_dict); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5556 vim_free(tofree); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5557 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5558 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5559 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5560 * 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
|
5561 * 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
|
5562 * 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
|
5563 * 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
|
5564 * 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
|
5565 * FALSE when the return gets pending. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5566 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5567 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5568 do_return( |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5569 exarg_T *eap, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5570 int reanimate, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5571 int is_cmd, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5572 void *rettv) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5573 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5574 int idx; |
18904
2bdc2e1f6e1f
patch 8.2.0013: not using a typedef for condstack
Bram Moolenaar <Bram@vim.org>
parents:
18816
diff
changeset
|
5575 cstack_T *cstack = eap->cstack; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5576 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5577 if (reanimate) |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5578 // Undo the return. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5579 current_funccal->returned = FALSE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5580 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5581 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5582 * 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
|
5583 * 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
|
5584 * 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
|
5585 * Otherwise, return normally. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5586 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5587 idx = cleanup_conditionals(eap->cstack, 0, TRUE); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5588 if (idx >= 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5589 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5590 cstack->cs_pending[idx] = CSTP_RETURN; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5591 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5592 if (!is_cmd && !reanimate) |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5593 // 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
|
5594 // 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
|
5595 // 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
|
5596 cstack->cs_rettv[idx] = rettv; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5597 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5598 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5599 // 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
|
5600 // return rettv. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5601 if (reanimate) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5602 rettv = current_funccal->rettv; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5603 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5604 if (rettv != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5605 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5606 // 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
|
5607 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
|
5608 *(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
|
5609 else |
25306
078edc1821bf
patch 8.2.3190: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
25296
diff
changeset
|
5610 emsg(_(e_out_of_memory)); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5611 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5612 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5613 cstack->cs_rettv[idx] = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5614 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5615 if (reanimate) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5616 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5617 // 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
|
5618 // 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
|
5619 // return value. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5620 current_funccal->rettv->v_type = VAR_NUMBER; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5621 current_funccal->rettv->vval.v_number = 0; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5622 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5623 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5624 report_make_pending(CSTP_RETURN, rettv); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5625 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5626 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5627 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5628 current_funccal->returned = TRUE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5629 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5630 // 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
|
5631 // 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
|
5632 // there. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5633 if (!reanimate && rettv != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5634 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5635 clear_tv(current_funccal->rettv); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5636 *current_funccal->rettv = *(typval_T *)rettv; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5637 if (!is_cmd) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5638 vim_free(rettv); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5639 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5640 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5641 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5642 return idx < 0; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5643 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5644 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5645 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5646 * 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
|
5647 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5648 void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5649 discard_pending_return(void *rettv) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5650 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5651 free_tv((typval_T *)rettv); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5652 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5653 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5654 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5655 * 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
|
5656 * 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
|
5657 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5658 char_u * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5659 get_return_cmd(void *rettv) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5660 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5661 char_u *s = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5662 char_u *tofree = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5663 char_u numbuf[NUMBUFLEN]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5664 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5665 if (rettv != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5666 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
|
5667 if (s == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5668 s = (char_u *)""; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5669 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5670 STRCPY(IObuff, ":return "); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5671 STRNCPY(IObuff + 8, s, IOSIZE - 8); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5672 if (STRLEN(s) + 8 >= IOSIZE) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5673 STRCPY(IObuff + IOSIZE - 4, "..."); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5674 vim_free(tofree); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5675 return vim_strsave(IObuff); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5676 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5677 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5678 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5679 * Get next function line. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5680 * 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
|
5681 * 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
|
5682 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5683 char_u * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5684 get_func_line( |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5685 int c UNUSED, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5686 void *cookie, |
17178
40c4cb095d53
patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents:
17168
diff
changeset
|
5687 int indent UNUSED, |
21883
a427f5f26419
patch 8.2.1491: Vim9: crash when compiling heredoc lines start with comment
Bram Moolenaar <Bram@vim.org>
parents:
21821
diff
changeset
|
5688 getline_opt_T options UNUSED) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5689 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5690 funccall_T *fcp = (funccall_T *)cookie; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5691 ufunc_T *fp = fcp->func; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5692 char_u *retval; |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5693 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
|
5694 |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5695 // 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
|
5696 if (fcp->dbg_tick != debug_tick) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5697 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5698 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
|
5699 SOURCING_LNUM); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5700 fcp->dbg_tick = debug_tick; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5701 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5702 #ifdef FEAT_PROFILE |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5703 if (do_profiling == PROF_YES) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5704 func_line_end(cookie); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5705 #endif |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5706 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5707 gap = &fp->uf_lines; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5708 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
|
5709 || fcp->returned) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5710 retval = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5711 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5712 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5713 // Skip NULL lines (continuation lines). |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5714 while (fcp->linenr < gap->ga_len |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5715 && ((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
|
5716 ++fcp->linenr; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5717 if (fcp->linenr >= gap->ga_len) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5718 retval = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5719 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5720 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5721 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
|
5722 SOURCING_LNUM = fcp->linenr; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5723 #ifdef FEAT_PROFILE |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5724 if (do_profiling == PROF_YES) |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23699
diff
changeset
|
5725 func_line_start(cookie, SOURCING_LNUM); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5726 #endif |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5727 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5728 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5729 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5730 // 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
|
5731 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
|
5732 { |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
5733 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
|
5734 // Find next breakpoint. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5735 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
|
5736 SOURCING_LNUM); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5737 fcp->dbg_tick = debug_tick; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5738 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5739 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5740 return retval; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5741 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5742 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5743 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5744 * 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
|
5745 * 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
|
5746 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5747 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5748 func_has_ended(void *cookie) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5749 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5750 funccall_T *fcp = (funccall_T *)cookie; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5751 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5752 // 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
|
5753 // an error inside a try conditional. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5754 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
|
5755 || fcp->returned); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5756 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5757 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5758 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5759 * 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
|
5760 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5761 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5762 func_has_abort( |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5763 void *cookie) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5764 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5765 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
|
5766 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5767 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5768 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5769 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5770 * 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
|
5771 * 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
|
5772 * explicitly (pt_auto is FALSE). |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5773 * Changes "rettv" in-place. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5774 * Returns the updated "selfdict_in". |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5775 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5776 dict_T * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5777 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
|
5778 { |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5779 char_u *fname; |
28008
cc7d54a134e4
patch 8.2.4529: Vim9: comparing partial with function fails
Bram Moolenaar <Bram@vim.org>
parents:
28006
diff
changeset
|
5780 ufunc_T *fp = NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5781 char_u fname_buf[FLEN_FIXED + 1]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5782 int error; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5783 dict_T *selfdict = selfdict_in; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5784 |
28008
cc7d54a134e4
patch 8.2.4529: Vim9: comparing partial with function fails
Bram Moolenaar <Bram@vim.org>
parents:
28006
diff
changeset
|
5785 if (rettv->v_type == VAR_PARTIAL && rettv->vval.v_partial != NULL |
cc7d54a134e4
patch 8.2.4529: Vim9: comparing partial with function fails
Bram Moolenaar <Bram@vim.org>
parents:
28006
diff
changeset
|
5786 && rettv->vval.v_partial->pt_func != NULL) |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5787 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
|
5788 else |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5789 { |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5790 fname = rettv->v_type == VAR_FUNC ? rettv->vval.v_string |
28008
cc7d54a134e4
patch 8.2.4529: Vim9: comparing partial with function fails
Bram Moolenaar <Bram@vim.org>
parents:
28006
diff
changeset
|
5791 : rettv->vval.v_partial == NULL ? NULL |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5792 : rettv->vval.v_partial->pt_name; |
28008
cc7d54a134e4
patch 8.2.4529: Vim9: comparing partial with function fails
Bram Moolenaar <Bram@vim.org>
parents:
28006
diff
changeset
|
5793 if (fname == NULL) |
cc7d54a134e4
patch 8.2.4529: Vim9: comparing partial with function fails
Bram Moolenaar <Bram@vim.org>
parents:
28006
diff
changeset
|
5794 { |
cc7d54a134e4
patch 8.2.4529: Vim9: comparing partial with function fails
Bram Moolenaar <Bram@vim.org>
parents:
28006
diff
changeset
|
5795 // There is no point binding a dict to a NULL function, just create |
cc7d54a134e4
patch 8.2.4529: Vim9: comparing partial with function fails
Bram Moolenaar <Bram@vim.org>
parents:
28006
diff
changeset
|
5796 // a function reference. |
cc7d54a134e4
patch 8.2.4529: Vim9: comparing partial with function fails
Bram Moolenaar <Bram@vim.org>
parents:
28006
diff
changeset
|
5797 rettv->v_type = VAR_FUNC; |
cc7d54a134e4
patch 8.2.4529: Vim9: comparing partial with function fails
Bram Moolenaar <Bram@vim.org>
parents:
28006
diff
changeset
|
5798 rettv->vval.v_string = NULL; |
cc7d54a134e4
patch 8.2.4529: Vim9: comparing partial with function fails
Bram Moolenaar <Bram@vim.org>
parents:
28006
diff
changeset
|
5799 } |
cc7d54a134e4
patch 8.2.4529: Vim9: comparing partial with function fails
Bram Moolenaar <Bram@vim.org>
parents:
28006
diff
changeset
|
5800 else |
28006
02f787034998
patch 8.2.4528: crash when using null_function for a partial
Bram Moolenaar <Bram@vim.org>
parents:
27978
diff
changeset
|
5801 { |
02f787034998
patch 8.2.4528: crash when using null_function for a partial
Bram Moolenaar <Bram@vim.org>
parents:
27978
diff
changeset
|
5802 char_u *tofree = NULL; |
02f787034998
patch 8.2.4528: crash when using null_function for a partial
Bram Moolenaar <Bram@vim.org>
parents:
27978
diff
changeset
|
5803 |
02f787034998
patch 8.2.4528: crash when using null_function for a partial
Bram Moolenaar <Bram@vim.org>
parents:
27978
diff
changeset
|
5804 // Translate "s:func" to the stored function name. |
02f787034998
patch 8.2.4528: crash when using null_function for a partial
Bram Moolenaar <Bram@vim.org>
parents:
27978
diff
changeset
|
5805 fname = fname_trans_sid(fname, fname_buf, &tofree, &error); |
02f787034998
patch 8.2.4528: crash when using null_function for a partial
Bram Moolenaar <Bram@vim.org>
parents:
27978
diff
changeset
|
5806 fp = find_func(fname, FALSE); |
02f787034998
patch 8.2.4528: crash when using null_function for a partial
Bram Moolenaar <Bram@vim.org>
parents:
27978
diff
changeset
|
5807 vim_free(tofree); |
02f787034998
patch 8.2.4528: crash when using null_function for a partial
Bram Moolenaar <Bram@vim.org>
parents:
27978
diff
changeset
|
5808 } |
02f787034998
patch 8.2.4528: crash when using null_function for a partial
Bram Moolenaar <Bram@vim.org>
parents:
27978
diff
changeset
|
5809 } |
02f787034998
patch 8.2.4528: crash when using null_function for a partial
Bram Moolenaar <Bram@vim.org>
parents:
27978
diff
changeset
|
5810 |
28008
cc7d54a134e4
patch 8.2.4529: Vim9: comparing partial with function fails
Bram Moolenaar <Bram@vim.org>
parents:
28006
diff
changeset
|
5811 if (fp != NULL && (fp->uf_flags & FC_DICT)) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5812 { |
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
|
5813 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
|
5814 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5815 if (pt != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5816 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5817 pt->pt_refcount = 1; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5818 pt->pt_dict = selfdict; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5819 pt->pt_auto = TRUE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5820 selfdict = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5821 if (rettv->v_type == VAR_FUNC) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5822 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5823 // 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
|
5824 // selfdict. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5825 pt->pt_name = rettv->vval.v_string; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5826 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5827 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5828 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5829 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
|
5830 int i; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5831 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5832 // 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
|
5833 // 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
|
5834 // be referenced elsewhere. |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5835 if (ret_pt->pt_name != NULL) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5836 { |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5837 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
|
5838 func_ref(pt->pt_name); |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5839 } |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5840 else |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5841 { |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5842 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
|
5843 func_ptr_ref(pt->pt_func); |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5844 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5845 if (ret_pt->pt_argc > 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5846 { |
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
|
5847 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
|
5848 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
|
5849 // out of memory: drop the arguments |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5850 pt->pt_argc = 0; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5851 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5852 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5853 pt->pt_argc = ret_pt->pt_argc; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5854 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
|
5855 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
|
5856 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5857 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5858 partial_unref(ret_pt); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5859 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5860 rettv->v_type = VAR_PARTIAL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5861 rettv->vval.v_partial = pt; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5862 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5863 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5864 return selfdict; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5865 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5866 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5867 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5868 * Return the name of the executed function. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5869 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5870 char_u * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5871 func_name(void *cookie) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5872 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5873 return ((funccall_T *)cookie)->func->uf_name; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5874 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5875 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5876 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5877 * 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
|
5878 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5879 linenr_T * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5880 func_breakpoint(void *cookie) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5881 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5882 return &((funccall_T *)cookie)->breakpoint; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5883 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5884 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5885 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5886 * 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
|
5887 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5888 int * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5889 func_dbg_tick(void *cookie) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5890 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5891 return &((funccall_T *)cookie)->dbg_tick; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5892 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5893 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5894 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5895 * 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
|
5896 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5897 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5898 func_level(void *cookie) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5899 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5900 return ((funccall_T *)cookie)->level; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5901 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5902 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5903 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5904 * 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
|
5905 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5906 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5907 current_func_returned(void) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5908 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5909 return current_funccal->returned; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5910 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5911 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5912 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5913 free_unref_funccal(int copyID, int testing) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5914 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5915 int did_free = FALSE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5916 int did_free_funccal = FALSE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5917 funccall_T *fc, **pfc; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5918 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5919 for (pfc = &previous_funccal; *pfc != NULL; ) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5920 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5921 if (can_free_funccal(*pfc, copyID)) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5922 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5923 fc = *pfc; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5924 *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
|
5925 free_funccal_contents(fc); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5926 did_free = TRUE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5927 did_free_funccal = TRUE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5928 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5929 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5930 pfc = &(*pfc)->caller; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5931 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5932 if (did_free_funccal) |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5933 // 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
|
5934 // collected, so run again. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5935 (void)garbage_collect(testing); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5936 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5937 return did_free; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5938 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5939 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5940 /* |
9951
d990a4394c9d
commit https://github.com/vim/vim/commit/ba2099034f92a2814494f37bddb0c57d034401b4
Christian Brabandt <cb@256bit.org>
parents:
9844
diff
changeset
|
5941 * 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
|
5942 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5943 static funccall_T * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5944 get_funccal(void) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5945 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5946 int i; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5947 funccall_T *funccal; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5948 funccall_T *temp_funccal; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5949 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5950 funccal = current_funccal; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5951 if (debug_backtrace_level > 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5952 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5953 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
|
5954 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5955 temp_funccal = funccal->caller; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5956 if (temp_funccal) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5957 funccal = temp_funccal; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5958 else |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5959 // backtrace level overflow. reset to max |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5960 debug_backtrace_level = i; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5961 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5962 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5963 return funccal; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5964 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5965 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5966 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5967 * 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
|
5968 * 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
|
5969 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5970 hashtab_T * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5971 get_funccal_local_ht() |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5972 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5973 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
|
5974 return NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5975 return &get_funccal()->l_vars.dv_hashtab; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5976 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5977 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5978 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5979 * Return the l: scope variable. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5980 * 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
|
5981 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5982 dictitem_T * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5983 get_funccal_local_var() |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5984 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5985 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
|
5986 return NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5987 return &get_funccal()->l_vars_var; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5988 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5989 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5990 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5991 * 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
|
5992 * 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
|
5993 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5994 hashtab_T * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5995 get_funccal_args_ht() |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5996 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5997 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
|
5998 return NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5999 return &get_funccal()->l_avars.dv_hashtab; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6000 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6001 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6002 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6003 * Return the a: scope variable. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6004 * 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
|
6005 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6006 dictitem_T * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6007 get_funccal_args_var() |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6008 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
6009 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
|
6010 return NULL; |
10795
8afee415119d
patch 8.0.0287: debug mode: cannot access function arguments
Christian Brabandt <cb@256bit.org>
parents:
10722
diff
changeset
|
6011 return &get_funccal()->l_avars_var; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6012 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6013 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6014 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6015 * 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
|
6016 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6017 void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6018 list_func_vars(int *first) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6019 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
6020 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
|
6021 list_hashtable_vars(¤t_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
|
6022 "l:", FALSE, first); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6023 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6024 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6025 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6026 * 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
|
6027 * the dict that contains it. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6028 * Otherwise return NULL. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6029 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6030 dict_T * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6031 get_current_funccal_dict(hashtab_T *ht) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6032 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6033 if (current_funccal != NULL |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6034 && ht == ¤t_funccal->l_vars.dv_hashtab) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6035 return ¤t_funccal->l_vars; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6036 return NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6037 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6038 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6039 /* |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6040 * Search hashitem in parent scope. |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6041 */ |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6042 hashitem_T * |
9731
f85d94eee05b
commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
6043 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
|
6044 { |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6045 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
|
6046 hashtab_T *ht; |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6047 hashitem_T *hi = NULL; |
9731
f85d94eee05b
commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
6048 char_u *varname; |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6049 |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6050 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
|
6051 return NULL; |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6052 |
20433
5950284a517f
patch 8.2.0771: Vim9: cannot call a compiled closure from not compiled code
Bram Moolenaar <Bram@vim.org>
parents:
20397
diff
changeset
|
6053 // Search in parent scope, which can be referenced from a lambda. |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6054 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
|
6055 while (current_funccal != NULL) |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6056 { |
9731
f85d94eee05b
commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
6057 ht = find_var_ht(name, &varname); |
f85d94eee05b
commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
6058 if (ht != NULL && *varname != NUL) |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
6059 { |
9731
f85d94eee05b
commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
6060 hi = hash_find(ht, varname); |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
6061 if (!HASHITEM_EMPTY(hi)) |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
6062 { |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
6063 *pht = ht; |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
6064 break; |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
6065 } |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
6066 } |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
6067 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
|
6068 break; |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
6069 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
|
6070 } |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6071 current_funccal = old_current_funccal; |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6072 |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6073 return hi; |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6074 } |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6075 |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6076 /* |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6077 * Search variable in parent scope. |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6078 */ |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6079 dictitem_T * |
9731
f85d94eee05b
commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
6080 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
|
6081 { |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6082 dictitem_T *v = NULL; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6083 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
|
6084 hashtab_T *ht; |
9731
f85d94eee05b
commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
6085 char_u *varname; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6086 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6087 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
|
6088 return NULL; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6089 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
6090 // 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
|
6091 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
|
6092 while (current_funccal) |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6093 { |
9731
f85d94eee05b
commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
6094 ht = find_var_ht(name, &varname); |
f85d94eee05b
commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
6095 if (ht != NULL && *varname != NUL) |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6096 { |
9731
f85d94eee05b
commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
6097 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
|
6098 if (v != NULL) |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6099 break; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6100 } |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6101 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
|
6102 break; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6103 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
|
6104 } |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6105 current_funccal = old_current_funccal; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6106 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6107 return v; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6108 } |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6109 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6110 /* |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6111 * 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
|
6112 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6113 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6114 set_ref_in_previous_funccal(int copyID) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6115 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6116 funccall_T *fc; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6117 |
25104
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6118 for (fc = previous_funccal; fc != NULL; fc = fc->caller) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6119 { |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6120 fc->fc_copyID = copyID + 1; |
25104
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6121 if (set_ref_in_ht(&fc->l_vars.dv_hashtab, copyID + 1, NULL) |
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6122 || set_ref_in_ht(&fc->l_avars.dv_hashtab, copyID + 1, NULL) |
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6123 || set_ref_in_list_items(&fc->l_varlist, copyID + 1, NULL)) |
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6124 return TRUE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6125 } |
25104
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6126 return FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6127 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6128 |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6129 static int |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6130 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
|
6131 { |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6132 if (fc->fc_copyID != copyID) |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6133 { |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6134 fc->fc_copyID = copyID; |
25104
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6135 if (set_ref_in_ht(&fc->l_vars.dv_hashtab, copyID, NULL) |
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6136 || set_ref_in_ht(&fc->l_avars.dv_hashtab, copyID, NULL) |
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6137 || set_ref_in_list_items(&fc->l_varlist, copyID, NULL) |
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6138 || set_ref_in_func(NULL, fc->func, copyID)) |
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6139 return TRUE; |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6140 } |
25104
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6141 return FALSE; |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6142 } |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6143 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6144 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6145 * 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
|
6146 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6147 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6148 set_ref_in_call_stack(int copyID) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6149 { |
16969
8c794a694d66
patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents:
16872
diff
changeset
|
6150 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
|
6151 funccal_entry_T *entry; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6152 |
25104
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6153 for (fc = current_funccal; fc != NULL; fc = fc->caller) |
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6154 if (set_ref_in_funccal(fc, copyID)) |
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6155 return TRUE; |
16969
8c794a694d66
patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents:
16872
diff
changeset
|
6156 |
8c794a694d66
patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents:
16872
diff
changeset
|
6157 // Also go through the funccal_stack. |
25104
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6158 for (entry = funccal_stack; entry != NULL; entry = entry->next) |
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6159 for (fc = entry->top_funccal; fc != NULL; fc = fc->caller) |
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6160 if (set_ref_in_funccal(fc, copyID)) |
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6161 return TRUE; |
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6162 return FALSE; |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6163 } |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6164 |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6165 /* |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6166 * 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
|
6167 */ |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6168 int |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6169 set_ref_in_functions(int copyID) |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6170 { |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6171 int todo; |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6172 hashitem_T *hi = NULL; |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6173 ufunc_T *fp; |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6174 |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6175 todo = (int)func_hashtab.ht_used; |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6176 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
|
6177 { |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6178 if (!HASHITEM_EMPTY(hi)) |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6179 { |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6180 --todo; |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6181 fp = HI2UF(hi); |
25104
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6182 if (!func_name_refcount(fp->uf_name) |
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6183 && set_ref_in_func(NULL, fp, copyID)) |
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6184 return TRUE; |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6185 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6186 } |
25104
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6187 return FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6188 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6189 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6190 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6191 * Set "copyID" in all function arguments. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6192 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6193 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6194 set_ref_in_func_args(int copyID) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6195 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6196 int i; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6197 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6198 for (i = 0; i < funcargs.ga_len; ++i) |
25104
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6199 if (set_ref_in_item(((typval_T **)funcargs.ga_data)[i], |
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6200 copyID, NULL, NULL)) |
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6201 return TRUE; |
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6202 return FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6203 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6204 |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6205 /* |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6206 * 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
|
6207 * 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
|
6208 */ |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6209 int |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6210 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
|
6211 { |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6212 ufunc_T *fp = fp_in; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6213 funccall_T *fc; |
19013
dd9ab0674eec
patch 8.2.0067: ERROR_UNKNOWN clashes on some systems
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
6214 int error = FCERR_NONE; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6215 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
|
6216 char_u *tofree = NULL; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6217 char_u *fname; |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6218 int abort = FALSE; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6219 |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6220 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
|
6221 return FALSE; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6222 |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6223 if (fp_in == NULL) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6224 { |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6225 fname = fname_trans_sid(name, fname_buf, &tofree, &error); |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27092
diff
changeset
|
6226 fp = find_func(fname, FALSE); |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6227 } |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6228 if (fp != NULL) |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6229 { |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6230 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
|
6231 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
|
6232 } |
20255
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20244
diff
changeset
|
6233 |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6234 vim_free(tofree); |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6235 return abort; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6236 } |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6237 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
6238 #endif // FEAT_EVAL |