Mercurial > vim
annotate src/userfunc.c @ 27991:e8cad604c218
Added tag v8.2.4520 for changeset 27ae8ea82d7ab9e0e4f8f894394dad7fd6344a5a
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 06 Mar 2022 21:00:07 +0100 |
parents | 442ca2007bec |
children | 02f787034998 |
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; |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
432 } |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
433 } |
24400
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
434 } |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
435 |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
436 if (varargs) |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
437 { |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
438 char_u *p; |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
439 |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
440 // 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
|
441 // uf_va_type. |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
442 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
|
443 [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
|
444 --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
|
445 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
|
446 if (p == NULL) |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
447 // 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
|
448 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
|
449 else |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
450 { |
24400
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
451 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
|
452 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
|
453 { |
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
454 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
|
455 ((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
|
456 return FAIL; |
24400
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
457 } |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
458 } |
24400
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
459 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
|
460 return FAIL; |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
461 } |
24400
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
462 |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
463 return OK; |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
464 } |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
465 |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
466 static int |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
467 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
|
468 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
469 if (ret_type == NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
470 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
|
471 else |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
472 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
473 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
|
474 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
475 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
|
476 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
|
477 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
478 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
|
479 return FAIL; |
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 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
482 return OK; |
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 |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
485 /* |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
486 * 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
|
487 */ |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
488 static int |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
489 register_closure(ufunc_T *fp) |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
490 { |
9733
59565cdd7261
commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents:
9731
diff
changeset
|
491 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
|
492 // no change |
9733
59565cdd7261
commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents:
9731
diff
changeset
|
493 return OK; |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
494 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
|
495 fp->uf_scoped = current_funccal; |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
496 current_funccal->fc_refcount++; |
9733
59565cdd7261
commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents:
9731
diff
changeset
|
497 |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
498 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
|
499 return FAIL; |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
500 ((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
|
501 [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
|
502 return OK; |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
503 } |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
504 |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
505 static void |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
506 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
|
507 { |
23829
950875545045
patch 8.2.2456: Coverity warning for strcpy() into fixed size array
Bram Moolenaar <Bram@vim.org>
parents:
23808
diff
changeset
|
508 // 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
|
509 // 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
|
510 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
|
511 |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
512 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
|
513 { |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
514 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
|
515 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
|
516 { |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
517 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
|
518 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
|
519 } |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
520 } |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
521 } |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
522 |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
523 /* |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
524 * 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
|
525 */ |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
526 char_u * |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
527 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
|
528 { |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
529 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
|
530 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
|
531 |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
532 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
|
533 return name; |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
534 } |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
535 |
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
|
536 #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
|
537 /* |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
538 * 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
|
539 * 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
|
540 */ |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
541 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
|
542 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
|
543 { |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
544 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
|
545 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
|
546 |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
547 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
|
548 if (fp == NULL) |
21066
48cfc37fe4fc
patch 8.2.1084: Lua: registering function has useless code
Bram Moolenaar <Bram@vim.org>
parents:
21058
diff
changeset
|
549 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
|
550 |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
551 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
|
552 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
|
553 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
|
554 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
|
555 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
|
556 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
|
557 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
|
558 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
|
559 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
|
560 |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
561 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
|
562 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
|
563 |
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 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
|
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 #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
|
567 |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
568 /* |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
569 * 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
|
570 * 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
|
571 * 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
|
572 * "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
|
573 * 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
|
574 */ |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
575 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
|
576 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
|
577 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
|
578 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
|
579 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
|
580 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
|
581 { |
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
|
582 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
|
583 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
|
584 |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
585 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
|
586 { |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
587 if (*s == ':') |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
588 { |
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
|
589 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
|
590 { |
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
591 *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
|
592 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
|
593 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
|
594 } |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
595 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
|
596 *ret_type = s; |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
597 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
|
598 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
|
599 { |
baf9069f64ca
patch 8.2.2445: Vim9: no proper error for lambda missing return type
Bram Moolenaar <Bram@vim.org>
parents:
23727
diff
changeset
|
600 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
|
601 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
|
602 } |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
603 } |
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 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
|
605 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
|
606 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
|
607 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
|
608 ++s; |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
609 } |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
610 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
|
611 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
|
612 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
|
613 || !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
|
614 { |
9c5275b1c763
patch 8.2.2212: Vim9: lambda with => does not work at the script level
Bram Moolenaar <Bram@vim.org>
parents:
23332
diff
changeset
|
615 *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
|
616 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
|
617 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
|
618 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
|
619 } |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
620 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
|
621 } |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
622 |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
623 /* |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
624 * 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
|
625 * return TRUE. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
626 * Otherwise return FALSE; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
627 * 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
|
628 */ |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
629 static int |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
630 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
|
631 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
632 char_u *p = *cmd; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
633 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
634 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
|
635 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
636 if (*p == '(') |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
637 return FALSE; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
638 *cmd = p; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
639 return TRUE; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
640 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
641 return FALSE; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
642 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
643 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
644 /* |
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
|
645 * 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
|
646 * 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
|
647 * 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
|
648 */ |
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
|
649 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
|
650 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
|
651 { |
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
|
652 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
|
653 { |
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
|
654 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
|
655 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
|
656 |
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
|
657 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
|
658 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
|
659 { |
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
|
660 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
|
661 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
|
662 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
|
663 } |
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
|
664 |
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
|
665 // 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
|
666 // 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
|
667 // 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
|
668 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
|
669 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
|
670 } |
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
|
671 } |
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
|
672 |
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 /* |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
674 * 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
|
675 * 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
|
676 * "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
|
677 * "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
|
678 */ |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
679 static int |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
680 get_function_body( |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
681 exarg_T *eap, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
682 garray_T *newlines, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
683 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
|
684 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
|
685 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
686 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
|
687 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
|
688 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
|
689 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
|
690 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
|
691 || eap->cmdidx == CMD_block; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
692 #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
|
693 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
|
694 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
|
695 int nesting = 0; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
696 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
|
697 int indent = 2; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
698 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
|
699 int ret = FAIL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
700 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
|
701 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
|
702 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
|
703 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
|
704 |
24826
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
705 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
|
706 |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
707 // 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
|
708 // 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
|
709 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
|
710 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
|
711 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
712 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
|
713 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
|
714 goto theend; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
715 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
|
716 ((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
|
717 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
718 |
25265
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
719 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
|
720 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
|
721 getline_options = vim9_function |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
722 ? 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
|
723 for (;;) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
724 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
725 char_u *theline; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
726 char_u *p; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
727 char_u *arg; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
728 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
729 if (KeyTyped) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
730 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
731 msg_scroll = TRUE; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
732 saved_wait_return = FALSE; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
733 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
734 need_wait_return = FALSE; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
735 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
736 if (line_arg != NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
737 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
738 // 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
|
739 theline = line_arg; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
740 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
|
741 if (p == NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
742 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
|
743 else |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
744 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
745 *p = NUL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
746 line_arg = p + 1; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
747 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
748 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
749 else |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
750 { |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
751 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
|
752 getline_options); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
753 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
754 if (KeyTyped) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
755 lines_left = Rows - 1; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
756 if (theline == NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
757 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
758 // 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
|
759 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
|
760 if (skip_until != NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
761 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
|
762 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
|
763 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
|
764 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
|
765 emsg(_(e_missing_enddef)); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
766 else |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
767 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
|
768 goto theend; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
769 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
770 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
771 // 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
|
772 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
|
773 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
|
774 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
|
775 else |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
776 sourcing_lnum_off = 0; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
777 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
778 if (skip_until != NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
779 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
780 // 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
|
781 // * ":append" and "." |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
782 // * ":python <<EOF" and "EOF" |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
783 // * ":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
|
784 if (heredoc_trimmed == NULL |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
785 || (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
|
786 || STRNCMP(theline, heredoc_trimmed, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
787 STRLEN(heredoc_trimmed)) == 0) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
788 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
789 if (heredoc_trimmed == NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
790 p = theline; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
791 else if (is_heredoc) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
792 p = skipwhite(theline) == theline |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
793 ? 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
|
794 else |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
795 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
|
796 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
|
797 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
798 VIM_CLEAR(skip_until); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
799 VIM_CLEAR(heredoc_trimmed); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
800 getline_options = vim9_function |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
801 ? 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
|
802 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
|
803 |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
804 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
|
805 { |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
806 // 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
|
807 // lines. |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
808 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
|
809 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
|
810 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
|
811 ((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
|
812 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
|
813 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
|
814 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
|
815 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
|
816 } |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
817 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
818 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
819 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
820 else |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
821 { |
25265
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
822 int c; |
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
823 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
|
824 char_u *cmd; |
24188
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 // skip ':' and blanks |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
827 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
|
828 ; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
829 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
830 // 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
|
831 // 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
|
832 cmd = p; |
25265
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
833 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
|
834 ? *p == '}' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
835 : (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
|
836 ? "enddef" : "endfunction", 4) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
837 && *p != ':')) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
838 { |
27978
442ca2007bec
patch 8.2.4514: Vim9: some flow commands can be shortened
Bram Moolenaar <Bram@vim.org>
parents:
27893
diff
changeset
|
839 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
|
840 && p < cmd + 6) |
442ca2007bec
patch 8.2.4514: Vim9: some flow commands can be shortened
Bram Moolenaar <Bram@vim.org>
parents:
27893
diff
changeset
|
841 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
|
842 if (nesting-- == 0) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
843 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
844 char_u *nextcmd = NULL; |
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 if (*p == '|' || *p == '}') |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
847 nextcmd = p + 1; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
848 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
|
849 nextcmd = line_arg; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
850 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
|
851 && (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
|
852 { |
25632
c204815f3058
patch 8.2.3352: Vim9: error for nested :enddef has wrong line number
Bram Moolenaar <Bram@vim.org>
parents:
25561
diff
changeset
|
853 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
|
854 + 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
|
855 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
|
856 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
|
857 else |
7a21b2581dce
patch 8.2.2645: using inline function is not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
24202
diff
changeset
|
858 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
|
859 _("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
|
860 p, TRUE); |
7a21b2581dce
patch 8.2.2645: using inline function is not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
24202
diff
changeset
|
861 } |
7a21b2581dce
patch 8.2.2645: using inline function is not properly tested
Bram Moolenaar <Bram@vim.org>
parents:
24202
diff
changeset
|
862 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
|
863 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
864 // 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
|
865 // 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
|
866 // 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
|
867 // line. |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
868 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
|
869 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
|
870 && *eap->cmdlinep != |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
871 ((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
|
872 [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
|
873 { |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
874 // *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
|
875 // 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
|
876 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
|
877 *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
|
878 [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
|
879 --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
|
880 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
881 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
882 break; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
883 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
884 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
885 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
886 // 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
|
887 // 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
|
888 // for "enddef". |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
889 // 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
|
890 // not find it. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
891 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
|
892 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
893 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
|
894 emsg(_(e_mismatched_endfunction)); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
895 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
896 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
|
897 emsg(_(e_mismatched_enddef)); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
898 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
899 // 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
|
900 // at "end". |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
901 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
|
902 indent -= 2; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
903 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
|
904 || 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
|
905 || 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
|
906 || 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
|
907 indent += 2; |
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 // 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
|
910 // 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
|
911 // 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
|
912 c = *p; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
913 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
|
914 || (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
|
915 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
916 if (*p == '!') |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
917 p = skipwhite(p + 1); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
918 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
|
919 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
|
920 NULL, NULL)); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
921 if (*skipwhite(p) == '(') |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
922 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
923 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
|
924 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
|
925 else |
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 ++nesting; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
928 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
|
929 nesting_inline[nesting] = FALSE; |
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
930 indent += 2; |
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
931 } |
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
932 } |
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
933 } |
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
934 |
25296
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
935 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
|
936 { |
25296
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
937 // 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
|
938 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
|
939 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
|
940 --end; |
25473
9a4cb96c9550
patch 8.2.3273: autocmd test fails
Bram Moolenaar <Bram@vim.org>
parents:
25469
diff
changeset
|
941 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
|
942 { |
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
|
943 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
|
944 |
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
|
945 // 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
|
946 --end; |
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
947 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
|
948 --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
|
949 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
|
950 if (!is_block) |
25265
1d6ff96306fc
patch 8.2.3169: Vim9: cannot handle nested inline function
Bram Moolenaar <Bram@vim.org>
parents:
25186
diff
changeset
|
951 { |
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
|
952 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
|
953 |
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
|
954 // 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
|
955 // "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
|
956 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
|
957 || 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
|
958 } |
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
|
959 |
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
|
960 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
|
961 { |
25296
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
962 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
|
963 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
|
964 else |
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
965 { |
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
966 ++nesting; |
ec0421c25be9
patch 8.2.3185: Vim9: start of inline function found in comment line
Bram Moolenaar <Bram@vim.org>
parents:
25269
diff
changeset
|
967 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
|
968 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
|
969 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
|
970 } |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
971 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
972 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
973 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
974 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
975 // 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
|
976 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
|
977 if (!vim9_function |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
978 && ((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
|
979 || (p[0] == 'c' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
980 && (!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
|
981 && (!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
|
982 && (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
|
983 || !ASCII_ISALPHA(p[6]))))))) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
984 || (p[0] == 'i' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
985 && (!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
|
986 && (!ASCII_ISALPHA(p[2]) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
987 || (p[2] == 's' |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
988 && (!ASCII_ISALPHA(p[3]) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
989 || p[3] == 'e')))))))) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
990 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
|
991 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
992 // 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
|
993 arg = skipwhite(skiptowhite(p)); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
994 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
|
995 && ((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
|
996 && (!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
|
997 || ((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
|
998 && !ASCII_ISALPHA(p[3])))) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
999 || (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
|
1000 && (!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
|
1001 || (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
|
1002 && (!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
|
1003 || (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
|
1004 && !ASCII_ISALPHA(p[3])) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1005 || (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
|
1006 && (!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
|
1007 || (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
|
1008 && (!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
|
1009 )) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1010 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1011 // ":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
|
1012 p = skipwhite(arg + 2); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1013 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
|
1014 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1015 // Ignore leading white space. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1016 p = skipwhite(p + 4); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1017 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
|
1018 skipwhite(theline) - theline); |
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 if (*p == NUL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1021 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
|
1022 else |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1023 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
|
1024 getline_options = GETLINE_NONE; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1025 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
|
1026 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
|
1027 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
|
1028 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1029 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1030 // 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
|
1031 // 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
|
1032 // 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
|
1033 // 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
|
1034 arg = skipwhite(skiptowhite(p)); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1035 if (*arg == '[') |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1036 arg = vim_strchr(arg, ']'); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1037 if (arg != NULL) |
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 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
|
1040 && arg[1] == '<' && arg[2] =='<'); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1041 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1042 if (!found) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1043 // 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
|
1044 arg = skipwhite(skiptowhite(arg)); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1045 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
|
1046 && (checkforcmd(&p, "let", 2) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1047 || checkforcmd(&p, "var", 3) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1048 || checkforcmd(&p, "final", 5) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1049 || checkforcmd(&p, "const", 5)))) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1050 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1051 p = skipwhite(arg + 3); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1052 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
|
1053 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1054 // Ignore leading white space. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1055 p = skipwhite(p + 4); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1056 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
|
1057 skipwhite(theline) - theline); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1058 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1059 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
|
1060 getline_options = GETLINE_NONE; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1061 is_heredoc = TRUE; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1062 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1063 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1064 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1065 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1066 // Add the line to the function. |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1067 if (ga_grow(newlines, 1 + sourcing_lnum_off) == FAIL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1068 goto theend; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1069 |
24826
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1070 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
|
1071 { |
26771
fc859aea8cec
patch 8.2.3914: various spelling mistakes in comments
Bram Moolenaar <Bram@vim.org>
parents:
26757
diff
changeset
|
1072 // 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
|
1073 // 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
|
1074 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
|
1075 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
|
1076 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
|
1077 } |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1078 else |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1079 { |
a8d64f1a223b
patch 8.2.2951: Vim9: cannot use heredoc for :python, :lua, etc.
Bram Moolenaar <Bram@vim.org>
parents:
24687
diff
changeset
|
1080 // 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
|
1081 // 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
|
1082 // 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
|
1083 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
|
1084 } |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1085 if (p == NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1086 goto theend; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1087 ((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
|
1088 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1089 // 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
|
1090 // 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
|
1091 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
|
1092 ((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
|
1093 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1094 // 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
|
1095 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
|
1096 line_arg = NULL; |
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 |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1099 // 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
|
1100 if (!did_emsg) |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1101 ret = OK; |
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 theend: |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1104 vim_free(skip_until); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1105 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
|
1106 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
|
1107 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
|
1108 return ret; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1109 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1110 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1111 /* |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1112 * 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
|
1113 * until the matching "}". |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1114 * 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
|
1115 * 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
|
1116 */ |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1117 static int |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1118 lambda_function_body( |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1119 char_u **arg, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1120 typval_T *rettv, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1121 evalarg_T *evalarg, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1122 garray_T *newargs, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1123 garray_T *argtypes, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1124 int varargs, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1125 garray_T *default_args, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1126 char_u *ret_type) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1127 { |
24422
41cf1155ab90
patch 8.2.2751: Coverity warns for using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
24412
diff
changeset
|
1128 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
|
1129 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
|
1130 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
|
1131 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
|
1132 exarg_T eap; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1133 garray_T newlines; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1134 char_u *cmdline = NULL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1135 int ret = FAIL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1136 partial_T *pt; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1137 char_u *name; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1138 int lnum_save = -1; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1139 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
|
1140 |
24202
c50c5464e6dc
patch 8.2.2642: Vim9: no clear error for wrong inline function
Bram Moolenaar <Bram@vim.org>
parents:
24190
diff
changeset
|
1141 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
|
1142 { |
26883
7f150a4936f2
patch 8.2.3970: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
1143 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
|
1144 return FAIL; |
c50c5464e6dc
patch 8.2.2642: Vim9: no clear error for wrong inline function
Bram Moolenaar <Bram@vim.org>
parents:
24190
diff
changeset
|
1145 } |
c50c5464e6dc
patch 8.2.2642: Vim9: no clear error for wrong inline function
Bram Moolenaar <Bram@vim.org>
parents:
24190
diff
changeset
|
1146 |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1147 CLEAR_FIELD(eap); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1148 eap.cmdidx = CMD_block; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1149 eap.forceit = FALSE; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1150 eap.cmdlinep = &cmdline; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1151 eap.skip = !evaluate; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1152 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
|
1153 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
|
1154 else |
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 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
|
1157 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
|
1158 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1159 |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
1160 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
|
1161 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
|
1162 &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
|
1163 goto erret; |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1164 |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1165 // 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
|
1166 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
|
1167 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
|
1168 { |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1169 int idx; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1170 char_u *last; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1171 size_t plen; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1172 char_u *pnl; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1173 |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1174 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
|
1175 { |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1176 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
|
1177 |
24655
3876d9629ebd
patch 8.2.2866: Vim9: memory leak when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24653
diff
changeset
|
1178 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
|
1179 goto erret; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1180 |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1181 // 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
|
1182 // 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
|
1183 // 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
|
1184 // 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
|
1185 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
|
1186 p = (char_u *)""; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1187 plen = STRLEN(p); |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1188 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
|
1189 if (pnl != NULL) |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1190 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
|
1191 ((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
|
1192 ((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
|
1193 } |
24655
3876d9629ebd
patch 8.2.2866: Vim9: memory leak when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24653
diff
changeset
|
1194 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
|
1195 goto erret; |
26747
a8a4e1e7b111
patch 8.2.3902: Vim9: double free with nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
1196 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
|
1197 // 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
|
1198 last = cmdline; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1199 else |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1200 // nothing is following the "}" |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1201 last = (char_u *)"}"; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1202 plen = STRLEN(last); |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1203 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
|
1204 if (pnl != NULL) |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1205 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
|
1206 ((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
|
1207 ((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
|
1208 } |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1209 |
26747
a8a4e1e7b111
patch 8.2.3902: Vim9: double free with nested :def function
Bram Moolenaar <Bram@vim.org>
parents:
26721
diff
changeset
|
1210 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
|
1211 { |
26053
e861c5aaedd8
patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents:
26046
diff
changeset
|
1212 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
|
1213 |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1214 // Something comes after the "}". |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1215 *arg = eap.nextcmd; |
24190
5f3a2d31c48d
patch 8.2.2636: memory leak when compiling inline function
Bram Moolenaar <Bram@vim.org>
parents:
24188
diff
changeset
|
1216 |
5f3a2d31c48d
patch 8.2.2636: memory leak when compiling inline function
Bram Moolenaar <Bram@vim.org>
parents:
24188
diff
changeset
|
1217 // "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
|
1218 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
|
1219 { |
e861c5aaedd8
patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents:
26046
diff
changeset
|
1220 ((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
|
1221 evalarg->eval_using_cmdline = TRUE; |
e861c5aaedd8
patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents:
26046
diff
changeset
|
1222 } |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1223 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1224 else |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1225 *arg = (char_u *)""; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1226 |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1227 if (!evaluate) |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1228 { |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1229 ret = OK; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1230 goto erret; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1231 } |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1232 |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1233 name = get_lambda_name(); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1234 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
|
1235 if (ufunc == NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1236 goto erret; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1237 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
|
1238 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
|
1239 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
|
1240 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
|
1241 ufunc->uf_refcount = 1; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1242 ufunc->uf_args = *newargs; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1243 newargs->ga_data = NULL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1244 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
|
1245 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
|
1246 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
|
1247 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1248 // 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
|
1249 lnum_save = SOURCING_LNUM; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1250 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
|
1251 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1252 // parse argument types |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1253 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
|
1254 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1255 SOURCING_LNUM = lnum_save; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1256 goto erret; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1257 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1258 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1259 // 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
|
1260 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
|
1261 goto erret; |
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 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
|
1264 if (pt == NULL) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1265 goto erret; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1266 pt->pt_func = ufunc; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1267 pt->pt_refcount = 1; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1268 |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1269 ufunc->uf_lines = newlines; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1270 newlines.ga_data = NULL; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1271 if (sandbox) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1272 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
|
1273 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
|
1274 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
|
1275 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
|
1276 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
|
1277 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
|
1278 set_function_type(ufunc); |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1279 |
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
|
1280 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
|
1281 |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1282 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
|
1283 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
|
1284 ufunc = NULL; |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1285 ret = OK; |
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 erret: |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1288 if (lnum_save >= 0) |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1289 SOURCING_LNUM = lnum_save; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1290 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
|
1291 if (newargs != NULL) |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1292 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
|
1293 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
|
1294 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
|
1295 { |
827fcf174f15
patch 8.2.2663: Vim9: leaking memory when inline function has an error
Bram Moolenaar <Bram@vim.org>
parents:
24208
diff
changeset
|
1296 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
|
1297 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
|
1298 } |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1299 return ret; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1300 } |
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 /* |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1303 * 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
|
1304 * "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
|
1305 * 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
|
1306 * 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
|
1307 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1308 int |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
1309 get_lambda_tv( |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
1310 char_u **arg, |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
1311 typval_T *rettv, |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
1312 int types_optional, |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
1313 evalarg_T *evalarg) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1314 { |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21032
diff
changeset
|
1315 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
|
1316 && (evalarg->eval_flags & EVAL_EVALUATE); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1317 garray_T newargs; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1318 garray_T newlines; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1319 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
|
1320 garray_T argtypes; |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1321 garray_T default_args; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1322 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
|
1323 partial_T *pt = NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1324 int varargs; |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1325 char_u *ret_type = NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1326 int ret; |
21220
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21218
diff
changeset
|
1327 char_u *s; |
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21218
diff
changeset
|
1328 char_u *start, *end; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1329 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
|
1330 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
|
1331 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
|
1332 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
|
1333 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
|
1334 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
|
1335 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
|
1336 int vim9script = in_vim9script(); |
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
1337 |
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
1338 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
|
1339 return NOTDONE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1340 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1341 ga_init(&newargs); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1342 ga_init(&newlines); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1343 |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1344 // 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
|
1345 // 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
|
1346 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
|
1347 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
|
1348 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
|
1349 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
|
1350 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
|
1351 { |
1d11e3adbe52
patch 8.2.2205: Vim9: memory leak when parsing lambda fails
Bram Moolenaar <Bram@vim.org>
parents:
23318
diff
changeset
|
1352 if (types_optional) |
1d11e3adbe52
patch 8.2.2205: Vim9: memory leak when parsing lambda fails
Bram Moolenaar <Bram@vim.org>
parents:
23318
diff
changeset
|
1353 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
|
1354 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
|
1355 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1356 |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1357 // Parse the arguments for real. |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1358 if (evaluate) |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1359 pnewargs = &newargs; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1360 else |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1361 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
|
1362 *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
|
1363 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
|
1364 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
|
1365 &varargs, &default_args, |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1366 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
|
1367 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
|
1368 || (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
|
1369 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
|
1370 { |
1d11e3adbe52
patch 8.2.2205: Vim9: memory leak when parsing lambda fails
Bram Moolenaar <Bram@vim.org>
parents:
23318
diff
changeset
|
1371 if (types_optional) |
1d11e3adbe52
patch 8.2.2205: Vim9: memory leak when parsing lambda fails
Bram Moolenaar <Bram@vim.org>
parents:
23318
diff
changeset
|
1372 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
|
1373 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
|
1374 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
|
1375 } |
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
|
1376 *arg = s; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1377 |
23644
03acf9c49f07
patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents:
23630
diff
changeset
|
1378 // 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
|
1379 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
|
1380 { |
03acf9c49f07
patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents:
23630
diff
changeset
|
1381 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
|
1382 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
|
1383 } |
03acf9c49f07
patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents:
23630
diff
changeset
|
1384 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1385 // 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
|
1386 if (evaluate) |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1387 eval_lavars_used = &eval_lavars; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1388 |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1389 *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
|
1390 |
23332
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1391 // 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
|
1392 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
|
1393 { |
24422
41cf1155ab90
patch 8.2.2751: Coverity warns for using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
24412
diff
changeset
|
1394 if (evalarg == NULL) |
41cf1155ab90
patch 8.2.2751: Coverity warns for using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
24412
diff
changeset
|
1395 // cannot happen? |
41cf1155ab90
patch 8.2.2751: Coverity warns for using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
24412
diff
changeset
|
1396 goto theend; |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1397 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
|
1398 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
|
1399 &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
|
1400 goto errret; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1401 goto theend; |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1402 } |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1403 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
|
1404 { |
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1405 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
|
1406 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
|
1407 } |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1408 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1409 // 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
|
1410 start = *arg; |
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21218
diff
changeset
|
1411 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
|
1412 if (ret == FAIL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1413 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
|
1414 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
|
1415 { |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21032
diff
changeset
|
1416 // 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
|
1417 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
|
1418 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
|
1419 } |
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21032
diff
changeset
|
1420 |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1421 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
|
1422 { |
23318
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1423 *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
|
1424 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
|
1425 { |
26915
3631d2deb36c
patch 8.2.3986: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26897
diff
changeset
|
1426 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
|
1427 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
|
1428 } |
c76240efdf02
patch 8.2.2204: Vim9: using -> both for method and lambda is confusing
Bram Moolenaar <Bram@vim.org>
parents:
23285
diff
changeset
|
1429 ++*arg; |
19826
293a22b677a8
patch 8.2.0469: Vim9: no error for missing ] after list
Bram Moolenaar <Bram@vim.org>
parents:
19685
diff
changeset
|
1430 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1431 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1432 if (evaluate) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1433 { |
21040
d9e0db9b2b99
patch 8.2.1071: Vim9: no line break allowed inside a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21032
diff
changeset
|
1434 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
|
1435 int flags = FC_LAMBDA; |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
1436 char_u *p; |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1437 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
|
1438 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
|
1439 |
17659
121bdff812b4
patch 8.1.1827: allocating more memory than needed for extended structs
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
1440 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
|
1441 if (fp == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1442 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
|
1443 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
|
1444 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
|
1445 if (pt == NULL) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
1446 goto errret; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1447 |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
1448 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
|
1449 if (ga_grow(&newlines, 1) == FAIL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1450 goto errret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1451 |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1452 // 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
|
1453 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
|
1454 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
|
1455 line_end = end; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1456 |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1457 // 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
|
1458 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
|
1459 p = alloc(len); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1460 if (p == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1461 goto errret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1462 ((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
|
1463 STRCPY(p, "return "); |
24651
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1464 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
|
1465 |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1466 if (line_end != end) |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1467 { |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1468 // 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
|
1469 // 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
|
1470 while (*line_end == '\n') |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1471 { |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1472 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
|
1473 goto errret; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1474 start = line_end + 1; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1475 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
|
1476 if (line_end == NULL) |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1477 line_end = end; |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1478 ((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
|
1479 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
|
1480 } |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1481 } |
5dea95170907
patch 8.2.2864: Vim9: crash when using inline function
Bram Moolenaar <Bram@vim.org>
parents:
24448
diff
changeset
|
1482 |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
1483 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
|
1484 // 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
|
1485 flags |= FC_NOARGS; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1486 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1487 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
|
1488 set_ufunc_name(fp, name); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1489 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
|
1490 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
|
1491 if (types_optional) |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1492 { |
24400
62e978382fa0
patch 8.2.2740: Vim9: lambda with varargs doesn't work
Bram Moolenaar <Bram@vim.org>
parents:
24398
diff
changeset
|
1493 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
|
1494 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
|
1495 goto errret; |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1496 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
|
1497 { |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1498 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
|
1499 &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
|
1500 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
|
1501 goto errret; |
cdb706d5c43d
patch 8.2.2209: Vim9: return type of => lambda not parsed
Bram Moolenaar <Bram@vim.org>
parents:
23320
diff
changeset
|
1502 } |
23420
42294d4d4f6e
patch 8.2.2253: Vim9: expr test fails
Bram Moolenaar <Bram@vim.org>
parents:
23398
diff
changeset
|
1503 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
|
1504 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
|
1505 } |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
1506 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1507 fp->uf_lines = newlines; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1508 if (current_funccal != NULL && eval_lavars) |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1509 { |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
1510 flags |= FC_CLOSURE; |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
1511 if (register_closure(fp) == FAIL) |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1512 goto errret; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1513 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1514 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1515 #ifdef FEAT_PROFILE |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1516 if (prof_def_func()) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1517 func_do_profile(fp); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1518 #endif |
14323
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1519 if (sandbox) |
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
1520 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
|
1521 // 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
|
1522 // 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
|
1523 fp->uf_varargs = !vim9script || varargs; |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
1524 fp->uf_flags = flags; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1525 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
|
1526 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
|
1527 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
|
1528 |
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
|
1529 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
|
1530 |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
1531 pt->pt_func = fp; |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
1532 pt->pt_refcount = 1; |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
1533 rettv->vval.v_partial = pt; |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
1534 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
|
1535 |
308d29307910
patch 8.2.2558: no error if a lambda argument shadows a variable
Bram Moolenaar <Bram@vim.org>
parents:
24004
diff
changeset
|
1536 hash_add(&func_hashtab, UF2HIKEY(fp)); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1537 } |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1538 |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
1539 theend: |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1540 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
|
1541 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
|
1542 evalarg->eval_tofree = tofree1; |
21220
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21218
diff
changeset
|
1543 else |
23644
03acf9c49f07
patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents:
23630
diff
changeset
|
1544 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
|
1545 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
|
1546 if (types_optional) |
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
1547 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
|
1548 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1549 return OK; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1550 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1551 errret: |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1552 ga_clear_strings(&newargs); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1553 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
|
1554 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
|
1555 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
|
1556 { |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
1557 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
|
1558 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
|
1559 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
|
1560 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1561 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
|
1562 vim_free(pt); |
21222
a4d00a2dadd6
patch 8.2.1162: crash when using a lambda
Bram Moolenaar <Bram@vim.org>
parents:
21220
diff
changeset
|
1563 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
|
1564 evalarg->eval_tofree = tofree1; |
21220
ad13736a1783
patch 8.2.1161: Vim9: using freed memory
Bram Moolenaar <Bram@vim.org>
parents:
21218
diff
changeset
|
1565 else |
23644
03acf9c49f07
patch 8.2.2364: Vim9: line break in lambda accesses freed memory
Bram Moolenaar <Bram@vim.org>
parents:
23630
diff
changeset
|
1566 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
|
1567 vim_free(tofree2); |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
1568 eval_lavars_used = old_eval_lavars; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1569 return FAIL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1570 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1571 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1572 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1573 * 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
|
1574 * name it contains, otherwise return "name". |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1575 * 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
|
1576 * "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
|
1577 * 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
|
1578 * 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
|
1579 * 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
|
1580 * 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
|
1581 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1582 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
|
1583 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
|
1584 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
|
1585 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
|
1586 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
|
1587 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
|
1588 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
|
1589 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
|
1590 int *found_var) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1591 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1592 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
|
1593 typval_T *tv = NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1594 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
|
1595 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
|
1596 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
|
1597 int did_type = FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1598 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1599 if (partialp != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1600 *partialp = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1601 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1602 cc = name[*lenp]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1603 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
|
1604 |
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
|
1605 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
|
1606 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
|
1607 if (v != NULL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1608 { |
26046
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1609 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
|
1610 } |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1611 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
|
1612 { |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1613 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
|
1614 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
|
1615 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
|
1616 |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1617 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
|
1618 { |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1619 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
|
1620 len -= 2; |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1621 } |
27698
3813036f19cb
patch 8.2.4375: ctx_imports is not used
Bram Moolenaar <Bram@vim.org>
parents:
27682
diff
changeset
|
1622 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
|
1623 |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
1624 // 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
|
1625 if (import != NULL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1626 { |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
1627 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
|
1628 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
|
1629 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
|
1630 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
|
1631 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
|
1632 name[len] = cc; |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
1633 *lenp = 0; |
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
1634 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
|
1635 } |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1636 } |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1637 |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1638 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
|
1639 { |
26506
4a1d2abc2016
patch 8.2.3783: confusing error for using a variable as a function
Bram Moolenaar <Bram@vim.org>
parents:
26504
diff
changeset
|
1640 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
|
1641 *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
|
1642 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
|
1643 { |
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1644 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
|
1645 { |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1646 *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
|
1647 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
|
1648 } |
26046
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1649 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
|
1650 *lenp = (int)STRLEN(s); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1651 } |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1652 |
26046
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1653 if (tv->v_type == VAR_PARTIAL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1654 { |
26046
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1655 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
|
1656 |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1657 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
|
1658 { |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1659 *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
|
1660 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
|
1661 } |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1662 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
|
1663 *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
|
1664 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
|
1665 *lenp = (int)STRLEN(s); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1666 } |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1667 |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1668 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
|
1669 { |
26046
f773ef3c641d
patch 8.2.3557: Vim9: cannot call imported funcref at script level
Bram Moolenaar <Bram@vim.org>
parents:
25826
diff
changeset
|
1670 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
|
1671 { |
26980
8796f1384750
patch 8.2.4019: Vim9: import mechanism is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
26966
diff
changeset
|
1672 svar_T *sv = find_typval_in_script(tv, 0); |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1673 |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1674 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
|
1675 *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
|
1676 } |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
1677 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
|
1678 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1679 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1680 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1681 return name; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1682 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1683 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1684 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1685 * 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
|
1686 * "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
|
1687 */ |
18576
e9675870c480
patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents:
18572
diff
changeset
|
1688 void |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1689 emsg_funcname(char *ermsg, char_u *name) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1690 { |
27088
3956e3bb47ec
patch 8.2.4073: Coverity warns for using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
27076
diff
changeset
|
1691 char_u *p = name; |
3956e3bb47ec
patch 8.2.4073: Coverity warns for using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
27076
diff
changeset
|
1692 |
3956e3bb47ec
patch 8.2.4073: Coverity warns for using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
27076
diff
changeset
|
1693 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
|
1694 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
|
1695 semsg(_(ermsg), p); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1696 if (p != name) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1697 vim_free(p); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1698 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1699 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1700 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1701 * 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
|
1702 * Return OK or FAIL. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1703 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1704 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1705 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
|
1706 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
|
1707 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
|
1708 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
|
1709 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
|
1710 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
|
1711 funcexe_T *funcexe) // various values |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1712 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1713 char_u *argp; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1714 int ret = OK; |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1715 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
|
1716 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
|
1717 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
|
1718 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
|
1719 ? FALSE : (evalarg->eval_flags & EVAL_EVALUATE); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1720 |
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 * Get the arguments. |
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 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
|
1725 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
|
1726 : funcexe->fe_partial->pt_argc)) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1727 { |
21118
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21066
diff
changeset
|
1728 // 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
|
1729 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
|
1730 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1731 if (*argp == ')' || *argp == ',' || *argp == NUL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1732 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
|
1733 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
|
1734 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1735 ret = FAIL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1736 break; |
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 ++argcount; |
21552
cbc570e66d11
patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents:
21528
diff
changeset
|
1739 // 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
|
1740 // 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
|
1741 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
|
1742 { |
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
|
1743 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
|
1744 { |
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
|
1745 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
|
1746 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
|
1747 ",", 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
|
1748 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
|
1749 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
|
1750 } |
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
|
1751 } |
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
|
1752 else |
21552
cbc570e66d11
patch 8.2.1326: Vim9: skipping over white space after list
Bram Moolenaar <Bram@vim.org>
parents:
21528
diff
changeset
|
1753 argp = skipwhite(argp); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1754 if (*argp != ',') |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1755 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
|
1756 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
|
1757 { |
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
|
1758 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
|
1759 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
|
1760 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
|
1761 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
|
1762 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1763 } |
21118
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21066
diff
changeset
|
1764 argp = skipwhite_and_linebreak(argp, evalarg); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1765 if (*argp == ')') |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1766 ++argp; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1767 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1768 ret = FAIL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1769 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1770 if (ret == OK) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1771 { |
25400
5c7192180b89
patch 8.2.3237: when a builtin function gives an error processing continues
Bram Moolenaar <Bram@vim.org>
parents:
25396
diff
changeset
|
1772 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
|
1773 int did_emsg_before = did_emsg; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1774 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1775 if (get_vim_var_nr(VV_TESTING)) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1776 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1777 // 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
|
1778 // 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
|
1779 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
|
1780 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
|
1781 for (i = 0; i < argcount; ++i) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1782 if (ga_grow(&funcargs, 1) == OK) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1783 ((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
|
1784 &argvars[i]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1785 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1786 |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17462
diff
changeset
|
1787 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
|
1788 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
|
1789 { |
25400
5c7192180b89
patch 8.2.3237: when a builtin function gives an error processing continues
Bram Moolenaar <Bram@vim.org>
parents:
25396
diff
changeset
|
1790 // 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
|
1791 // 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
|
1792 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
|
1793 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
|
1794 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1795 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1796 funcargs.ga_len -= i; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1797 } |
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
|
1798 else if (!aborting() && evaluate) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1799 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1800 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
|
1801 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
|
1802 else |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
1803 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
|
1804 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1805 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1806 while (--argcount >= 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1807 clear_tv(&argvars[argcount]); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1808 |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
1809 if (vim9script) |
21737
a849c984b485
patch 8.2.1418: Vim9: invalid error for missing white space
Bram Moolenaar <Bram@vim.org>
parents:
21699
diff
changeset
|
1810 *arg = argp; |
a849c984b485
patch 8.2.1418: Vim9: invalid error for missing white space
Bram Moolenaar <Bram@vim.org>
parents:
21699
diff
changeset
|
1811 else |
a849c984b485
patch 8.2.1418: Vim9: invalid error for missing white space
Bram Moolenaar <Bram@vim.org>
parents:
21699
diff
changeset
|
1812 *arg = skipwhite(argp); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1813 return ret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1814 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1815 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1816 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1817 * 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
|
1818 * 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
|
1819 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1820 static int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1821 eval_fname_sid(char_u *p) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1822 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1823 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
|
1824 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1825 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1826 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1827 * 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
|
1828 * 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
|
1829 * 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
|
1830 * (slow). |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1831 */ |
19330
9c8b803fe598
patch 8.2.0223: some instructions not yet tested
Bram Moolenaar <Bram@vim.org>
parents:
19328
diff
changeset
|
1832 char_u * |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1833 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
|
1834 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1835 int llen; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1836 char_u *fname; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1837 int i; |
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 llen = eval_fname_script(name); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1840 if (llen > 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1841 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1842 fname_buf[0] = K_SPECIAL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1843 fname_buf[1] = KS_EXTRA; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1844 fname_buf[2] = (int)KE_SNR; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1845 i = 3; |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
1846 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
|
1847 { |
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
|
1848 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
|
1849 *error = FCERR_SCRIPT; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1850 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1851 { |
16378
3d6b282e2d6e
patch 8.1.1194: typos and small problems in source files
Bram Moolenaar <Bram@vim.org>
parents:
16003
diff
changeset
|
1852 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
|
1853 (long)current_sctx.sc_sid); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1854 i = (int)STRLEN(fname_buf); |
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 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1857 if (i + STRLEN(name + llen) < FLEN_FIXED) |
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 STRCPY(fname_buf + i, name + llen); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1860 fname = fname_buf; |
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 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1863 { |
16764
ef00b6bc186b
patch 8.1.1384: using "int" for alloc() often results in compiler warnings
Bram Moolenaar <Bram@vim.org>
parents:
16708
diff
changeset
|
1864 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
|
1865 if (fname == NULL) |
19013
dd9ab0674eec
patch 8.2.0067: ERROR_UNKNOWN clashes on some systems
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
1866 *error = FCERR_OTHER; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1867 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1868 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1869 *tofree = fname; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1870 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
|
1871 STRCPY(fname + i, name + llen); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1872 } |
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 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1875 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1876 fname = name; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1877 return fname; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1878 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1879 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1880 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1881 * 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
|
1882 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1883 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
|
1884 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
|
1885 { |
27068
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1886 hashitem_T *hi; |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1887 char_u buffer[200]; |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1888 |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1889 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
|
1890 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
|
1891 |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1892 // A script-local function is stored as "<SNR>99_name". |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1893 buffer[0] = K_SPECIAL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1894 buffer[1] = KS_EXTRA; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1895 buffer[2] = (int)KE_SNR; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1896 vim_snprintf((char *)buffer + 3, sizeof(buffer) - 3, "%ld_%s", |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1897 (long)sid, name); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1898 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
|
1899 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
|
1900 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
|
1901 return NULL; |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1902 } |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1903 |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1904 /* |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1905 * 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
|
1906 */ |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1907 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
|
1908 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
|
1909 { |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1910 hashitem_T *hi; |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1911 char_u buffer[200]; |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1912 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
|
1913 |
27464
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
1914 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
|
1915 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
|
1916 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
|
1917 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
|
1918 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
|
1919 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
|
1920 { |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1921 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
|
1922 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
|
1923 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
|
1924 |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
1925 // 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
|
1926 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
|
1927 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
|
1928 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
|
1929 |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1930 // 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
|
1931 // "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
|
1932 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
|
1933 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
|
1934 else |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1935 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
|
1936 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
|
1937 { |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1938 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
|
1939 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
|
1940 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
|
1941 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
|
1942 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
|
1943 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
|
1944 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
|
1945 } |
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1946 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1947 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1948 return NULL; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1949 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1950 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1951 /* |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1952 * 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
|
1953 * 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
|
1954 * functions. |
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
1955 * 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
|
1956 * Return NULL for unknown function. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1957 */ |
21564
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
1958 ufunc_T * |
27348
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
1959 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
|
1960 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1961 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
|
1962 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
|
1963 |
27348
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
1964 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
|
1965 { |
27807
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
1966 // 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
|
1967 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
|
1968 && (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
|
1969 { |
26530
2fbd05a873e3
patch 8.2.3794: Vim9: cannot find script-local func using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
26506
diff
changeset
|
1970 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
|
1971 ? 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
|
1972 if (func != NULL) |
9faab49c880f
patch 8.2.0960: cannot use :import in legacy Vim script
Bram Moolenaar <Bram@vim.org>
parents:
20709
diff
changeset
|
1973 return func; |
9faab49c880f
patch 8.2.0960: cannot use :import in legacy Vim script
Bram Moolenaar <Bram@vim.org>
parents:
20709
diff
changeset
|
1974 } |
27807
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
1975 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
|
1976 { |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
1977 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
|
1978 long sid; |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
1979 |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
1980 // 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
|
1981 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
|
1982 if (*p == '_') |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
1983 { |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
1984 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
|
1985 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
|
1986 return func; |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
1987 } |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
1988 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1989 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
1990 |
27348
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
1991 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
|
1992 { |
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
1993 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
|
1994 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
|
1995 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
|
1996 return HI2UF(hi); |
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
1997 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
1998 |
27068
6a4fc2e6e6eb
patch 8.2.4063: Vim9: exported function in autoload script not found
Bram Moolenaar <Bram@vim.org>
parents:
27053
diff
changeset
|
1999 // 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
|
2000 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
|
2001 ? 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
|
2002 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2003 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2004 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2005 * 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
|
2006 * "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
|
2007 * 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
|
2008 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2009 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
|
2010 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
|
2011 { |
27348
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
2012 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
|
2013 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2014 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
|
2015 return fp; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2016 return NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2017 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2018 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2019 /* |
22236
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22188
diff
changeset
|
2020 * 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
|
2021 */ |
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22188
diff
changeset
|
2022 int |
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22188
diff
changeset
|
2023 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
|
2024 { |
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22188
diff
changeset
|
2025 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
|
2026 } |
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22188
diff
changeset
|
2027 |
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22188
diff
changeset
|
2028 /* |
27464
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
2029 * 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
|
2030 */ |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
2031 int |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
2032 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
|
2033 { |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
2034 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
|
2035 && (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
|
2036 && 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
|
2037 } |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
2038 |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
2039 /* |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2040 * 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
|
2041 * "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
|
2042 * Takes care of script-local function names. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2043 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2044 static void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2045 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
|
2046 { |
22236
3d0632b260fd
patch 8.2.1667: local function name cannot shadow a global function name
Bram Moolenaar <Bram@vim.org>
parents:
22188
diff
changeset
|
2047 if (!func_is_global(fp)) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2048 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2049 STRCPY(buf, "<SNR>"); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2050 STRCAT(buf, fp->uf_name + 3); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2051 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2052 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2053 STRCPY(buf, fp->uf_name); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2054 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2055 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2056 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2057 * 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
|
2058 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2059 static void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2060 add_nr_var( |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2061 dict_T *dp, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2062 dictitem_T *v, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2063 char *name, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2064 varnumber_T nr) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2065 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2066 STRCPY(v->di_key, name); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2067 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
|
2068 hash_add(&dp->dv_hashtab, DI2HIKEY(v)); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2069 v->di_tv.v_type = VAR_NUMBER; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2070 v->di_tv.v_lock = VAR_FIXED; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2071 v->di_tv.vval.v_number = nr; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2072 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2073 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2074 /* |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2075 * Free "fc". |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2076 */ |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2077 static void |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2078 free_funccal(funccall_T *fc) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2079 { |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2080 int i; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
2081 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
2082 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
|
2083 { |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2084 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
|
2085 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2086 // 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
|
2087 // 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
|
2088 // 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
|
2089 // 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
|
2090 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
|
2091 fp->uf_scoped = NULL; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
2092 } |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
2093 ga_clear(&fc->fc_funcs); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2094 |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
2095 func_ptr_unref(fc->func); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2096 vim_free(fc); |
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 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2099 /* |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2100 * 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
|
2101 * 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
|
2102 * 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
|
2103 */ |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2104 static void |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2105 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
|
2106 { |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2107 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
|
2108 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2109 // 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
|
2110 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
|
2111 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2112 // 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
|
2113 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
|
2114 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2115 // 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
|
2116 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
|
2117 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
|
2118 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2119 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
|
2120 } |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2121 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2122 /* |
11299
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2123 * 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
|
2124 * 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
|
2125 */ |
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2126 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
|
2127 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
|
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 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
|
2130 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
|
2131 |
11299
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2132 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
|
2133 |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2134 // 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
|
2135 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
|
2136 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
|
2137 else |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2138 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
|
2139 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2140 // 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
|
2141 // 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
|
2142 // in it. |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2143 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
|
2144 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
|
2145 else |
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2146 { |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2147 int todo; |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2148 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
|
2149 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
|
2150 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2151 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
|
2152 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2153 // 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
|
2154 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
|
2155 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
|
2156 { |
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2157 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
|
2158 { |
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2159 --todo; |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2160 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
|
2161 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
|
2162 } |
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2163 } |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2164 } |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2165 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2166 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
|
2167 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
|
2168 else |
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 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
|
2171 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2172 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
|
2173 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2174 // 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
|
2175 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
|
2176 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
|
2177 } |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2178 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2179 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
|
2180 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
|
2181 else |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2182 { |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2183 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
|
2184 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2185 // "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
|
2186 // 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
|
2187 // 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
|
2188 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
|
2189 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
|
2190 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2191 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
|
2192 // 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
|
2193 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
|
2194 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
|
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 // 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
|
2197 // 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
|
2198 // 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
|
2199 // 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
|
2200 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
|
2201 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
|
2202 } |
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 } |
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2204 } |
22324
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2205 |
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2206 /* |
26566
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
2207 * 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
|
2208 */ |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
2209 static int |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
2210 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
|
2211 { |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
2212 return isdigit(*name) |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
2213 || (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
|
2214 } |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
2215 |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
2216 /* |
22324
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2217 * There are two kinds of function names: |
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2218 * 1. ordinary names, function defined with :function or :def |
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2219 * 2. numbered functions and lambdas |
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2220 * 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
|
2221 * 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
|
2222 * looked up by name. |
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2223 */ |
22326
fb69b43d73f3
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents:
22324
diff
changeset
|
2224 int |
22324
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2225 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
|
2226 { |
26566
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
2227 return numbered_function(name) || *name == '<'; |
22324
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2228 } |
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2229 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2230 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2231 * 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
|
2232 * 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
|
2233 * 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
|
2234 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2235 static void |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2236 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
|
2237 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2238 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
|
2239 int i; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2240 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2241 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
|
2242 return; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2243 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2244 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
|
2245 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
|
2246 && 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
|
2247 && 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
|
2248 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
|
2249 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2250 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
|
2251 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2252 *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
|
2253 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
|
2254 return; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2255 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2256 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2257 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
|
2258 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
|
2259 ((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
|
2260 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2261 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2262 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2263 * 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
|
2264 * 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
|
2265 * 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
|
2266 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2267 static int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2268 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
|
2269 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2270 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
|
2271 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2272 // 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
|
2273 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
|
2274 return FALSE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2275 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2276 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
|
2277 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
|
2278 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2279 // 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
|
2280 // 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
|
2281 // 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
|
2282 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
|
2283 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2284 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
|
2285 return FALSE; |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
2286 } |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
2287 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
|
2288 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
|
2289 return TRUE; |
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 return FALSE; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2292 } |
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 static void |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2295 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
|
2296 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2297 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
|
2298 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
|
2299 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
|
2300 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
|
2301 VIM_CLEAR(fp->uf_block_ids); |
19685
d64f403289db
patch 8.2.0399: various memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19579
diff
changeset
|
2302 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
|
2303 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
|
2304 |
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
2305 // 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
|
2306 // 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
|
2307 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
|
2308 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
|
2309 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
|
2310 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
|
2311 |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
2312 #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
|
2313 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
|
2314 { |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
2315 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
|
2316 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
|
2317 } |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
2318 |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
2319 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
|
2320 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
|
2321 #endif |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2322 #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
|
2323 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
|
2324 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
|
2325 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
|
2326 #endif |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2327 } |
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 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2330 * 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
|
2331 * 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
|
2332 * 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
|
2333 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2334 static void |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2335 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
|
2336 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2337 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
|
2338 return; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2339 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
|
2340 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2341 // 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
|
2342 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
|
2343 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
|
2344 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
|
2345 } |
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 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2348 * 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
|
2349 * 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
|
2350 * 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
|
2351 * 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
|
2352 */ |
22326
fb69b43d73f3
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents:
22324
diff
changeset
|
2353 static int |
20257
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20255
diff
changeset
|
2354 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
|
2355 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2356 // 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
|
2357 // 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
|
2358 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
|
2359 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
|
2360 |
20257
683c2da4982b
patch 8.2.0684: Vim9: memory leak when using lambda
Bram Moolenaar <Bram@vim.org>
parents:
20255
diff
changeset
|
2361 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
|
2362 { |
22324
a4ed0de125d9
patch 8.2.1711: Vim9: leaking memory when using partial
Bram Moolenaar <Bram@vim.org>
parents:
22298
diff
changeset
|
2363 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
|
2364 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
|
2365 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
|
2366 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
|
2367 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
|
2368 } |
22326
fb69b43d73f3
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents:
22324
diff
changeset
|
2369 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
|
2370 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2371 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2372 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2373 * 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
|
2374 * 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
|
2375 */ |
26445
568f93dcdc62
patch 8.2.3753: Vim9: function unreferenced while called is never deleted
Bram Moolenaar <Bram@vim.org>
parents:
26439
diff
changeset
|
2376 void |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2377 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
|
2378 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2379 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
|
2380 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
|
2381 || (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
|
2382 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
|
2383 else |
90d859a402cc
patch 8.2.1290: Vim9: cannot replace a global function
Bram Moolenaar <Bram@vim.org>
parents:
21461
diff
changeset
|
2384 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
|
2385 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2386 |
21558
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2387 /* |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2388 * 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
|
2389 * 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
|
2390 */ |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2391 int |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2392 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
|
2393 { |
27348
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
2394 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
|
2395 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
|
2396 |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2397 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
|
2398 { |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21791
diff
changeset
|
2399 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
|
2400 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
|
2401 } |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2402 |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27092
diff
changeset
|
2403 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
|
2404 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
|
2405 { |
23699
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
2406 // TODO: handle ! to overwrite |
26857
2aeea8611342
patch 8.2.3957: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26833
diff
changeset
|
2407 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
|
2408 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
|
2409 } |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2410 |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2411 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
|
2412 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
|
2413 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
|
2414 |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2415 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
|
2416 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
|
2417 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
|
2418 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
|
2419 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
|
2420 || 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
|
2421 == FAIL |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2422 || 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
|
2423 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
|
2424 |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2425 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
|
2426 : 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
|
2427 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
|
2428 { |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2429 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
|
2430 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
|
2431 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
|
2432 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
|
2433 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
|
2434 } |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2435 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
|
2436 { |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2437 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
|
2438 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
|
2439 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
|
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 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
|
2442 |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2443 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
|
2444 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
|
2445 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
|
2446 |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2447 // 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
|
2448 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
|
2449 |
23699
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
2450 // 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
|
2451 // 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
|
2452 // 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
|
2453 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
|
2454 { |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2455 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
|
2456 |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2457 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
|
2458 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
|
2459 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
|
2460 { |
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
2461 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
|
2462 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
|
2463 } |
23285
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2464 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
|
2465 --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
|
2466 } |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2467 |
112fa621b127
patch 8.2.2188: Vim9: crash when calling global function from :def function
Bram Moolenaar <Bram@vim.org>
parents:
23252
diff
changeset
|
2468 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
|
2469 |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2470 failed: |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2471 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
|
2472 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
|
2473 } |
1c4d4aa22b37
patch 8.2.1329: Vim9: cannot define global function inside :def function
Bram Moolenaar <Bram@vim.org>
parents:
21552
diff
changeset
|
2474 |
22908
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2475 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
|
2476 |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2477 /* |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2478 * 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
|
2479 * 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
|
2480 * 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
|
2481 */ |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2482 int |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2483 funcdepth_increment(void) |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2484 { |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2485 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
|
2486 { |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
2487 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
|
2488 return FAIL; |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2489 } |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2490 ++funcdepth; |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2491 return OK; |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2492 } |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2493 |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2494 void |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2495 funcdepth_decrement(void) |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2496 { |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2497 --funcdepth; |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2498 } |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2499 |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2500 /* |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2501 * 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
|
2502 */ |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2503 int |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2504 funcdepth_get(void) |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2505 { |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2506 return funcdepth; |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2507 } |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2508 |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2509 /* |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2510 * 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
|
2511 * 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
|
2512 * 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
|
2513 */ |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2514 void |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2515 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
|
2516 { |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2517 funcdepth = depth; |
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2518 } |
11299
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2519 |
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
2520 /* |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2521 * Call a user function. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2522 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2523 static void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2524 call_user_func( |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2525 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
|
2526 int argcount, // nr of args |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2527 typval_T *argvars, // arguments |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2528 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
|
2529 funcexe_T *funcexe, // context |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2530 dict_T *selfdict) // Dictionary for "self" |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2531 { |
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
|
2532 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
|
2533 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
|
2534 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
|
2535 funccall_T *fc; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2536 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
|
2537 int default_arg_err = FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2538 dictitem_T *v; |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2539 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
|
2540 int i; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2541 int ai; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2542 int islambda = FALSE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2543 char_u numbuf[NUMBUFLEN]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2544 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
|
2545 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
|
2546 int tv_to_free_len = 0; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2547 #ifdef FEAT_PROFILE |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23699
diff
changeset
|
2548 profinfo_T profile_info; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2549 #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
|
2550 ESTACK_CHECK_DECLARATION |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2551 |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23699
diff
changeset
|
2552 #ifdef FEAT_PROFILE |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23699
diff
changeset
|
2553 CLEAR_FIELD(profile_info); |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23699
diff
changeset
|
2554 #endif |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23699
diff
changeset
|
2555 |
22908
54219df706b5
patch 8.2.2001: Vim9: :def function does not apply 'maxfuncdepth'
Bram Moolenaar <Bram@vim.org>
parents:
22816
diff
changeset
|
2556 // 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
|
2557 if (funcdepth_increment() == FAIL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2558 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2559 rettv->v_type = VAR_NUMBER; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2560 rettv->vval.v_number = -1; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2561 return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2562 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2563 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2564 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
|
2565 |
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
|
2566 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
|
2567 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
|
2568 return; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2569 fc->caller = current_funccal; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2570 current_funccal = fc; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2571 fc->func = fp; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2572 fc->rettv = rettv; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2573 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
|
2574 // 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
|
2575 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
|
2576 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
|
2577 // Set up fields for closure. |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
2578 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
|
2579 func_ptr_ref(fp); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2580 |
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
|
2581 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
|
2582 { |
23976
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2583 #ifdef FEAT_PROFILE |
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2584 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
|
2585 #endif |
20538
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20532
diff
changeset
|
2586 // 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
|
2587 #ifdef FEAT_PROFILE |
23976
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2588 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
|
2589 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
|
2590 #endif |
27678
1646525507aa
patch 8.2.4365: sticky command modifiers are too sticky
Bram Moolenaar <Bram@vim.org>
parents:
27669
diff
changeset
|
2591 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
|
2592 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
|
2593 funcdepth_decrement(); |
23717
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23699
diff
changeset
|
2594 #ifdef FEAT_PROFILE |
e3720756acdc
patch 8.2.2400: Vim9: compiled functions are not profiled
Bram Moolenaar <Bram@vim.org>
parents:
23699
diff
changeset
|
2595 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
|
2596 || (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
|
2597 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
|
2598 #endif |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2599 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
|
2600 free_funccal(fc); |
27678
1646525507aa
patch 8.2.4365: sticky command modifiers are too sticky
Bram Moolenaar <Bram@vim.org>
parents:
27669
diff
changeset
|
2601 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
|
2602 return; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2603 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2604 |
26323
3841da4eac23
patch 8.2.3692: Vim9: cannot use :func inside a :def function
Bram Moolenaar <Bram@vim.org>
parents:
26205
diff
changeset
|
2605 islambda = fp->uf_flags & FC_LAMBDA; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2606 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2607 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2608 * 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
|
2609 * 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
|
2610 * 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
|
2611 */ |
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 * Init l: variables. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2614 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2615 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
|
2616 if (selfdict != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2617 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2618 // 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
|
2619 // 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
|
2620 v = &fc->fixvar[fixvar_idx++].var; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2621 name = v->di_key; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2622 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
|
2623 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
|
2624 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
|
2625 v->di_tv.v_type = VAR_DICT; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2626 v->di_tv.v_lock = 0; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2627 v->di_tv.vval.v_dict = selfdict; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2628 ++selfdict->dv_refcount; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2629 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2630 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2631 /* |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2632 * 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
|
2633 * 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
|
2634 * 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
|
2635 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2636 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
|
2637 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
|
2638 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
|
2639 (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
|
2640 ? 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
|
2641 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
|
2642 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
|
2643 { |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2644 // 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
|
2645 // 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
|
2646 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
|
2647 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
|
2648 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
|
2649 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
|
2650 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
|
2651 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
|
2652 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
|
2653 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
|
2654 } |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
2655 CLEAR_FIELD(fc->l_varlist); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2656 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
|
2657 fc->l_varlist.lv_lock = VAR_FIXED; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2658 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2659 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2660 * 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
|
2661 * Set a:name to named arguments. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2662 * 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
|
2663 * 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
|
2664 */ |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2665 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
|
2666 { |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2667 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
|
2668 (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
|
2669 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
|
2670 (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
|
2671 } |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2672 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
|
2673 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2674 int addlocal = FALSE; |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2675 typval_T def_rettv; |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2676 int isdefault = FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2677 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2678 ai = i - fp->uf_args.ga_len; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2679 if (ai < 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2680 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2681 // named argument a:name |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2682 name = FUNCARG(fp, i); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2683 if (islambda) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2684 addlocal = TRUE; |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2685 |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2686 // 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
|
2687 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
|
2688 && (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
|
2689 && 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
|
2690 if (isdefault) |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2691 { |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2692 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
|
2693 |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2694 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
|
2695 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
|
2696 |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2697 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
|
2698 [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
|
2699 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
|
2700 { |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2701 default_arg_err = 1; |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2702 break; |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2703 } |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2704 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2705 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2706 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2707 { |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2708 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
|
2709 // 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
|
2710 break; |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2711 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2712 // "..." argument a:1, a:2, etc. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2713 sprintf((char *)numbuf, "%d", ai + 1); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2714 name = numbuf; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2715 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2716 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
|
2717 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2718 v = &fc->fixvar[fixvar_idx++].var; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2719 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
|
2720 STRCPY(v->di_key, name); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2721 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2722 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2723 { |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2724 v = dictitem_alloc(name); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2725 if (v == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2726 break; |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2727 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
|
2728 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2729 |
17127
d244a9be99db
patch 8.1.1563: crash when using closures
Bram Moolenaar <Bram@vim.org>
parents:
16969
diff
changeset
|
2730 // 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
|
2731 // "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
|
2732 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
|
2733 v->di_tv.v_lock = VAR_FIXED; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2734 |
24448
faac16c365b6
patch 8.2.2764: memory leak when default function argument is allocated
Bram Moolenaar <Bram@vim.org>
parents:
24436
diff
changeset
|
2735 if (isdefault) |
faac16c365b6
patch 8.2.2764: memory leak when default function argument is allocated
Bram Moolenaar <Bram@vim.org>
parents:
24436
diff
changeset
|
2736 // 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
|
2737 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
|
2738 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2739 if (addlocal) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2740 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2741 // 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
|
2742 // 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
|
2743 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
|
2744 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
|
2745 } |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
2746 else |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
2747 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
|
2748 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2749 if (ai >= 0 && ai < MAX_FUNC_ARGS) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2750 { |
16003
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2751 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
|
2752 |
879829e44091
patch 8.1.1007: using closure may consume a lot of memory
Bram Moolenaar <Bram@vim.org>
parents:
15820
diff
changeset
|
2753 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
|
2754 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
|
2755 list_append(&fc->l_varlist, li); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2756 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2757 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2758 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2759 // 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
|
2760 ++RedrawingDisabled; |
14323
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
2761 |
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
2762 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
|
2763 { |
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
2764 using_sandbox = TRUE; |
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
2765 ++sandbox; |
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
2766 } |
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
2767 |
20538
9f921ba86d05
patch 8.2.0823: Vim9: script reload test is disabled
Bram Moolenaar <Bram@vim.org>
parents:
20532
diff
changeset
|
2768 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
|
2769 ESTACK_CHECK_SETUP |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2770 if (p_verbose >= 12) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2771 { |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2772 ++no_wait_return; |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2773 verbose_enter_scroll(); |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2774 |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2775 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
|
2776 if (p_verbose >= 14) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2777 { |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2778 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
|
2779 char_u numbuf2[NUMBUFLEN]; |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2780 char_u *tofree; |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2781 char_u *s; |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2782 |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2783 msg_puts("("); |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2784 for (i = 0; i < argcount; ++i) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2785 { |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2786 if (i > 0) |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2787 msg_puts(", "); |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2788 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
|
2789 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
|
2790 else |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2791 { |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2792 // 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
|
2793 ++emsg_off; |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2794 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
|
2795 --emsg_off; |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2796 if (s != NULL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2797 { |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2798 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
|
2799 { |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2800 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
|
2801 s = buf; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2802 } |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2803 msg_puts((char *)s); |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2804 vim_free(tofree); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2805 } |
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 } |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2808 msg_puts(")"); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2809 } |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2810 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
|
2811 |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2812 verbose_leave_scroll(); |
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2813 --no_wait_return; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2814 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2815 #ifdef FEAT_PROFILE |
23976
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2816 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
|
2817 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
|
2818 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
|
2819 #endif |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2820 |
27678
1646525507aa
patch 8.2.4365: sticky command modifiers are too sticky
Bram Moolenaar <Bram@vim.org>
parents:
27669
diff
changeset
|
2821 // "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
|
2822 sticky_cmdmod_flags = 0; |
1646525507aa
patch 8.2.4365: sticky command modifiers are too sticky
Bram Moolenaar <Bram@vim.org>
parents:
27669
diff
changeset
|
2823 |
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
|
2824 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
|
2825 current_sctx = fp->uf_script_ctx; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2826 save_did_emsg = did_emsg; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2827 did_emsg = FALSE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2828 |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2829 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
|
2830 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
|
2831 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
|
2832 { |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2833 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
|
2834 |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
2835 // 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
|
2836 // 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
|
2837 ++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
|
2838 (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
|
2839 --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
|
2840 } |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2841 else |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
2842 // 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
|
2843 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
|
2844 DOCMD_NOWAIT|DOCMD_VERBOSE|DOCMD_REPEAT); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2845 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2846 --RedrawingDisabled; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2847 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2848 // 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
|
2849 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
|
2850 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2851 clear_tv(rettv); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2852 rettv->v_type = VAR_NUMBER; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2853 rettv->vval.v_number = -1; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2854 } |
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 #ifdef FEAT_PROFILE |
23976
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2857 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
|
2858 { |
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2859 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
|
2860 |
03819ebd3e6d
patch 8.2.2530: Vim9: not enough testing for profiling
Bram Moolenaar <Bram@vim.org>
parents:
23925
diff
changeset
|
2861 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
|
2862 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
|
2863 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2864 #endif |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2865 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2866 // 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
|
2867 if (p_verbose >= 12) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2868 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2869 ++no_wait_return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2870 verbose_enter_scroll(); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2871 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2872 if (aborting()) |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2873 smsg(_("%s aborted"), SOURCING_NAME); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2874 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
|
2875 smsg(_("%s returning #%ld"), SOURCING_NAME, |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2876 (long)fc->rettv->vval.v_number); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2877 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2878 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2879 char_u buf[MSG_BUF_LEN]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2880 char_u numbuf2[NUMBUFLEN]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2881 char_u *tofree; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2882 char_u *s; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2883 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2884 // 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
|
2885 // 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
|
2886 // 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
|
2887 ++emsg_off; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2888 s = tv2string(fc->rettv, &tofree, numbuf2, 0); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2889 --emsg_off; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2890 if (s != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2891 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2892 if (vim_strsize(s) > MSG_BUF_CLEN) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2893 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2894 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
|
2895 s = buf; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2896 } |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2897 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
|
2898 vim_free(tofree); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2899 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2900 } |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
2901 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
|
2902 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2903 verbose_leave_scroll(); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2904 --no_wait_return; |
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 |
19075
af1eca322b9e
patch 8.2.0098: exe stack length can be wrong without being detected
Bram Moolenaar <Bram@vim.org>
parents:
19035
diff
changeset
|
2907 ESTACK_CHECK_NOW |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2908 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
|
2909 current_sctx = save_current_sctx; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2910 #ifdef FEAT_PROFILE |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2911 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
|
2912 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
|
2913 #endif |
14323
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
2914 if (using_sandbox) |
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
2915 --sandbox; |
27678
1646525507aa
patch 8.2.4365: sticky command modifiers are too sticky
Bram Moolenaar <Bram@vim.org>
parents:
27669
diff
changeset
|
2916 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
|
2917 |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2918 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
|
2919 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2920 ++no_wait_return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2921 verbose_enter_scroll(); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2922 |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
2923 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
|
2924 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
|
2925 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2926 verbose_leave_scroll(); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2927 --no_wait_return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2928 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2929 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2930 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
|
2931 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
|
2932 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
|
2933 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
|
2934 cleanup_function_call(fc); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2935 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2936 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
2937 /* |
23252
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
2938 * 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
|
2939 * 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
|
2940 */ |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
2941 int |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
2942 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
|
2943 { |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
2944 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
|
2945 |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
2946 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
|
2947 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
|
2948 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
|
2949 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
|
2950 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
|
2951 } |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
2952 |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
2953 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2954 * 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
|
2955 */ |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2956 int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2957 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
|
2958 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
|
2959 int argcount, |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2960 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
|
2961 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
|
2962 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
|
2963 dict_T *selfdict) |
14430
2fba714294b9
patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents:
14323
diff
changeset
|
2964 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2965 int error; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2966 |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
2967 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
|
2968 *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
|
2969 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
|
2970 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
|
2971 return error; |
35583da6397e
patch 8.2.2172: Vim9: number of arguments is not always checked
Bram Moolenaar <Bram@vim.org>
parents:
23249
diff
changeset
|
2972 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
|
2973 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
|
2974 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2975 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2976 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
|
2977 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
|
2978 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2979 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2980 * 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
|
2981 * 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
|
2982 * redo buffer. |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2983 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2984 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
|
2985 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
|
2986 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2987 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
|
2988 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
|
2989 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
2990 ++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
|
2991 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
|
2992 (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
|
2993 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
|
2994 // 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
|
2995 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
|
2996 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
|
2997 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
|
2998 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
|
2999 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
|
3000 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3001 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
|
3002 } |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3003 |
14927
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3004 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
|
3005 |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3006 /* |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3007 * 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
|
3008 * 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
|
3009 */ |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3010 void |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3011 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
|
3012 { |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3013 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
|
3014 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
|
3015 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
|
3016 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
|
3017 } |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3018 |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3019 void |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3020 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
|
3021 { |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3022 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
|
3023 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
|
3024 else |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3025 { |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3026 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
|
3027 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
|
3028 } |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3029 } |
162d79d273e6
patch 8.1.0475: memory not freed on exit when quit in autocmd
Bram Moolenaar <Bram@vim.org>
parents:
14706
diff
changeset
|
3030 |
17370
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17251
diff
changeset
|
3031 funccall_T * |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17251
diff
changeset
|
3032 get_current_funccal(void) |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17251
diff
changeset
|
3033 { |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17251
diff
changeset
|
3034 return current_funccal; |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17251
diff
changeset
|
3035 } |
ba06a1c42274
patch 8.1.1684: profiling functionality is spread out
Bram Moolenaar <Bram@vim.org>
parents:
17251
diff
changeset
|
3036 |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3037 /* |
27669
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
3038 * 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
|
3039 * - 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
|
3040 * - 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
|
3041 * 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
|
3042 */ |
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
3043 int |
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
3044 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
|
3045 { |
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
3046 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
|
3047 } |
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
3048 |
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
3049 /* |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3050 * 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
|
3051 */ |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3052 void |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3053 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
|
3054 { |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3055 hashitem_T *hi; |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3056 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
|
3057 long_u todo = 1; |
20193
cf13b26be258
patch 8.2.0652: compiler warning for char conversion
Bram Moolenaar <Bram@vim.org>
parents:
20189
diff
changeset
|
3058 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
|
3059 size_t len; |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3060 |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3061 buf[0] = K_SPECIAL; |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3062 buf[1] = KS_EXTRA; |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3063 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
|
3064 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
|
3065 len = STRLEN(buf); |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3066 |
21564
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3067 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
|
3068 { |
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3069 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
|
3070 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
|
3071 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
|
3072 { |
21564
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3073 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
|
3074 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
|
3075 { |
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3076 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
|
3077 |
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3078 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
|
3079 |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3080 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
|
3081 { |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3082 // 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
|
3083 // it from the hashtable. |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3084 if (func_remove(fp)) |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3085 fp->uf_refcount--; |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3086 } |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3087 else |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3088 { |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3089 func_clear(fp, TRUE); |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3090 // 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
|
3091 // 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
|
3092 // over. |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3093 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
|
3094 break; |
03fc95628eb0
patch 8.2.2614: Vim9: function is deleted while executing
Bram Moolenaar <Bram@vim.org>
parents:
24069
diff
changeset
|
3095 } |
21564
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3096 } |
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
diff
changeset
|
3097 --todo; |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3098 } |
21564
30a997217524
patch 8.2.1332: Vim9: memory leak when using nested global function
Bram Moolenaar <Bram@vim.org>
parents:
21558
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 } |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3101 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3102 #if defined(EXITFREE) || defined(PROTO) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3103 void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3104 free_all_functions(void) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3105 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3106 hashitem_T *hi; |
9844
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3107 ufunc_T *fp; |
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3108 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
|
3109 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
|
3110 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
|
3111 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3112 // 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
|
3113 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
|
3114 { |
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
3115 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
|
3116 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
|
3117 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
|
3118 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
|
3119 } |
4ae86195f559
patch 8.0.0535: memory leak when exiting from within a user function
Christian Brabandt <cb@256bit.org>
parents:
11158
diff
changeset
|
3120 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3121 // 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
|
3122 // 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
|
3123 // 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
|
3124 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
|
3125 { |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3126 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
|
3127 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
|
3128 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
|
3129 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3130 // 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
|
3131 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
|
3132 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
|
3133 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
|
3134 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3135 // 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
|
3136 // 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
|
3137 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
|
3138 ++skipped; |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3139 else |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3140 { |
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
|
3141 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
|
3142 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
|
3143 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
|
3144 { |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3145 skipped = 0; |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3146 break; |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3147 } |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3148 } |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3149 --todo; |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3150 } |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3151 } |
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
3152 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3153 // 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
|
3154 // 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
|
3155 skipped = 0; |
9844
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3156 while (func_hashtab.ht_used > skipped) |
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3157 { |
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3158 todo = func_hashtab.ht_used; |
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3159 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
|
3160 if (!HASHITEM_EMPTY(hi)) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3161 { |
9844
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3162 --todo; |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3163 // 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
|
3164 // 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
|
3165 fp = HI2UF(hi); |
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3166 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
|
3167 ++skipped; |
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3168 else |
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3169 { |
22326
fb69b43d73f3
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents:
22324
diff
changeset
|
3170 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
|
3171 { |
fb69b43d73f3
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents:
22324
diff
changeset
|
3172 skipped = 0; |
fb69b43d73f3
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents:
22324
diff
changeset
|
3173 break; |
fb69b43d73f3
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents:
22324
diff
changeset
|
3174 } |
fb69b43d73f3
patch 8.2.1712: Vim9: leaking memory when calling a lambda
Bram Moolenaar <Bram@vim.org>
parents:
22324
diff
changeset
|
3175 // 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
|
3176 ++skipped; |
9844
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3177 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3178 } |
9844
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3179 } |
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3180 if (skipped == 0) |
9ce5941b77d3
commit https://github.com/vim/vim/commit/c257487035f83aabe1c7e07f0552309e98f1bcb1
Christian Brabandt <cb@256bit.org>
parents:
9735
diff
changeset
|
3181 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
|
3182 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3183 free_def_functions(); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3184 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3185 #endif |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3186 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3187 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3188 * 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
|
3189 * 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
|
3190 * name. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3191 * "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
|
3192 */ |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3193 int |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3194 builtin_function(char_u *name, int len) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3195 { |
27189
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3196 int i; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3197 |
20079
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3198 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
|
3199 return FALSE; |
27189
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3200 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
|
3201 { |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3202 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
|
3203 return FALSE; |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3204 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
|
3205 { |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3206 // "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
|
3207 if (name[i] == '.') |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3208 return FALSE; |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3209 break; |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3210 } |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3211 } |
a10936038ec9
patch 8.2.4123: complete function cannot be import.Name
Bram Moolenaar <Bram@vim.org>
parents:
27171
diff
changeset
|
3212 return TRUE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3213 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3214 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3215 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3216 func_call( |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3217 char_u *name, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3218 typval_T *args, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3219 partial_T *partial, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3220 dict_T *selfdict, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3221 typval_T *rettv) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3222 { |
19201
e7b4fff348dd
patch 8.2.0159: non-materialized range() list causes problems
Bram Moolenaar <Bram@vim.org>
parents:
19183
diff
changeset
|
3223 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
|
3224 listitem_T *item; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3225 typval_T argv[MAX_FUNC_ARGS + 1]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3226 int argc = 0; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3227 int r = 0; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3228 |
20392
4c317d8c1051
patch 8.2.0751: Vim9: performance can be improved
Bram Moolenaar <Bram@vim.org>
parents:
20339
diff
changeset
|
3229 CHECK_LIST_MATERIALIZE(l); |
19934
3ff714d765ba
patch 8.2.0523: loops are repeated
Bram Moolenaar <Bram@vim.org>
parents:
19912
diff
changeset
|
3230 FOR_ALL_LIST_ITEMS(l, item) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3231 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3232 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
|
3233 { |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
3234 emsg(_(e_too_many_arguments)); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3235 break; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3236 } |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3237 // 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
|
3238 // 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
|
3239 copy_tv(&item->li_tv, &argv[argc++]); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3240 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3241 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3242 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
|
3243 { |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17462
diff
changeset
|
3244 funcexe_T funcexe; |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17462
diff
changeset
|
3245 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
3246 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
|
3247 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
|
3248 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
|
3249 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
|
3250 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
|
3251 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
|
3252 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
|
3253 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3254 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3255 // Free the arguments. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3256 while (argc > 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3257 clear_tv(&argv[--argc]); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3258 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3259 return r; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3260 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3261 |
18104
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3262 static int callback_depth = 0; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3263 |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3264 int |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3265 get_callback_depth(void) |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3266 { |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3267 return callback_depth; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3268 } |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3269 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3270 /* |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3271 * 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
|
3272 * 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
|
3273 */ |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3274 int |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3275 call_callback( |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3276 callback_T *callback, |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3277 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
|
3278 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
|
3279 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
|
3280 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
|
3281 // PLUS ONE elements! |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3282 { |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17462
diff
changeset
|
3283 funcexe_T funcexe; |
18104
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3284 int ret; |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17462
diff
changeset
|
3285 |
26452
65b4109a4297
patch 8.2.3756: might crash when callback is not valid
Bram Moolenaar <Bram@vim.org>
parents:
26445
diff
changeset
|
3286 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
|
3287 return FAIL; |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
3288 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
|
3289 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
|
3290 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
|
3291 ++callback_depth; |
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3292 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
|
3293 --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
|
3294 |
dfa658800f21
patch 8.2.3798: a :def callback function postpones an error message
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3295 // 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
|
3296 // 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
|
3297 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
|
3298 { |
dfa658800f21
patch 8.2.3798: a :def callback function postpones an error message
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3299 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
|
3300 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
|
3301 } |
dfa658800f21
patch 8.2.3798: a :def callback function postpones an error message
Bram Moolenaar <Bram@vim.org>
parents:
26534
diff
changeset
|
3302 |
18104
e59ff7b5d7a7
patch 8.1.2047: cannot check the current state
Bram Moolenaar <Bram@vim.org>
parents:
17883
diff
changeset
|
3303 return ret; |
16872
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3304 } |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3305 |
a836d122231a
patch 8.1.1437: code to handle callbacks is duplicated
Bram Moolenaar <Bram@vim.org>
parents:
16825
diff
changeset
|
3306 /* |
26388
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3307 * 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
|
3308 * 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
|
3309 * 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
|
3310 */ |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3311 varnumber_T |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3312 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
|
3313 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
|
3314 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
|
3315 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
|
3316 // 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
|
3317 { |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3318 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
|
3319 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
|
3320 |
27285
53edd190a607
patch 8.2.4171: cannot invoke option function using autoload import
Bram Moolenaar <Bram@vim.org>
parents:
27279
diff
changeset
|
3321 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
|
3322 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
|
3323 |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3324 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
|
3325 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
|
3326 return retval; |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3327 } |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3328 |
8aba638e91eb
patch 8.2.3725: cannot use a lambda for 'completefunc' and 'omnifunc'
Bram Moolenaar <Bram@vim.org>
parents:
26348
diff
changeset
|
3329 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3330 * 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
|
3331 * 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
|
3332 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3333 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
|
3334 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
|
3335 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3336 switch (error) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3337 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3338 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
|
3339 if (funcexe->fe_found_var) |
4a1d2abc2016
patch 8.2.3783: confusing error for using a variable as a function
Bram Moolenaar <Bram@vim.org>
parents:
26504
diff
changeset
|
3340 semsg(_(e_not_callable_type_str), name); |
4a1d2abc2016
patch 8.2.3783: confusing error for using a variable as a function
Bram Moolenaar <Bram@vim.org>
parents:
26504
diff
changeset
|
3341 else |
26602
fac6673086df
patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26574
diff
changeset
|
3342 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
|
3343 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3344 case FCERR_NOTMETHOD: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3345 emsg_funcname( |
26897
d02d40f0261c
patch 8.2.3977: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26883
diff
changeset
|
3346 N_(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
|
3347 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3348 case FCERR_DELETED: |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
3349 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
|
3350 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3351 case FCERR_TOOMANY: |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
3352 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
|
3353 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3354 case FCERR_TOOFEW: |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
3355 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
|
3356 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3357 case FCERR_SCRIPT: |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3358 emsg_funcname( |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
3359 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
|
3360 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3361 case FCERR_DICT: |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
3362 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
|
3363 name); |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3364 break; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3365 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3366 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3367 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3368 /* |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3369 * 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
|
3370 * |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3371 * 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
|
3372 * 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
|
3373 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3374 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3375 call_func( |
16634
a1ba0bd74e7d
patch 8.1.1319: computing function length name in many places
Bram Moolenaar <Bram@vim.org>
parents:
16615
diff
changeset
|
3376 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
|
3377 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
|
3378 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
|
3379 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
|
3380 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
|
3381 // 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
|
3382 funcexe_T *funcexe) // more arguments |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3383 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3384 int ret = FAIL; |
19013
dd9ab0674eec
patch 8.2.0067: ERROR_UNKNOWN clashes on some systems
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
3385 int error = FCERR_NONE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3386 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
|
3387 ufunc_T *fp = NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3388 char_u fname_buf[FLEN_FIXED + 1]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3389 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
|
3390 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
|
3391 char_u *name = NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3392 int argcount = argcount_in; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3393 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
|
3394 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
|
3395 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
|
3396 // "funcexe->fe_basetv" is not NULL |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3397 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
|
3398 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
|
3399 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
|
3400 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
|
3401 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
|
3402 |
17883
6249953b0609
patch 8.1.1938: may crash when out of memory
Bram Moolenaar <Bram@vim.org>
parents:
17809
diff
changeset
|
3403 // 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
|
3404 // 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
|
3405 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
|
3406 |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3407 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
|
3408 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
|
3409 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
|
3410 { |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3411 // 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
|
3412 // 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
|
3413 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
|
3414 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
|
3415 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
|
3416 |
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3417 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
|
3418 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3419 |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3420 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
|
3421 *funcexe->fe_doesrange = FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3422 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3423 if (partial != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3424 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3425 // 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
|
3426 // 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
|
3427 // 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
|
3428 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
|
3429 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
|
3430 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
|
3431 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3432 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
|
3433 { |
e9675870c480
patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents:
18572
diff
changeset
|
3434 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
|
3435 { |
19013
dd9ab0674eec
patch 8.2.0067: ERROR_UNKNOWN clashes on some systems
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
3436 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
|
3437 goto theend; |
e9675870c480
patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents:
18572
diff
changeset
|
3438 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3439 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
|
3440 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3441 for (i = 0; i < argcount_in; ++i) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3442 argv[i + argv_clear] = argvars_in[i]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3443 argvars = argv; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3444 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
|
3445 |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3446 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
|
3447 && 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
|
3448 { |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3449 // 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
|
3450 // 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
|
3451 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
|
3452 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
|
3453 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
|
3454 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
|
3455 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
|
3456 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
|
3457 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
|
3458 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
|
3459 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
|
3460 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3461 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3462 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3463 |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3464 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
|
3465 && 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
|
3466 { |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
3467 // 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
|
3468 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
|
3469 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
|
3470 (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
|
3471 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
|
3472 } |
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
3473 |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3474 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
|
3475 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3476 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
|
3477 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
|
3478 |
5470c36ed7e6
patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents:
21566
diff
changeset
|
3479 // 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
|
3480 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
|
3481 { |
5470c36ed7e6
patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents:
21566
diff
changeset
|
3482 is_global = TRUE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3483 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
|
3484 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3485 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3486 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
|
3487 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
|
3488 error = FCERR_UNKNOWN; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3489 |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3490 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
|
3491 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3492 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3493 * User defined function. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3494 */ |
19886
4d033d36ba23
patch 8.2.0499: calling a lambda is slower than evaluating a string
Bram Moolenaar <Bram@vim.org>
parents:
19826
diff
changeset
|
3495 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
|
3496 { |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27092
diff
changeset
|
3497 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
|
3498 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
|
3499 && 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
|
3500 // 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
|
3501 // 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
|
3502 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
|
3503 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3504 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3505 // 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
|
3506 if (fp == NULL |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3507 && 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
|
3508 rfname, rfname, TRUE, NULL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3509 && !aborting()) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3510 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3511 // 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
|
3512 fp = find_func(rfname, is_global); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3513 } |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3514 // Try loading a package. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3515 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
|
3516 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3517 // 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
|
3518 fp = find_func(rfname, is_global); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3519 } |
20079
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3520 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
|
3521 { |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3522 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
|
3523 |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
3524 // 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
|
3525 // 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
|
3526 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
|
3527 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
|
3528 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3529 |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
3530 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
|
3531 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
|
3532 #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
|
3533 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
|
3534 { |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
3535 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
|
3536 |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
3537 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
|
3538 } |
ae185f35e256
patch 8.2.1054: not so easy to pass a lua function to Vim
Bram Moolenaar <Bram@vim.org>
parents:
20996
diff
changeset
|
3539 #endif |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
3540 else if (fp != NULL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3541 { |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3542 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
|
3543 // 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
|
3544 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
|
3545 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
|
3546 |
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3547 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
|
3548 { |
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
3549 // 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
|
3550 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
|
3551 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
|
3552 argcount++; |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3553 argvars = argv; |
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3554 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
|
3555 } |
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
3556 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3557 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
|
3558 funcexe, selfdict); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3559 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3560 } |
26534
28745eec1dda
patch 8.2.3796: the funcexe_T struct members are not named consistently
Bram Moolenaar <Bram@vim.org>
parents:
26530
diff
changeset
|
3561 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
|
3562 { |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3563 /* |
17638
9ffec4eb8d33
patch 8.1.1816: cannot use a user defined function as a method
Bram Moolenaar <Bram@vim.org>
parents:
17612
diff
changeset
|
3564 * 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
|
3565 * 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
|
3566 */ |
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3567 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
|
3568 funcexe->fe_basetv); |
17612
e259d11e2900
patch 8.1.1803: all builtin functions are global
Bram Moolenaar <Bram@vim.org>
parents:
17606
diff
changeset
|
3569 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3570 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3571 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3572 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3573 * 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
|
3574 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3575 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
|
3576 } |
21586
5470c36ed7e6
patch 8.2.1343: Vim9: cannot find global function when using g:
Bram Moolenaar <Bram@vim.org>
parents:
21566
diff
changeset
|
3577 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3578 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3579 * 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
|
3580 * 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
|
3581 * 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
|
3582 * 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
|
3583 * 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
|
3584 * 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
|
3585 * 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
|
3586 * 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
|
3587 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3588 update_force_abort(); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3589 } |
19013
dd9ab0674eec
patch 8.2.0067: ERROR_UNKNOWN clashes on some systems
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
3590 if (error == FCERR_NONE) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3591 ret = OK; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3592 |
18576
e9675870c480
patch 8.1.2282: crash when passing many arguments through a partial
Bram Moolenaar <Bram@vim.org>
parents:
18572
diff
changeset
|
3593 theend: |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3594 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3595 * 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
|
3596 * 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
|
3597 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3598 if (!aborting()) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3599 { |
26506
4a1d2abc2016
patch 8.2.3783: confusing error for using a variable as a function
Bram Moolenaar <Bram@vim.org>
parents:
26504
diff
changeset
|
3600 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
|
3601 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3602 |
17646
e5397617d6ca
patch 8.1.1820: using expr->FuncRef() does not work
Bram Moolenaar <Bram@vim.org>
parents:
17638
diff
changeset
|
3603 // 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
|
3604 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
|
3605 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
|
3606 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3607 vim_free(tofree); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3608 vim_free(name); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3609 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3610 return ret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3611 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3612 |
21401
aa7675a4a0cd
patch 8.2.1251: Vim9: warning for pointer usage, test failure undetected
Bram Moolenaar <Bram@vim.org>
parents:
21319
diff
changeset
|
3613 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
|
3614 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
|
3615 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3616 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
|
3617 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3618 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3619 /* |
19579
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3620 * 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
|
3621 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3622 static void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3623 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
|
3624 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3625 int j; |
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 msg_start(); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3628 if (indent) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3629 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
|
3630 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
|
3631 msg_puts("def "); |
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3632 else |
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3633 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
|
3634 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
|
3635 msg_putchar('('); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3636 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
|
3637 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3638 if (j) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3639 msg_puts(", "); |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3640 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
|
3641 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
|
3642 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3643 char *tofree; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3644 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3645 msg_puts(": "); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3646 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
|
3647 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
|
3648 } |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
3649 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
|
3650 { |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
3651 msg_puts(" = "); |
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
3652 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
|
3653 [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
|
3654 } |
9562
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 if (fp->uf_varargs) |
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 if (j) |
15543
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3659 msg_puts(", "); |
dd725a8ab112
patch 8.1.0779: argument for message functions is inconsistent
Bram Moolenaar <Bram@vim.org>
parents:
15470
diff
changeset
|
3660 msg_puts("..."); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3661 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3662 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
|
3663 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3664 if (j) |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3665 msg_puts(", "); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3666 msg_puts("..."); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3667 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
|
3668 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
|
3669 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3670 char *tofree; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3671 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3672 msg_puts(": "); |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3673 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
|
3674 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
|
3675 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3676 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3677 msg_putchar(')'); |
19579
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3678 |
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
|
3679 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
|
3680 { |
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3681 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
|
3682 { |
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3683 char *tofree; |
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3684 |
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3685 msg_puts(": "); |
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3686 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
|
3687 vim_free(tofree); |
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3688 } |
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3689 } |
aae19dd172c0
patch 8.2.0346: Vim9: finding common list type not tested
Bram Moolenaar <Bram@vim.org>
parents:
19443
diff
changeset
|
3690 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
|
3691 msg_puts(" abort"); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3692 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
|
3693 msg_puts(" range"); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3694 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
|
3695 msg_puts(" dict"); |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
3696 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
|
3697 msg_puts(" closure"); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3698 msg_clr_eos(); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3699 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
|
3700 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
|
3701 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3702 |
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 * 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
|
3705 * 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
|
3706 * 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
|
3707 * 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
|
3708 * "is_global" is NULL. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3709 * flags: |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3710 * TFN_INT: internal function name OK |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3711 * TFN_QUIET: be quiet |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3712 * 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
|
3713 * 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
|
3714 * 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
|
3715 */ |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
3716 char_u * |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3717 trans_function_name( |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3718 char_u **pp, |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
3719 int *is_global, |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3720 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
|
3721 int flags, |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3722 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
|
3723 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
|
3724 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
|
3725 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3726 char_u *name = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3727 char_u *start; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3728 char_u *end; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3729 int lead; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3730 char_u sid_buf[20]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3731 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
|
3732 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
|
3733 int prefix_g = FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3734 lval_T lv; |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
3735 int vim9script = in_vim9script(); |
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
3736 int vim9_local; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3737 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3738 if (fdp != NULL) |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
3739 CLEAR_POINTER(fdp); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3740 start = *pp; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3741 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3742 // 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
|
3743 // command). |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3744 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
|
3745 && (*pp)[2] == (int)KE_SNR) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3746 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3747 *pp += 3; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3748 len = get_id_len(pp) + 3; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3749 return vim_strnsave(start, len); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3750 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3751 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3752 // 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
|
3753 // 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
|
3754 lead = eval_fname_script(start); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3755 if (lead > 2) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3756 start += lead; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3757 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3758 // 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
|
3759 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
|
3760 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
|
3761 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
|
3762 && end[-1] == AUTOLOAD_CHAR && *end == '(')) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3763 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3764 if (!skip) |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
3765 emsg(_(e_function_name_required)); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3766 goto theend; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3767 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3768 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
|
3769 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3770 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3771 * 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
|
3772 * 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
|
3773 * interrupt, or an exception. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3774 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3775 if (!aborting()) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3776 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3777 if (end != NULL) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26857
diff
changeset
|
3778 semsg(_(e_invalid_argument_str), start); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3779 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3780 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3781 *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
|
3782 goto theend; |
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 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3785 if (lv.ll_tv != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3786 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3787 if (fdp != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3788 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3789 fdp->fd_dict = lv.ll_dict; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3790 fdp->fd_newkey = lv.ll_newkey; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3791 lv.ll_newkey = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3792 fdp->fd_di = lv.ll_di; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3793 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3794 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
|
3795 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3796 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
|
3797 *pp = end; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3798 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3799 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
|
3800 && lv.ll_tv->vval.v_partial != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3801 { |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
3802 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
|
3803 *pp = end; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3804 if (partial != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3805 *partial = lv.ll_tv->vval.v_partial; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3806 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3807 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3808 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3809 if (!skip && !(flags & TFN_QUIET) && (fdp == NULL |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3810 || 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
|
3811 emsg(_(e_funcref_required)); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3812 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3813 *pp = end; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3814 name = NULL; |
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 goto theend; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3817 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3818 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3819 if (lv.ll_name == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3820 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3821 // 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
|
3822 *pp = end; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3823 goto theend; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3824 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3825 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3826 // 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
|
3827 if (lv.ll_exp_name != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3828 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3829 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
|
3830 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
|
3831 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
|
3832 if (name == lv.ll_exp_name) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3833 name = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3834 } |
27076
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3835 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
|
3836 { |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3837 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
|
3838 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
|
3839 |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3840 // 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
|
3841 *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
|
3842 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
|
3843 { |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3844 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
|
3845 } |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3846 else |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3847 { |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3848 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
|
3849 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
|
3850 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
|
3851 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
|
3852 "%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
|
3853 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
|
3854 } |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3855 *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
|
3856 *pp = end; |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3857 goto theend; |
ceff6a546748
patch 8.2.4067: Vim9: cannot call imported function with :call
Bram Moolenaar <Bram@vim.org>
parents:
27068
diff
changeset
|
3858 } |
9717
6226de5f8137
commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents:
9688
diff
changeset
|
3859 else if (!(flags & TFN_NO_DEREF)) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3860 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3861 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
|
3862 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
|
3863 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
|
3864 if (name == *pp) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3865 name = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3866 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3867 if (name != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3868 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3869 name = vim_strsave(name); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3870 *pp = end; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3871 if (STRNCMP(name, "<SNR>", 5) == 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3872 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3873 // Change "<SNR>" to the byte sequence. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3874 name[0] = K_SPECIAL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3875 name[1] = KS_EXTRA; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3876 name[2] = (int)KE_SNR; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3877 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
|
3878 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3879 goto theend; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3880 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3881 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3882 if (lv.ll_exp_name != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3883 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3884 len = (int)STRLEN(lv.ll_exp_name); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3885 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
|
3886 && STRNCMP(lv.ll_name, "s:", 2) == 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3887 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3888 // 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
|
3889 // leading "s:" then remove it. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3890 lv.ll_name += 2; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3891 len -= 2; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3892 lead = 2; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3893 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3894 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3895 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3896 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3897 // skip over "s:" and "g:" |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3898 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
|
3899 { |
27464
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3900 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
|
3901 { |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3902 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
|
3903 { |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3904 *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
|
3905 } |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3906 else |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3907 { |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3908 // 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
|
3909 // 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
|
3910 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
|
3911 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
|
3912 } |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3913 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3914 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
|
3915 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3916 len = (int)(end - lv.ll_name); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3917 } |
22496
454b78ca8247
patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents:
22415
diff
changeset
|
3918 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
|
3919 { |
454b78ca8247
patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents:
22415
diff
changeset
|
3920 if (!skip) |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
3921 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
|
3922 goto theend; |
454b78ca8247
patch 8.2.1796: Vim9: invalid memory access with weird function name
Bram Moolenaar <Bram@vim.org>
parents:
22415
diff
changeset
|
3923 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3924 |
23237
033b2a97d59b
patch 8.2.2164: Vim9: autoload function doesn't work in uppercased script
Bram Moolenaar <Bram@vim.org>
parents:
23229
diff
changeset
|
3925 // 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
|
3926 // 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
|
3927 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
|
3928 |
9562
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 * Copy the function name to allocated memory. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3931 * 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
|
3932 * Accept <SNR>123_name() outside a script. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3933 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3934 if (skip) |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
3935 lead = 0; // do nothing |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
3936 else if (lead > 0 || vim9_local) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3937 { |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
3938 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
|
3939 { |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
3940 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
|
3941 { |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
3942 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
|
3943 ? 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
|
3944 : 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
|
3945 start); |
d504745607bc
patch 8.2.4324: Vim9: script-local function name can start with "_"
Bram Moolenaar <Bram@vim.org>
parents:
27563
diff
changeset
|
3946 goto theend; |
d504745607bc
patch 8.2.4324: Vim9: script-local function name can start with "_"
Bram Moolenaar <Bram@vim.org>
parents:
27563
diff
changeset
|
3947 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3948 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
|
3949 } |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
3950 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
|
3951 && 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
|
3952 || eval_fname_sid(*pp)) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3953 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3954 // 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
|
3955 if (current_sctx.sc_sid <= 0) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3956 { |
26439
b18f3b0f317c
patch 8.2.3750: error messages are everywhere
Bram Moolenaar <Bram@vim.org>
parents:
26388
diff
changeset
|
3957 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
|
3958 goto theend; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3959 } |
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
|
3960 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
|
3961 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
|
3962 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
|
3963 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3964 lead += (int)STRLEN(sid_buf); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3965 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3966 } |
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
|
3967 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
|
3968 || (vim9script && *lv.ll_name == '_'))) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3969 { |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
3970 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
|
3971 : 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
|
3972 start); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3973 goto theend; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3974 } |
9717
6226de5f8137
commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents:
9688
diff
changeset
|
3975 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
|
3976 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3977 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
|
3978 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3979 if (cp != NULL && cp < end) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3980 { |
26966
ac75c145f0a9
patch 8.2.4012: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26962
diff
changeset
|
3981 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
|
3982 goto theend; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3983 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3984 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3985 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
3986 name = alloc(len + lead + extra + 1); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3987 if (name != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3988 { |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
3989 if (!skip && (lead > 0 || vim9_local)) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3990 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3991 name[0] = K_SPECIAL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3992 name[1] = KS_EXTRA; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3993 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
|
3994 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
|
3995 STRCPY(name + 3, sid_buf); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
3996 } |
27464
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3997 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
|
3998 { |
a14c4d3e3260
patch 8.2.4260: Vim9: can still use a global function without g:
Bram Moolenaar <Bram@vim.org>
parents:
27457
diff
changeset
|
3999 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
|
4000 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
|
4001 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4002 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
|
4003 name[lead + extra + len] = NUL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4004 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4005 *pp = end; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4006 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4007 theend: |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4008 clear_lval(&lv); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4009 return name; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4010 } |
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 /* |
20079
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4013 * 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
|
4014 * 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
|
4015 * "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
|
4016 * 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
|
4017 * 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
|
4018 */ |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4019 char_u * |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4020 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
|
4021 { |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4022 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
|
4023 |
21279
8d1d11afd8c8
patch 8.2.1190: Vim9: checking for Vim9 syntax is spread out
Bram Moolenaar <Bram@vim.org>
parents:
21263
diff
changeset
|
4024 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
|
4025 { |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4026 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
|
4027 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
|
4028 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
|
4029 } |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4030 return NULL; |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4031 } |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4032 |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4033 /* |
26721
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4034 * 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
|
4035 * 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
|
4036 * 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
|
4037 * 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
|
4038 * 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
|
4039 */ |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4040 char_u * |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4041 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
|
4042 { |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4043 char sid_buf[25]; |
27782
40ae50de0d27
patch 8.2.4417: using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
27780
diff
changeset
|
4044 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
|
4045 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
|
4046 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
|
4047 |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4048 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
|
4049 return NULL; |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4050 |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4051 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
|
4052 && 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
|
4053 { |
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4054 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
|
4055 |
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4056 // 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
|
4057 // 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
|
4058 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
|
4059 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
|
4060 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
|
4061 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
|
4062 || (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
|
4063 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
|
4064 ++p; |
f1d5822ca0d7
patch 8.2.4416: Vim9: using a script-local function requires using "s:"
Bram Moolenaar <Bram@vim.org>
parents:
27698
diff
changeset
|
4065 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
|
4066 } |
27782
40ae50de0d27
patch 8.2.4417: using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
27780
diff
changeset
|
4067 else |
40ae50de0d27
patch 8.2.4417: using NULL pointer
Bram Moolenaar <Bram@vim.org>
parents:
27780
diff
changeset
|
4068 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
|
4069 |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4070 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
|
4071 { |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4072 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
|
4073 return NULL; |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4074 } |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4075 // 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
|
4076 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
|
4077 (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
|
4078 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
|
4079 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
|
4080 return NULL; |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4081 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
|
4082 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
|
4083 |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4084 return newname; |
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 |
9c9b8d95b05f
patch 8.2.3889: duplicate code for translating script-local function name
Bram Moolenaar <Bram@vim.org>
parents:
26602
diff
changeset
|
4087 /* |
27807
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4088 * 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
|
4089 * 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
|
4090 */ |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4091 char_u * |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4092 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
|
4093 { |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4094 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
|
4095 |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4096 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
|
4097 { |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4098 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
|
4099 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
|
4100 } |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4101 return n; |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4102 } |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4103 |
292a6bd86c30
patch 8.2.4429: using script-local function from the wrong script
Bram Moolenaar <Bram@vim.org>
parents:
27782
diff
changeset
|
4104 /* |
26348
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4105 * 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
|
4106 * 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
|
4107 */ |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4108 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
|
4109 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
|
4110 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
|
4111 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
|
4112 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
|
4113 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
|
4114 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
|
4115 { |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4116 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
|
4117 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
|
4118 |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4119 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
|
4120 { |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4121 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
|
4122 (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
|
4123 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
|
4124 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
|
4125 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
|
4126 } |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4127 else |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4128 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
|
4129 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
|
4130 *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
|
4131 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
|
4132 } |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4133 |
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4134 /* |
20709
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4135 * 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
|
4136 * 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
|
4137 */ |
22973
4c97c0747017
patch 8.2.2033: Vim9: :def without argument gives compilation error
Bram Moolenaar <Bram@vim.org>
parents:
22908
diff
changeset
|
4138 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
|
4139 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
|
4140 { |
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
|
4141 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
|
4142 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
|
4143 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
|
4144 |
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
|
4145 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
|
4146 { |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4147 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
|
4148 { |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4149 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
|
4150 |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4151 --todo; |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4152 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
|
4153 && (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
|
4154 ? !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
|
4155 && !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
|
4156 : !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
|
4157 && 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
|
4158 { |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4159 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
|
4160 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
|
4161 { |
26915
3631d2deb36c
patch 8.2.3986: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26897
diff
changeset
|
4162 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
|
4163 return; |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4164 } |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4165 } |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4166 } |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4167 } |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4168 } |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4169 |
a2262c80a4e0
patch 8.2.0908: crash when changing the function table while listing it
Bram Moolenaar <Bram@vim.org>
parents:
20546
diff
changeset
|
4170 /* |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4171 * ":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
|
4172 * 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
|
4173 * 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
|
4174 * "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
|
4175 * 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
|
4176 */ |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4177 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
|
4178 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
|
4179 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4180 int j; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4181 int c; |
27476
4f1cf9579e4e
patch 8.2.4266: compiler warning for uninitialized variable
Bram Moolenaar <Bram@vim.org>
parents:
27472
diff
changeset
|
4182 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
|
4183 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
|
4184 int is_global = FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4185 char_u *p; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4186 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
|
4187 char_u *whitep; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4188 char_u *line_arg = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4189 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
|
4190 garray_T argtypes; |
16615
1a911bd57f11
patch 8.1.1310: named function arguments are never optional
Bram Moolenaar <Bram@vim.org>
parents:
16606
diff
changeset
|
4191 garray_T default_args; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4192 garray_T newlines; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4193 int varargs = FALSE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4194 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
|
4195 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
|
4196 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
|
4197 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
|
4198 int free_fp = FALSE; |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
4199 int overwrite = FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4200 dictitem_T *v; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4201 funcdict_T fudi; |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4202 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
|
4203 int paren; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4204 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
|
4205 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
|
4206 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
|
4207 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
|
4208 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4209 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4210 * ":function" without argument: list functions. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4211 */ |
20138
d0a9766167ab
patch 8.2.0624: Vim9: no check for space before #comment
Bram Moolenaar <Bram@vim.org>
parents:
20081
diff
changeset
|
4212 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
|
4213 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4214 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
|
4215 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
|
4216 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
|
4217 return NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4218 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4219 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4220 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4221 * ":function /pat": list functions matching pattern. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4222 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4223 if (*eap->arg == '/') |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4224 { |
19892
5feb426d2ea1
patch 8.2.0502: Vim9: some code is not tested
Bram Moolenaar <Bram@vim.org>
parents:
19888
diff
changeset
|
4225 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
|
4226 if (!eap->skip) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4227 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4228 regmatch_T regmatch; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4229 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4230 c = *p; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4231 *p = NUL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4232 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
|
4233 *p = c; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4234 if (regmatch.regprog != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4235 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4236 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
|
4237 list_functions(®match); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4238 vim_regfree(regmatch.regprog); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4239 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4240 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4241 if (*p == '/') |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4242 ++p; |
25521
2063b858cad9
patch 8.2.3297: cannot use all commands inside a {} block
Bram Moolenaar <Bram@vim.org>
parents:
25473
diff
changeset
|
4243 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
|
4244 return NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4245 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4246 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4247 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
|
4248 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
|
4249 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
|
4250 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4251 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4252 * 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
|
4253 * func normal function name |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4254 * "name" == func, "fudi.fd_dict" == NULL |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4255 * dict.func new dictionary entry |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4256 * "name" == NULL, "fudi.fd_dict" set, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4257 * "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
|
4258 * 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
|
4259 * "name" == func, "fudi.fd_dict" set, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4260 * "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
|
4261 * 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
|
4262 * "name" == NULL, "fudi.fd_dict" set, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4263 * "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
|
4264 * s:func script-local function name |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4265 * 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
|
4266 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4267 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
|
4268 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
|
4269 { |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4270 // 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
|
4271 paren = TRUE; |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4272 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
|
4273 } |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4274 else |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4275 { |
27869
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4276 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
|
4277 { |
27869
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4278 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
|
4279 { |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4280 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
|
4281 return NULL; |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4282 } |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4283 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
|
4284 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
|
4285 { |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4286 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
|
4287 eap->arg); |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4288 return NULL; |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4289 } |
6a0ecde89d35
patch 8.2.4460: Vim9: wrong error for defining dict function
Bram Moolenaar <Bram@vim.org>
parents:
27807
diff
changeset
|
4290 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
|
4291 } |
5c4ab8d4472c
patch 8.2.4360: Vim9: allowing use of "s:" leads to inconsistencies
Bram Moolenaar <Bram@vim.org>
parents:
27611
diff
changeset
|
4292 |
26348
bf1a7ce3f14a
patch 8.2.3705: cannot pass a lambda name to function() or funcref()
Bram Moolenaar <Bram@vim.org>
parents:
26323
diff
changeset
|
4293 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
|
4294 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
|
4295 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
|
4296 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
|
4297 { |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4298 /* |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4299 * 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
|
4300 * 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
|
4301 * 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
|
4302 */ |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4303 if (!aborting()) |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4304 { |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4305 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
|
4306 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
|
4307 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
|
4308 return NULL; |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4309 } |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4310 else |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4311 eap->skip = TRUE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4312 } |
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
|
4313 |
27049
140102677c12
patch 8.2.4053: Vim9: autoload mechanism doesn't fully work yet
Bram Moolenaar <Bram@vim.org>
parents:
27043
diff
changeset
|
4314 // 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
|
4315 // 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
|
4316 // 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
|
4317 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
|
4318 { |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4319 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
|
4320 |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4321 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
|
4322 { |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4323 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
|
4324 name = prefixed; |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4325 } |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4326 } |
27563
a54064e14114
patch 8.2.4308: Vim9: cannot list autoload function
Bram Moolenaar <Bram@vim.org>
parents:
27482
diff
changeset
|
4327 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
|
4328 && 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
|
4329 { |
55613f0d59bc
patch 8.2.4264: Vim9: can use old style autoload function name
Bram Moolenaar <Bram@vim.org>
parents:
27464
diff
changeset
|
4330 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
|
4331 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
|
4332 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4333 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4334 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4335 // 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
|
4336 // 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
|
4337 saved_did_emsg = did_emsg; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4338 did_emsg = FALSE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4339 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4340 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4341 * ":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
|
4342 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4343 if (!paren) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4344 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4345 if (!ends_excmd(*skipwhite(p))) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4346 { |
26883
7f150a4936f2
patch 8.2.3970: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
4347 semsg(_(e_trailing_characters_str), p); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4348 goto ret_free; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4349 } |
25521
2063b858cad9
patch 8.2.3297: cannot use all commands inside a {} block
Bram Moolenaar <Bram@vim.org>
parents:
25473
diff
changeset
|
4350 set_nextcmd(eap, p); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4351 if (eap->nextcmd != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4352 *p = NUL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4353 if (!eap->skip && !got_int) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4354 { |
27114
98a01021e465
patch 8.2.4086: "cctx" argument of find_func_even_dead() is unused
Bram Moolenaar <Bram@vim.org>
parents:
27092
diff
changeset
|
4355 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
|
4356 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
|
4357 { |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4358 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
|
4359 |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4360 // 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
|
4361 // 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
|
4362 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
|
4363 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
|
4364 } |
336483164ca6
patch 8.2.0595: Vim9: not all commands using ends_excmd() tested
Bram Moolenaar <Bram@vim.org>
parents:
20045
diff
changeset
|
4365 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4366 if (fp != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4367 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4368 list_func_head(fp, TRUE); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4369 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
|
4370 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4371 if (FUNCLINE(fp, j) == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4372 continue; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4373 msg_putchar('\n'); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4374 msg_outnum((long)(j + 1)); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4375 if (j < 9) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4376 msg_putchar(' '); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4377 if (j < 99) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4378 msg_putchar(' '); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4379 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
|
4380 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
|
4381 ui_breakcheck(); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4382 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4383 if (!got_int) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4384 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4385 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
|
4386 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
|
4387 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
|
4388 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4389 msg_puts(" endfunction"); |
9562
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 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4392 else |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
4393 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
|
4394 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4395 goto ret_free; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4396 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4397 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4398 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4399 * ":function name(arg1, arg2)" Define function. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4400 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4401 p = skipwhite(p); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4402 if (*p != '(') |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4403 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4404 if (!eap->skip) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4405 { |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
4406 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
|
4407 goto ret_free; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4408 } |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4409 // 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
|
4410 if (vim_strchr(p, '(') != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4411 p = vim_strchr(p, '('); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4412 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4413 |
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
|
4414 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
|
4415 { |
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
|
4416 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
|
4417 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
|
4418 } |
7d0959080545
patch 8.2.2405: Vim9: no need to allow white space before "(" for :def
Bram Moolenaar <Bram@vim.org>
parents:
23717
diff
changeset
|
4419 |
21479
90d859a402cc
patch 8.2.1290: Vim9: cannot replace a global function
Bram Moolenaar <Bram@vim.org>
parents:
21461
diff
changeset
|
4420 // 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
|
4421 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
|
4422 { |
26877
06a137af96f8
patch 8.2.3967: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26865
diff
changeset
|
4423 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
|
4424 goto ret_free; |
90d859a402cc
patch 8.2.1290: Vim9: cannot replace a global function
Bram Moolenaar <Bram@vim.org>
parents:
21461
diff
changeset
|
4425 } |
90d859a402cc
patch 8.2.1290: Vim9: cannot replace a global function
Bram Moolenaar <Bram@vim.org>
parents:
21461
diff
changeset
|
4426 |
27028
c9474ae175f4
patch 8.2.4043: using int for second argument of ga_init2()
Bram Moolenaar <Bram@vim.org>
parents:
27022
diff
changeset
|
4427 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
|
4428 |
20279
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4429 if (!eap->skip && name_arg == NULL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4430 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4431 // 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
|
4432 // (that we are overwriting). |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4433 if (name != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4434 arg = name; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4435 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4436 arg = fudi.fd_newkey; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4437 if (arg != NULL && (fudi.fd_di == NULL |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4438 || (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
|
4439 && 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
|
4440 { |
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
|
4441 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
|
4442 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
|
4443 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4444 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
|
4445 { |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4446 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
|
4447 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
|
4448 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
|
4449 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
|
4450 ++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
|
4451 } |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4452 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
|
4453 ? 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
|
4454 : 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
|
4455 ; |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4456 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
|
4457 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
|
4458 |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4459 // 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
|
4460 // 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
|
4461 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
|
4462 && 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
|
4463 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
|
4464 + 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
|
4465 { |
7821550ba3a8
patch 8.2.3782: Vim9: no error if a function shadows a script variable
Bram Moolenaar <Bram@vim.org>
parents:
26452
diff
changeset
|
4466 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
|
4467 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
|
4468 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4469 } |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4470 // Disallow using the g: dict. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4471 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
|
4472 { |
26962
85866e069c24
patch 8.2.4010: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26958
diff
changeset
|
4473 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
|
4474 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
|
4475 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4476 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4477 |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4478 // 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
|
4479 // invalid. |
23511
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
4480 ++p; |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4481 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
|
4482 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
|
4483 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
|
4484 eap, lines_to_free) == FAIL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4485 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
|
4486 whitep = p; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4487 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4488 if (eap->cmdidx == CMD_def) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4489 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4490 // 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
|
4491 if (*skipwhite(p) == ':') |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4492 { |
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
|
4493 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
|
4494 { |
164cef0bc7ab
patch 8.2.3317: Vim9: No error for missing white space before return type
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
4495 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
|
4496 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
|
4497 } |
164cef0bc7ab
patch 8.2.3317: Vim9: No error for missing white space before return type
Bram Moolenaar <Bram@vim.org>
parents:
25521
diff
changeset
|
4498 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
|
4499 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
|
4500 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
|
4501 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
|
4502 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
|
4503 { |
20830
9064044fd4f6
patch 8.2.0967: unnecessary type casts for vim_strnsave()
Bram Moolenaar <Bram@vim.org>
parents:
20816
diff
changeset
|
4504 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
|
4505 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
|
4506 p = skipwhite(p); |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4507 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4508 else |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4509 { |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21791
diff
changeset
|
4510 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
|
4511 ret_type = NULL; |
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4512 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4513 } |
21435
8ec9e2b54ce7
patch 8.2.1268: Vim9: no error for using double quote comment
Bram Moolenaar <Bram@vim.org>
parents:
21401
diff
changeset
|
4514 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
|
4515 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4516 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4517 // 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
|
4518 for (;;) |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
4519 { |
23511
7e8703464f01
patch 8.2.2298: Vim9: comment right after "(" of function not recognized
Bram Moolenaar <Bram@vim.org>
parents:
23446
diff
changeset
|
4520 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
|
4521 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
|
4522 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
|
4523 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4524 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
|
4525 p += 5; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4526 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4527 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
|
4528 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4529 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
|
4530 p += 4; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4531 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4532 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
|
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 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
|
4535 p += 5; |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
4536 } |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4537 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
|
4538 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4539 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
|
4540 p += 7; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4541 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
|
4542 { |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
4543 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
|
4544 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
|
4545 goto erret; |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4546 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4547 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4548 else |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4549 break; |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
4550 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4551 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4552 // 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
|
4553 // 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
|
4554 if (*p == '\n') |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4555 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
|
4556 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
|
4557 && !(*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
|
4558 && 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
|
4559 && !(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
|
4560 && (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
|
4561 && !eap->skip |
8ec9e2b54ce7
patch 8.2.1268: Vim9: no error for using double quote comment
Bram Moolenaar <Bram@vim.org>
parents:
21401
diff
changeset
|
4562 && !did_emsg) |
26883
7f150a4936f2
patch 8.2.3970: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
4563 semsg(_(e_trailing_characters_str), p); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4564 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4565 /* |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4566 * 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
|
4567 * found. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4568 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4569 if (KeyTyped) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4570 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4571 // 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
|
4572 // 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
|
4573 // 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
|
4574 if (!eap->skip && !eap->forceit) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4575 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4576 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
|
4577 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
|
4578 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
|
4579 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
|
4580 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4581 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4582 if (!eap->skip && did_emsg) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4583 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4584 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4585 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
|
4586 cmdline_row = msg_row; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4587 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4588 |
17251
984eef966002
patch 8.1.1625: script line numbers are not exactly right
Bram Moolenaar <Bram@vim.org>
parents:
17178
diff
changeset
|
4589 // 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
|
4590 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
|
4591 |
24653
0ef7bb28f2c3
patch 8.2.2865: skipping over function body fails
Bram Moolenaar <Bram@vim.org>
parents:
24651
diff
changeset
|
4592 // 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
|
4593 // skipping. |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
4594 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
|
4595 || eap->skip) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4596 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4597 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4598 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4599 * 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
|
4600 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4601 if (fudi.fd_dict == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4602 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4603 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
|
4604 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
|
4605 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
|
4606 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
|
4607 |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
4608 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
|
4609 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
|
4610 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
|
4611 |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4612 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
|
4613 { |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4614 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
|
4615 |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4616 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
|
4617 { |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4618 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
|
4619 { |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4620 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
|
4621 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
|
4622 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
|
4623 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
|
4624 // 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
|
4625 // 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
|
4626 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
|
4627 } |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4628 else |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4629 { |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4630 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
|
4631 |
27893
8e630053c59c
patch 8.2.4472: Coverity warns for use of a freed function name
Bram Moolenaar <Bram@vim.org>
parents:
27869
diff
changeset
|
4632 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
|
4633 { |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4634 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
|
4635 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
|
4636 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
|
4637 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
|
4638 } |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4639 } |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4640 } |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4641 } |
322b79b002b7
patch 8.2.4162: Vim9: no error for redefining function with export
Bram Moolenaar <Bram@vim.org>
parents:
27233
diff
changeset
|
4642 if (var_conflict) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4643 { |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
4644 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
|
4645 goto erret; |
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 |
27348
9a9c34c84cd4
patch 8.2.4202: Vim9: cannot export function that exists globally
Bram Moolenaar <Bram@vim.org>
parents:
27291
diff
changeset
|
4648 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
|
4649 if (vim9script) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4650 { |
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
|
4651 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
|
4652 |
27698
3813036f19cb
patch 8.2.4375: ctx_imports is not used
Bram Moolenaar <Bram@vim.org>
parents:
27682
diff
changeset
|
4653 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
|
4654 } |
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
|
4655 |
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
|
4656 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
|
4657 { |
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
|
4658 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
|
4659 |
15008
67e3103d6e18
patch 8.1.0515: reloading a script gives errors for existing functions
Bram Moolenaar <Bram@vim.org>
parents:
15000
diff
changeset
|
4660 // 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
|
4661 // 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
|
4662 // 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
|
4663 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
|
4664 || (!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
|
4665 && (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
|
4666 || 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
|
4667 { |
26205
9e5e331828da
patch 8.2.3634: error for already defined function uses wrong line number
Bram Moolenaar <Bram@vim.org>
parents:
26203
diff
changeset
|
4668 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
|
4669 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
|
4670 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
|
4671 else |
26857
2aeea8611342
patch 8.2.3957: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26833
diff
changeset
|
4672 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
|
4673 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4674 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4675 if (fp->uf_calls > 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4676 { |
15008
67e3103d6e18
patch 8.1.0515: reloading a script gives errors for existing functions
Bram Moolenaar <Bram@vim.org>
parents:
15000
diff
changeset
|
4677 emsg_funcname( |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
4678 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
|
4679 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4680 } |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
4681 if (fp->uf_refcount > 1) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
4682 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4683 // 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
|
4684 // create a new one. |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
4685 --fp->uf_refcount; |
9733
59565cdd7261
commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents:
9731
diff
changeset
|
4686 fp->uf_flags |= FC_REMOVED; |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
4687 fp = NULL; |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
4688 overwrite = TRUE; |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
4689 } |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
4690 else |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
4691 { |
19035
b920ae62c7b1
patch 8.2.0078: expanding <sfile> works differently the second time
Bram Moolenaar <Bram@vim.org>
parents:
19013
diff
changeset
|
4692 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
|
4693 |
b920ae62c7b1
patch 8.2.0078: expanding <sfile> works differently the second time
Bram Moolenaar <Bram@vim.org>
parents:
19013
diff
changeset
|
4694 // 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
|
4695 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
|
4696 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
|
4697 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
|
4698 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
|
4699 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
|
4700 #ifdef FEAT_PROFILE |
2fba714294b9
patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents:
14323
diff
changeset
|
4701 fp->uf_profiling = FALSE; |
2fba714294b9
patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents:
14323
diff
changeset
|
4702 fp->uf_prof_initialized = FALSE; |
2fba714294b9
patch 8.1.0229: crash when dumping profiling data
Christian Brabandt <cb@256bit.org>
parents:
14323
diff
changeset
|
4703 #endif |
23360
eb7d8f39363c
patch 8.2.2223: Vim9: Reloading marks a :def function as deleted
Bram Moolenaar <Bram@vim.org>
parents:
23354
diff
changeset
|
4704 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
|
4705 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4706 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4707 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4708 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4709 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4710 char numbuf[20]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4711 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4712 fp = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4713 if (fudi.fd_newkey == NULL && !eap->forceit) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4714 { |
26952
b34ddbca305c
patch 8.2.4005: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26915
diff
changeset
|
4715 emsg(_(e_dictionary_entry_already_exists)); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4716 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4717 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4718 if (fudi.fd_di == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4719 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4720 // 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
|
4721 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
|
4722 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4723 } |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4724 // 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
|
4725 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
|
4726 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4727 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4728 // 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
|
4729 // Funcref! |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4730 vim_free(name); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4731 sprintf(numbuf, "%d", ++func_nr); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4732 name = vim_strsave((char_u *)numbuf); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4733 if (name == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4734 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4735 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4736 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4737 if (fp == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4738 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4739 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
|
4740 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4741 int slen, plen; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4742 char_u *scriptname; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4743 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4744 // 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
|
4745 j = FAIL; |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
4746 if (SOURCING_NAME != NULL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4747 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4748 scriptname = autoload_name(name); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4749 if (scriptname != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4750 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4751 p = vim_strchr(scriptname, '/'); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4752 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
|
4753 slen = (int)STRLEN(SOURCING_NAME); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4754 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
|
4755 SOURCING_NAME + slen - plen) == 0) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4756 j = OK; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4757 vim_free(scriptname); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4758 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4759 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4760 if (j == FAIL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4761 { |
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
|
4762 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
|
4763 |
ccdd5e9a3763
patch 8.2.2758: Vim9: wrong line number for autoload function with wrong name
Bram Moolenaar <Bram@vim.org>
parents:
24422
diff
changeset
|
4764 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
|
4765 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
|
4766 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
|
4767 SOURCING_LNUM = save_lnum; |
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 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4770 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4771 |
17659
121bdff812b4
patch 8.1.1827: allocating more memory than needed for extended structs
Bram Moolenaar <Bram@vim.org>
parents:
17646
diff
changeset
|
4772 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
|
4773 if (fp == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4774 goto erret; |
26566
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4775 fp_allocated = TRUE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4776 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4777 if (fudi.fd_dict != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4778 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4779 if (fudi.fd_di == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4780 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4781 // add new dict entry |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4782 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
|
4783 if (fudi.fd_di == 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 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
|
4786 fp = NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4787 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4788 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4789 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
|
4790 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4791 vim_free(fudi.fd_di); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4792 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
|
4793 fp = NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4794 goto erret; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4795 } |
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 else |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4798 // overwrite existing dict entry |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4799 clear_tv(&fudi.fd_di->di_tv); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4800 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
|
4801 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
|
4802 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4803 // behave like "dict" was used |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4804 flags |= FC_DICT; |
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 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4807 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
|
4808 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
|
4809 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
|
4810 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
|
4811 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4812 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
|
4813 { |
22643
71b57779177d
patch 8.2.1870: Vim9: no need to keep all script variables
Bram Moolenaar <Bram@vim.org>
parents:
22596
diff
changeset
|
4814 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
|
4815 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
|
4816 |
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
|
4817 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
|
4818 |
19297
84703c85a583
patch 8.2.0207: crash when missing member type on list argument
Bram Moolenaar <Bram@vim.org>
parents:
19285
diff
changeset
|
4819 // 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
|
4820 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
|
4821 |
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
|
4822 // 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
|
4823 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
|
4824 |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
4825 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
|
4826 { |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
4827 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
|
4828 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
|
4829 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
|
4830 } |
22816
8a5369f5f2b4
patch 8.2.1956: Vim9: cannot specify argument types for lambda
Bram Moolenaar <Bram@vim.org>
parents:
22643
diff
changeset
|
4831 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
|
4832 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4833 // 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
|
4834 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
|
4835 { |
24188
c20e763bc73c
patch 8.2.2635: Vim9: cannot define an inline function
Bram Moolenaar <Bram@vim.org>
parents:
24146
diff
changeset
|
4836 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
|
4837 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
|
4838 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
|
4839 } |
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
|
4840 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
|
4841 } |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
4842 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
|
4843 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
|
4844 |
26566
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4845 if (fp_allocated) |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4846 { |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4847 // 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
|
4848 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
|
4849 if (overwrite) |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4850 { |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4851 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
|
4852 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
|
4853 } |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4854 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
|
4855 { |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4856 free_fp = TRUE; |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4857 goto erret; |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4858 } |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4859 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
|
4860 } |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4861 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4862 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
|
4863 newlines.ga_data = NULL; |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
4864 if ((flags & FC_CLOSURE) != 0) |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
4865 { |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
4866 if (register_closure(fp) == FAIL) |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
4867 goto erret; |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
4868 } |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
4869 else |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
4870 fp->uf_scoped = NULL; |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
4871 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4872 #ifdef FEAT_PROFILE |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4873 if (prof_def_func()) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4874 func_do_profile(fp); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4875 #endif |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4876 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
|
4877 if (sandbox) |
9df95cf9ea7e
patch 8.1.0177: defining function in sandbox is inconsistent
Christian Brabandt <cb@256bit.org>
parents:
14303
diff
changeset
|
4878 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
|
4879 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
|
4880 flags |= FC_VIM9; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4881 fp->uf_flags = flags; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4882 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
|
4883 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
|
4884 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
|
4885 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
|
4886 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
|
4887 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
|
4888 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4889 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
|
4890 // 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
|
4891 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
|
4892 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
4893 |
20532
cb4831fa7e25
patch 8.2.0820: Vim9: function type isn't set until compiled
Bram Moolenaar <Bram@vim.org>
parents:
20528
diff
changeset
|
4894 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
|
4895 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
|
4896 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
|
4897 // :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
|
4898 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
|
4899 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4900 goto ret_free; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4901 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4902 erret: |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4903 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
|
4904 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
|
4905 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
|
4906 { |
e979bf909fd8
patch 8.2.2505: Vim9: crash after defining function with invalid return type
Bram Moolenaar <Bram@vim.org>
parents:
23888
diff
changeset
|
4907 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
|
4908 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
|
4909 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4910 errret_2: |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4911 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
|
4912 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
|
4913 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
|
4914 if (free_fp) |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4915 { |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4916 vim_free(fp); |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4917 fp = NULL; |
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
4918 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4919 ret_free: |
19685
d64f403289db
patch 8.2.0399: various memory leaks
Bram Moolenaar <Bram@vim.org>
parents:
19579
diff
changeset
|
4920 ga_clear_strings(&argtypes); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4921 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
|
4922 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
|
4923 vim_free(name); |
20015
c001ee73519a
patch 8.2.0563: Vim9: cannot split a function line
Bram Moolenaar <Bram@vim.org>
parents:
20007
diff
changeset
|
4924 vim_free(ret_type); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4925 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
|
4926 |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4927 return fp; |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4928 } |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4929 |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4930 /* |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4931 * ":function" |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4932 */ |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4933 void |
49b50843e725
patch 8.2.0695: Vim9: cannot define a function inside a function
Bram Moolenaar <Bram@vim.org>
parents:
20257
diff
changeset
|
4934 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
|
4935 { |
27022
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
4936 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
|
4937 |
eebbcc83fb75
patch 8.2.4040: keeping track of allocated lines is too complicated
Bram Moolenaar <Bram@vim.org>
parents:
27018
diff
changeset
|
4938 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
|
4939 (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
|
4940 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
|
4941 } |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
4942 |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
4943 /* |
22188
ec0a5ae32d5e
patch 8.2.1643: Vim9: :defcompile compiles dead functions
Bram Moolenaar <Bram@vim.org>
parents:
21983
diff
changeset
|
4944 * :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
|
4945 * 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
|
4946 */ |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
4947 void |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
4948 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
|
4949 { |
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
|
4950 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
|
4951 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
|
4952 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
|
4953 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
|
4954 |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
4955 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
|
4956 { |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
4957 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
|
4958 { |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
4959 --todo; |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
4960 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
|
4961 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
|
4962 && 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
|
4963 && (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
|
4964 { |
24895
e61a2085c89b
patch 8.2.2985: Vim9: a compiled function cannot be debugged
Bram Moolenaar <Bram@vim.org>
parents:
24890
diff
changeset
|
4965 (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
|
4966 |
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
|
4967 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
|
4968 { |
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
|
4969 // 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
|
4970 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
|
4971 changed = func_hashtab.ht_changed; |
20544
e8132bec4b0f
patch 8.2.0826: Vim9: crash in :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
20542
diff
changeset
|
4972 hi = func_hashtab.ht_array; |
20546
1ea55bad1234
patch 8.2.0827: Vim9: crash in :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
20544
diff
changeset
|
4973 --hi; |
20544
e8132bec4b0f
patch 8.2.0826: Vim9: crash in :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
20542
diff
changeset
|
4974 } |
e8132bec4b0f
patch 8.2.0826: Vim9: crash in :defcompile
Bram Moolenaar <Bram@vim.org>
parents:
20542
diff
changeset
|
4975 } |
20528
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
4976 } |
489cb75c76b6
patch 8.2.0818: Vim9: using a discovery phase doesn't work well
Bram Moolenaar <Bram@vim.org>
parents:
20433
diff
changeset
|
4977 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4978 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4979 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4980 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4981 * 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
|
4982 * Return 2 if "p" starts with "s:". |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4983 * Return 0 otherwise. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4984 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4985 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4986 eval_fname_script(char_u *p) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4987 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
4988 // 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
|
4989 // the standard library function. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4990 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
|
4991 || MB_STRNICMP(p + 1, "SNR>", 4) == 0)) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4992 return 5; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4993 if (p[0] == 's' && p[1] == ':') |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4994 return 2; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4995 return 0; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4996 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4997 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
4998 int |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
4999 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
|
5000 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5001 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
|
5002 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
|
5003 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
|
5004 } |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5005 |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5006 /* |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5007 * 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
|
5008 * 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
|
5009 */ |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5010 int |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5011 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
|
5012 { |
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5013 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
|
5014 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5015 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5016 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5017 * 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
|
5018 * 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
|
5019 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5020 int |
9717
6226de5f8137
commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents:
9688
diff
changeset
|
5021 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
|
5022 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5023 char_u *nm = name; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5024 char_u *p; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5025 int n = FALSE; |
9717
6226de5f8137
commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents:
9688
diff
changeset
|
5026 int flag; |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5027 int is_global = FALSE; |
9717
6226de5f8137
commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents:
9688
diff
changeset
|
5028 |
6226de5f8137
commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents:
9688
diff
changeset
|
5029 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
|
5030 if (no_deref) |
6226de5f8137
commit https://github.com/vim/vim/commit/b54c3ff3174dbb5dfbfcabdf95200b047beaa644
Christian Brabandt <cb@256bit.org>
parents:
9688
diff
changeset
|
5031 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
|
5032 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
|
5033 nm = skipwhite(nm); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5034 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5035 // 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
|
5036 // "funcname(...", not "funcname!...". |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5037 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
|
5038 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
|
5039 vim_free(p); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5040 return n; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5041 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5042 |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
5043 #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
|
5044 char_u * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5045 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
|
5046 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5047 char_u *nm = name; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5048 char_u *p; |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5049 int is_global = FALSE; |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5050 |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5051 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
|
5052 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
|
5053 |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5054 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
|
5055 && (!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
|
5056 return p; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5057 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5058 vim_free(p); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5059 return NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5060 } |
15555
d89c5b339c2a
patch 8.1.0785: depending on the configuration some functions are unused
Bram Moolenaar <Bram@vim.org>
parents:
15543
diff
changeset
|
5061 #endif |
9562
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 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5064 * 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
|
5065 * function names. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5066 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5067 char_u * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5068 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
|
5069 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5070 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
|
5071 static int changed; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5072 static hashitem_T *hi; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5073 ufunc_T *fp; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5074 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5075 if (idx == 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5076 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5077 done = 0; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5078 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
|
5079 changed = func_hashtab.ht_changed; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5080 } |
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
|
5081 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
|
5082 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5083 if (done++ > 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5084 ++hi; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5085 while (HASHITEM_EMPTY(hi)) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5086 ++hi; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5087 fp = HI2UF(hi); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5088 |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5089 // 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
|
5090 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
|
5091 || 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
|
5092 return (char_u *)""; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5093 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5094 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
|
5095 return fp->uf_name; // prevents overflow |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5096 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5097 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
|
5098 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
|
5099 && xp->xp_context != EXPAND_DISASSEMBLE) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5100 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5101 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
|
5102 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
|
5103 STRCAT(IObuff, ")"); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5104 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5105 return IObuff; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5106 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5107 return NULL; |
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 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5111 * ":delfunction {name}" |
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 void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5114 ex_delfunction(exarg_T *eap) |
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 ufunc_T *fp = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5117 char_u *p; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5118 char_u *name; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5119 funcdict_T fudi; |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5120 int is_global = FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5121 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5122 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
|
5123 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
|
5124 NULL, NULL); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5125 vim_free(fudi.fd_newkey); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5126 if (name == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5127 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5128 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
|
5129 emsg(_(e_funcref_required)); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5130 return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5131 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5132 if (!ends_excmd(*skipwhite(p))) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5133 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5134 vim_free(name); |
26883
7f150a4936f2
patch 8.2.3970: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
5135 semsg(_(e_trailing_characters_str), p); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5136 return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5137 } |
25521
2063b858cad9
patch 8.2.3297: cannot use all commands inside a {} block
Bram Moolenaar <Bram@vim.org>
parents:
25473
diff
changeset
|
5138 set_nextcmd(eap, p); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5139 if (eap->nextcmd != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5140 *p = NUL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5141 |
26566
ba52a5ef59f1
patch 8.2.3812: Vim9: leaking memory in numbered function test
Bram Moolenaar <Bram@vim.org>
parents:
26556
diff
changeset
|
5142 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
|
5143 { |
b916d59f259f
patch 8.2.3408: can delete a numbered function
Bram Moolenaar <Bram@vim.org>
parents:
25737
diff
changeset
|
5144 if (!eap->skip) |
26865
bce848ec8b1b
patch 8.2.3961: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26857
diff
changeset
|
5145 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
|
5146 vim_free(name); |
b916d59f259f
patch 8.2.3408: can delete a numbered function
Bram Moolenaar <Bram@vim.org>
parents:
25737
diff
changeset
|
5147 return; |
b916d59f259f
patch 8.2.3408: can delete a numbered function
Bram Moolenaar <Bram@vim.org>
parents:
25737
diff
changeset
|
5148 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5149 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
|
5150 fp = find_func(name, is_global); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5151 vim_free(name); |
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 if (!eap->skip) |
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 if (fp == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5156 { |
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
|
5157 if (!eap->forceit) |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
5158 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
|
5159 return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5160 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5161 if (fp->uf_calls > 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5162 { |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
5163 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
|
5164 return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5165 } |
20189
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5166 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
|
5167 { |
21821
0deb6f96a5a3
patch 8.2.1460: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
21791
diff
changeset
|
5168 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
|
5169 return; |
63cc54100ae4
patch 8.2.0650: Vim9: script function can be deleted
Bram Moolenaar <Bram@vim.org>
parents:
20144
diff
changeset
|
5170 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5171 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5172 if (fudi.fd_dict != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5173 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5174 // 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
|
5175 // 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
|
5176 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
|
5177 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5178 else |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5179 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5180 // 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
|
5181 // 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
|
5182 // 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
|
5183 // 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
|
5184 // one or more. |
9733
59565cdd7261
commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents:
9731
diff
changeset
|
5185 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
|
5186 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5187 // 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
|
5188 // 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
|
5189 if (func_remove(fp)) |
59565cdd7261
commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents:
9731
diff
changeset
|
5190 fp->uf_refcount--; |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5191 } |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5192 else |
10815
f883a1224396
patch 8.0.0297: double free on exit when using a closure
Christian Brabandt <cb@256bit.org>
parents:
10795
diff
changeset
|
5193 func_clear_free(fp, FALSE); |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5194 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5195 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5196 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5197 |
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 * 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
|
5200 * becomes zero. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5201 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5202 void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5203 func_unref(char_u *name) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5204 { |
9655
f1920505bc16
commit https://github.com/vim/vim/commit/97baee80f0906ee2f651ee1215ec033e84f866ad
Christian Brabandt <cb@256bit.org>
parents:
9638
diff
changeset
|
5205 ufunc_T *fp = NULL; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5206 |
9733
59565cdd7261
commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents:
9731
diff
changeset
|
5207 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
|
5208 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
|
5209 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
|
5210 if (fp == NULL && numbered_function(name)) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5211 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5212 #ifdef EXITFREE |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5213 if (!entered_free_all_mem) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5214 #endif |
10359
66f1b5bf3fa6
commit https://github.com/vim/vim/commit/95f096030ed1a8afea028f2ea295d6f6a70f466f
Christian Brabandt <cb@256bit.org>
parents:
10042
diff
changeset
|
5215 internal_error("func_unref()"); |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5216 } |
23699
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
5217 func_ptr_unref(fp); |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5218 } |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5219 |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5220 /* |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5221 * 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
|
5222 * 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
|
5223 * 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
|
5224 */ |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5225 void |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5226 func_ptr_unref(ufunc_T *fp) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5227 { |
23699
317018f62643
patch 8.2.2391: memory leak when creating a global function with closure
Bram Moolenaar <Bram@vim.org>
parents:
23644
diff
changeset
|
5228 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
|
5229 || (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
|
5230 && 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
|
5231 && 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
|
5232 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5233 // 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
|
5234 // when "uf_calls" becomes zero. |
9655
f1920505bc16
commit https://github.com/vim/vim/commit/97baee80f0906ee2f651ee1215ec033e84f866ad
Christian Brabandt <cb@256bit.org>
parents:
9638
diff
changeset
|
5235 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
|
5236 func_clear_free(fp, FALSE); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5237 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5238 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5239 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5240 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5241 * Count a reference to a Function. |
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 void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5244 func_ref(char_u *name) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5245 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5246 ufunc_T *fp; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5247 |
9733
59565cdd7261
commit https://github.com/vim/vim/commit/8dd3a43d75550e9b5736066124c97697564f769e
Christian Brabandt <cb@256bit.org>
parents:
9731
diff
changeset
|
5248 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
|
5249 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
|
5250 fp = find_func(name, FALSE); |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5251 if (fp != NULL) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5252 ++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
|
5253 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
|
5254 // 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
|
5255 // 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
|
5256 internal_error("func_ref()"); |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5257 } |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5258 |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5259 /* |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5260 * Count a reference to a Function. |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5261 */ |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5262 void |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5263 func_ptr_ref(ufunc_T *fp) |
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 if (fp != NULL) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5266 ++fp->uf_refcount; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5267 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5268 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5269 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5270 * 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
|
5271 * referenced from anywhere that is in use. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5272 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5273 static int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5274 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
|
5275 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5276 return (fc->l_varlist.lv_copyID != copyID |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5277 && 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
|
5278 && fc->l_avars.dv_copyID != copyID |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
5279 && fc->fc_copyID != copyID); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5280 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5281 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5282 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5283 * ":return [expr]" |
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 void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5286 ex_return(exarg_T *eap) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5287 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5288 char_u *arg = eap->arg; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5289 typval_T rettv; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5290 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
|
5291 evalarg_T evalarg; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5292 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5293 if (current_funccal == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5294 { |
26757
3a2b222107a6
patch 8.2.3907: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26747
diff
changeset
|
5295 emsg(_(e_return_not_inside_function)); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5296 return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5297 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5298 |
26053
e861c5aaedd8
patch 8.2.3560: using freed memory with lambda
Bram Moolenaar <Bram@vim.org>
parents:
26046
diff
changeset
|
5299 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
|
5300 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
|
5301 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5302 if (eap->skip) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5303 ++emsg_skip; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5304 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5305 eap->nextcmd = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5306 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
|
5307 && eval0(arg, &rettv, eap, &evalarg) != FAIL) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5308 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5309 if (!eap->skip) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5310 returning = do_return(eap, FALSE, TRUE, &rettv); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5311 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5312 clear_tv(&rettv); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5313 } |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5314 // 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
|
5315 else if (!eap->skip) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5316 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5317 // 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
|
5318 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
|
5319 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5320 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5321 * 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
|
5322 * aborting error, an interrupt, or an exception. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5323 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5324 if (!aborting()) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5325 returning = do_return(eap, FALSE, TRUE, NULL); |
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 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5328 // 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
|
5329 // 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
|
5330 // 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
|
5331 if (returning) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5332 eap->nextcmd = NULL; |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5333 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
|
5334 set_nextcmd(eap, arg); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5335 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5336 if (eap->skip) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5337 --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
|
5338 clear_evalarg(&evalarg, eap); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5339 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5340 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5341 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5342 * ":1,25call func(arg1, arg2)" function call. |
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 void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5345 ex_call(exarg_T *eap) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5346 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5347 char_u *arg = eap->arg; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5348 char_u *startarg; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5349 char_u *name; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5350 char_u *tofree; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5351 int len; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5352 typval_T rettv; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5353 linenr_T lnum; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5354 int doesrange; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5355 int failed = FALSE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5356 funcdict_T fudi; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5357 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
|
5358 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
|
5359 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
|
5360 int found_var = FALSE; |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
5361 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
|
5362 |
b0baa80cb53f
patch 8.2.1110: Vim9: line continuation does not work in function arguments
Bram Moolenaar <Bram@vim.org>
parents:
21066
diff
changeset
|
5363 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
|
5364 if (eap->skip) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5365 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5366 // 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
|
5367 // 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
|
5368 // :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
|
5369 ++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
|
5370 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
|
5371 clear_tv(&rettv); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5372 --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
|
5373 clear_evalarg(&evalarg, eap); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5374 return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5375 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5376 |
23527
27ca5534a408
patch 8.2.2306: Vim9: when using function reference type is not checked
Bram Moolenaar <Bram@vim.org>
parents:
23511
diff
changeset
|
5377 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
|
5378 &fudi, &partial, vim9script ? &type : NULL); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5379 if (fudi.fd_newkey != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5380 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5381 // 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
|
5382 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
|
5383 vim_free(fudi.fd_newkey); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5384 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5385 if (tofree == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5386 return; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5387 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5388 // 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
|
5389 // the arguments. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5390 if (fudi.fd_dict != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5391 ++fudi.fd_dict->dv_refcount; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5392 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5393 // 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
|
5394 // 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
|
5395 // from trans_function_name(). |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5396 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
|
5397 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
|
5398 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
|
5399 FALSE, FALSE, &found_var); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5400 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5401 // 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
|
5402 // backward compatibility. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5403 startarg = skipwhite(arg); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5404 if (*startarg != '(') |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5405 { |
26602
fac6673086df
patch 8.2.3830: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26574
diff
changeset
|
5406 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
|
5407 goto end; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5408 } |
27682
f60d0d823897
patch 8.2.4367: calling in_vim9script() multiple times
Bram Moolenaar <Bram@vim.org>
parents:
27678
diff
changeset
|
5409 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
|
5410 { |
d923be9d752d
patch 8.2.3404: Vim9: no error for white space before "("
Bram Moolenaar <Bram@vim.org>
parents:
25694
diff
changeset
|
5411 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
|
5412 goto end; |
d923be9d752d
patch 8.2.3404: Vim9: no error for white space before "("
Bram Moolenaar <Bram@vim.org>
parents:
25694
diff
changeset
|
5413 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5414 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5415 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5416 * 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
|
5417 * arguments. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5418 * 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
|
5419 * call, and the loop is broken. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5420 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5421 if (eap->skip) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5422 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5423 ++emsg_skip; |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5424 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
|
5425 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5426 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5427 lnum = eap->line1; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5428 for ( ; lnum <= eap->line2; ++lnum) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5429 { |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17462
diff
changeset
|
5430 funcexe_T funcexe; |
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17462
diff
changeset
|
5431 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5432 if (!eap->skip && eap->addr_count > 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5433 { |
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
|
5434 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
|
5435 { |
32787e326de2
patch 8.1.0511: ml_get error when calling a function with a range
Bram Moolenaar <Bram@vim.org>
parents:
14968
diff
changeset
|
5436 // 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
|
5437 // 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
|
5438 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
|
5439 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
|
5440 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5441 curwin->w_cursor.lnum = lnum; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5442 curwin->w_cursor.col = 0; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5443 curwin->w_cursor.coladd = 0; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5444 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5445 arg = startarg; |
17606
ff097edaae89
patch 8.1.1800: function call functions have too many arguments
Bram Moolenaar <Bram@vim.org>
parents:
17462
diff
changeset
|
5446 |
20007
aadd1cae2ff5
patch 8.2.0559: clearing a struct is verbose
Bram Moolenaar <Bram@vim.org>
parents:
19946
diff
changeset
|
5447 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
|
5448 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
|
5449 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
|
5450 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
|
5451 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
|
5452 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
|
5453 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
|
5454 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
|
5455 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
|
5456 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
|
5457 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
|
5458 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5459 failed = TRUE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5460 break; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5461 } |
13262
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5462 if (has_watchexpr()) |
69278c25429d
patch 8.0.1505: debugger can't break on a condition
Christian Brabandt <cb@256bit.org>
parents:
13244
diff
changeset
|
5463 dbg_check_breakpoint(eap); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5464 |
17763
117c7795a979
patch 8.1.1878: negative float before method not parsed correctly
Bram Moolenaar <Bram@vim.org>
parents:
17732
diff
changeset
|
5465 // 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
|
5466 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
|
5467 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
|
5468 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5469 failed = TRUE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5470 break; |
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 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5473 clear_tv(&rettv); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5474 if (doesrange || eap->skip) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5475 break; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5476 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5477 // 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
|
5478 // 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
|
5479 // 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
|
5480 // characters below is executed. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5481 if (aborting()) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5482 break; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5483 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5484 if (eap->skip) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5485 --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
|
5486 clear_evalarg(&evalarg, eap); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5487 |
25826
5040fae521f6
patch 8.2.3448: :endtry after function call that throws not found
Bram Moolenaar <Bram@vim.org>
parents:
25761
diff
changeset
|
5488 // 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
|
5489 // 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
|
5490 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
|
5491 && (!failed || eap->cstack->cs_trylevel > 0)) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5492 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5493 // 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
|
5494 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
|
5495 if (!ends_excmd2(eap->arg, arg)) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5496 { |
25826
5040fae521f6
patch 8.2.3448: :endtry after function call that throws not found
Bram Moolenaar <Bram@vim.org>
parents:
25761
diff
changeset
|
5497 if (!failed && !aborting()) |
19421
208644ebdff8
patch 8.2.0268: trycatch test fails
Bram Moolenaar <Bram@vim.org>
parents:
19419
diff
changeset
|
5498 { |
208644ebdff8
patch 8.2.0268: trycatch test fails
Bram Moolenaar <Bram@vim.org>
parents:
19419
diff
changeset
|
5499 emsg_severe = TRUE; |
26883
7f150a4936f2
patch 8.2.3970: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
26877
diff
changeset
|
5500 semsg(_(e_trailing_characters_str), arg); |
19421
208644ebdff8
patch 8.2.0268: trycatch test fails
Bram Moolenaar <Bram@vim.org>
parents:
19419
diff
changeset
|
5501 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5502 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5503 else |
25521
2063b858cad9
patch 8.2.3297: cannot use all commands inside a {} block
Bram Moolenaar <Bram@vim.org>
parents:
25473
diff
changeset
|
5504 set_nextcmd(eap, arg); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5505 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5506 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5507 end: |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5508 dict_unref(fudi.fd_dict); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5509 vim_free(tofree); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5510 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5511 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5512 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5513 * 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
|
5514 * 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
|
5515 * 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
|
5516 * 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
|
5517 * 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
|
5518 * FALSE when the return gets pending. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5519 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5520 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5521 do_return( |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5522 exarg_T *eap, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5523 int reanimate, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5524 int is_cmd, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5525 void *rettv) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5526 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5527 int idx; |
18904
2bdc2e1f6e1f
patch 8.2.0013: not using a typedef for condstack
Bram Moolenaar <Bram@vim.org>
parents:
18816
diff
changeset
|
5528 cstack_T *cstack = eap->cstack; |
9562
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 (reanimate) |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5531 // Undo the return. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5532 current_funccal->returned = FALSE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5533 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5534 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5535 * 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
|
5536 * 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
|
5537 * 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
|
5538 * Otherwise, return normally. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5539 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5540 idx = cleanup_conditionals(eap->cstack, 0, TRUE); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5541 if (idx >= 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5542 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5543 cstack->cs_pending[idx] = CSTP_RETURN; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5544 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5545 if (!is_cmd && !reanimate) |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5546 // 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
|
5547 // 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
|
5548 // 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
|
5549 cstack->cs_rettv[idx] = rettv; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5550 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5551 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5552 // 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
|
5553 // return rettv. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5554 if (reanimate) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5555 rettv = current_funccal->rettv; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5556 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5557 if (rettv != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5558 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5559 // 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
|
5560 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
|
5561 *(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
|
5562 else |
25306
078edc1821bf
patch 8.2.3190: error messages are spread out
Bram Moolenaar <Bram@vim.org>
parents:
25296
diff
changeset
|
5563 emsg(_(e_out_of_memory)); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5564 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5565 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5566 cstack->cs_rettv[idx] = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5567 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5568 if (reanimate) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5569 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5570 // 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
|
5571 // 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
|
5572 // return value. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5573 current_funccal->rettv->v_type = VAR_NUMBER; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5574 current_funccal->rettv->vval.v_number = 0; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5575 } |
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 report_make_pending(CSTP_RETURN, rettv); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5578 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5579 else |
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 current_funccal->returned = TRUE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5582 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5583 // 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
|
5584 // 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
|
5585 // there. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5586 if (!reanimate && rettv != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5587 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5588 clear_tv(current_funccal->rettv); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5589 *current_funccal->rettv = *(typval_T *)rettv; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5590 if (!is_cmd) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5591 vim_free(rettv); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5592 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5593 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5594 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5595 return idx < 0; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5596 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5597 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5598 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5599 * 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
|
5600 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5601 void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5602 discard_pending_return(void *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 free_tv((typval_T *)rettv); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5605 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5606 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5607 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5608 * 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
|
5609 * 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
|
5610 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5611 char_u * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5612 get_return_cmd(void *rettv) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5613 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5614 char_u *s = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5615 char_u *tofree = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5616 char_u numbuf[NUMBUFLEN]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5617 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5618 if (rettv != NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5619 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
|
5620 if (s == NULL) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5621 s = (char_u *)""; |
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 STRCPY(IObuff, ":return "); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5624 STRNCPY(IObuff + 8, s, IOSIZE - 8); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5625 if (STRLEN(s) + 8 >= IOSIZE) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5626 STRCPY(IObuff + IOSIZE - 4, "..."); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5627 vim_free(tofree); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5628 return vim_strsave(IObuff); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5629 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5630 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5631 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5632 * Get next function line. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5633 * 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
|
5634 * 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
|
5635 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5636 char_u * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5637 get_func_line( |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5638 int c UNUSED, |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5639 void *cookie, |
17178
40c4cb095d53
patch 8.1.1588: in :let-heredoc line continuation is recognized
Bram Moolenaar <Bram@vim.org>
parents:
17168
diff
changeset
|
5640 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
|
5641 getline_opt_T options UNUSED) |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5642 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5643 funccall_T *fcp = (funccall_T *)cookie; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5644 ufunc_T *fp = fcp->func; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5645 char_u *retval; |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5646 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
|
5647 |
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5648 // 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
|
5649 if (fcp->dbg_tick != debug_tick) |
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 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
|
5652 SOURCING_LNUM); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5653 fcp->dbg_tick = debug_tick; |
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 #ifdef FEAT_PROFILE |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5656 if (do_profiling == PROF_YES) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5657 func_line_end(cookie); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5658 #endif |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5659 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5660 gap = &fp->uf_lines; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5661 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
|
5662 || fcp->returned) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5663 retval = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5664 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5665 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5666 // Skip NULL lines (continuation lines). |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5667 while (fcp->linenr < gap->ga_len |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5668 && ((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
|
5669 ++fcp->linenr; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5670 if (fcp->linenr >= gap->ga_len) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5671 retval = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5672 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5673 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5674 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
|
5675 SOURCING_LNUM = fcp->linenr; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5676 #ifdef FEAT_PROFILE |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5677 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
|
5678 func_line_start(cookie, SOURCING_LNUM); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5679 #endif |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5680 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5681 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5682 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5683 // 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
|
5684 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
|
5685 { |
18991
847cc7932c42
patch 8.2.0056: execution stack is incomplete and inefficient
Bram Moolenaar <Bram@vim.org>
parents:
18962
diff
changeset
|
5686 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
|
5687 // Find next breakpoint. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5688 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
|
5689 SOURCING_LNUM); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5690 fcp->dbg_tick = debug_tick; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5691 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5692 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5693 return retval; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5694 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5695 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5696 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5697 * 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
|
5698 * 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
|
5699 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5700 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5701 func_has_ended(void *cookie) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5702 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5703 funccall_T *fcp = (funccall_T *)cookie; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5704 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5705 // 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
|
5706 // an error inside a try conditional. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5707 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
|
5708 || fcp->returned); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5709 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5710 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5711 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5712 * 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
|
5713 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5714 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5715 func_has_abort( |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5716 void *cookie) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5717 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5718 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
|
5719 } |
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 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5722 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5723 * 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
|
5724 * 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
|
5725 * explicitly (pt_auto is FALSE). |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5726 * Changes "rettv" in-place. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5727 * Returns the updated "selfdict_in". |
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 dict_T * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5730 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
|
5731 { |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5732 char_u *fname; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5733 char_u *tofree = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5734 ufunc_T *fp; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5735 char_u fname_buf[FLEN_FIXED + 1]; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5736 int error; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5737 dict_T *selfdict = selfdict_in; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5738 |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5739 if (rettv->v_type == VAR_PARTIAL && rettv->vval.v_partial->pt_func != NULL) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5740 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
|
5741 else |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5742 { |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5743 fname = rettv->v_type == VAR_FUNC ? rettv->vval.v_string |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5744 : rettv->vval.v_partial->pt_name; |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5745 // Translate "s:func" to the stored function name. |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5746 fname = fname_trans_sid(fname, 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
|
5747 fp = find_func(fname, FALSE); |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5748 vim_free(tofree); |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5749 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5750 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5751 if (fp != NULL && (fp->uf_flags & FC_DICT)) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5752 { |
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
|
5753 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
|
5754 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5755 if (pt != NULL) |
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 pt->pt_refcount = 1; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5758 pt->pt_dict = selfdict; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5759 pt->pt_auto = TRUE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5760 selfdict = NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5761 if (rettv->v_type == VAR_FUNC) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5762 { |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5763 // 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
|
5764 // selfdict. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5765 pt->pt_name = rettv->vval.v_string; |
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 else |
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 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
|
5770 int i; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5771 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5772 // 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
|
5773 // 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
|
5774 // be referenced elsewhere. |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5775 if (ret_pt->pt_name != NULL) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5776 { |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5777 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
|
5778 func_ref(pt->pt_name); |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5779 } |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5780 else |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5781 { |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5782 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
|
5783 func_ptr_ref(pt->pt_func); |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
5784 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5785 if (ret_pt->pt_argc > 0) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5786 { |
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
|
5787 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
|
5788 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
|
5789 // out of memory: drop the arguments |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5790 pt->pt_argc = 0; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5791 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5792 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5793 pt->pt_argc = ret_pt->pt_argc; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5794 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
|
5795 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
|
5796 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5797 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5798 partial_unref(ret_pt); |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5799 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5800 rettv->v_type = VAR_PARTIAL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5801 rettv->vval.v_partial = pt; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5802 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5803 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5804 return selfdict; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5805 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5806 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5807 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5808 * Return the name of the executed function. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5809 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5810 char_u * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5811 func_name(void *cookie) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5812 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5813 return ((funccall_T *)cookie)->func->uf_name; |
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 |
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 * 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
|
5818 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5819 linenr_T * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5820 func_breakpoint(void *cookie) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5821 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5822 return &((funccall_T *)cookie)->breakpoint; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5823 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5824 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5825 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5826 * 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
|
5827 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5828 int * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5829 func_dbg_tick(void *cookie) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5830 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5831 return &((funccall_T *)cookie)->dbg_tick; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5832 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5833 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5834 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5835 * 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
|
5836 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5837 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5838 func_level(void *cookie) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5839 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5840 return ((funccall_T *)cookie)->level; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5841 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5842 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5843 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5844 * 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
|
5845 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5846 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5847 current_func_returned(void) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5848 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5849 return current_funccal->returned; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5850 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5851 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5852 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5853 free_unref_funccal(int copyID, int testing) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5854 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5855 int did_free = FALSE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5856 int did_free_funccal = FALSE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5857 funccall_T *fc, **pfc; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5858 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5859 for (pfc = &previous_funccal; *pfc != NULL; ) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5860 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5861 if (can_free_funccal(*pfc, copyID)) |
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 fc = *pfc; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5864 *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
|
5865 free_funccal_contents(fc); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5866 did_free = TRUE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5867 did_free_funccal = TRUE; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5868 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5869 else |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5870 pfc = &(*pfc)->caller; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5871 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5872 if (did_free_funccal) |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5873 // 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
|
5874 // collected, so run again. |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5875 (void)garbage_collect(testing); |
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 did_free; |
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 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5880 /* |
9951
d990a4394c9d
commit https://github.com/vim/vim/commit/ba2099034f92a2814494f37bddb0c57d034401b4
Christian Brabandt <cb@256bit.org>
parents:
9844
diff
changeset
|
5881 * 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
|
5882 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5883 static funccall_T * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5884 get_funccal(void) |
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 int i; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5887 funccall_T *funccal; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5888 funccall_T *temp_funccal; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5889 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5890 funccal = current_funccal; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5891 if (debug_backtrace_level > 0) |
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 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
|
5894 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5895 temp_funccal = funccal->caller; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5896 if (temp_funccal) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5897 funccal = temp_funccal; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5898 else |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
5899 // backtrace level overflow. reset to max |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5900 debug_backtrace_level = i; |
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 return funccal; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5904 } |
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 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5907 * 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
|
5908 * 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
|
5909 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5910 hashtab_T * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5911 get_funccal_local_ht() |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5912 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5913 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
|
5914 return NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5915 return &get_funccal()->l_vars.dv_hashtab; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5916 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5917 |
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 * Return the l: scope variable. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5920 * 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
|
5921 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5922 dictitem_T * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5923 get_funccal_local_var() |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5924 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5925 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
|
5926 return NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5927 return &get_funccal()->l_vars_var; |
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 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5930 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5931 * 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
|
5932 * 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
|
5933 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5934 hashtab_T * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5935 get_funccal_args_ht() |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5936 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5937 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
|
5938 return NULL; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5939 return &get_funccal()->l_avars.dv_hashtab; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5940 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5941 |
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 * Return the a: scope variable. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5944 * 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
|
5945 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5946 dictitem_T * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5947 get_funccal_args_var() |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5948 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5949 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
|
5950 return NULL; |
10795
8afee415119d
patch 8.0.0287: debug mode: cannot access function arguments
Christian Brabandt <cb@256bit.org>
parents:
10722
diff
changeset
|
5951 return &get_funccal()->l_avars_var; |
9562
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 |
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 * 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
|
5956 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5957 void |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5958 list_func_vars(int *first) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5959 { |
19181
94eda51ba9ba
patch 8.2.0149: maintaining a Vim9 branch separately is more work
Bram Moolenaar <Bram@vim.org>
parents:
19075
diff
changeset
|
5960 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
|
5961 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
|
5962 "l:", FALSE, first); |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5963 } |
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 * 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
|
5967 * the dict that contains it. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5968 * Otherwise return NULL. |
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 dict_T * |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5971 get_current_funccal_dict(hashtab_T *ht) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5972 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5973 if (current_funccal != NULL |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5974 && ht == ¤t_funccal->l_vars.dv_hashtab) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5975 return ¤t_funccal->l_vars; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
5976 return NULL; |
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 /* |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
5980 * Search hashitem in parent scope. |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
5981 */ |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
5982 hashitem_T * |
9731
f85d94eee05b
commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
5983 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
|
5984 { |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
5985 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
|
5986 hashtab_T *ht; |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
5987 hashitem_T *hi = NULL; |
9731
f85d94eee05b
commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
5988 char_u *varname; |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
5989 |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
5990 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
|
5991 return NULL; |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
5992 |
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
|
5993 // 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
|
5994 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
|
5995 while (current_funccal != NULL) |
9688
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
5996 { |
9731
f85d94eee05b
commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
5997 ht = find_var_ht(name, &varname); |
f85d94eee05b
commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
5998 if (ht != NULL && *varname != NUL) |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
5999 { |
9731
f85d94eee05b
commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
6000 hi = hash_find(ht, varname); |
9721
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
6001 if (!HASHITEM_EMPTY(hi)) |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
6002 { |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
6003 *pht = ht; |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
6004 break; |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
6005 } |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
6006 } |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
6007 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
|
6008 break; |
79862f44c647
commit https://github.com/vim/vim/commit/580164481924ed8611eb79f0247a0eb1ca0b3b9a
Christian Brabandt <cb@256bit.org>
parents:
9717
diff
changeset
|
6009 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
|
6010 } |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6011 current_funccal = old_current_funccal; |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6012 |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6013 return hi; |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6014 } |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6015 |
2ea935bdd1a1
commit https://github.com/vim/vim/commit/10ce39a0d52272a3dfff2feb8c631529f29e6740
Christian Brabandt <cb@256bit.org>
parents:
9686
diff
changeset
|
6016 /* |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6017 * Search variable in parent scope. |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6018 */ |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6019 dictitem_T * |
9731
f85d94eee05b
commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
6020 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
|
6021 { |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6022 dictitem_T *v = NULL; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6023 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
|
6024 hashtab_T *ht; |
9731
f85d94eee05b
commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
6025 char_u *varname; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6026 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6027 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
|
6028 return NULL; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6029 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
6030 // 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
|
6031 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
|
6032 while (current_funccal) |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6033 { |
9731
f85d94eee05b
commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
6034 ht = find_var_ht(name, &varname); |
f85d94eee05b
commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
6035 if (ht != NULL && *varname != NUL) |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6036 { |
9731
f85d94eee05b
commit https://github.com/vim/vim/commit/ba96e9af388804364425185b47eed14988302865
Christian Brabandt <cb@256bit.org>
parents:
9727
diff
changeset
|
6037 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
|
6038 if (v != NULL) |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6039 break; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6040 } |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6041 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
|
6042 break; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6043 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
|
6044 } |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6045 current_funccal = old_current_funccal; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6046 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6047 return v; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6048 } |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6049 |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6050 /* |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6051 * 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
|
6052 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6053 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6054 set_ref_in_previous_funccal(int copyID) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6055 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6056 funccall_T *fc; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6057 |
25104
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6058 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
|
6059 { |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6060 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
|
6061 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
|
6062 || 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
|
6063 || 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
|
6064 return TRUE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6065 } |
25104
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6066 return FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6067 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6068 |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6069 static int |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6070 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
|
6071 { |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6072 if (fc->fc_copyID != copyID) |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6073 { |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6074 fc->fc_copyID = copyID; |
25104
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6075 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
|
6076 || 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
|
6077 || 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
|
6078 || 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
|
6079 return TRUE; |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6080 } |
25104
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6081 return FALSE; |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6082 } |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6083 |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6084 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6085 * 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
|
6086 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6087 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6088 set_ref_in_call_stack(int copyID) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6089 { |
16969
8c794a694d66
patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents:
16872
diff
changeset
|
6090 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
|
6091 funccal_entry_T *entry; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6092 |
25104
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6093 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
|
6094 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
|
6095 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
|
6096 |
8c794a694d66
patch 8.1.1485: double free when garbage_collect() is used in autocommand
Bram Moolenaar <Bram@vim.org>
parents:
16872
diff
changeset
|
6097 // 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
|
6098 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
|
6099 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
|
6100 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
|
6101 return TRUE; |
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6102 return FALSE; |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6103 } |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6104 |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6105 /* |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6106 * 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
|
6107 */ |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6108 int |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6109 set_ref_in_functions(int copyID) |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6110 { |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6111 int todo; |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6112 hashitem_T *hi = NULL; |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6113 ufunc_T *fp; |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6114 |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6115 todo = (int)func_hashtab.ht_used; |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6116 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
|
6117 { |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6118 if (!HASHITEM_EMPTY(hi)) |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6119 { |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6120 --todo; |
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6121 fp = HI2UF(hi); |
25104
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6122 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
|
6123 && 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
|
6124 return TRUE; |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6125 } |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6126 } |
25104
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6127 return FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6128 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6129 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6130 /* |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6131 * Set "copyID" in all function arguments. |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6132 */ |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6133 int |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6134 set_ref_in_func_args(int copyID) |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6135 { |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6136 int i; |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6137 |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6138 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
|
6139 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
|
6140 copyID, NULL, NULL)) |
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6141 return TRUE; |
80cab530472b
patch 8.2.3089: garbage collection has useless code
Bram Moolenaar <Bram@vim.org>
parents:
25064
diff
changeset
|
6142 return FALSE; |
9562
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6143 } |
86af4a48c00a
commit https://github.com/vim/vim/commit/a9b579f3d7463720a316e11e77a7a9fbb9267986
Christian Brabandt <cb@256bit.org>
parents:
diff
changeset
|
6144 |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6145 /* |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6146 * 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
|
6147 * 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
|
6148 */ |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6149 int |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6150 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
|
6151 { |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6152 ufunc_T *fp = fp_in; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6153 funccall_T *fc; |
19013
dd9ab0674eec
patch 8.2.0067: ERROR_UNKNOWN clashes on some systems
Bram Moolenaar <Bram@vim.org>
parents:
18991
diff
changeset
|
6154 int error = FCERR_NONE; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6155 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
|
6156 char_u *tofree = NULL; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6157 char_u *fname; |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6158 int abort = FALSE; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6159 |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6160 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
|
6161 return FALSE; |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6162 |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6163 if (fp_in == NULL) |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6164 { |
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6165 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
|
6166 fp = find_func(fname, FALSE); |
9723
80ac9cf77c9b
commit https://github.com/vim/vim/commit/437bafe4c8a83ed71ee006eda7f54b65a90f0d4c
Christian Brabandt <cb@256bit.org>
parents:
9721
diff
changeset
|
6167 } |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6168 if (fp != NULL) |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6169 { |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6170 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
|
6171 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
|
6172 } |
20255
aac52c32a91f
patch 8.2.0683: Vim9: parsing type does not always work
Bram Moolenaar <Bram@vim.org>
parents:
20244
diff
changeset
|
6173 |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6174 vim_free(tofree); |
9735
8037eb704e93
commit https://github.com/vim/vim/commit/bc7ce675b2d1c9fb58c067eff3edd59abc30aba4
Christian Brabandt <cb@256bit.org>
parents:
9733
diff
changeset
|
6175 return abort; |
9686
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6176 } |
8c2553beff0f
commit https://github.com/vim/vim/commit/1e96d9bf98f9ab84d5af7f98d6a961d91b17364f
Christian Brabandt <cb@256bit.org>
parents:
9655
diff
changeset
|
6177 |
18816
15539899a112
patch 8.1.2396: using old C style comments
Bram Moolenaar <Bram@vim.org>
parents:
18576
diff
changeset
|
6178 #endif // FEAT_EVAL |